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.uri;
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.introspection.Version;
27 import org.openecomp.aai.introspection.exceptions.AAIUnknownObjectException;
28 import org.openecomp.aai.serialization.db.EdgeType;
29 import org.openecomp.aai.util.AAIApiServerURLBase;
30 import org.openecomp.aai.workarounds.LegacyURITransformer;
32 import javax.ws.rs.core.MultivaluedMap;
33 import java.io.UnsupportedEncodingException;
34 import java.net.MalformedURLException;
36 import java.net.URISyntaxException;
37 import java.util.List;
40 * Given a URI a Relationship Object is returned.
42 * The relationship-data objects are created from the keys in the model.
43 * The keys are processed in the order they appear in the model.
47 public class URIToRelationshipObject implements Parsable {
49 private Introspector result = null;
51 private LegacyURITransformer uriTransformer = null;
53 private Version originalVersion = null;
55 private Introspector relationship = null;
57 private Loader loader = null;
59 private String baseURL;
61 private final URI uri;
63 * Instantiates a new URI to relationship object.
65 * @param loader the loader
67 * @throws IllegalArgumentException the illegal argument exception
68 * @throws AAIException the AAI exception
69 * @throws UnsupportedEncodingException the unsupported encoding exception
70 * @throws MalformedURLException the malformed URL exception
72 public URIToRelationshipObject(Loader loader, URI uri) throws AAIException {
75 uriTransformer = LegacyURITransformer.getInstance();
76 originalVersion = loader.getVersion();
79 relationship = loader.introspectorFromName("relationship");
80 } catch (AAIUnknownObjectException e1) {
81 throw new RuntimeException("Fatal error - could not load relationship object!", e1);
84 this.baseURL = AAIApiServerURLBase.get(originalVersion);
89 public URIToRelationshipObject(Loader loader, URI uri, String baseURL) throws AAIException {
92 if (baseURL != null) {
93 this.baseURL = baseURL;
102 public String getCloudRegionTransform(){
110 public void processNamespace(Introspector obj) {
118 public boolean useOriginalLoader() {
126 * @throws AAIException
127 * @throws UnsupportedEncodingException
128 * @throws URISyntaxException
130 public Introspector getResult() throws UnsupportedEncodingException, AAIException, URISyntaxException {
131 URIParser parser = new URIParser(this.loader, this.uri);
133 URI originalUri = parser.getOriginalURI();
135 URI relatedLink = new URI(this.baseURL + this.originalVersion + "/" + originalUri);
136 this.relationship.setValue("related-link", relatedLink);
137 if (this.originalVersion.compareTo(Version.v10) >= 0) {
138 //only return the path section of the URI past v10
139 relatedLink = new URI(relatedLink.getRawPath());
142 this.relationship.setValue("related-link", relatedLink.toString());
144 this.result = relationship;
149 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
150 throws AAIException {
151 for (String key : obj.getKeys()) {
153 Introspector data = loader.introspectorFromName("relationship-data");
154 data.setValue("relationship-key", obj.getDbName() + "." + key);
155 data.setValue("relationship-value", obj.getValue(key));
157 ((List<Object>)relationship.getValue("relationship-data")).add(data.getUnderlyingObject());
158 } catch (AAIUnknownObjectException e) {
159 throw new RuntimeException("Fatal error - relationship-data object not found!");
162 relationship.setValue("related-to", obj.getDbName());
166 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
167 boolean isFinalContainer) throws AAIException {