Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / serialization / db / DBSerializer.java
index 7cd0e78..dc47833 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.serialization.db;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import com.google.common.base.CaseFormat;
-import org.apache.commons.lang.StringUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ws.rs.core.UriBuilder;
+
+import org.apache.commons.lang3.StringUtils;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -45,9 +72,19 @@ import org.onap.aai.edges.enums.EdgeType;
 import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
 import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.IntrospectorFactory;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.introspection.PropertyPredicates;
 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
-import org.onap.aai.introspection.sideeffect.*;
+import org.onap.aai.introspection.sideeffect.DataCopy;
+import org.onap.aai.introspection.sideeffect.DataLinkReader;
+import org.onap.aai.introspection.sideeffect.DataLinkWriter;
+import org.onap.aai.introspection.sideeffect.OwnerCheck;
+import org.onap.aai.introspection.sideeffect.PrivateEdge;
+import org.onap.aai.introspection.sideeffect.SideEffectRunner;
 import org.onap.aai.logging.ErrorLogHelper;
 import org.onap.aai.logging.LogFormatTools;
 import org.onap.aai.logging.StopWatch;
@@ -67,24 +104,16 @@ import org.onap.aai.setup.SchemaVersion;
 import org.onap.aai.setup.SchemaVersions;
 import org.onap.aai.util.AAIConfig;
 import org.onap.aai.util.AAIConstants;
-import org.onap.aai.util.delta.*;
+import org.onap.aai.util.delta.DeltaAction;
+import org.onap.aai.util.delta.ObjectDelta;
+import org.onap.aai.util.delta.PropertyDelta;
+import org.onap.aai.util.delta.PropertyDeltaFactory;
+import org.onap.aai.util.delta.RelationshipDelta;
 import org.onap.aai.workarounds.NamingExceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
 
-import javax.ws.rs.core.UriBuilder;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 public class DBSerializer {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(DBSerializer.class);
@@ -96,6 +125,7 @@ public class DBSerializer {
 
     private final TransactionalGraphEngine engine;
     private final String sourceOfTruth;
+    private final Set<String> groups;
     private final ModelType introspectionType;
     private final SchemaVersion version;
     private final Loader latestLoader;
@@ -111,9 +141,11 @@ public class DBSerializer {
     private Map<String, ObjectDelta> objectDeltas = new LinkedHashMap<>();
     private Map<Vertex, Boolean> updatedVertexes = new LinkedHashMap<>();
     private Set<Vertex> edgeVertexes = new LinkedHashSet<>();
-    private Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> impliedDeleteUriObjectPair = new LinkedHashMap<>();
+    private Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> impliedDeleteUriObjectPair =
+            new LinkedHashMap<>();
     private int notificationDepth;
     private boolean isDeltaEventsEnabled;
+    private boolean isMultiTenancyEnabled;
 
     /**
      * Instantiates a new DB serializer.
@@ -128,11 +160,33 @@ public class DBSerializer {
             String sourceOfTruth) throws AAIException {
         this.engine = engine;
         this.sourceOfTruth = sourceOfTruth;
+        this.groups = Collections.EMPTY_SET;
+        this.introspectionType = introspectionType;
+        this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
+        SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
+        this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType,
+                latestVersion);
+        this.version = version;
+        this.loader =
+                SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+        this.namedPropNodes = this.latestLoader.getNamedPropNodes();
+        this.baseURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
+        this.currentTimeMillis = System.currentTimeMillis();
+        // If creating the DBSerializer the old way then set the notification depth to maximum
+        this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
+        initBeans();
+    }
+
+    public DBSerializer(SchemaVersion version, TransactionalGraphEngine engine, ModelType introspectionType,
+            String sourceOfTruth, Set<String> groups) throws AAIException {
+        this.engine = engine;
+        this.sourceOfTruth = sourceOfTruth;
+        this.groups = groups;
         this.introspectionType = introspectionType;
         this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
         SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
-        this.latestLoader =
-                SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, latestVersion);
+        this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType,
+                latestVersion);
         this.version = version;
         this.loader =
                 SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
@@ -144,21 +198,19 @@ public class DBSerializer {
         initBeans();
     }
 
-    public DBSerializer(SchemaVersion version,
-                        TransactionalGraphEngine engine,
-                        ModelType introspectionType,
-                        String sourceOfTruth,
-                        int notificationDepth) throws AAIException {
+    public DBSerializer(SchemaVersion version, TransactionalGraphEngine engine, ModelType introspectionType,
+            String sourceOfTruth, int notificationDepth) throws AAIException {
         this.engine = engine;
         this.sourceOfTruth = sourceOfTruth;
+        this.groups = Collections.EMPTY_SET;
         this.introspectionType = introspectionType;
         this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
         SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
-        this.latestLoader =
-            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, latestVersion);
+        this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType,
+                latestVersion);
         this.version = version;
         this.loader =
-            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+                SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
         this.namedPropNodes = this.latestLoader.getNamedPropNodes();
         this.baseURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
         this.currentTimeMillis = System.currentTimeMillis();
@@ -166,22 +218,59 @@ public class DBSerializer {
         initBeans();
     }
 
-    public DBSerializer(SchemaVersion version,
-                        TransactionalGraphEngine engine,
-                        ModelType introspectionType,
-                        String sourceOfTruth,
-                        int notificationDepth,
-                        String serverBase) throws AAIException {
+    public DBSerializer(SchemaVersion version, TransactionalGraphEngine engine, ModelType introspectionType,
+            String sourceOfTruth, Set<String> groups, int notificationDepth) throws AAIException {
         this.engine = engine;
         this.sourceOfTruth = sourceOfTruth;
+        this.groups = groups;
         this.introspectionType = introspectionType;
         this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
         SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
-        this.latestLoader =
-            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, latestVersion);
+        this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType,
+                latestVersion);
         this.version = version;
         this.loader =
-            SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+                SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+        this.namedPropNodes = this.latestLoader.getNamedPropNodes();
+        this.baseURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
+        this.currentTimeMillis = System.currentTimeMillis();
+        this.notificationDepth = notificationDepth;
+        initBeans();
+    }
+
+    public DBSerializer(SchemaVersion version, TransactionalGraphEngine engine, ModelType introspectionType,
+            String sourceOfTruth, int notificationDepth, String serverBase) throws AAIException {
+        this.engine = engine;
+        this.sourceOfTruth = sourceOfTruth;
+        this.groups = Collections.EMPTY_SET;
+        this.introspectionType = introspectionType;
+        this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
+        SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
+        this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType,
+                latestVersion);
+        this.version = version;
+        this.loader =
+                SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
+        this.namedPropNodes = this.latestLoader.getNamedPropNodes();
+        this.baseURL = serverBase;
+        this.currentTimeMillis = System.currentTimeMillis();
+        this.notificationDepth = notificationDepth;
+        initBeans();
+    }
+
+    public DBSerializer(SchemaVersion version, TransactionalGraphEngine engine, ModelType introspectionType,
+            String sourceOfTruth, Set<String> groups, int notificationDepth, String serverBase) throws AAIException {
+        this.engine = engine;
+        this.sourceOfTruth = sourceOfTruth;
+        this.groups = groups;
+        this.introspectionType = introspectionType;
+        this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
+        SchemaVersion latestVersion = schemaVersions.getDefaultVersion();
+        this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType,
+                latestVersion);
+        this.version = version;
+        this.loader =
+                SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, version);
         this.namedPropNodes = this.latestLoader.getNamedPropNodes();
         this.baseURL = serverBase;
         this.currentTimeMillis = System.currentTimeMillis();
@@ -196,7 +285,10 @@ public class DBSerializer {
         setEdgeIngestor(ei);
         EdgeSerializer es = ctx.getBean(EdgeSerializer.class);
         setEdgeSerializer(es);
-        isDeltaEventsEnabled = Boolean.parseBoolean(SpringContextAware.getApplicationContext().getEnvironment().getProperty("delta.events.enabled", FALSE));
+        isDeltaEventsEnabled = Boolean.parseBoolean(
+                SpringContextAware.getApplicationContext().getEnvironment().getProperty("delta.events.enabled", FALSE));
+        isMultiTenancyEnabled = Boolean.parseBoolean(SpringContextAware.getApplicationContext().getEnvironment()
+                .getProperty("multi.tenancy.enabled", FALSE));
     }
 
     public void setEdgeSerializer(EdgeSerializer edgeSer) {
@@ -219,13 +311,18 @@ public class DBSerializer {
         return updatedVertexes;
     }
 
-    public Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> getImpliedDeleteUriObjectPair(){
+    public Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> getImpliedDeleteUriObjectPair() {
         return impliedDeleteUriObjectPair;
     }
 
+    public Set<String> getGroups() {
+        return this.groups;
+    }
+
     /**
      * Touch standard vertex properties.
-     *  @param v the v
+     * 
+     * @param v the v
      * @param isNewVertex the is new vertex
      */
     public void touchStandardVertexProperties(Vertex v, boolean isNewVertex) {
@@ -239,7 +336,7 @@ public class DBSerializer {
             v.property(AAIProperties.LAST_MOD_TS, currentTimeMillis);
             v.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, this.sourceOfTruth);
         } else {
-            if(isDeltaEventsEnabled) {
+            if (isDeltaEventsEnabled) {
                 standardVertexPropsDeltas(v, timeNowInSec);
             }
             v.property(AAIProperties.RESOURCE_VERSION, timeNowInSec);
@@ -256,47 +353,54 @@ public class DBSerializer {
             getObjectDeltas().get(uri).setAction(objDeltaAction);
         }
 
-        addPropDelta(uri, AAIProperties.AAI_UUID, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.AAI_UUID).value()), objDeltaAction);
-        addPropDelta(uri, AAIProperties.NODE_TYPE, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.NODE_TYPE).value()), objDeltaAction);
-        addPropDelta(uri, AAIProperties.SOURCE_OF_TRUTH, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.SOURCE_OF_TRUTH).value()), objDeltaAction);
-        addPropDelta(uri, AAIProperties.CREATED_TS, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.CREATED_TS).value()), objDeltaAction);
+        addPropDelta(uri, AAIProperties.AAI_UUID,
+                PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.AAI_UUID).value()),
+                objDeltaAction);
+        addPropDelta(uri, AAIProperties.NODE_TYPE,
+                PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.NODE_TYPE).value()),
+                objDeltaAction);
+        addPropDelta(uri, AAIProperties.SOURCE_OF_TRUTH,
+                PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.SOURCE_OF_TRUTH).value()),
+                objDeltaAction);
+        addPropDelta(uri, AAIProperties.CREATED_TS,
+                PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.CREATED_TS).value()),
+                objDeltaAction);
 
         if (objDeltaAction.equals(DeltaAction.UPDATE)) {
+            addPropDelta(uri, AAIProperties.RESOURCE_VERSION, PropertyDeltaFactory.getDelta(objDeltaAction,
+                    timeNowInSec, v.property(AAIProperties.RESOURCE_VERSION).value()), objDeltaAction);
+            addPropDelta(uri, AAIProperties.LAST_MOD_TS, PropertyDeltaFactory.getDelta(objDeltaAction,
+                    currentTimeMillis, v.property(AAIProperties.LAST_MOD_TS).value()), objDeltaAction);
             addPropDelta(
-                uri,
-                AAIProperties.RESOURCE_VERSION,
-                PropertyDeltaFactory.getDelta(objDeltaAction, timeNowInSec, v.property(AAIProperties.RESOURCE_VERSION).value()),
-                objDeltaAction
-            );
-            addPropDelta(
-                uri,
-                AAIProperties.LAST_MOD_TS,
-                PropertyDeltaFactory.getDelta(objDeltaAction, currentTimeMillis, v.property(AAIProperties.LAST_MOD_TS).value()),
-                objDeltaAction
-            );
-            addPropDelta(
-                uri,
-                AAIProperties.LAST_MOD_SOURCE_OF_TRUTH,
-                PropertyDeltaFactory.getDelta(objDeltaAction, this.sourceOfTruth, v.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value()),
-                objDeltaAction
-            );
+                    uri, AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, PropertyDeltaFactory.getDelta(objDeltaAction,
+                            this.sourceOfTruth, v.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value()),
+                    objDeltaAction);
         } else {
-            addPropDelta(uri, AAIProperties.RESOURCE_VERSION, PropertyDeltaFactory.getDelta(objDeltaAction, v.property(AAIProperties.RESOURCE_VERSION).value()), objDeltaAction);
-            addPropDelta(uri, AAIProperties.LAST_MOD_TS, PropertyDeltaFactory.getDelta(objDeltaAction, v.property(AAIProperties.LAST_MOD_TS).value()), objDeltaAction);
-            addPropDelta(uri, AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, PropertyDeltaFactory.getDelta(objDeltaAction, v.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value()), objDeltaAction);
+            addPropDelta(uri, AAIProperties.RESOURCE_VERSION,
+                    PropertyDeltaFactory.getDelta(objDeltaAction, v.property(AAIProperties.RESOURCE_VERSION).value()),
+                    objDeltaAction);
+            addPropDelta(uri, AAIProperties.LAST_MOD_TS,
+                    PropertyDeltaFactory.getDelta(objDeltaAction, v.property(AAIProperties.LAST_MOD_TS).value()),
+                    objDeltaAction);
+            addPropDelta(uri, AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, PropertyDeltaFactory.getDelta(objDeltaAction,
+                    v.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value()), objDeltaAction);
         }
     }
 
-    public Map<String, ObjectDelta> getObjectDeltas() {return objectDeltas;}
+    public Map<String, ObjectDelta> getObjectDeltas() {
+        return objectDeltas;
+    }
 
     private void addPropDelta(String uri, String prop, PropertyDelta delta, DeltaAction objDeltaAction) {
-        ObjectDelta objectDelta = this.objectDeltas.getOrDefault(uri, new ObjectDelta(uri, objDeltaAction, this.sourceOfTruth, this.currentTimeMillis));
+        ObjectDelta objectDelta = this.objectDeltas.getOrDefault(uri,
+                new ObjectDelta(uri, objDeltaAction, this.sourceOfTruth, this.currentTimeMillis));
         objectDelta.addPropertyDelta(prop, delta);
         objectDeltas.put(uri, objectDelta);
     }
 
     private void addRelationshipDelta(String uri, RelationshipDelta delta, DeltaAction objDeltaAction) {
-        ObjectDelta objectDelta = this.objectDeltas.getOrDefault(uri, new ObjectDelta(uri, objDeltaAction, this.sourceOfTruth, this.currentTimeMillis));
+        ObjectDelta objectDelta = this.objectDeltas.getOrDefault(uri,
+                new ObjectDelta(uri, objDeltaAction, this.sourceOfTruth, this.currentTimeMillis));
         objectDelta.addRelationshipDelta(delta);
         objectDeltas.put(uri, objectDelta);
     }
@@ -434,12 +538,12 @@ public class DBSerializer {
         List<Vertex> dependentVertexes = new ArrayList<>();
         List<Vertex> processedVertexes = new ArrayList<>();
 
-        boolean isComplexType ;
+        boolean isComplexType;
         boolean isListType;
 
         // If the notification depth is set to maximum
         // this is the behavior of the expected clients
-        if(notificationDepth == AAIProperties.MAXIMUM_DEPTH) {
+        if (notificationDepth == AAIProperties.MAXIMUM_DEPTH) {
             if (!obj.isContainer()) {
                 this.touchStandardVertexProperties(v, false);
             }
@@ -484,7 +588,9 @@ public class DBSerializer {
                         if (oldValue != null) {
                             v.property(dbProperty).remove();
                             if (isDeltaEventsEnabled) {
-                                addPropDelta(uri, dbProperty, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, oldValue), DeltaAction.UPDATE);
+                                addPropDelta(uri, dbProperty,
+                                        PropertyDeltaFactory.getDelta(DeltaAction.DELETE, oldValue),
+                                        DeltaAction.UPDATE);
                             }
                             this.updatedVertexes.putIfAbsent(v, false);
                         }
@@ -508,7 +614,8 @@ public class DBSerializer {
                         engine.setListProperty(v, property, list);
                         if (list == null || list.isEmpty()) { // property delete scenario, there is no new value
                             if (oldVal != null && !oldVal.isEmpty()) { // and there is an old value
-                                addPropDelta(uri, property, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, oldVal), DeltaAction.UPDATE);
+                                addPropDelta(uri, property, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, oldVal),
+                                        DeltaAction.UPDATE);
                             }
                         } else { // is either a create or update and is handled by the called method
                             createDeltaProperty(uri, list, property, oldVal);
@@ -562,11 +669,12 @@ public class DBSerializer {
         }
 
         ImpliedDelete impliedDelete = new ImpliedDelete(engine, this);
-        List<Vertex> impliedDeleteVertices = impliedDelete.execute(v.id(), sourceOfTruth, obj.getName(), dependentVertexes);
+        List<Vertex> impliedDeleteVertices =
+                impliedDelete.execute(v.id(), sourceOfTruth, obj.getName(), dependentVertexes);
 
-        if(notificationDepth == AAIProperties.MINIMUM_DEPTH){
-            for(Vertex curVertex : impliedDeleteVertices){
-                if(!curVertex.property("aai-uri").isPresent()){
+        if (notificationDepth == AAIProperties.MINIMUM_DEPTH) {
+            for (Vertex curVertex : impliedDeleteVertices) {
+                if (!curVertex.property("aai-uri").isPresent()) {
                     LOGGER.debug("Encountered an vertex {} with missing aai-uri", curVertex.id());
                     continue;
                 }
@@ -575,11 +683,12 @@ public class DBSerializer {
 
                 LinkedHashMap<String, Introspector> curObjRelated = new LinkedHashMap<>();
 
-                if(!curObj.isTopLevel()){
-                    curObjRelated.putAll(this.getRelatedObjects(engine.getQueryEngine(), curVertex, curObj, this.loader));
+                if (!curObj.isTopLevel()) {
+                    curObjRelated
+                            .putAll(this.getRelatedObjects(engine.getQueryEngine(), curVertex, curObj, this.loader));
                 }
 
-                if(!impliedDeleteUriObjectPair.containsKey(curAaiUri)){
+                if (!impliedDeleteUriObjectPair.containsKey(curAaiUri)) {
                     impliedDeleteUriObjectPair.put(curAaiUri, new Pair<>(curObj, curObjRelated));
                 }
             }
@@ -589,14 +698,12 @@ public class DBSerializer {
 
         // touch svp using vertex list for what changed
         // if the notification depth is zero
-        if(notificationDepth == AAIProperties.MINIMUM_DEPTH){
-            this.updatedVertexes.entrySet().stream()
-                .filter(e -> !e.getValue())
-                .filter(e -> !edgeVertexes.contains(e.getKey()))
-                .forEach(e -> {
-                    this.touchStandardVertexProperties(e.getKey(), false);
-                    e.setValue(true);
-                });
+        if (notificationDepth == AAIProperties.MINIMUM_DEPTH) {
+            this.updatedVertexes.entrySet().stream().filter(e -> !e.getValue())
+                    .filter(e -> !edgeVertexes.contains(e.getKey())).forEach(e -> {
+                        this.touchStandardVertexProperties(e.getKey(), false);
+                        e.setValue(true);
+                    });
         }
         this.executePostSideEffects(obj, v);
         return processedVertexes;
@@ -606,12 +713,14 @@ public class DBSerializer {
         if (oldValue == null) {
             addPropDelta(uri, dbProperty, PropertyDeltaFactory.getDelta(DeltaAction.CREATE, value), DeltaAction.UPDATE);
         } else {
-            addPropDelta(uri, dbProperty, PropertyDeltaFactory.getDelta(DeltaAction.UPDATE, value, oldValue), DeltaAction.UPDATE);
+            addPropDelta(uri, dbProperty, PropertyDeltaFactory.getDelta(DeltaAction.UPDATE, value, oldValue),
+                    DeltaAction.UPDATE);
         }
     }
 
-    public HashMap<String, Introspector> getRelatedObjects(QueryEngine queryEngine, Vertex v,
-                                                            Introspector obj, Loader loader) throws IllegalArgumentException, SecurityException, UnsupportedEncodingException, AAIException {
+    public HashMap<String, Introspector> getRelatedObjects(QueryEngine queryEngine, Vertex v, Introspector obj,
+            Loader loader)
+            throws IllegalArgumentException, SecurityException, UnsupportedEncodingException, AAIException {
 
         HashMap<String, Introspector> relatedVertices = new HashMap<>();
         VertexProperty aaiUriProperty = v.property(AAIProperties.AAI_URI);
@@ -619,10 +728,10 @@ public class DBSerializer {
         if (!aaiUriProperty.isPresent()) {
             if (LOGGER.isDebugEnabled()) {
                 LOGGER.debug("For the given vertex {}, it seems aai-uri is not present so not getting related objects",
-                    v.id().toString());
+                        v.id().toString());
             } else {
                 LOGGER.info(
-                    "It seems aai-uri is not present in vertex, so not getting related objects, for more info enable debug log");
+                        "It seems aai-uri is not present in vertex, so not getting related objects, for more info enable debug log");
             }
             return relatedVertices;
         }
@@ -636,13 +745,14 @@ public class DBSerializer {
             // into a list of aai-uris so falling back to the old mechanism for finding parents
             if (uriList == null) {
                 LOGGER.info(
-                    "Falling back to the old mechanism due to unable to convert aai-uri to list of uris but this is not optimal");
+                        "Falling back to the old mechanism due to unable to convert aai-uri to list of uris but this is not optimal");
                 vertexChain = queryEngine.findParents(v);
             } else if (uriList.length == 1) {
                 // If the uri list is size 1 the only uri in the list is the one represented by v thus no need to query
                 vertexChain = Collections.singletonList(v);
             } else {
-                // the uriList at element 0 is the node in question and should not be included in the vertex chain lookup.
+                // the uriList at element 0 is the node in question and should not be included in the vertex chain
+                // lookup.
                 vertexChain = queryEngine.findParents(Arrays.copyOfRange(uriList, 1, uriList.length));
                 // inject v into start of vertexChain
                 vertexChain.add(0, v);
@@ -711,7 +821,7 @@ public class DBSerializer {
      * @throws AAIException
      */
     String[] convertIntrospectorToUriList(String aaiUri, Introspector obj, Loader loader)
-        throws UnsupportedEncodingException, AAIException {
+            throws UnsupportedEncodingException, AAIException {
 
         List<String> uriList = new ArrayList<>();
         String template;
@@ -775,17 +885,15 @@ public class DBSerializer {
      * @throws AAIException the AAI exception
      */
     private void processRelationshipList(Introspector wrapped, Vertex v)
-        throws UnsupportedEncodingException, AAIException {
+            throws UnsupportedEncodingException, AAIException {
 
         List<Object> relationships = wrapped.getValue("relationship");
         String mainUri = getURIForVertex(v).toString();
         String aNodeType = v.property(AAIProperties.NODE_TYPE).value().toString();
-        EdgeRuleQuery.Builder cousinQueryBuilder = new EdgeRuleQuery.Builder(aNodeType)
-            .edgeType(EdgeType.COUSIN)
-            .version(wrapped.getVersion());
-        EdgeRuleQuery.Builder treeQueryBuilder = new EdgeRuleQuery.Builder(aNodeType)
-            .edgeType(EdgeType.TREE)
-            .version(wrapped.getVersion());
+        EdgeRuleQuery.Builder cousinQueryBuilder =
+                new EdgeRuleQuery.Builder(aNodeType).edgeType(EdgeType.COUSIN).version(wrapped.getVersion());
+        EdgeRuleQuery.Builder treeQueryBuilder =
+                new EdgeRuleQuery.Builder(aNodeType).edgeType(EdgeType.TREE).version(wrapped.getVersion());
 
         EdgeIngestor edgeIngestor = SpringContextAware.getBean(EdgeIngestor.class);
 
@@ -800,8 +908,9 @@ public class DBSerializer {
                 QueryParser parser = engine.getQueryBuilder().createQueryFromRelationship(wrappedRel);
                 List<Vertex> results = parser.getQueryBuilder().toList();
                 if (results.isEmpty()) {
-                    final AAIException ex = new AAIException(AAI_6129,
-                        String.format("Node of type %s. Could not find object at: %s", parser.getResultType(), parser.getUri()));
+                    final AAIException ex =
+                            new AAIException(AAI_6129, String.format("Node of type %s. Could not find object at: %s",
+                                    parser.getResultType(), parser.getUri()));
                     ex.getTemplateVars().add(parser.getResultType());
                     ex.getTemplateVars().add(parser.getUri().toString());
                     throw ex;
@@ -810,7 +919,8 @@ public class DBSerializer {
                     if (results.get(0).property(AAIProperties.AAI_URI).isPresent()) {
                         relUri = results.get(0).value(AAIProperties.AAI_URI);
                     } else {
-                        LOGGER.warn("Not processing the vertex {} because its missing required property aai-uri", results.get(0).id());
+                        LOGGER.warn("Not processing the vertex {} because its missing required property aai-uri",
+                                results.get(0).id());
                         continue;
                     }
                 }
@@ -825,11 +935,11 @@ public class DBSerializer {
                 if (!edgeIngestor.hasRule(ruleQuery)) {
                     EdgeRuleQuery treeQuery = treeQueryBuilder.to(bNodeType).build();
                     if (edgeIngestor.hasRule(treeQuery)) {
-                        throw new AAIException(AAI_6145); //attempted to create cousin edge for a parent-child edge rule
+                        throw new AAIException(AAI_6145); // attempted to create cousin edge for a parent-child edge
+                                                          // rule
                     }
-                    throw new AAIException("AAI_6120", String.format(
-                        "No EdgeRule found for passed nodeTypes: %s, %s.",
-                        aNodeType, bNodeType));
+                    throw new AAIException("AAI_6120",
+                            String.format("No EdgeRule found for passed nodeTypes: %s, %s.", aNodeType, bNodeType));
                 } else {
                     try {
                         final List<EdgeRule> rules = new ArrayList<>(edgeIngestor.getRules(ruleQuery).values());
@@ -854,18 +964,17 @@ public class DBSerializer {
         List<Path> paths = this.engine.getQueryEngine().findCousinsAsPath(v);
         Set<Path> toRemove = new HashSet<>();
 
-
-        //  for each path 3 things can happen:
-        //      1. The edge rule that created it is not in this version no action is to be taken on that edge
-        //      2. The edge rule exits in this version it's included in the request the edge is left alone
-        //      3. The edge rule exits in this version and is not included in the request it is marked for removal
+        // for each path 3 things can happen:
+        // 1. The edge rule that created it is not in this version no action is to be taken on that edge
+        // 2. The edge rule exits in this version it's included in the request the edge is left alone
+        // 3. The edge rule exits in this version and is not included in the request it is marked for removal
         for (Path path : paths) {
             if (path.size() < 3) {
                 continue;
             }
 
             // Path represents
-            //       v   ----related-to-->    otherV
+            // v ----related-to--> otherV
             // In the above case,
             // path objects get(0) returns vertex v
             // path objects.get(1) returns edge related-to
@@ -909,7 +1018,7 @@ public class DBSerializer {
             List<Vertex> results = parser.getQueryBuilder().toList();
             if (results.isEmpty()) {
                 final AAIException ex = new AAIException(AAI_6129,
-                    "Node of type " + parser.getResultType() + ". Could not find object at: " + parser.getUri());
+                        "Node of type " + parser.getResultType() + ". Could not find object at: " + parser.getUri());
                 ex.getTemplateVars().add(parser.getResultType());
                 ex.getTemplateVars().add(parser.getUri().toString());
                 throw ex;
@@ -924,11 +1033,11 @@ public class DBSerializer {
                 EdgeRuleQuery.Builder baseQ = new EdgeRuleQuery.Builder(vType, cousinType).label(label);
 
                 if (!edgeRules.hasRule(baseQ.build())) {
-                    throw new AAIException("AAI_6120", String.format(
-                        "No EdgeRule found for passed nodeTypes: %s, %s%s.",
-                        aNodeType, cousinType, label != null ? (" with label " + label) : ""));
+                    throw new AAIException("AAI_6120",
+                            String.format("No EdgeRule found for passed nodeTypes: %s, %s%s.", aNodeType, cousinType,
+                                    label != null ? (" with label " + label) : ""));
                 } else if (edgeRules.hasRule(baseQ.edgeType(EdgeType.TREE).build())
-                    && !edgeRules.hasRule(baseQ.edgeType(EdgeType.COUSIN).build())) {
+                        && !edgeRules.hasRule(baseQ.edgeType(EdgeType.COUSIN).build())) {
                     throw new AAIException(AAI_6145);
                 }
 
@@ -941,7 +1050,7 @@ public class DBSerializer {
         }
 
         for (Path path : toRemove) {
-            if(isDeltaEventsEnabled) {
+            if (isDeltaEventsEnabled) {
                 deltaForEdge(mainUri, path.get(1), DeltaAction.DELETE_REL, DeltaAction.UPDATE);
             }
             this.updatedVertexes.putIfAbsent(v, false);
@@ -951,7 +1060,8 @@ public class DBSerializer {
 
         for (Pair<Vertex, String> create : toBeCreated) {
             try {
-                Edge e = edgeSer.addEdge(this.engine.asAdmin().getTraversalSource(), v, create.getValue0(), create.getValue1());
+                Edge e = edgeSer.addEdge(this.engine.asAdmin().getTraversalSource(), v, create.getValue0(),
+                        create.getValue1());
                 if (isDeltaEventsEnabled) {
                     deltaForEdge(mainUri, e, DeltaAction.CREATE_REL, DeltaAction.UPDATE);
                 }
@@ -963,15 +1073,12 @@ public class DBSerializer {
         }
     }
 
-
     private void deltaForEdge(String mainUri, Edge edge, DeltaAction edgeAction, DeltaAction mainAction) {
-        RelationshipDelta relationshipDelta = new RelationshipDelta(
-            edgeAction,
-            edge.inVertex().property(AAIProperties.AAI_UUID).value().toString(),
-            edge.outVertex().property(AAIProperties.AAI_UUID).value().toString(),
-            edge.inVertex().property(AAIProperties.AAI_URI).value().toString(),
-            edge.outVertex().property(AAIProperties.AAI_URI).value().toString(),
-            edge.label());
+        RelationshipDelta relationshipDelta =
+                new RelationshipDelta(edgeAction, edge.inVertex().property(AAIProperties.AAI_UUID).value().toString(),
+                        edge.outVertex().property(AAIProperties.AAI_UUID).value().toString(),
+                        edge.inVertex().property(AAIProperties.AAI_URI).value().toString(),
+                        edge.outVertex().property(AAIProperties.AAI_URI).value().toString(), edge.label());
         edge.properties().forEachRemaining(p -> relationshipDelta.addProp(p.key(), p.value().toString()));
         addRelationshipDelta(mainUri, relationshipDelta, mainAction);
     }
@@ -1077,8 +1184,9 @@ public class DBSerializer {
                 }
             }
             e = edgeSer.addTreeEdge(this.engine.asAdmin().getTraversalSource(), parent, child);
-            if(isDeltaEventsEnabled) {
-                deltaForEdge(child.property(AAIProperties.AAI_URI).value().toString(), e, DeltaAction.CREATE_REL, DeltaAction.CREATE);
+            if (isDeltaEventsEnabled) {
+                deltaForEdge(child.property(AAIProperties.AAI_URI).value().toString(), e, DeltaAction.CREATE_REL,
+                        DeltaAction.CREATE);
             }
         }
         return child;
@@ -1111,7 +1219,7 @@ public class DBSerializer {
      * @throws URISyntaxException
      */
     public Introspector dbToObject(List<Vertex> vertices, final Introspector obj, int depth, boolean nodeOnly,
-                                   String cleanUp, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIException {
+            String cleanUp, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIException {
         final int internalDepth;
         if (depth == Integer.MAX_VALUE) {
             internalDepth = depth--;
@@ -1122,7 +1230,7 @@ public class DBSerializer {
         if (vertices.size() > 1 && !obj.isContainer()) {
             dbTimeMsecs += StopWatch.stopIfStarted();
             throw new AAIException("AAI_6136",
-                "query object mismatch: this object cannot hold multiple items." + obj.getDbName());
+                    "query object mismatch: this object cannot hold multiple items." + obj.getDbName());
         } else if (obj.isContainer()) {
             final List getList;
             String listProperty = null;
@@ -1160,7 +1268,11 @@ public class DBSerializer {
             for (Future<Object> future : futures) {
                 try {
                     getList.add(future.get());
-                } catch (ExecutionException | InterruptedException e) {
+                } catch (InterruptedException e) {
+                    dbTimeMsecs += StopWatch.stopIfStarted();
+                    Thread.currentThread().interrupt();
+                    throw new AAIException("AAI_4000", e);
+                } catch (ExecutionException e) {
                     dbTimeMsecs += StopWatch.stopIfStarted();
                     throw new AAIException("AAI_4000", e);
                 }
@@ -1234,7 +1346,7 @@ public class DBSerializer {
      * @throws URISyntaxException
      */
     private Introspector dbToObject(Introspector obj, Vertex v, Set<Vertex> seen, int depth, boolean nodeOnly,
-                                    String cleanUp, boolean isSkipRelatedTo) throws AAIException, UnsupportedEncodingException {
+            String cleanUp, boolean isSkipRelatedTo) throws AAIException, UnsupportedEncodingException {
 
         if (depth < 0) {
             return null;
@@ -1283,7 +1395,7 @@ public class DBSerializer {
 
                         try {
                             rule = edgeRules.getRule(
-                                new EdgeRuleQuery.Builder(vType, childDbName).edgeType(EdgeType.TREE).build());
+                                    new EdgeRuleQuery.Builder(vType, childDbName).edgeType(EdgeType.TREE).build());
                         } catch (EdgeRuleNotFoundException e) {
                             throw new NoEdgeRuleFoundException(e);
                         } catch (AmbiguousRuleChoiceException e) {
@@ -1306,16 +1418,16 @@ public class DBSerializer {
                                 if (!seen.contains(childVertex)) {
                                     Introspector argumentObject = obj.newIntrospectorInstanceOfNestedProperty(property);
 
-                                    Object result =
-                                        dbToObject(argumentObject, childVertex, seen, depth, nodeOnly, cleanUp, isSkipRelatedTo);
-                                    if (result != null) {
+                                    Object result = dbToObject(argumentObject, childVertex, seen, depth, nodeOnly,
+                                            cleanUp, isSkipRelatedTo);
+                                    if (result != null && getList != null) {
                                         getList.add(argumentObject.getUnderlyingObject());
                                     }
 
                                     processed++;
                                 } else {
                                     LOGGER.warn("Cycle found while serializing vertex id={}",
-                                        childVertex.id().toString());
+                                            childVertex.id().toString());
                                 }
                             }
                             if (processed == 0) {
@@ -1409,7 +1521,8 @@ public class DBSerializer {
         return simplePropsHashMap;
     }
 
-    public Introspector dbToRelationshipObject(Vertex v, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIException {
+    public Introspector dbToRelationshipObject(Vertex v, boolean isSkipRelatedTo)
+            throws UnsupportedEncodingException, AAIException {
         Introspector relationshipList = this.latestLoader.introspectorFromName("relationship-list");
         relationshipList = createRelationshipList(v, relationshipList, FALSE, isSkipRelatedTo);
         return relationshipList;
@@ -1465,23 +1578,22 @@ public class DBSerializer {
 
         EdgeIngestor edgeIngestor = SpringContextAware.getBean(EdgeIngestor.class);
 
-        EdgeRuleQuery.Builder queryBuilder = new EdgeRuleQuery.Builder(aNodeType)
-            .edgeType(EdgeType.COUSIN)
-            .version(obj.getVersion());
+        EdgeRuleQuery.Builder queryBuilder =
+                new EdgeRuleQuery.Builder(aNodeType).edgeType(EdgeType.COUSIN).version(obj.getVersion());
 
-        for (Path path : paths){
-            if(path.size() < 3){
+        for (Path path : paths) {
+            if (path.size() < 3) {
                 continue;
             }
 
             // Path represents
-            //       v   ----related-to-->    otherV
+            // v ----related-to--> otherV
             // In the above case,
             // path objects get(0) returns vertex v
             // path objects.get(1) returns edge related-to
             // path objects.get(2) returns vertex otherV
             Edge edge = path.get(1);
-            Vertex otherV= path.get(2);
+            Vertex otherV = path.get(2);
 
             // TODO: Come back and revisit this code
             // Create a query based on the a nodetype and b nodetype
@@ -1503,8 +1615,8 @@ public class DBSerializer {
             String edgeLabel = edge.label();
             EdgeRuleQuery ruleQuery = queryBuilder.to(bNodeType).label(edgeLabel).build();
 
-            if(!edgeIngestor.hasRule(ruleQuery)){
-                LOGGER.debug( "Caught an edge rule not found for query {}", ruleQuery);
+            if (!edgeIngestor.hasRule(ruleQuery)) {
+                LOGGER.debug("Caught an edge rule not found for query {}", ruleQuery);
                 continue;
             }
 
@@ -1601,7 +1713,6 @@ public class DBSerializer {
         return uri;
     }
 
-
     public void addRelatedToProperty(Introspector relationship, Vertex cousinVertex, String cousinType)
             throws AAIUnknownObjectException {
 
@@ -1693,8 +1804,9 @@ public class DBSerializer {
                 e = this.getEdgeBetween(EdgeType.COUSIN, inputVertex, relatedVertex, label);
                 if (e == null) {
                     e = edgeSer.addEdge(this.engine.asAdmin().getTraversalSource(), inputVertex, relatedVertex, label);
-                    if(isDeltaEventsEnabled) {
-                        deltaForEdge(inputVertex.property(AAIProperties.AAI_URI).value().toString(), e, DeltaAction.CREATE_REL, DeltaAction.UPDATE);
+                    if (isDeltaEventsEnabled) {
+                        deltaForEdge(inputVertex.property(AAIProperties.AAI_URI).value().toString(), e,
+                                DeltaAction.CREATE_REL, DeltaAction.UPDATE);
                     }
                 } else {
                     // attempted to link two vertexes already linked
@@ -1779,29 +1891,29 @@ public class DBSerializer {
     /**
      * Gets all the edges between the vertexes with the label and type.
      *
-     * @param aVertex the out vertex
-     * @param bVertex the in vertex
+     * @param vertexOut the out vertex
+     * @param vertexIn the in vertex
      * @param label
      * @return the edges between
      * @throws AAIException the AAI exception
      */
-    private Edge getEdgesBetween(EdgeType type, Vertex aVertex, Vertex bVertex, String label) throws AAIException {
+    private Edge getEdgesBetween(EdgeType type, Vertex vertexOut, Vertex vertexIn, String label) throws AAIException {
 
         Edge edge = null;
 
-        if (bVertex != null) {
-            String aType = aVertex.<String>property(AAIProperties.NODE_TYPE).value();
-            String bType = bVertex.<String>property(AAIProperties.NODE_TYPE).value();
-            EdgeRuleQuery q = new EdgeRuleQuery.Builder(aType, bType).edgeType(type).label(label).build();
+        if (vertexIn != null) {
+            String aType = vertexOut.<String>property(AAIProperties.NODE_TYPE).value();
+            String bType = vertexIn.<String>property(AAIProperties.NODE_TYPE).value();
+            EdgeRuleQuery query = new EdgeRuleQuery.Builder(aType, bType).edgeType(type).label(label).build();
             EdgeRule rule;
             try {
-                rule = edgeRules.getRule(q);
+                rule = edgeRules.getRule(query);
             } catch (EdgeRuleNotFoundException e) {
                 throw new NoEdgeRuleFoundException(e);
             } catch (AmbiguousRuleChoiceException e) {
                 throw new MultipleEdgeRuleFoundException(e);
             }
-            edge = this.getEdgeBetweenWithLabel(type, aVertex, bVertex, rule);
+            edge = this.getEdgeBetweenWithLabel(type, vertexOut, vertexIn, rule);
         }
 
         return edge;
@@ -1810,19 +1922,19 @@ public class DBSerializer {
     /**
      * Gets the edge between with the label and edge type.
      *
-     * @param aVertex the out vertex
-     * @param bVertex the in vertex
+     * @param vertexOut the out vertex
+     * @param vertexIn the in vertex
      * @param label
      * @return the edge between
      * @throws AAIException the AAI exception
      * @throws NoEdgeRuleFoundException
      */
-    public Edge getEdgeBetween(EdgeType type, Vertex aVertex, Vertex bVertex, String label) throws AAIException {
+    public Edge getEdgeBetween(EdgeType type, Vertex vertexOut, Vertex vertexIn, String label) throws AAIException {
 
         StopWatch.conditionalStart();
-        if (bVertex != null) {
+        if (vertexIn != null) {
 
-            Edge edge = this.getEdgesBetween(type, aVertex, bVertex, label);
+            Edge edge = this.getEdgesBetween(type, vertexOut, vertexIn, label);
             if (edge != null) {
                 dbTimeMsecs += StopWatch.stopIfStarted();
                 return edge;
@@ -1874,7 +1986,7 @@ public class DBSerializer {
             throw new AAIException(AAI_6129, e);
         }
         if (edge != null) {
-            if(isDeltaEventsEnabled) {
+            if (isDeltaEventsEnabled) {
                 String mainUri = inputVertex.property(AAIProperties.AAI_URI).value().toString();
                 deltaForEdge(mainUri, edge, DeltaAction.DELETE_REL, DeltaAction.UPDATE);
             }
@@ -1923,23 +2035,22 @@ public class DBSerializer {
 
         for (Vertex v : vertices) {
             LOGGER.debug("Removing vertex {} with label {}", v.id(), v.label());
-            if(isDeltaEventsEnabled) {
+            if (isDeltaEventsEnabled) {
                 deltaForVertexDelete(v);
             }
-            //add the cousin vertexes of v to have their resource-version updated and notified on.
-            v.edges(Direction.BOTH)
-                .forEachRemaining(e -> {
-                    if (e.property(EdgeProperty.CONTAINS.toString()).isPresent()
+            // add the cousin vertexes of v to have their resource-version updated and notified on.
+            v.edges(Direction.BOTH).forEachRemaining(e -> {
+                if (e.property(EdgeProperty.CONTAINS.toString()).isPresent()
                         && AAIDirection.NONE.toString().equals(e.<String>value(EdgeProperty.CONTAINS.toString()))) {
-                        e.bothVertices().forEachRemaining(cousinV -> {
-                            if (!v.equals(cousinV)) {
-                                edgeVertexes.add(cousinV);
-                            }
-                        });
-                    }
-                });
+                    e.bothVertices().forEachRemaining(cousinV -> {
+                        if (!v.equals(cousinV)) {
+                            edgeVertexes.add(cousinV);
+                        }
+                    });
+                }
+            });
 
-            //if somewhere along the way v was added to the sets tracking the what is to be updated/notified on
+            // if somewhere along the way v was added to the sets tracking the what is to be updated/notified on
             // it should be removed from them as v is to be deleted
             edgeVertexes.remove(v);
             updatedVertexes.remove(v);
@@ -1949,19 +2060,21 @@ public class DBSerializer {
         dbTimeMsecs += StopWatch.stopIfStarted();
     }
 
-    private void deltaForVertexDelete(Vertex v) {
-        String aaiUri = v.property(AAIProperties.AAI_URI).value().toString();
-        v.keys().forEach(k -> {
+    private void deltaForVertexDelete(Vertex vertex) {
+        String aaiUri = vertex.property(AAIProperties.AAI_URI).value().toString();
+        vertex.keys().forEach(k -> {
             List<Object> list = new ArrayList<>();
-            v.properties(k).forEachRemaining(vp -> list.add(vp.value()));
+            vertex.properties(k).forEachRemaining(vp -> list.add(vp.value()));
             if (list.size() == 1) {
-                addPropDelta(aaiUri, k, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list.get(0)), DeltaAction.DELETE);
+                addPropDelta(aaiUri, k, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list.get(0)),
+                        DeltaAction.DELETE);
             } else {
                 addPropDelta(aaiUri, k, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list), DeltaAction.DELETE);
             }
 
         });
-        v.edges(Direction.BOTH).forEachRemaining(e -> deltaForEdge(aaiUri, e, DeltaAction.DELETE, DeltaAction.DELETE));
+        vertex.edges(Direction.BOTH)
+                .forEachRemaining(e -> deltaForEdge(aaiUri, e, DeltaAction.DELETE, DeltaAction.DELETE));
     }
 
     /**
@@ -1999,21 +2112,21 @@ public class DBSerializer {
     /**
      * Delete.
      *
-     * @param v the v
+     * @param vertex the vertex
      * @param resourceVersion the resource version
      * @throws IllegalArgumentException the illegal argument exception
      * @throws AAIException the AAI exception
      * @throws InterruptedException the interrupted exception
      */
-    public void delete(Vertex v, String resourceVersion, boolean enableResourceVersion)
+    public void delete(Vertex vertex, String resourceVersion, boolean enableResourceVersion)
             throws IllegalArgumentException, AAIException {
 
-        boolean result = verifyDeleteSemantics(v, resourceVersion, enableResourceVersion);
+        boolean result = verifyDeleteSemantics(vertex, resourceVersion, enableResourceVersion);
 
         if (result) {
 
             try {
-                deleteWithTraversal(v);
+                deleteWithTraversal(vertex);
             } catch (IllegalStateException e) {
                 throw new AAIException("AAI_6110", e);
             }
@@ -2036,7 +2149,7 @@ public class DBSerializer {
         nodeType = vertex.<String>property(AAIProperties.NODE_TYPE).orElse(null);
         if (enableResourceVersion) {
             this.verifyResourceVersion("delete", nodeType,
-                vertex.<String>property(AAIProperties.RESOURCE_VERSION).orElse(null), resourceVersion, nodeType);
+                    vertex.<String>property(AAIProperties.RESOURCE_VERSION).orElse(null), resourceVersion, nodeType);
         }
         List<Vertex> vertices = new ArrayList<>();
         vertices.add(vertex);
@@ -2076,9 +2189,9 @@ public class DBSerializer {
         dbTimeMsecs += StopWatch.stopIfStarted();
         if (!preventDeleteVertices.isEmpty()) {
             aaiExceptionCode = "AAI_6110";
-            errorDetail = String.format(
-                    "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types %s",
-                    preventDeleteVertices);
+            errorDetail =
+                    String.format("Object is being reference by additional objects preventing it from being deleted."
+                            + " Please clean up references from the following types %s", preventDeleteVertices);
             result = false;
         }
         if (!result) {
@@ -2192,10 +2305,12 @@ public class DBSerializer {
 
     private void executePreSideEffects(Introspector obj, Vertex self) throws AAIException {
 
-        SideEffectRunner runner = new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataCopy.class)
-                .addSideEffect(PrivateEdge.class).build();
-
-        runner.execute(obj, self);
+        SideEffectRunner.Builder runnerBuilder = new SideEffectRunner.Builder(this.engine, this)
+                .addSideEffect(DataCopy.class).addSideEffect(PrivateEdge.class);
+        if (isMultiTenancyEnabled) {
+            runnerBuilder.addSideEffect(OwnerCheck.class);
+        }
+        runnerBuilder.build().execute(obj, self);
     }
 
     private void executePostSideEffects(Introspector obj, Vertex self) throws AAIException {
@@ -2208,10 +2323,13 @@ public class DBSerializer {
 
     private void enrichData(Introspector obj, Vertex self) throws AAIException {
 
-        SideEffectRunner runner =
-                new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataLinkReader.class).build();
+        SideEffectRunner.Builder runnerBuilder =
+                new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataLinkReader.class);
 
-        runner.execute(obj, self);
+        if (isMultiTenancyEnabled) {
+            runnerBuilder.addSideEffect(OwnerCheck.class);
+        }
+        runnerBuilder.build().execute(obj, self);
     }
 
     public double getDBTimeMsecs() {
@@ -2223,7 +2341,7 @@ public class DBSerializer {
      * This is for a one-time run with Tenant Isloation to only filter relationships
      *
      * @param obj the obj
-     * @param v the vertex from the graph
+     * @param vertex the vertex from the graph
      * @param depth the depth
      * @param nodeOnly specify if to exclude relationships or not
      * @param filterCousinNodes
@@ -2240,11 +2358,10 @@ public class DBSerializer {
      * @throws AAIUnknownObjectException
      * @throws URISyntaxException
      */
-    public Introspector dbToObjectWithFilters(Introspector obj, Vertex v, Set<Vertex> seen, int depth, boolean nodeOnly,
-                                              List<String> filterCousinNodes, List<String> filterParentNodes)
-        throws AAIException, UnsupportedEncodingException {
-        return dbToObjectWithFilters(obj, v, seen, depth, nodeOnly,
-        filterCousinNodes, filterParentNodes, false);
+    public Introspector dbToObjectWithFilters(Introspector obj, Vertex vertex, Set<Vertex> seen, int depth,
+            boolean nodeOnly, List<String> filterCousinNodes, List<String> filterParentNodes)
+            throws AAIException, UnsupportedEncodingException {
+        return dbToObjectWithFilters(obj, vertex, seen, depth, nodeOnly, filterCousinNodes, filterParentNodes, false);
     }
 
     /**
@@ -2253,7 +2370,7 @@ public class DBSerializer {
      * TODO: Chnage the original dbToObject to take filter parent/cousins
      *
      * @param obj the obj
-     * @param v the vertex from the graph
+     * @param vertexParam the vertex from the graph
      * @param depth the depth
      * @param nodeOnly specify if to exclude relationships or not
      * @param filterCousinNodes
@@ -2272,21 +2389,21 @@ public class DBSerializer {
      * @throws URISyntaxException
      */
     // TODO - See if you can merge the 2 dbToObjectWithFilters
-    public Introspector dbToObjectWithFilters(Introspector obj, Vertex v, Set<Vertex> seen, int depth, boolean nodeOnly,
-            List<String> filterCousinNodes, List<String> filterParentNodes, boolean isSkipRelatedTo)
+    public Introspector dbToObjectWithFilters(Introspector obj, Vertex vertexParam, Set<Vertex> seen, int depth,
+            boolean nodeOnly, List<String> filterCousinNodes, List<String> filterParentNodes, boolean isSkipRelatedTo)
             throws AAIException, UnsupportedEncodingException {
         String cleanUp = FALSE;
         if (depth < 0) {
             return null;
         }
         depth--;
-        seen.add(v);
+        seen.add(vertexParam);
         boolean modified = false;
         for (String property : obj.getProperties(PropertyPredicates.isVisible())) {
             List<Object> getList = null;
 
             if (!(obj.isComplexType(property) || obj.isListType(property))) {
-                this.copySimpleProperty(property, obj, v);
+                this.copySimpleProperty(property, obj, vertexParam);
                 modified = true;
             } else {
                 if (obj.isComplexType(property)) {
@@ -2294,7 +2411,7 @@ public class DBSerializer {
 
                     if (!property.equals("relationship-list") && depth >= 0) {
                         Introspector argumentObject = obj.newIntrospectorInstanceOfProperty(property);
-                        Object result = dbToObjectWithFilters(argumentObject, v, seen, depth + 1, nodeOnly,
+                        Object result = dbToObjectWithFilters(argumentObject, vertexParam, seen, depth + 1, nodeOnly,
                                 filterCousinNodes, filterParentNodes, isSkipRelatedTo);
                         if (result != null) {
                             obj.setValue(property, argumentObject.getUnderlyingObject());
@@ -2303,8 +2420,8 @@ public class DBSerializer {
                     } else if (property.equals("relationship-list") && !nodeOnly) {
                         /* relationships need to be handled correctly */
                         Introspector relationshipList = obj.newIntrospectorInstanceOfProperty(property);
-                        relationshipList =
-                                createFilteredRelationshipList(v, relationshipList, cleanUp, filterCousinNodes, isSkipRelatedTo);
+                        relationshipList = createFilteredRelationshipList(vertexParam, relationshipList, cleanUp,
+                                filterCousinNodes, isSkipRelatedTo);
                         if (relationshipList != null) {
                             obj.setValue(property, relationshipList.getUnderlyingObject());
                             modified = true;
@@ -2319,16 +2436,17 @@ public class DBSerializer {
                     String genericType = obj.getGenericTypeClass(property).getSimpleName();
                     if (obj.isComplexGenericType(property) && depth >= 0) {
                         final String childDbName = convertFromCamelCase(genericType);
-                        String vType = v.<String>property(AAIProperties.NODE_TYPE).orElse(null);
+                        String vertexType = vertexParam.<String>property(AAIProperties.NODE_TYPE).orElse(null);
                         EdgeRule rule;
 
                         boolean isThisParentRequired =
                                 filterParentNodes.parallelStream().anyMatch(childDbName::contains);
 
-                        EdgeRuleQuery q = new EdgeRuleQuery.Builder(vType, childDbName).edgeType(EdgeType.TREE).build();
+                        EdgeRuleQuery query =
+                                new EdgeRuleQuery.Builder(vertexType, childDbName).edgeType(EdgeType.TREE).build();
 
                         try {
-                            rule = edgeRules.getRule(q);
+                            rule = edgeRules.getRule(query);
                         } catch (EdgeRuleNotFoundException e) {
                             throw new NoEdgeRuleFoundException(e);
                         } catch (AmbiguousRuleChoiceException e) {
@@ -2337,7 +2455,7 @@ public class DBSerializer {
                         if (!rule.getContains().equals(AAIDirection.NONE.toString()) && isThisParentRequired) {
                             Direction ruleDirection = rule.getDirection();
                             List<Vertex> verticesList = new ArrayList<>();
-                            v.vertices(ruleDirection, rule.getLabel()).forEachRemaining(vertex -> {
+                            vertexParam.vertices(ruleDirection, rule.getLabel()).forEachRemaining(vertex -> {
                                 if (vertex.property(AAIProperties.NODE_TYPE).orElse("").equals(childDbName)) {
                                     verticesList.add(vertex);
                                 }
@@ -2352,7 +2470,7 @@ public class DBSerializer {
 
                                     Object result = dbToObjectWithFilters(argumentObject, childVertex, seen, depth,
                                             nodeOnly, filterCousinNodes, filterParentNodes, isSkipRelatedTo);
-                                    if (result != null) {
+                                    if (result != null && getList != null) {
                                         getList.add(argumentObject.getUnderlyingObject());
                                     }
 
@@ -2371,7 +2489,7 @@ public class DBSerializer {
                             }
                         }
                     } else if (obj.isSimpleGenericType(property)) {
-                        List<Object> temp = this.engine.getListProperty(v, property);
+                        List<Object> temp = this.engine.getListProperty(vertexParam, property);
                         if (temp != null) {
                             getList = obj.getValue(property);
                             getList.addAll(temp);
@@ -2389,7 +2507,7 @@ public class DBSerializer {
         if (!modified) {
             return null;
         }
-        this.enrichData(obj, v);
+        this.enrichData(obj, vertexParam);
         return obj;
 
     }
@@ -2397,7 +2515,7 @@ public class DBSerializer {
     /**
      * Creates the relationship list with the filtered node types.
      *
-     * @param v the v
+     * @param vertex the vertex
      * @param obj the obj
      * @param cleanUp the clean up
      * @return the object
@@ -2406,9 +2524,9 @@ public class DBSerializer {
      * @throws UnsupportedEncodingException the unsupported encoding exception
      * @throws AAIException the AAI exception
      */
-    private Introspector createFilteredRelationshipList(Vertex v, Introspector obj, String cleanUp,
+    private Introspector createFilteredRelationshipList(Vertex vertex, Introspector obj, String cleanUp,
             List<String> filterNodes, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIException {
-        List<Vertex> allCousins = this.engine.getQueryEngine().findCousinVertices(v);
+        List<Vertex> allCousins = this.engine.getQueryEngine().findCousinVertices(vertex);
 
         Iterator<Vertex> cousinVertices = allCousins.stream().filter(item -> {
             String node = (String) item.property(AAIProperties.NODE_TYPE).orElse("");
@@ -2441,7 +2559,7 @@ public class DBSerializer {
         return this.edgeVertexes;
     }
 
-    public void addVertexToEdgeVertexes(Vertex vertex){
+    public void addVertexToEdgeVertexes(Vertex vertex) {
         this.edgeVertexes.add(vertex);
     }