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