2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.onap.aai.query.builder;
23 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
25 import org.apache.tinkerpop.gremlin.structure.Vertex;
26 import org.onap.aai.db.props.AAIProperties;
27 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.introspection.Introspector;
29 import org.onap.aai.introspection.Loader;
30 import org.onap.aai.parsers.query.QueryParser;
31 import org.onap.aai.parsers.query.TraversalStrategy;
33 import javax.ws.rs.core.MultivaluedMap;
34 import java.io.UnsupportedEncodingException;
36 import java.util.ArrayList;
37 import java.util.List;
40 * The Class GremlinTraversal.
42 public class HistoryGremlinTraversal<E> extends GremlinTraversal<E> {
45 * Instantiates a new gremlin traversal.
47 * @param loader the loader
49 public HistoryGremlinTraversal(Loader loader, GraphTraversalSource source) {
50 super(loader, source);
54 * Instantiates a new gremlin traversal.
56 * @param loader the loader
57 * @param start the start
59 public HistoryGremlinTraversal(Loader loader, GraphTraversalSource source, Vertex start) {
60 super(loader, source, start);
64 protected HistoryGremlinTraversal(List<String> traversal, Loader loader, GraphTraversalSource source,
65 GremlinQueryBuilder<E> gtb) {
66 super(traversal, loader, source, gtb);
73 public QueryParser createQueryFromURI(URI uri) throws UnsupportedEncodingException, AAIException {
74 return factory.buildURIParser(uri);
81 public QueryParser createQueryFromRelationship(Introspector relationship)
82 throws UnsupportedEncodingException, AAIException {
83 return factory.buildRelationshipParser(relationship);
90 public QueryParser createQueryFromURI(URI uri, MultivaluedMap<String, String> queryParams)
91 throws UnsupportedEncodingException, AAIException {
92 return factory.buildURIParser(uri, queryParams);
99 public QueryParser createQueryFromObjectName(String objName) {
100 return factory.buildObjectNameParser(objName);
107 public QueryBuilder<E> newInstance(Vertex start) {
108 return new HistoryGremlinTraversal<>(loader, source, start);
115 public QueryBuilder<E> newInstance() {
116 return new HistoryGremlinTraversal<>(loader, source);
120 protected QueryBuilder<E> cloneQueryAtStep(int index) {
128 List<String> newList = new ArrayList<>();
129 for (int i = 0; i < idx; i++) {
130 newList.add(this.list.get(i));
133 return new HistoryGremlinTraversal<>(newList, loader, source, this);
137 protected void vertexHas(String key, Object value) {
138 super.vertexHas(key, value);
139 touchHistoryProperties(key, value);
143 protected void vertexHasNot(String key) {
144 super.vertexHasNot(key);
145 touchHistoryProperties(key);
150 protected void vertexHas(String key) {
151 super.vertexHas(key);
152 touchHistoryProperties(key);
156 * This is required for the subgraphstrategies to work
158 private void touchHistoryProperties(String key){
159 if(key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
160 list.add(".where(__.properties('" + key + "'))");
165 private void touchHistoryProperties(String key, Object value) {
166 if(key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
167 list.add(".where(__.properties('" + key + "').hasValue(" + value + "))");