From f0d0c453645d19788da666d0e3c7c6ed9bb2516a Mon Sep 17 00:00:00 2001 From: "Maharajh, Robby (rx2202)" Date: Thu, 22 Mar 2018 16:12:12 -0400 Subject: Add to aai-common query builder get parent step Issue-ID: AAI-962 Change-Id: Ib4aa4ec3453f2c7099e1d7191917b44b323f2bb6 Signed-off-by: Maharajh, Robby (rx2202) --- .../aai/query/builder/GraphTraversalBuilder.java | 16 +++++++++ .../aai/query/builder/GremlinQueryBuilder.java | 18 ++++++++++ .../org/onap/aai/query/builder/QueryBuilder.java | 39 ++++++++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) (limited to 'aai-core/src/main') diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java index 85b484a7..b298dbb9 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java @@ -26,6 +26,7 @@ import java.util.Optional; import java.util.Set; import org.apache.tinkerpop.gremlin.process.traversal.P; +import org.apache.tinkerpop.gremlin.process.traversal.Path; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; @@ -477,6 +478,16 @@ public abstract class GraphTraversalBuilder extends QueryBuilder { stepIndex++; return this; } + + /** + * {@inheritDoc} + */ + @Override + public QueryBuilder path(){ + this.traversal.path(); + stepIndex++; + return (QueryBuilder)this; + } @Override public QueryBuilder outE() { @@ -757,4 +768,9 @@ public abstract class GraphTraversalBuilder extends QueryBuilder { return this.completeTraversal.toList(); } + protected QueryBuilder has(String key, String value) { + traversal.has(key, value); + + return (QueryBuilder)this; + } } diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java index 55faa4dc..010dfa50 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.google.common.base.Joiner; +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.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Direction; @@ -525,6 +527,16 @@ public abstract class GremlinQueryBuilder extends QueryBuilder { stepIndex++; return this; } + + /** + * {@inheritDoc} + */ + @Override + public QueryBuilder path(){ + this.list.add(".path()"); + stepIndex++; + return (QueryBuilder)this; + } @Override public QueryBuilder outE() { @@ -678,5 +690,11 @@ public abstract class GremlinQueryBuilder extends QueryBuilder { return (List)this.completeTraversal.toList(); } + + protected QueryBuilder has(String key, String value) { + this.list.add(".has('" + key + "','" + value + "')"); + + return (QueryBuilder)this; + } } diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java index 89c15f25..0350aba2 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java @@ -27,6 +27,7 @@ import java.util.Map; import javax.ws.rs.core.MultivaluedMap; +import org.apache.tinkerpop.gremlin.process.traversal.Path; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -36,6 +37,8 @@ import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; import org.onap.aai.parsers.query.QueryParser; import org.onap.aai.parsers.query.QueryParserStrategy; +import org.onap.aai.serialization.db.AAIDirection; +import org.onap.aai.serialization.db.EdgeProperty; import org.onap.aai.serialization.db.EdgeType; /** @@ -405,16 +408,48 @@ public abstract class QueryBuilder implements Iterator { * @return a QueryBuilder with the simplePath step appended to its traversal */ public abstract QueryBuilder simplePath(); + + /** + * + * @return QueryBuilder with the path step appended to its traversal + */ + public abstract QueryBuilder path(); public abstract void markContainer(); public abstract QueryBuilder getContainerQuery(); public abstract List toList(); - + + /** + * Used to skip step if there is an optional property missing. + * @param key + * @param value + * @return + */ public QueryBuilder getVerticesByProperty(String key, MissingOptionalParameter value) { return (QueryBuilder) this; } - + /** + * TODO the edge direction is hardcoded here, make it more generic + * Returns the parent edge of the vertex + * @return + */ + public QueryBuilder getParentEdge() { + this.outE().has(EdgeProperty.CONTAINS.toString(), AAIDirection.IN.toString()); + return (QueryBuilder)this; + } + + /** + * TODO the edge direction is hardcoded here, make it more generic + * Returns the parent vertex of the vertex + * @return + */ + public QueryBuilder getParentVertex() { + this.getParentEdge().inV(); + return (QueryBuilder)this; + } + + protected abstract QueryBuilder has(String key, String value); } -- cgit 1.2.3-korg