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 java.io.UnsupportedEncodingException;
24 import java.net.MalformedURLException;
26 import java.net.URISyntaxException;
27 import java.util.List;
29 import javax.ws.rs.core.MultivaluedMap;
31 import org.openecomp.aai.exceptions.AAIException;
32 import org.openecomp.aai.introspection.Introspector;
33 import org.openecomp.aai.introspection.Loader;
34 import org.openecomp.aai.introspection.Version;
35 import org.openecomp.aai.introspection.exceptions.AAIUnknownObjectException;
36 import org.openecomp.aai.serialization.db.EdgeType;
37 import org.openecomp.aai.util.AAIApiServerURLBase;
38 import org.openecomp.aai.workarounds.LegacyURITransformer;
41 * Given a URI a Relationship Object is returned.
43 * The relationship-data objects are created from the keys in the model.
44 * The keys are processed in the order they appear in the model.
48 public class URIToRelationshipObject implements Parsable {
50 private Introspector result = null;
52 private LegacyURITransformer uriTransformer = null;
54 private Version originalVersion = null;
56 private Introspector relationship = null;
58 private Loader loader = null;
60 private String baseURL;
62 private final URI uri;
64 * Instantiates a new URI to relationship object.
66 * @param loader the loader
68 * @throws IllegalArgumentException the illegal argument exception
69 * @throws AAIException the AAI exception
70 * @throws UnsupportedEncodingException the unsupported encoding exception
71 * @throws MalformedURLException the malformed URL exception
73 public URIToRelationshipObject(Loader loader, URI uri) throws AAIException {
76 uriTransformer = LegacyURITransformer.getInstance();
77 originalVersion = loader.getVersion();
80 relationship = loader.introspectorFromName("relationship");
81 } catch (AAIUnknownObjectException e1) {
82 throw new RuntimeException("Fatal error - could not load relationship object!", e1);
85 this.baseURL = AAIApiServerURLBase.get(originalVersion);
90 public URIToRelationshipObject(Loader loader, URI uri, String baseURL) throws AAIException {
93 if (baseURL != null) {
94 this.baseURL = baseURL;
103 public String getCloudRegionTransform(){
111 public void processNamespace(Introspector obj) {
119 public boolean useOriginalLoader() {
127 * @throws AAIException
128 * @throws UnsupportedEncodingException
129 * @throws URISyntaxException
131 public Introspector getResult() throws UnsupportedEncodingException, AAIException, URISyntaxException {
132 URIParser parser = new URIParser(this.loader, this.uri);
134 URI originalUri = parser.getOriginalURI();
136 URI relatedLink = new URI(this.baseURL + this.originalVersion + "/" + originalUri);
137 this.relationship.setValue("related-link", relatedLink);
138 if (this.originalVersion.compareTo(Version.v10) >= 0) {
139 //only return the path section of the URI past v10
140 relatedLink = new URI(relatedLink.getRawPath());
143 this.relationship.setValue("related-link", relatedLink.toString());
145 this.result = relationship;
150 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
151 throws AAIException {
152 for (String key : obj.getKeys()) {
154 Introspector data = loader.introspectorFromName("relationship-data");
155 data.setValue("relationship-key", obj.getDbName() + "." + key);
156 data.setValue("relationship-value", obj.getValue(key));
158 ((List<Object>)relationship.getValue("relationship-data")).add(data.getUnderlyingObject());
159 } catch (AAIUnknownObjectException e) {
160 throw new RuntimeException("Fatal error - relationship-data object not found!");
163 relationship.setValue("related-to", obj.getDbName());
167 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
168 boolean isFinalContainer) throws AAIException {