diff options
Diffstat (limited to 'aai-core/src/main')
3 files changed, 25 insertions, 24 deletions
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 3c5c4489..b8a354ea 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 @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2023 Deutsche Telekom. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -62,6 +64,9 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { protected GraphTraversal<Vertex, E> traversal = null; protected Admin<Vertex, E> completeTraversal = null; + protected QueryBuilder<E> containerQuery; + protected QueryBuilder<E> parentQuery; + /** * Instantiates a new graph traversal builder. * @@ -351,7 +356,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { traversal.has(AAIProperties.NODE_TYPE, type); } stepIndex++; - markContainer(); + markContainerIndex(); return (QueryBuilder<Vertex>) this; } @@ -838,21 +843,16 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { return this; } - /** - * @{inheritDoc} - */ @Override public <E2> E2 getQuery() { return (E2) this.traversal; } - /** - * @{inheritDoc} - */ @Override public QueryBuilder<E> getParentQuery() { - - return cloneQueryAtStep(parentStepIndex); + return this.parentQuery != null + ? this.parentQuery + : cloneQueryAtStep(parentStepIndex); } @Override @@ -861,26 +861,22 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { if (this.parentStepIndex == 0) { return removeQueryStepsBetween(0, containerStepIndex); } else { - return cloneQueryAtStep(containerStepIndex); + return this.containerQuery; } } - /** - * @{inheritDoc} - */ @Override public void markParentBoundary() { + this.parentQuery = cloneQueryAtStep(stepIndex); parentStepIndex = stepIndex; } @Override - public void markContainer() { + public void markContainerIndex() { + this.containerQuery = cloneQueryAtStep(stepIndex); containerStepIndex = stepIndex; } - /** - * @{inheritDoc} - */ @Override public Vertex getStart() { return this.start; @@ -945,7 +941,9 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { if (this.completeTraversal == null) { executeQuery(); } - return this.completeTraversal.toList(); + // clone is necessary since toList would optimize traversal steps + // which messes with the indeces that are registered while parsing + return this.completeTraversal.clone().toList(); } protected QueryBuilder<Edge> has(String key, String value) { 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 4500a47e..e68cfe69 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 @@ -574,7 +574,7 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> { list.add(".has('aai-node-type', '" + type + "')"); } stepIndex++; - this.markContainer(); + this.markContainerIndex(); return (QueryBuilder<Vertex>) this; } @@ -879,7 +879,7 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> { } @Override - public void markContainer() { + public void markContainerIndex() { this.containerStepIndex = stepIndex; } 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 2bc90726..6d56d1af 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 @@ -487,7 +487,7 @@ public abstract class QueryBuilder<E> implements Iterator<E> { * This is necessary in cases such as "if the Optional Property 1 is sent, * find all Nodes of type A with edges to Nodes of type B with property 1, * otherwise, simply find all nodes of type A". - * + * * @param type * @param outNodeType * @param inNodeType @@ -506,7 +506,7 @@ public abstract class QueryBuilder<E> implements Iterator<E> { * This is necessary in cases such as "if the Optional Property 1 is sent, * find all Nodes of type A with edges to Nodes of type B with property 1, * otherwise, simply find all nodes of type A". - * + * * @param type * @param outNodeType * @param inNodeType @@ -603,7 +603,7 @@ public abstract class QueryBuilder<E> implements Iterator<E> { public abstract <E2> E2 getQuery(); /** - * Form boundary. + * Marks the current step index as the boundary to the parent. */ public abstract void markParentBoundary(); @@ -721,7 +721,10 @@ public abstract class QueryBuilder<E> implements Iterator<E> { */ public abstract QueryBuilder<Path> path(); - public abstract void markContainer(); + /** + * Marks the current step index as the container step. + */ + public abstract void markContainerIndex(); public abstract QueryBuilder<E> getContainerQuery(); |