[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 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
26 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.onap.aai.db.props.AAIProperties;
29 import org.onap.aai.introspection.Loader;
30
31 public class HistoryTraversalURIOptimizedQuery<E> extends TraversalURIOptimizedQuery {
32
33     public HistoryTraversalURIOptimizedQuery(Loader loader, GraphTraversalSource source) {
34         super(loader, source);
35     }
36
37     public HistoryTraversalURIOptimizedQuery(Loader loader, GraphTraversalSource source, Vertex start) {
38         super(loader, source, start);
39     }
40
41     protected HistoryTraversalURIOptimizedQuery(GraphTraversal traversal, Loader loader, GraphTraversalSource source,
42                                                 GraphTraversalBuilder gtb) {
43         super(traversal, loader, source, gtb);
44     }
45
46     protected HistoryTraversalURIOptimizedQuery(GraphTraversal traversal, Loader loader, GraphTraversalSource source,
47                                                 GraphTraversalBuilder gtb, Map<Integer, String> stepToAaiUri) {
48         super(traversal, loader, source, gtb, stepToAaiUri);
49     }
50
51     @Override
52     protected void vertexHas(String key, Object value) {
53         super.vertexHas(key, value);
54         touchHistoryProperties(key, value);
55     }
56
57     @Override
58     protected void vertexHasNot(String key) {
59         super.vertexHasNot(key);
60         touchHistoryProperties(key);
61     }
62
63     @Override
64     protected void vertexHas(String key) {
65         super.vertexHas(key);
66         touchHistoryProperties(key);
67     }
68
69     private void touchHistoryProperties(String key) {
70         if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
71             traversal.where(__.properties(key));
72         }
73     }
74
75     private void touchHistoryProperties(String key, Object value) {
76         if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
77             traversal.where(__.properties(key).hasValue(value));
78         }
79     }
80 }