Update the aai-common with the latest code
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / parsers / query / QueryParser.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 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
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.openecomp.aai.parsers.query;
22
23 import java.net.URI;
24
25 import org.apache.tinkerpop.gremlin.structure.Vertex;
26
27 import org.openecomp.aai.db.props.AAIProperties;
28 import org.openecomp.aai.introspection.Loader;
29 import org.openecomp.aai.introspection.LoaderFactory;
30 import org.openecomp.aai.query.builder.QueryBuilder;
31
32 /**
33  * The Class QueryParser.
34  */
35 public abstract class QueryParser {
36
37         protected Loader loader = null;
38         protected Loader latestLoader = null;
39         protected QueryBuilder<Vertex> queryBuilder = null;
40         
41         protected QueryBuilder<Vertex> parentQueryBuilder = null;
42         
43         protected URI uri = null;
44         
45         protected String resultResource = "";
46         
47         protected String parentResourceType = "";
48         
49         protected String containerResource = "";
50                 
51         /**
52          * Instantiates a new query parser.
53          *
54          * @param loader the loader
55          * @param queryBuilder the query builder
56          * @param uri the uri
57          */
58         protected QueryParser(Loader loader, QueryBuilder<Vertex> queryBuilder, URI uri) {
59                 this.uri = uri;
60                 this.queryBuilder = queryBuilder;
61                 this.loader = loader;
62                 this.latestLoader = LoaderFactory.createLoaderForVersion(loader.getModelType(), AAIProperties.LATEST);
63         }
64         
65         /**
66          * Instantiates a new query parser.
67          *
68          * @param loader the loader
69          * @param queryBuilder the query builder
70          */
71         protected QueryParser(Loader loader, QueryBuilder<Vertex> queryBuilder) {
72                 this.queryBuilder = queryBuilder;
73                 this.loader = loader;
74                 this.latestLoader = LoaderFactory.createLoaderForVersion(loader.getModelType(), AAIProperties.LATEST);
75         }
76         
77         /**
78          * Gets the container type.
79          *
80          * @return the container type
81          */
82         public String getContainerType() {
83                 
84                 return this.containerResource;
85         }
86         
87         /**
88          * Gets the parent result type.
89          *
90          * @return the parent result type
91          */
92         public String getParentResultType() {
93                 return this.parentResourceType;
94         }
95         
96         /**
97          * Gets the result type.
98          *
99          * @return the result type
100          */
101         public String getResultType() {
102                 return this.resultResource;
103         }
104         
105         /**
106          * Gets the query builder.
107          *
108          * @return the query builder
109          */
110         public QueryBuilder<Vertex> getQueryBuilder() {
111                 return this.queryBuilder;
112         }
113         
114         /**
115          * Gets the uri.
116          *
117          * @return the uri
118          */
119         public URI getUri() {
120                 return this.uri;
121         }
122         
123         /**
124          * Gets the parent query builder.
125          *
126          * @return the parent query builder
127          */
128         public QueryBuilder<Vertex> getParentQueryBuilder() {
129                 if (this.parentQueryBuilder != null) {
130                         return this.parentQueryBuilder;
131                 } else {
132                         return this.queryBuilder;
133                 }
134         }
135         
136         /**
137          * Checks if is dependent.
138          *
139          * @return true, if is dependent
140          */
141         public boolean isDependent() {
142                 return !this.queryBuilder.getQuery().toString().equals(this.queryBuilder.getParentQuery().getQuery().toString());
143         }
144
145 }
146
147