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.onap.aai.exceptions.AAIException;
23 import org.onap.aai.introspection.Introspector;
24 import org.onap.aai.introspection.Loader;
25 import org.onap.aai.parsers.uri.Parsable;
26 import org.onap.aai.parsers.uri.URIParser;
27 import org.onap.aai.parsers.uri.URIToDBKey;
28 import org.onap.aai.query.builder.QueryBuilder;
29 import org.onap.aai.serialization.db.EdgeType;
31 import javax.ws.rs.core.MultivaluedMap;
32 import javax.ws.rs.core.UriBuilder;
33 import java.io.UnsupportedEncodingException;
38 * The Class UniqueURIQueryParser.
40 public class UniqueURIQueryParser extends QueryParser implements Parsable {
43 private URIToDBKey dbKeyParser = null;
45 private Introspector previous = null;
47 private boolean endsInContainer = false;
49 private Introspector finalContainer = null;
51 private String parentName = "";
54 * Instantiates a new unique URI query parser.
56 * @param loader the loader
57 * @param queryBuilder the query builder
59 * @throws UnsupportedEncodingException the unsupported encoding exception
60 * @throws IllegalArgumentException the illegal argument exception
61 * @throws AAIException the AAI exception
63 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder, URI uri) throws UnsupportedEncodingException, IllegalArgumentException, AAIException {
64 super(loader, queryBuilder, uri);
65 URIParser parser = new URIParser(loader, uri);
68 if (!endsInContainer) {
69 this.dbKeyParser = new URIToDBKey(loader, uri);
70 String dbKey = (String)dbKeyParser.getResult();
71 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
72 queryBuilder.markParentBoundary();
74 if (!(parentName.equals("") || parentName.equals(this.resultResource))) {
75 URI parentUri = UriBuilder.fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(containerResource))).build();
76 this.dbKeyParser = new URIToDBKey(loader, parentUri);
77 this.parentQueryBuilder = queryBuilder.newInstance().getVerticesByIndexedProperty("aai-unique-key", (String)dbKeyParser.getResult());
78 this.parentResourceType = parentName;
80 this.containerResource = "";
82 URI parentUri = UriBuilder.fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(this.finalContainer.getDbName()))).build();
83 this.dbKeyParser = new URIToDBKey(loader, parentUri);
84 String dbKey = (String)dbKeyParser.getResult();
85 this.parentResourceType = parentName;
87 if (!dbKey.equals("")) {
88 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
89 queryBuilder.markParentBoundary();
90 queryBuilder.createEdgeTraversal(EdgeType.TREE, previous, finalContainer);
94 queryBuilder.createContainerQuery(finalContainer);
102 * Instantiates a new unique URI query parser.
104 * @param loader the loader
105 * @param queryBuilder the query builder
107 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder) {
108 super(loader, queryBuilder);
115 public void processNamespace(Introspector obj) {
123 public String getCloudRegionTransform() {
131 public boolean useOriginalLoader() {
137 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
138 throws AAIException {
139 this.resultResource = obj.getDbName();
140 if (previous != null) {
141 this.parentName = previous.getDbName();
149 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
150 boolean isFinalContainer) throws AAIException {
151 this.containerResource = obj.getName();
152 if (previous != null) {
153 this.parentName = previous.getDbName();
155 if (isFinalContainer) {
156 this.endsInContainer = true;
157 this.resultResource = obj.getChildDBName();
159 this.finalContainer = obj;