Update schema service to fail to start
[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.introspection.Loader;
25 import org.onap.aai.introspection.LoaderFactory;
26 import org.onap.aai.introspection.LoaderUtil;
27 import org.onap.aai.query.builder.QueryBuilder;
28 import org.onap.aai.setup.SchemaVersion;
29 import org.onap.aai.setup.SchemaVersions;
30 import java.net.URI;
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                 LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class);
63                 SchemaVersion latest = ((SchemaVersions) SpringContextAware.getBean("schemaVersions")).getDefaultVersion();
64
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                 this.latestLoader = LoaderUtil.getLatestVersion();
78         }
79
80         /**
81          * Gets the container type.
82          *
83          * @return the container type
84          */
85         public String getContainerType() {
86
87                 return this.containerResource;
88         }
89
90         /**
91          * Gets the parent result type.
92          *
93          * @return the parent result type
94          */
95         public String getParentResultType() {
96                 return this.parentResourceType;
97         }
98
99         /**
100          * Gets the result type.
101          *
102          * @return the result type
103          */
104         public String getResultType() {
105                 return this.resultResource;
106         }
107
108         /**
109          * Gets the query builder.
110          *
111          * @return the query builder
112          */
113         public QueryBuilder<Vertex> getQueryBuilder() {
114                 return this.queryBuilder;
115         }
116
117         /**
118          * Gets the uri.
119          *
120          * @return the uri
121          */
122         public URI getUri() {
123                 return this.uri;
124         }
125
126         /**
127          * Gets the parent query builder.
128          *
129          * @return the parent query builder
130          */
131         public QueryBuilder<Vertex> getParentQueryBuilder() {
132                 if (this.parentQueryBuilder != null) {
133                         return this.parentQueryBuilder;
134                 } else {
135                         return this.queryBuilder;
136                 }
137         }
138
139         /**
140          * Checks if is dependent.
141          *
142          * @return true, if is dependent
143          */
144         public boolean isDependent() {
145                 return !this.queryBuilder.getQuery().toString().equals(this.queryBuilder.getParentQuery().getQuery().toString());
146         }
147
148 }
149
150