+ private static void makeEdgeLabels(JanusGraphManagement graphMgmt) {
+ try {
+ EdgeIngestor edgeIngestor = SpringContextAware.getBean(EdgeIngestor.class);
+
+ Set<String> labels = Optional.ofNullable(edgeIngestor.getAllCurrentRules())
+ .map(collectValues(EdgeRule::getLabel))
+ .orElseGet(HashSet::new);
+
+ labels.forEach(label -> {
+ if (graphMgmt.containsRelationType(label)) {
+ LOGGER.debug(" EdgeLabel [{}] already existed. ", label);
+ } else {
+ LOGGER.debug("Making EdgeLabel: [{}]", label);
+ graphMgmt.makeEdgeLabel(label).multiplicity(Multiplicity.valueOf("MULTI")).make();
+ }
+ });
+ } catch (EdgeRuleNotFoundException e) {
+ LOGGER.error("Unable to find all rules {}", LogFormatTools.getStackTop(e));
+ }
+ }
+
+ /**
+ * Returns a function collecting all the values in a {@link com.google.common.collect.Multimap}
+ * given a mapping function
+ *
+ * @param f The mapper function
+ * @param <K> The type of key used by the provided {@link com.google.common.collect.Multimap}
+ * @param <V> The type of value used by the provided {@link com.google.common.collect.Multimap}
+ * @param <V0> The type which <V> is mapped to
+ */
+ private static <K, V, V0> Function<Multimap<K, V>, Set<V0>> collectValues(Function<V, V0> f) {
+ return as -> as.values().stream().map(f).collect(Collectors.toSet());
+ }
+