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 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.onap.aai.db.props.AAIProperties;
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;
39 * The Class GremlinTraversal.
41 public class HistoryGremlinTraversal<E> extends GremlinTraversal<E> {
44 * Instantiates a new gremlin traversal.
46 * @param loader the loader
48 public HistoryGremlinTraversal(Loader loader, GraphTraversalSource source) {
49 super(loader, source);
53 * Instantiates a new gremlin traversal.
55 * @param loader the loader
56 * @param start the start
58 public HistoryGremlinTraversal(Loader loader, GraphTraversalSource source, Vertex start) {
59 super(loader, source, start);
62 protected HistoryGremlinTraversal(List<String> traversal, Loader loader, GraphTraversalSource source,
63 GremlinQueryBuilder<E> gtb) {
64 super(traversal, loader, source, gtb);
71 public QueryParser createQueryFromURI(URI uri) throws UnsupportedEncodingException, AAIException {
72 return factory.buildURIParser(uri);
79 public QueryParser createQueryFromRelationship(Introspector relationship)
80 throws UnsupportedEncodingException, AAIException {
81 return factory.buildRelationshipParser(relationship);
88 public QueryParser createQueryFromURI(URI uri, MultivaluedMap<String, String> queryParams)
89 throws UnsupportedEncodingException, AAIException {
90 return factory.buildURIParser(uri, queryParams);
97 public QueryParser createQueryFromObjectName(String objName) {
98 return factory.buildObjectNameParser(objName);
105 public QueryBuilder<E> newInstance(Vertex start) {
106 return new HistoryGremlinTraversal<>(loader, source, start);
113 public QueryBuilder<E> newInstance() {
114 return new HistoryGremlinTraversal<>(loader, source);
118 protected QueryBuilder<E> cloneQueryAtStep(int index) {
126 List<String> newList = new ArrayList<>();
127 for (int i = 0; i < idx; i++) {
128 newList.add(this.list.get(i));
131 return new HistoryGremlinTraversal<>(newList, loader, source, this);
135 protected void vertexHas(String key, Object value) {
136 super.vertexHas(key, value);
137 touchHistoryProperties(key, value);
141 protected void vertexHasNot(String key) {
142 super.vertexHasNot(key);
143 touchHistoryProperties(key);
148 protected void vertexHas(String key) {
149 super.vertexHas(key);
150 touchHistoryProperties(key);
154 * This is required for the subgraphstrategies to work
156 private void touchHistoryProperties(String key) {
157 if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
158 list.add(".where(__.properties('" + key + "'))");
163 private void touchHistoryProperties(String key, Object value) {
164 if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
165 list.add(".where(__.properties('" + key + "').hasValue(" + value + "))");