2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.parsers.query;
24 import org.onap.aai.exceptions.AAIException;
25 import org.onap.aai.introspection.Introspector;
26 import org.onap.aai.introspection.Loader;
27 import org.onap.aai.parsers.uri.Parsable;
28 import org.onap.aai.parsers.uri.URIParser;
29 import org.onap.aai.parsers.uri.URIToDBKey;
30 import org.onap.aai.query.builder.QueryBuilder;
31 import org.onap.aai.serialization.db.EdgeType;
33 import javax.ws.rs.core.MultivaluedMap;
34 import javax.ws.rs.core.UriBuilder;
35 import java.io.UnsupportedEncodingException;
40 * The Class UniqueURIQueryParser.
42 public class UniqueURIQueryParser extends QueryParser implements Parsable {
45 private URIToDBKey dbKeyParser = null;
47 private Introspector previous = null;
49 private boolean endsInContainer = false;
51 private Introspector finalContainer = null;
53 private String parentName = "";
56 * Instantiates a new unique URI query parser.
58 * @param loader the loader
59 * @param queryBuilder the query builder
61 * @throws UnsupportedEncodingException the unsupported encoding exception
62 * @throws IllegalArgumentException the illegal argument exception
63 * @throws AAIException the AAI exception
65 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder, URI uri) throws UnsupportedEncodingException, IllegalArgumentException, AAIException {
66 super(loader, queryBuilder, uri);
67 URIParser parser = new URIParser(loader, uri);
70 if (!endsInContainer) {
71 this.dbKeyParser = new URIToDBKey(loader, uri);
72 String dbKey = (String)dbKeyParser.getResult();
73 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
74 queryBuilder.markParentBoundary();
76 if (!(parentName.equals("") || parentName.equals(this.resultResource))) {
77 URI parentUri = UriBuilder.fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(containerResource))).build();
78 this.dbKeyParser = new URIToDBKey(loader, parentUri);
79 this.parentQueryBuilder = queryBuilder.newInstance().getVerticesByIndexedProperty("aai-unique-key", (String)dbKeyParser.getResult());
80 this.parentResourceType = parentName;
82 this.containerResource = "";
84 URI parentUri = UriBuilder.fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(this.finalContainer.getDbName()))).build();
85 this.dbKeyParser = new URIToDBKey(loader, parentUri);
86 String dbKey = (String)dbKeyParser.getResult();
87 this.parentResourceType = parentName;
89 if (!dbKey.equals("")) {
90 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
91 queryBuilder.markParentBoundary();
92 queryBuilder.createEdgeTraversal(EdgeType.TREE, previous, finalContainer);
96 queryBuilder.createContainerQuery(finalContainer);
104 * Instantiates a new unique URI query parser.
106 * @param loader the loader
107 * @param queryBuilder the query builder
109 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder) {
110 super(loader, queryBuilder);
117 public void processNamespace(Introspector obj) {
125 public String getCloudRegionTransform() {
133 public boolean useOriginalLoader() {
139 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
140 throws AAIException {
141 this.resultResource = obj.getDbName();
142 if (previous != null) {
143 this.parentName = previous.getDbName();
151 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
152 boolean isFinalContainer) throws AAIException {
153 this.containerResource = obj.getName();
154 if (previous != null) {
155 this.parentName = previous.getDbName();
157 if (isFinalContainer) {
158 this.endsInContainer = true;
159 this.resultResource = obj.getChildDBName();
161 this.finalContainer = obj;