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