2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.query.builder;
24 import java.io.UnsupportedEncodingException;
26 import java.util.ArrayList;
27 import java.util.List;
29 import javax.ws.rs.core.MultivaluedMap;
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32 import org.apache.tinkerpop.gremlin.structure.Vertex;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.introspection.Introspector;
35 import org.onap.aai.introspection.Loader;
36 import org.onap.aai.parsers.query.QueryParser;
37 import org.onap.aai.parsers.query.TraversalStrategy;
38 import org.onap.aai.serialization.db.EdgeRules;
41 * The Class GremlinTraversal.
43 public class GremlinTraversal<E> extends GremlinQueryBuilder<E> {
46 * Instantiates a new gremlin traversal.
48 * @param loader the loader
50 public GremlinTraversal(Loader loader, GraphTraversalSource source, EdgeRules ers) {
51 super(loader, source, ers);
52 this.factory = new TraversalStrategy(this.loader, this);
56 * Instantiates a new gremlin traversal.
58 * @param loader the loader
60 public GremlinTraversal(Loader loader, GraphTraversalSource source) {
61 super(loader, source);
62 this.factory = new TraversalStrategy(this.loader, this);
66 * Instantiates a new gremlin traversal.
68 * @param loader the loader
69 * @param start the start
71 public GremlinTraversal(Loader loader, GraphTraversalSource source, Vertex start) {
72 super(loader, source, start);
73 this.factory = new TraversalStrategy(this.loader, this);
77 * Instantiates a new gremlin traversal.
79 * @param loader the loader
80 * @param start the start
82 public GremlinTraversal(Loader loader, GraphTraversalSource source, Vertex start, EdgeRules ers) {
83 super(loader, source, start, ers);
84 this.factory = new TraversalStrategy(this.loader, this);
87 protected GremlinTraversal(List<String> traversal, Loader loader, GraphTraversalSource source, GremlinQueryBuilder<E> gtb) {
88 super(loader, source);
89 this.list = traversal;
90 this.stepIndex = gtb.getStepIndex();
91 this.parentStepIndex = gtb.getParentStepIndex();
92 this.containerStepIndex = gtb.getContainerStepIndex();
93 this.factory = new TraversalStrategy(this.loader, this);
94 this.start = gtb.getStart();
101 public QueryParser createQueryFromURI(URI uri) throws UnsupportedEncodingException, AAIException {
102 return factory.buildURIParser(uri);
109 public QueryParser createQueryFromRelationship(Introspector relationship) throws UnsupportedEncodingException, AAIException {
110 return factory.buildRelationshipParser(relationship);
118 public QueryParser createQueryFromURI(URI uri, MultivaluedMap<String, String> queryParams)
119 throws UnsupportedEncodingException, AAIException {
120 return factory.buildURIParser(uri, queryParams);
127 public QueryParser createQueryFromObjectName(String objName) {
128 return factory.buildObjectNameParser(objName);
135 public QueryBuilder<E> newInstance(Vertex start) {
136 return new GremlinTraversal<>(loader, source, start);
143 public QueryBuilder<E> newInstance() {
144 return new GremlinTraversal<>(loader, source);
148 protected QueryBuilder<E> cloneQueryAtStep(int index) {
156 List<String> newList = new ArrayList<>();
157 for (int i = 0; i < idx; i++) {
158 newList.add(this.list.get(i));
161 return new GremlinTraversal<>(newList, loader, source, this);