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