From 235c881daa50e9ec5d4f488a7feafbd1247a3168 Mon Sep 17 00:00:00 2001 From: Pavel Paroulek Date: Thu, 29 Aug 2019 19:55:12 +0200 Subject: Changing composition evaluation Changing conditions determining when an association is a composition. Change-Id: I6edf87edff1c98953deb3f594ca43e42741f52e6 Issue-ID: AAI-531 Signed-off-by: Pavel Paroulek --- .../org/onap/aai/graphgraph/ModelExporter.java | 48 ++++++++++++++-------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java index 3716f27..ce7ae39 100644 --- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java +++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java @@ -56,10 +56,11 @@ public class ModelExporter { private static final String VELOCITY_TEMPLATE_FILENAME = "model_export.vm"; private static final boolean OXM_ENABLED = false; private static final String camelCaseRegex = "(?=[A-Z][a-z])"; + private static Map allEntities; private static Multimap getEdgeRules(String schemaVersion) { try { Multimap allRules = App.edgeIngestor.getAllRules(new SchemaVersion(schemaVersion)); - Map allEntities = App.moxyLoaders.get(schemaVersion).getAllObjects(); + allEntities = App.moxyLoaders.get(schemaVersion).getAllObjects(); if (OXM_ENABLED) { addOxmRelationships(allRules, allEntities); } @@ -183,9 +184,9 @@ public class ModelExporter { Multimap edgeRules) { return edgeRules.values().stream().flatMap(er -> { VelocityAssociation out = createVelocityAssociation(entities, er.getFrom(), er.getTo(), - er.getLabel(), er.getMultiplicityRule().name()); + er.getLabel(), er.getMultiplicityRule().name(), er.getContains()); VelocityAssociation in = createVelocityAssociation(entities, er.getTo(), er.getFrom(), - er.getLabel(), er.getMultiplicityRule().name()); + er.getLabel(), er.getMultiplicityRule().name(), er.getContains()); switch (er.getDirection()) { case OUT: return Stream.of(out); @@ -200,15 +201,34 @@ public class ModelExporter { } private static VelocityAssociation createVelocityAssociation(Set entities, - String from, String to, String label, String multiplicity) { - boolean composition = isComposition(label); - return new VelocityAssociation( - entities.stream().filter( ent -> ent.getName().equals(from)).findFirst().get(), - entities.stream().filter( ent -> ent.getName().equals(to)).findFirst().get(), - String.format("%s - %s (label: %s)", from, to, shortenLabel(label)), - multiplicity, - composition - ); + String from, String to, String label, String multiplicity, String contains) { + VelocityEntity fromEntity = entities.stream().filter(ent -> ent.getName().equals(from)) + .findFirst().get(); + VelocityEntity toEntity = entities.stream().filter(ent -> ent.getName().equals(to)).findFirst() + .get(); + switch (contains) { + case "IN": + return new VelocityAssociation( + fromEntity, + toEntity, + String.format("%s - %s (%s)", from, to, shortenLabel(label)), + multiplicity, + true); + case "OUT": + return new VelocityAssociation( + toEntity, + fromEntity, + String.format("%s - %s (%s)", to, from, shortenLabel(label)), + multiplicity, + true); + default: + return new VelocityAssociation( + fromEntity, + toEntity, + String.format("%s - %s (%s)", from, to, shortenLabel(label)), + multiplicity, + false); + } } private static String shortenLabel(String label) { @@ -220,10 +240,6 @@ public class ModelExporter { return label; } - private static boolean isComposition(String label) { - return label.equals("org.onap.relationships.inventory.BelongsTo"); - } - private static VelocityEntity findVelocityEntity(String entityName, Set entities) { if (entityName.startsWith("java.lang")){ return null; -- cgit 1.2.3-korg