2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.parsers.query;
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;
34 * The Class QueryParser.
36 public abstract class QueryParser {
38 protected Loader loader = null;
39 protected Loader latestLoader = null;
40 protected QueryBuilder<Vertex> queryBuilder = null;
42 protected QueryBuilder<Vertex> parentQueryBuilder = null;
44 protected URI uri = null;
46 protected String resultResource = "";
48 protected String parentResourceType = "";
50 protected String containerResource = "";
53 * Instantiates a new query parser.
55 * @param loader the loader
56 * @param queryBuilder the query builder
59 protected QueryParser(Loader loader, QueryBuilder<Vertex> queryBuilder, URI uri) {
61 this.queryBuilder = queryBuilder;
63 LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class);
64 SchemaVersion latest = SpringContextAware.getBean(SchemaVersions.class).getDefaultVersion();
65 this.latestLoader = loaderFactory.createLoaderForVersion(loader.getModelType(), latest);
69 * Instantiates a new query parser.
71 * @param loader the loader
72 * @param queryBuilder the query builder
74 protected QueryParser(Loader loader, QueryBuilder<Vertex> queryBuilder) {
75 this.queryBuilder = queryBuilder;
77 LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class);
78 SchemaVersion latest = SpringContextAware.getBean(SchemaVersions.class).getDefaultVersion();
79 this.latestLoader = loaderFactory.createLoaderForVersion(loader.getModelType(), latest);
83 * Gets the container type.
85 * @return the container type
87 public String getContainerType() {
89 return this.containerResource;
93 * Gets the parent result type.
95 * @return the parent result type
97 public String getParentResultType() {
98 return this.parentResourceType;
102 * Gets the result type.
104 * @return the result type
106 public String getResultType() {
107 return this.resultResource;
111 * Gets the query builder.
113 * @return the query builder
115 public QueryBuilder<Vertex> getQueryBuilder() {
116 return this.queryBuilder;
124 public URI getUri() {
129 * Gets the parent query builder.
131 * @return the parent query builder
133 public QueryBuilder<Vertex> getParentQueryBuilder() {
134 if (this.parentQueryBuilder != null) {
135 return this.parentQueryBuilder;
137 return this.queryBuilder;
142 * Checks if is dependent.
144 * @return true, if is dependent
146 public boolean isDependent() {
147 return !this.queryBuilder.getQuery().toString().equals(this.queryBuilder.getParentQuery().getQuery().toString());