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.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;
33 * The Class QueryParser.
35 public abstract class QueryParser {
37 protected Loader loader = null;
38 protected Loader latestLoader = null;
39 protected QueryBuilder<Vertex> queryBuilder = null;
41 protected QueryBuilder<Vertex> parentQueryBuilder = null;
43 protected URI uri = null;
45 protected String resultResource = "";
47 protected String parentResourceType = "";
49 protected String containerResource = "";
52 * Instantiates a new query parser.
54 * @param loader the loader
55 * @param queryBuilder the query builder
58 protected QueryParser(Loader loader, QueryBuilder<Vertex> queryBuilder, URI uri) {
60 this.queryBuilder = queryBuilder;
62 LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class);
63 SchemaVersion latest = ((SchemaVersions) SpringContextAware.getBean("schemaVersions")).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 this.latestLoader = LoaderUtil.getLatestVersion();
81 * Gets the container type.
83 * @return the container type
85 public String getContainerType() {
87 return this.containerResource;
91 * Gets the parent result type.
93 * @return the parent result type
95 public String getParentResultType() {
96 return this.parentResourceType;
100 * Gets the result type.
102 * @return the result type
104 public String getResultType() {
105 return this.resultResource;
109 * Gets the query builder.
111 * @return the query builder
113 public QueryBuilder<Vertex> getQueryBuilder() {
114 return this.queryBuilder;
122 public URI getUri() {
127 * Gets the parent query builder.
129 * @return the parent query builder
131 public QueryBuilder<Vertex> getParentQueryBuilder() {
132 if (this.parentQueryBuilder != null) {
133 return this.parentQueryBuilder;
135 return this.queryBuilder;
140 * Checks if is dependent.
142 * @return true, if is dependent
144 public boolean isDependent() {
145 return !this.queryBuilder.getQuery().toString().equals(this.queryBuilder.getParentQuery().getQuery().toString());