X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Faai%2Fserialization%2Fengines%2Fquery%2FGraphTraversalQueryEngine.java;h=a1967223dd6c08e656f8704f28cacc052cee9324;hb=323c3c56919bf25a3df9bffffd9bf5bc66fd5017;hp=7144aa6915dcdd32ff35556b13bfe46bcfab3126;hpb=eff9232ffe36022d63e6a70df7a3f0165015bbc8;p=aai%2Faai-common.git diff --git a/aai-core/src/main/java/org/openecomp/aai/serialization/engines/query/GraphTraversalQueryEngine.java b/aai-core/src/main/java/org/openecomp/aai/serialization/engines/query/GraphTraversalQueryEngine.java index 7144aa69..a1967223 100644 --- a/aai-core/src/main/java/org/openecomp/aai/serialization/engines/query/GraphTraversalQueryEngine.java +++ b/aai-core/src/main/java/org/openecomp/aai/serialization/engines/query/GraphTraversalQueryEngine.java @@ -32,9 +32,10 @@ import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Vertex; - import org.openecomp.aai.db.props.AAIProperties; import org.openecomp.aai.introspection.Loader; +import org.openecomp.aai.serialization.db.EdgeProperties; +import org.openecomp.aai.serialization.db.EdgeProperty; /* * This class needs some big explanation despite its compact size. @@ -62,7 +63,7 @@ public class GraphTraversalQueryEngine extends QueryEngine { @Override public List findParents(Vertex start) { - final GraphTraversal pipe = this.g.V(start).emit(v -> true).repeat(__.inE().has("isParent", true).outV()); + final GraphTraversal pipe = this.g.V(start).emit(v -> true).repeat(__.union(__.inE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), true).outV(), __.outE().has(EdgeProperties.in(EdgeProperty.IS_PARENT), true).inV())); return pipe.toList(); } @@ -73,7 +74,7 @@ public class GraphTraversalQueryEngine extends QueryEngine { public List findAllChildren(Vertex start) { GraphTraversal pipe = this.g - .V(start).emit(v -> true).repeat(__.outE().has("isParent", true).inV()); + .V(start).emit(v -> true).repeat(__.union(__.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), true).inV(), __.inE().has(EdgeProperties.in(EdgeProperty.IS_PARENT), true).outV())); return pipe.toList(); @@ -82,8 +83,8 @@ public class GraphTraversalQueryEngine extends QueryEngine { public List findChildrenOfType(Vertex start, String type) { GraphTraversal pipe = this.g.V(start).union( - __.outE().has("isParent", true).inV(), - __.inE().has("isParent-REV", true).outV() + __.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), true).inV(), + __.inE().has(EdgeProperties.in(EdgeProperty.IS_PARENT), true).outV() ).has(AAIProperties.NODE_TYPE, type).dedup(); return pipe.toList(); @@ -91,8 +92,8 @@ public class GraphTraversalQueryEngine extends QueryEngine { public List findChildren(Vertex start) { GraphTraversal pipe = this.g.V(start).union( - __.outE().has("isParent", true), - __.inE().has("isParent-REV", true) + __.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), true), + __.inE().has(EdgeProperties.in(EdgeProperty.IS_PARENT), true) ).otherV().dedup(); return pipe.toList(); @@ -104,9 +105,18 @@ public class GraphTraversalQueryEngine extends QueryEngine { @Override public List findDeletable(Vertex start) { GraphTraversal pipe = this.g - .V(start).emit(v -> true).repeat(__.outE().or( - __.has("isParent", true), - __.has("hasDelTarget", true)).inV()); + .V(start).emit(v -> true).repeat( + __.union( + __.outE().or( + __.has(EdgeProperties.out(EdgeProperty.IS_PARENT), true), + __.has(EdgeProperties.out(EdgeProperty.HAS_DEL_TARGET), true) + ).inV(), + __.inE().or( + __.has(EdgeProperties.in(EdgeProperty.IS_PARENT), true), + __.has(EdgeProperties.in(EdgeProperty.HAS_DEL_TARGET), true) + ).outV() + ) + ); return pipe.toList(); } @@ -138,12 +148,15 @@ public class GraphTraversalQueryEngine extends QueryEngine { @Override public Tree findSubGraph(Vertex start, int iterations, boolean nodeOnly) { final GraphTraversal t = this.g.V(start).emit(v -> true).times(iterations).repeat( - __.outE().has("isParent", true).inV()); + __.union( + __.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), true).inV(), + __.inE().has(EdgeProperties.in(EdgeProperty.IS_PARENT), true).outV()) + ); if (!nodeOnly) { t.union( __.identity(), - __.bothE().has("isParent", false).dedup().otherV() + __.bothE().and(__.has(EdgeProperties.out(EdgeProperty.IS_PARENT), false), __.has(EdgeProperties.in(EdgeProperty.IS_PARENT), false)).dedup().otherV() ); } t.tree(); @@ -158,8 +171,8 @@ public class GraphTraversalQueryEngine extends QueryEngine { public List findEdgesForVersion(Vertex start, Loader loader) { final Set objects = loader.getAllObjects().keySet(); GraphTraversal pipeline = this.g.V(start).union( - __.inE().has("isParent", false).has("isParent-REV", false).where(__.outV().has(AAIProperties.NODE_TYPE, P.within(objects))), - __.outE().has("isParent", false).has("isParent-REV", false).where(__.inV().has(AAIProperties.NODE_TYPE, P.within(objects))) + __.inE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), false).has(EdgeProperties.in(EdgeProperty.IS_PARENT), false).where(__.outV().has(AAIProperties.NODE_TYPE, P.within(objects))), + __.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), false).has(EdgeProperties.in(EdgeProperty.IS_PARENT), false).where(__.inV().has(AAIProperties.NODE_TYPE, P.within(objects))) ).dedup(); return pipeline.toList(); @@ -169,8 +182,8 @@ public class GraphTraversalQueryEngine extends QueryEngine { @Override public List findCousinVertices(Vertex start) { GraphTraversal pipeline = this.g.V(start).union( - __.inE().has("isParent", false).has("isParent-REV", false), - __.outE().has("isParent", false).has("isParent-REV", false)).otherV().dedup(); + __.inE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), false).has(EdgeProperties.in(EdgeProperty.IS_PARENT), false), + __.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), false).has(EdgeProperties.in(EdgeProperty.IS_PARENT), false)).otherV().dedup(); return pipeline.toList(); }