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.uri;
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.introspection.Version;
26 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
27 import org.onap.aai.serialization.db.EdgeType;
28 import org.onap.aai.util.AAIApiServerURLBase;
29 import org.onap.aai.workarounds.LegacyURITransformer;
31 import javax.ws.rs.core.MultivaluedMap;
32 import java.io.UnsupportedEncodingException;
33 import java.net.MalformedURLException;
35 import java.net.URISyntaxException;
36 import java.util.List;
39 * Given a URI a Relationship Object is returned.
41 * The relationship-data objects are created from the keys in the model.
42 * The keys are processed in the order they appear in the model.
46 public class URIToRelationshipObject implements Parsable {
48 private Introspector result = null;
50 private LegacyURITransformer uriTransformer = null;
52 private Version originalVersion = null;
54 private Introspector relationship = null;
56 private Loader loader = null;
58 private String baseURL;
60 private final URI uri;
62 * Instantiates a new URI to relationship object.
64 * @param loader the loader
66 * @throws IllegalArgumentException the illegal argument exception
67 * @throws AAIException the AAI exception
68 * @throws UnsupportedEncodingException the unsupported encoding exception
69 * @throws MalformedURLException the malformed URL exception
71 public URIToRelationshipObject(Loader loader, URI uri) throws AAIException {
74 uriTransformer = LegacyURITransformer.getInstance();
75 originalVersion = loader.getVersion();
78 relationship = loader.introspectorFromName("relationship");
79 } catch (AAIUnknownObjectException e1) {
80 throw new RuntimeException("Fatal error - could not load relationship object!", e1);
83 this.baseURL = AAIApiServerURLBase.get(originalVersion);
88 public URIToRelationshipObject(Loader loader, URI uri, String baseURL) throws AAIException {
91 if (baseURL != null) {
92 this.baseURL = baseURL;
101 public String getCloudRegionTransform(){
109 public void processNamespace(Introspector obj) {
117 public boolean useOriginalLoader() {
125 * @throws AAIException
126 * @throws UnsupportedEncodingException
127 * @throws URISyntaxException
129 public Introspector getResult() throws UnsupportedEncodingException, AAIException, URISyntaxException {
130 URIParser parser = new URIParser(this.loader, this.uri);
132 URI originalUri = parser.getOriginalURI();
134 URI relatedLink = new URI(this.baseURL + this.originalVersion + "/" + originalUri);
135 if (this.originalVersion.compareTo(Version.v10) >= 0) {
136 //only return the path section of the URI past v10
137 relatedLink = new URI(relatedLink.getRawPath());
140 this.relationship.setValue("related-link", relatedLink.toString());
142 this.result = relationship;
147 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
148 throws AAIException {
149 for (String key : obj.getKeys()) {
151 Introspector data = loader.introspectorFromName("relationship-data");
152 data.setValue("relationship-key", obj.getDbName() + "." + key);
153 data.setValue("relationship-value", obj.getValue(key));
155 ((List<Object>)relationship.getValue("relationship-data")).add(data.getUnderlyingObject());
156 } catch (AAIUnknownObjectException e) {
157 throw new RuntimeException("Fatal error - relationship-data object not found!");
160 relationship.setValue("related-to", obj.getDbName());
164 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
165 boolean isFinalContainer) throws AAIException {