diff options
Diffstat (limited to 'src/main/java/org/onap/aai/graphgraph/ModelExporter.java')
-rw-r--r-- | src/main/java/org/onap/aai/graphgraph/ModelExporter.java | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java index 0410250..3180c4c 100644 --- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java +++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java @@ -24,7 +24,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -151,17 +150,33 @@ public class ModelExporter { private static Set<VelocityAssociation> createVelocityAssociations(Set<VelocityEntity> entities, Multimap<String, EdgeRule> edgeRules) { - Set<VelocityAssociation> result = new HashSet<>(); - result.addAll(edgeRules.values().stream().map(er -> - new VelocityAssociation( - findVelocityEntity(er.getFrom(), entities), - findVelocityEntity(er.getTo(), entities), - String.format("%s - %s (label: %s)", er.getFrom(), er.getTo(), er.getLabel()), - er.getMultiplicityRule().name(), - er.getLabel().equals("org.onap.relationships.inventory.BelongsTo") - )).collect(Collectors.toSet())); - - return result; + return edgeRules.values().stream().flatMap(er -> { + VelocityAssociation out = createVelocityAssociation(entities, er.getFrom(), er.getTo(), + er.getLabel(), er.getMultiplicityRule().name()); + VelocityAssociation in = createVelocityAssociation(entities, er.getTo(), er.getFrom(), + er.getLabel(), er.getMultiplicityRule().name()); + switch (er.getDirection()) { + case OUT: + return Stream.of(out); + case IN: + return Stream.of(in); + case BOTH: + return Stream.of(out, in); + default: + return null; + } + }).collect(Collectors.toSet()); + } + + private static VelocityAssociation createVelocityAssociation(Set<VelocityEntity> entities, + String from, String to, String label, String multiplicity) { + return new VelocityAssociation( + findVelocityEntity(from, entities), + findVelocityEntity(to, entities), + String.format("%s - %s (label: %s)", from, to, label), + multiplicity, + label.equals("org.onap.relationships.inventory.BelongsTo") + ); } private static VelocityEntity findVelocityEntity(String from, Set<VelocityEntity> entities) { |