aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/aai/graphgraph/ModelExporter.java102
-rw-r--r--src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java11
-rw-r--r--src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java21
-rw-r--r--src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java33
-rw-r--r--src/main/resources/model_export.vm132
5 files changed, 238 insertions, 61 deletions
diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java
index 3180c4c..3716f27 100644
--- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java
+++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java
@@ -29,6 +29,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.tinkerpop.gremlin.structure.Direction;
@@ -44,28 +46,22 @@ import org.onap.aai.edges.enums.MultiplicityRule;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
import org.onap.aai.graphgraph.velocity.VelocityAssociation;
import org.onap.aai.graphgraph.velocity.VelocityEntity;
+import org.onap.aai.graphgraph.velocity.VelocityEntityProperty;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.setup.SchemaVersion;
public class ModelExporter {
private static final String AAIMODEL_UML_FILENAME = "aaimodel.uml";
- public static final String VELOCITY_TEMPLATE_FILENAME = "model_export.vm";
-
+ 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 Multimap<String, EdgeRule> getEdgeRules(String schemaVersion) {
try {
Multimap<String, EdgeRule> allRules = App.edgeIngestor.getAllRules(new SchemaVersion(schemaVersion));
- Map<String, Introspector> allEntities = App.moxyLoaders.get("v16").getAllObjects();
- for (Entry<String, Introspector> currentParent : allEntities.entrySet()) {
- currentParent.getValue().getProperties().stream()
- .filter(v -> allEntities.containsKey(v))
- .filter(v -> !currentParent.getKey().equals(v))
- .forEach(v -> {
- String key = currentParent.getKey() + "|" + v;
- if (!allRules.containsKey(key)) {
- allRules.put(key, createEdgeRule(currentParent.getKey(), v));
- }
- });
+ Map<String, Introspector> allEntities = App.moxyLoaders.get(schemaVersion).getAllObjects();
+ if (OXM_ENABLED) {
+ addOxmRelationships(allRules, allEntities);
}
return allRules;
} catch (EdgeRuleNotFoundException e) {
@@ -75,6 +71,21 @@ public class ModelExporter {
return null;
}
+ private static void addOxmRelationships(Multimap<String, EdgeRule> allRules,
+ Map<String, Introspector> allEntities) {
+ for (Entry<String, Introspector> currentParent : allEntities.entrySet()) {
+ currentParent.getValue().getProperties().stream()
+ .filter(v -> allEntities.containsKey(v))
+ .filter(v -> !currentParent.getKey().equals(v))
+ .forEach(v -> {
+ String key = currentParent.getKey() + "|" + v;
+ if (!allRules.containsKey(key)) {
+ allRules.put(key, createEdgeRule(currentParent.getKey(), v));
+ }
+ });
+ }
+ }
+
private static EdgeRule createEdgeRule(String parent, String child) {
Map<String, String> edgeRuleProps = new HashMap<>();
edgeRuleProps.put(EdgeField.FROM.toString(), child);
@@ -133,13 +144,33 @@ public class ModelExporter {
List<VelocityAssociation> associations = associationsList.stream()
.filter(a -> a.getFromEntityId().equals(e.getId())).collect(
Collectors.toList());
+ updateNeighbour(entityList, associations);
+ });
- entityList.forEach(entity -> entity.setProperties(allObjects.get(entity.getName()).getProperties()));
+ entityList.forEach(entity -> entity.setProperties(getPropertiesForEntity(allObjects.get(entity.getName()), entityList)));
- e.setNeighbours(associations);
+ }
+
+ private static void updateNeighbour(
+ Set<VelocityEntity> entityList, List<VelocityAssociation> associations) {
+ associations.forEach(ass -> {
+ VelocityEntity velocityEntity = entityList.stream()
+ .filter(e -> e.getId().equals(ass.getToEntityId())).findFirst().get();
+ velocityEntity.addNeighbours(ass);
});
}
+ private static Set<VelocityEntityProperty> getPropertiesForEntity(Introspector introspector,
+ Set<VelocityEntity> entityList) {
+ return introspector.getProperties().stream()
+ .map(p -> new VelocityEntityProperty(
+ p,
+ introspector.getType(p),
+ findVelocityEntity(introspector.getType(p), entityList)))
+ .collect(
+ Collectors.toSet());
+ }
+
private static Set<VelocityEntity> createEntityList(
Multimap<String, EdgeRule> edgeRules) {
return Objects.requireNonNull(edgeRules).values().stream()
@@ -170,16 +201,43 @@ public class ModelExporter {
private static VelocityAssociation createVelocityAssociation(Set<VelocityEntity> entities,
String from, String to, String label, String multiplicity) {
+ boolean composition = isComposition(label);
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")
+ 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
);
}
- private static VelocityEntity findVelocityEntity(String from, Set<VelocityEntity> entities) {
- return entities.stream().filter(e -> e.getName().equals(from)).findFirst().get();
+ private static String shortenLabel(String label) {
+ if (label.contains(".")) {
+ String[] split = label.split("\\.");
+ return split[split.length - 1];
+ }
+
+ return label;
+ }
+
+ private static boolean isComposition(String label) {
+ return label.equals("org.onap.relationships.inventory.BelongsTo");
+ }
+
+ private static VelocityEntity findVelocityEntity(String entityName, Set<VelocityEntity> entities) {
+ if (entityName.startsWith("java.lang")){
+ return null;
+ }
+
+ if ( ! entityName.startsWith("inventory.aai.onap.org")){
+ return null;
+ }
+
+ String[] split = entityName.split("\\.");
+ String entityNameRoot = split[split.length - 1];
+ final Pattern pattern = Pattern.compile(camelCaseRegex);
+ final Matcher matcher = pattern.matcher(entityNameRoot.substring(1, entityNameRoot.length()));
+ String finalEntityNameRoot = (entityNameRoot.charAt(0) + matcher.replaceAll("-")).toLowerCase();
+ return entities.stream().filter(e -> e.getName().equals(finalEntityNameRoot)).findFirst().orElse(null);
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java
index bcc314e..697fad1 100644
--- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java
+++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java
@@ -95,10 +95,21 @@ public class VelocityAssociation extends VelocityId {
}
@Override
+ public String toString() {
+ return "VelocityAssociation{" +
+ "name='" + name + '\'' +
+ ", fromEntity=" + fromEntity +
+ ", toEntity=" + toEntity +
+ '}';
+ }
+
+ @Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + fromEntity.hashCode();
result = 31 * result + toEntity.hashCode();
return result;
+
+
}
}
diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java
index 111f67c..39b92d4 100644
--- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java
+++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java
@@ -19,19 +19,20 @@
*/
package org.onap.aai.graphgraph.velocity;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class VelocityEntity extends VelocityId {
private String name;
- private List<VelocityAssociation> neighbours;
- private Set<String> properties;
+ private List<VelocityAssociation> neighbours = new LinkedList<>();
+ private Set<VelocityEntityProperty> properties;
- public Set<String> getProperties() {
+ public Set<VelocityEntityProperty> getProperties() {
return properties;
}
- public void setProperties(Set<String> properties) {
+ public void setProperties(Set<VelocityEntityProperty> properties) {
this.properties = properties;
}
@@ -55,6 +56,11 @@ public class VelocityEntity extends VelocityId {
this.neighbours = neighbours;
}
+ public void addNeighbours(VelocityAssociation neighbour) {
+ neighbours.add(neighbour);
+ }
+
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -73,4 +79,11 @@ public class VelocityEntity extends VelocityId {
public int hashCode() {
return name.hashCode();
}
+
+ @Override
+ public String toString() {
+ return "VelocityEntity{" +
+ "name='" + name + '\'' +
+ '}';
+ }
}
diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java
new file mode 100644
index 0000000..9ee2fbb
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java
@@ -0,0 +1,33 @@
+package org.onap.aai.graphgraph.velocity;
+
+import org.onap.aai.graphgraph.dto.Property;
+
+public class VelocityEntityProperty extends Property {
+
+ private final VelocityEntity entity;
+
+ public VelocityEntityProperty(String propertyName, String propertyValue, VelocityEntity entity) {
+ super(propertyName, propertyValue);
+ this.entity = entity;
+ }
+
+ public String getEntityId() {
+ return entity.getId();
+ }
+
+ public String getEntityName() {
+ return entity.getName();
+ }
+
+ public boolean hasEntity(){
+ return entity != null;
+ }
+
+ @Override
+ public String toString() {
+ return "VelocityEntityProperty{" +
+ " name=" + getPropertyName() +
+ " type=" + getPropertyValue() +
+ '}';
+ }
+}
diff --git a/src/main/resources/model_export.vm b/src/main/resources/model_export.vm
index c15805c..184d21a 100644
--- a/src/main/resources/model_export.vm
+++ b/src/main/resources/model_export.vm
@@ -1,44 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
-<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Z9InoLIpEemXwfLFUQ7Icw" name="AAIModel">
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Z9InoLIpEemXwfLFUQ7Icw"
+ name="AAIModel">
<packageImport xmi:type="uml:PackageImport" xmi:id="_aFqRgLIpEemXwfLFUQ7Icw">
- <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
+ <importedPackage xmi:type="uml:Model"
+ href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Package" xmi:id="_dl4P8LIpEemXwfLFUQ7Icw" name="Associations">
- #foreach($association in $associationList)
- <packagedElement xmi:type="uml:Association" xmi:id="$association.id" name="$association.name" memberEnd="$association.fromId $association.toId">
- <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="$association.randomId" source="org.eclipse.papyrus">
- <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="$association.randomId" key="nature" value="UML_Nature"/>
- </eAnnotations>
- <ownedEnd xmi:type="uml:Property" xmi:id="$association.toId" name="$association.fromEntityName" type="$association.fromEntityId" association="$association.id">
- #if($association.multiplicity == "MANY2ONE" || $association.multiplicity == "MANY2MANY")
- <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"/>
- <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="$association.randomId" value="*"/>
- #else
- <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId" value="1"/>
- <upperValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId" value="1"/>
- #end
- </ownedEnd>
- </packagedElement>
- #end
+ #foreach($association in $associationList)
+ <packagedElement xmi:type="uml:Association" xmi:id="$association.id"
+ name="$association.name" memberEnd="$association.fromId $association.toId">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="$association.randomId"
+ source="org.eclipse.papyrus">
+ <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="$association.randomId"
+ key="nature" value="UML_Nature"/>
+ </eAnnotations>
+ <ownedEnd xmi:type="uml:Property" xmi:id="$association.fromId"
+ name="$association.toEntityName" type="$association.toEntityId"
+ association="$association.id">
+ #if($association.multiplicity == "ONE2MANY" || $association.multiplicity ==
+ "MANY2MANY")
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="$association.randomId"
+ value="*"/>
+ #else
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId" value="1"/>
+ <upperValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId" value="1"/>
+ #end
+ </ownedEnd>
+ #if( ! $association.isComposition)
+ <ownedEnd xmi:type="uml:Property" xmi:id="$association.toId"
+ name="$association.fromEntityName" type="$association.fromEntityId"
+ association="$association.id">
+ #if($association.multiplicity == "MANY2ONE" || $association.multiplicity ==
+ "MANY2MANY")
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural"
+ xmi:id="$association.randomId" value="*"/>
+ #else
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"
+ value="1"/>
+ <upperValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"
+ value="1"/>
+ #end
+ </ownedEnd>
+ #end
+ </packagedElement>
+ #end
</packagedElement>
<packagedElement xmi:type="uml:Package" xmi:id="_rBN-QLIqEemXwfLFUQ7Icw" name="ObjectClasses">
- #foreach($entity in $entityList)
- <packagedElement xmi:type="uml:Class" xmi:id="$entity.id" name="$entity.name">
- #foreach($association in $entity.neighbours)
- <ownedAttribute xmi:type="uml:Property" xmi:id="$association.fromId" name="$association.toEntityName" type="$association.toEntityId" #if( $association.isComposition) aggregation="composite" #end association="$association.id">
- #if($association.multiplicity == "ONE2MANY" || $association.multiplicity == "MANY2MANY")
- <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"/>
- <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="$association.randomId" value="*"/>
- #else
- <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId" value="1"/>
- <upperValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId" value="1"/>
- #end
- </ownedAttribute>
- #end
- #foreach($prop in $entity.properties)
- <ownedAttribute xmi:type="uml:Property" xmi:id="$entity.randomId" name="$prop"/>
+ #foreach($entity in $entityList)
+ <packagedElement xmi:type="uml:Class" xmi:id="$entity.id" name="$entity.name">
+ #foreach($association in $entity.neighbours)
+ #if( $association.isComposition)
+ <ownedAttribute xmi:type="uml:Property" xmi:id="$association.toId"
+ name="$association.fromEntityName"
+ type="$association.fromEntityId" aggregation="composite"
+ association="$association.id">
+ #if($association.multiplicity == "MANY2ONE" || $association.multiplicity ==
+ "MANY2MANY")
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural"
+ xmi:id="$association.randomId" value="*"/>
+ #else
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"
+ value="1"/>
+ <upperValue xmi:type="uml:LiteralInteger" xmi:id="$association.randomId"
+ value="1"/>
+ #end
+ </ownedAttribute>
+ #end
+ #end
+ #foreach($prop in $entity.properties)
+ #if($prop.propertyValue.contains("java.lang"))
+ <ownedAttribute xmi:type="uml:Property" xmi:id="$entity.randomId"
+ name="$prop.propertyName">
+ #if($prop.propertyValue == "java.lang.String")
+ <type xmi:type="uml:PrimitiveType"
+ href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
+ #end#
+ #if($prop.propertyValue == "java.lang.Long")
+ <type xmi:type="uml:PrimitiveType"
+ href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
+ #end
+ #if($prop.propertyValue == "java.lang.Boolean")
+ <type xmi:type="uml:PrimitiveType"
+ href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Boolean"/>
+ #end
+ #if($prop.propertyValue == "java.lang.Integer")
+ <type xmi:type="uml:PrimitiveType"
+ href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
+ #end
+ </ownedAttribute>
+ #elseif(! $prop.hasEntity)
+ #* <ownedAttribute xmi:type="uml:Property" xmi:id="$entity.randomId" name="$prop.propertyName"/>*#
+ #else
+ <ownedAttribute xmi:type="uml:Property" xmi:id="$entity.randomId"
+ name="$prop.getEntityName()" type="$prop.getEntityId()"/>
+ #end
+ #end
+ </packagedElement>
#end
- </packagedElement>
- #end
</packagedElement>
</uml:Model> \ No newline at end of file