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;
34 import org.onap.aai.exceptions.AAIException;
35 import org.onap.aai.introspection.Introspector;
36 import org.onap.aai.introspection.Loader;
37 import org.onap.aai.parsers.query.QueryParser;
38 import org.onap.aai.parsers.query.TraversalStrategy;
39 import org.onap.aai.parsers.query.UniqueStrategy;
42 * The Class GremlinUnique.
44 public class GremlinUnique<E> extends GremlinQueryBuilder<E> {
47 * Instantiates a new gremlin unique.
49 * @param loader the loader
51 public GremlinUnique(Loader loader, GraphTraversalSource source) {
52 super(loader, source);
53 this.factory = new UniqueStrategy(this.loader, this);
57 * Instantiates a new gremlin unique.
59 * @param loader the loader
60 * @param start the start
62 public GremlinUnique(Loader loader, GraphTraversalSource source, Vertex start) {
63 super(loader, source, start);
64 this.factory = new UniqueStrategy(this.loader, this);
67 protected GremlinUnique(List<String> traversal, Loader loader, GraphTraversalSource source, GremlinQueryBuilder<E> gtb) {
68 super(loader, source);
69 this.list = traversal;
70 this.stepIndex = gtb.getStepIndex();
71 this.parentStepIndex = gtb.getParentStepIndex();
72 this.containerStepIndex = gtb.getContainerStepIndex();
73 this.factory = new TraversalStrategy(this.loader, this);
74 this.start = gtb.getStart();
81 public QueryParser createQueryFromURI(URI uri) throws UnsupportedEncodingException, AAIException {
82 return factory.buildURIParser(uri);
89 public QueryParser createQueryFromRelationship(Introspector relationship) throws UnsupportedEncodingException, AAIException {
90 return factory.buildRelationshipParser(relationship);
97 public QueryParser createQueryFromURI(URI uri, MultivaluedMap<String, String> queryParams)
98 throws UnsupportedEncodingException, AAIException {
99 return factory.buildURIParser(uri, queryParams);
106 public QueryParser createQueryFromObjectName(String objName) {
107 return factory.buildObjectNameParser(objName);
114 public QueryBuilder<E> newInstance() {
115 return new GremlinUnique<>(loader, source);
122 public QueryBuilder<E> newInstance(Vertex start) {
123 return new GremlinUnique<>(loader, source, start);
127 protected QueryBuilder<E> cloneQueryAtStep(int index) {
135 List<String> newList = new ArrayList<>();
136 for (int i = 0; i < idx; i++) {
137 newList.add(this.list.get(i));
140 return new GremlinUnique<>(newList, loader, source, this);