summaryrefslogtreecommitdiffstats
path: root/aai-core
diff options
context:
space:
mode:
authorHarish Venkata Kajur <vk250x@att.com>2018-12-28 17:25:05 -0500
committerHarish Venkata Kajur <vk250x@att.com>2018-12-28 17:30:03 -0500
commit69c5de8f6d5f4f05e152094bc1e40c03922dcd72 (patch)
treeb71cc7efe674b24b393ec4a79b2400483d9f5042 /aai-core
parente42c7cf9d25b5a5ec3e3bf2cbb5e04441ec45359 (diff)
Update DBSerializer for relationships retrieving
Enhance the code for how the db serializer works when it comes to dealing with the relationships For a particular vertex, when retrieving its relationship vertexes it doesn't need to get all the properties of the relationship vertex as it only cares about the aai-uri and named properties so only partially retrieving those props that is needed for relationships Issue-ID: AAI-1987 Change-Id: I1440c561d187ff180a599a3f52ac5c8715d5c8e3 Signed-off-by: Harish Venkata Kajur <vk250x@att.com>
Diffstat (limited to 'aai-core')
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java52
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java18
2 files changed, 38 insertions, 32 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
index 9d107b1f..95582b98 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
@@ -928,16 +928,7 @@ public class DBSerializer {
* @throws SecurityException the security exception
*/
private void copySimpleProperty(String property, Introspector obj, Vertex v) {
-
- final Map<PropertyMetadata, String> metadata = obj.getPropertyMetadata(property);
- String dbPropertyName = property;
-
- if (metadata.containsKey(PropertyMetadata.DB_ALIAS)) {
- dbPropertyName = metadata.get(PropertyMetadata.DB_ALIAS);
- }
-
-
- final Object temp = v.<Object>property(dbPropertyName).orElse(null);
+ final Object temp = getProperty(obj, property, v);
if (temp != null) {
obj.setValue(property, temp);
}
@@ -1181,10 +1172,9 @@ public class DBSerializer {
VertexProperty cousinVertexNodeType = cousin.property(AAIProperties.NODE_TYPE);
if(cousinVertexNodeType.isPresent()){
- if(namedPropNodes.contains(cousinVertexNodeType.value().toString())){
- Introspector cousinObj = loader.introspectorFromName(cousinVertexNodeType.value().toString());
- this.simpleDbToObject(cousinObj, cousin);
- this.addRelatedToProperty(result, cousinObj);
+ String cousinType = cousinVertexNodeType.value().toString();
+ if(namedPropNodes.contains(cousinType)){
+ this.addRelatedToProperty(result, cousin, cousinType);
}
}
@@ -1244,37 +1234,43 @@ public class DBSerializer {
return UriBuilder.fromPath(uri).build();
}
- /**
- * Adds the r
- *
- * @param relationship the relationship
- * @param child the throws IllegalArgumentException, AAIUnknownObjectException child
- * @throws AAIUnknownObjectException
- * @throws IllegalArgumentException elated to property.
- */
- public void addRelatedToProperty(Introspector relationship, Introspector child) throws AAIUnknownObjectException {
- String nameProps = child.getMetadata(ObjectMetadata.NAME_PROPS);
+ public void addRelatedToProperty(Introspector relationship, Vertex cousinVertex, String cousinType) throws AAIUnknownObjectException {
+ Introspector obj = loader.introspectorFromName(cousinType);
+ String nameProps = obj.getMetadata(ObjectMetadata.NAME_PROPS);
List<Introspector> relatedToProperties = new ArrayList<>();
if (nameProps != null) {
String[] props = nameProps.split(",");
for (String prop : props) {
+ final Object temp = getProperty(obj, prop, cousinVertex);
Introspector relatedTo = relationship.newIntrospectorInstanceOfNestedProperty("related-to-property");
- relatedTo.setValue("property-key", child.getDbName() + "." + prop);
- relatedTo.setValue("property-value", child.getValue(prop));
+ relatedTo.setValue("property-key", cousinType + "." + prop);
+ relatedTo.setValue("property-value", temp);
relatedToProperties.add(relatedTo);
}
}
if (!relatedToProperties.isEmpty()) {
List relatedToList = (List) relationship.getValue("related-to-property");
- for (Introspector obj : relatedToProperties) {
- relatedToList.add(obj.getUnderlyingObject());
+ for (Introspector introspector : relatedToProperties) {
+ relatedToList.add(introspector.getUnderlyingObject());
}
}
}
+ private Object getProperty(Introspector obj, String prop, Vertex vertex){
+
+ final Map<PropertyMetadata, String> metadata = obj.getPropertyMetadata(prop);
+ String dbPropertyName = prop;
+
+ if (metadata.containsKey(PropertyMetadata.DB_ALIAS)) {
+ dbPropertyName = metadata.get(PropertyMetadata.DB_ALIAS);
+ }
+
+ return vertex.<Object>property(dbPropertyName).orElse(null);
+ }
+
/**
* Creates the edge.
*
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
index 5041c7d1..42775cbf 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
@@ -47,6 +47,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -714,18 +715,27 @@ public class DbSerializerTest extends AAISetup {
@Test
public void addRelatedToPropertyTest() throws AAIException {
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf",
+ "vnf-id","myname",
+ "vnf-name","myname",
+ "aai-uri", "/network/generic-vnfs/generic-vnf/myname"
+ );
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
Introspector gv = loader.introspectorFromName("generic-vnf");
gv.setValue("vnf-name", "myname");
+
Introspector rel = loader.introspectorFromName("relationship");
DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine,
ModelType.MOXY, "AAI-TEST");
- dbser.addRelatedToProperty(rel, gv);
+ dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
- assertTrue(relToProps.size() == 1);
+ assertThat(relToProps.size(), is(1));
Introspector relToProp = relToProps.get(0);
- assertTrue("generic-vnf.vnf-name".equals(relToProp.getValue("property-key")));
- assertTrue("myname".equals(relToProp.getValue("property-value")));
+ assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
+ assertThat(relToProp.getValue("property-value"), is("myname"));
}
@Test