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=========================================================
21 package org.onap.aai.parsers.query;
23 import java.io.UnsupportedEncodingException;
26 import javax.ws.rs.core.MultivaluedMap;
27 import javax.ws.rs.core.UriBuilder;
29 import org.onap.aai.edges.enums.EdgeType;
30 import org.onap.aai.exceptions.AAIException;
31 import org.onap.aai.introspection.Introspector;
32 import org.onap.aai.introspection.Loader;
33 import org.onap.aai.parsers.uri.Parsable;
34 import org.onap.aai.parsers.uri.URIParser;
35 import org.onap.aai.parsers.uri.URIToDBKey;
36 import org.onap.aai.query.builder.QueryBuilder;
39 * The Class UniqueURIQueryParser.
41 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)
64 throws UnsupportedEncodingException, IllegalArgumentException, AAIException {
65 super(loader, queryBuilder, uri);
66 URIParser parser = new URIParser(loader, uri);
69 if (!endsInContainer) {
70 this.dbKeyParser = new URIToDBKey(loader, uri);
71 String dbKey = (String) dbKeyParser.getResult();
72 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
73 queryBuilder.markParentBoundary();
75 if (!(parentName.equals("") || parentName.equals(this.resultResource))) {
76 URI parentUri = UriBuilder
77 .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",
80 (String) dbKeyParser.getResult());
81 this.parentResourceType = parentName;
83 this.containerResource = "";
85 URI parentUri = UriBuilder
86 .fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(this.finalContainer.getDbName())))
88 this.dbKeyParser = new URIToDBKey(loader, parentUri);
89 String dbKey = (String) dbKeyParser.getResult();
90 this.parentResourceType = parentName;
92 if (!dbKey.equals("")) {
93 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
94 queryBuilder.markParentBoundary();
95 queryBuilder.createEdgeTraversal(EdgeType.TREE, previous, finalContainer);
99 queryBuilder.createContainerQuery(finalContainer);
105 * Instantiates a new unique URI query parser.
107 * @param loader the loader
108 * @param queryBuilder the query builder
110 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder) {
111 super(loader, queryBuilder);
118 public void processNamespace(Introspector obj) {
126 public String getCloudRegionTransform() {
134 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();
150 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
151 boolean isFinalContainer) throws AAIException {
152 this.containerResource = obj.getName();
153 if (previous != null) {
154 this.parentName = previous.getDbName();
156 if (isFinalContainer) {
157 this.endsInContainer = true;
158 this.resultResource = obj.getChildDBName();
160 this.finalContainer = obj;