* 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.__;
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;
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);
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;
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.
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);
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();
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();
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) {
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) {
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);
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);
}
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);
}
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);
}
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);
}
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;
}
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));
}
}
// 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;
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);
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;
}
// 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);
* @throws AAIException
*/
String[] convertIntrospectorToUriList(String aaiUri, Introspector obj, Loader loader)
- throws UnsupportedEncodingException, AAIException {
+ throws UnsupportedEncodingException, AAIException {
List<String> uriList = new ArrayList<>();
String template;
* @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);
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;
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;
}
}
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());
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
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;
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);
}
}
for (Path path : toRemove) {
- if(isDeltaEventsEnabled) {
+ if (isDeltaEventsEnabled) {
deltaForEdge(mainUri, path.get(1), DeltaAction.DELETE_REL, DeltaAction.UPDATE);
}
this.updatedVertexes.putIfAbsent(v, false);
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);
}
}
}
-
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);
}
}
}
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;
* @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--;
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;
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);
}
* @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;
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) {
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) {
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;
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
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;
}
return uri;
}
-
public void addRelatedToProperty(Introspector relationship, Vertex cousinVertex, String cousinType)
throws AAIUnknownObjectException {
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
/**
* 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;
/**
* 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;
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);
}
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);
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));
}
/**
/**
* 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);
}
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);
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) {
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 {
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() {
* 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
* @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);
}
/**
* 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
* @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)) {
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());
} 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;
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) {
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);
}
Object result = dbToObjectWithFilters(argumentObject, childVertex, seen, depth,
nodeOnly, filterCousinNodes, filterParentNodes, isSkipRelatedTo);
- if (result != null) {
+ if (result != null && getList != null) {
getList.add(argumentObject.getUnderlyingObject());
}
}
}
} 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);
if (!modified) {
return null;
}
- this.enrichData(obj, v);
+ this.enrichData(obj, vertexParam);
return obj;
}
/**
* 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
* @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("");
return this.edgeVertexes;
}
- public void addVertexToEdgeVertexes(Vertex vertex){
+ public void addVertexToEdgeVertexes(Vertex vertex) {
this.edgeVertexes.add(vertex);
}