2 * ============LICENSE_START=======================================================
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
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.openecomp.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.openecomp.aai.exceptions.AAIException;
30 import org.openecomp.aai.introspection.Introspector;
31 import org.openecomp.aai.introspection.Loader;
32 import org.openecomp.aai.parsers.uri.Parsable;
33 import org.openecomp.aai.parsers.uri.URIParser;
34 import org.openecomp.aai.parsers.uri.URIToDBKey;
35 import org.openecomp.aai.query.builder.QueryBuilder;
36 import org.openecomp.aai.serialization.db.EdgeType;
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);
118 public void processObject(Introspector obj, MultivaluedMap<String, String> uriKeys) {
119 this.resultResource = obj.getDbName();
120 if (previous != null) {
121 this.parentName = previous.getDbName();
133 public void processContainer(Introspector obj, MultivaluedMap<String, String> uriKeys, boolean isFinalContainer) {
134 this.containerResource = obj.getName();
135 if (previous != null) {
136 this.parentName = previous.getDbName();
138 if (isFinalContainer) {
139 this.endsInContainer = true;
140 this.resultResource = obj.getChildDBName();
142 this.finalContainer = obj;
151 public void processNamespace(Introspector obj) {
159 public String getCloudRegionTransform() {
167 public boolean useOriginalLoader() {