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 org.openecomp.aai.exceptions.AAIException;
24 import org.openecomp.aai.introspection.Introspector;
25 import org.openecomp.aai.introspection.Loader;
26 import org.openecomp.aai.parsers.uri.Parsable;
27 import org.openecomp.aai.parsers.uri.URIParser;
28 import org.openecomp.aai.parsers.uri.URIToDBKey;
29 import org.openecomp.aai.query.builder.QueryBuilder;
30 import org.openecomp.aai.serialization.db.EdgeType;
32 import javax.ws.rs.core.MultivaluedMap;
33 import javax.ws.rs.core.UriBuilder;
34 import java.io.UnsupportedEncodingException;
39 * The Class UniqueURIQueryParser.
41 public class UniqueURIQueryParser extends QueryParser implements Parsable {
44 private URIToDBKey dbKeyParser = null;
46 private Introspector previous = null;
48 private boolean endsInContainer = false;
50 private Introspector finalContainer = null;
52 private String parentName = "";
55 * Instantiates a new unique URI query parser.
57 * @param loader the loader
58 * @param queryBuilder the query builder
60 * @throws UnsupportedEncodingException the unsupported encoding exception
61 * @throws IllegalArgumentException the illegal argument exception
62 * @throws AAIException the AAI exception
64 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder, URI uri) 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.fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(containerResource))).build();
77 this.dbKeyParser = new URIToDBKey(loader, parentUri);
78 this.parentQueryBuilder = queryBuilder.newInstance().getVerticesByIndexedProperty("aai-unique-key", (String)dbKeyParser.getResult());
79 this.parentResourceType = parentName;
81 this.containerResource = "";
83 URI parentUri = UriBuilder.fromPath(uri.getRawPath().substring(0, uri.getRawPath().indexOf(this.finalContainer.getDbName()))).build();
84 this.dbKeyParser = new URIToDBKey(loader, parentUri);
85 String dbKey = (String)dbKeyParser.getResult();
86 this.parentResourceType = parentName;
88 if (!dbKey.equals("")) {
89 queryBuilder.getVerticesByIndexedProperty("aai-unique-key", dbKey);
90 queryBuilder.markParentBoundary();
91 queryBuilder.createEdgeTraversal(EdgeType.TREE, previous, finalContainer);
95 queryBuilder.createContainerQuery(finalContainer);
103 * Instantiates a new unique URI query parser.
105 * @param loader the loader
106 * @param queryBuilder the query builder
108 public UniqueURIQueryParser(Loader loader, QueryBuilder queryBuilder) {
109 super(loader, queryBuilder);
116 public void processNamespace(Introspector obj) {
124 public String getCloudRegionTransform() {
132 public boolean useOriginalLoader() {
138 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
139 throws AAIException {
140 this.resultResource = obj.getDbName();
141 if (previous != null) {
142 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;