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.config.SpringContextAware;
23 import org.onap.aai.exceptions.AAIException;
24 import org.onap.aai.introspection.Introspector;
25 import org.onap.aai.introspection.Loader;
26 import org.onap.aai.setup.SchemaVersion;
27 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
28 import org.onap.aai.edges.enums.EdgeType;
29 import org.onap.aai.setup.SchemaVersions;
30 import org.onap.aai.util.AAIConfig;
31 import org.onap.aai.util.AAIConstants;
33 import javax.ws.rs.core.MultivaluedMap;
34 import java.io.UnsupportedEncodingException;
35 import java.net.MalformedURLException;
37 import java.net.URISyntaxException;
38 import java.util.List;
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 SchemaVersion 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 originalVersion = loader.getVersion();
77 relationship = loader.introspectorFromName("relationship");
78 } catch (AAIUnknownObjectException e1) {
79 throw new RuntimeException("Fatal error - could not load relationship object!", e1);
82 this.baseURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
87 public URIToRelationshipObject(Loader loader, URI uri, String baseURL) throws AAIException {
90 if (baseURL != null) {
91 this.baseURL = baseURL;
100 public String getCloudRegionTransform(){
108 public void processNamespace(Introspector obj) {
116 public boolean useOriginalLoader() {
124 * @throws AAIException
125 * @throws UnsupportedEncodingException
126 * @throws URISyntaxException
128 public Introspector getResult() throws UnsupportedEncodingException, AAIException, URISyntaxException {
129 URIParser parser = new URIParser(this.loader, this.uri);
131 URI originalUri = parser.getOriginalURI();
133 URI relatedLink = new URI(this.baseURL + this.originalVersion + "/" + originalUri);
134 SchemaVersions schemaVersions = (SchemaVersions)SpringContextAware.getBean("schemaVersions");
135 if (this.originalVersion.compareTo(schemaVersions.getRelatedLinkVersion()) >= 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 for (String key : obj.getKeys()) {
150 Introspector data = loader.introspectorFromName("relationship-data");
151 data.setValue("relationship-key", obj.getDbName() + "." + key);
152 data.setValue("relationship-value", obj.getValue(key));
154 ((List<Object>)relationship.getValue("relationship-data")).add(data.getUnderlyingObject());
155 } catch (AAIUnknownObjectException e) {
156 throw new RuntimeException("Fatal error - relationship-data object not found!");
159 relationship.setValue("related-to", obj.getDbName());
163 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
164 boolean isFinalContainer) throws AAIException {