2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.aai.query.builder;
23 import java.io.UnsupportedEncodingException;
25 import java.util.ArrayList;
26 import java.util.List;
28 import javax.ws.rs.core.MultivaluedMap;
30 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
31 import org.apache.tinkerpop.gremlin.structure.Vertex;
32 import org.openecomp.aai.exceptions.AAIException;
33 import org.openecomp.aai.introspection.Introspector;
34 import org.openecomp.aai.introspection.Loader;
35 import org.openecomp.aai.parsers.query.QueryParser;
36 import org.openecomp.aai.parsers.query.TraversalStrategy;
39 * The Class GremlinTraversal.
41 public class GremlinTraversal<E> extends GremlinQueryBuilder<E> {
44 * Instantiates a new gremlin traversal.
46 * @param loader the loader
48 public GremlinTraversal(Loader loader, GraphTraversalSource source) {
49 super(loader, source);
50 this.factory = new TraversalStrategy(this.loader, this);
54 * Instantiates a new gremlin traversal.
56 * @param loader the loader
57 * @param start the start
59 public GremlinTraversal(Loader loader, GraphTraversalSource source, Vertex start) {
60 super(loader, source, start);
61 this.factory = new TraversalStrategy(this.loader, this);
64 protected GremlinTraversal(List<String> traversal, Loader loader, GraphTraversalSource source, GremlinQueryBuilder<E> gtb) {
65 super(loader, source);
66 this.list = traversal;
67 this.stepIndex = gtb.getStepIndex();
68 this.parentStepIndex = gtb.getParentStepIndex();
69 this.containerStepIndex = gtb.getContainerStepIndex();
70 this.factory = new TraversalStrategy(this.loader, this);
71 this.start = gtb.getStart();
78 public QueryParser createQueryFromURI(URI uri) throws UnsupportedEncodingException, AAIException {
79 return factory.buildURIParser(uri);
86 public QueryParser createQueryFromRelationship(Introspector relationship) throws UnsupportedEncodingException, AAIException {
87 return factory.buildRelationshipParser(relationship);
95 public QueryParser createQueryFromURI(URI uri, MultivaluedMap<String, String> queryParams)
96 throws UnsupportedEncodingException, AAIException {
97 return factory.buildURIParser(uri, queryParams);
104 public QueryParser createQueryFromObjectName(String objName) {
105 return factory.buildObjectNameParser(objName);
112 public QueryBuilder<E> newInstance(Vertex start) {
113 return new GremlinTraversal<>(loader, source, start);
120 public QueryBuilder<E> newInstance() {
121 return new GremlinTraversal<>(loader, source);
125 protected QueryBuilder<E> cloneQueryAtStep(int index) {
129 List<String> newList = new ArrayList<>();
130 for (int i = 0; i < index; i++) {
131 newList.add(this.list.get(i));
134 return new GremlinTraversal<>(newList, loader, source, this);