Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / query / builder / HistoryTraversalURIOptimizedQuery.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.query.builder;
22
23 import java.util.Map;
24
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
26 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
27 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
29 import org.onap.aai.db.props.AAIProperties;
30 import org.onap.aai.introspection.Loader;
31
32 public class HistoryTraversalURIOptimizedQuery<E> extends TraversalURIOptimizedQuery {
33
34     public HistoryTraversalURIOptimizedQuery(Loader loader, GraphTraversalSource source) {
35         super(loader, source);
36     }
37
38     public HistoryTraversalURIOptimizedQuery(Loader loader, GraphTraversalSource source, Vertex start) {
39         super(loader, source, start);
40     }
41
42     protected HistoryTraversalURIOptimizedQuery(GraphTraversal traversal, Loader loader, GraphTraversalSource source,
43             GraphTraversalBuilder gtb) {
44         super(traversal, loader, source, gtb);
45     }
46
47     protected HistoryTraversalURIOptimizedQuery(GraphTraversal traversal, Loader loader, GraphTraversalSource source,
48             GraphTraversalBuilder gtb, Map<Integer, String> stepToAaiUri) {
49         super(traversal, loader, source, gtb, stepToAaiUri);
50     }
51
52     @Override
53     protected void vertexHas(String key, Object value) {
54         super.vertexHas(key, value);
55         touchHistoryProperties(key, value);
56     }
57
58     @Override
59     protected void vertexHasNot(String key) {
60         super.vertexHasNot(key);
61         touchHistoryProperties(key);
62     }
63
64     @Override
65     protected void vertexHas(String key) {
66         super.vertexHas(key);
67         touchHistoryProperties(key);
68     }
69
70     private void touchHistoryProperties(String key) {
71         if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
72             traversal.where(__.properties(key));
73         }
74     }
75
76     private void touchHistoryProperties(String key, Object value) {
77         if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
78             traversal.where(__.properties(key).hasValue(value));
79         }
80     }
81 }