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;
25 import java.util.HashMap;
26 import java.util.List;
28 import javax.ws.rs.core.MultivaluedMap;
30 import org.openecomp.aai.exceptions.AAIException;
31 import org.openecomp.aai.introspection.Introspector;
32 import org.openecomp.aai.introspection.Loader;
33 import org.openecomp.aai.introspection.Version;
34 import org.openecomp.aai.schema.enums.ObjectMetadata;
35 import org.openecomp.aai.serialization.db.EdgeType;
38 * Given a URI this class returns an object, or series of nested objects
39 * with their keys populated based off the values in the URI.
41 * It populates the keys in the order they are listed in the model.
46 public class URIToObject implements Parsable {
49 private Introspector topEntity = null;
51 private String topEntityName = null;
53 private String entityName = null;
55 private Introspector entity = null;
57 private Introspector previous = null;
59 private List<Object> parentList = null;
61 private Version version = null;
62 private Loader loader = null;
63 private final HashMap<String, Introspector> relatedObjects;
66 * Instantiates a new URI to object.
68 * @param loader the loader
70 * @throws IllegalArgumentException the illegal argument exception
71 * @throws AAIException the AAI exception
72 * @throws UnsupportedEncodingException the unsupported encoding exception
74 public URIToObject(Loader loader, URI uri) throws AAIException, UnsupportedEncodingException {
76 URIParser parser = new URIParser(loader, uri);
77 this.relatedObjects = new HashMap<>();
80 this.loader = parser.getLoader();
81 this.version = loader.getVersion();
83 public URIToObject(Loader loader, URI uri, HashMap<String, Introspector> relatedObjects) throws AAIException, UnsupportedEncodingException {
85 URIParser parser = new URIParser(loader, uri);
86 this.relatedObjects = relatedObjects;
89 this.loader = parser.getLoader();
90 this.version = loader.getVersion();
98 public void processNamespace(Introspector obj) {
106 public String getCloudRegionTransform() {
114 public boolean useOriginalLoader() {
115 // TODO Auto-generated method stub
120 * Gets the top entity.
122 * @return the top entity
124 public Introspector getTopEntity() {
125 return this.topEntity;
133 public Introspector getEntity() {
138 * Gets the parent list.
140 * @return the parent list
142 public List<Object> getParentList() {
143 return this.parentList;
147 * Gets the entity name.
149 * @return the entity name
151 public String getEntityName() {
152 return this.entityName;
156 * Gets the top entity name.
158 * @return the top entity name
160 public String getTopEntityName() {
161 return this.topEntityName;
165 * Gets the object version.
167 * @return the object version
169 public Version getObjectVersion() {
170 return this.loader.getVersion();
172 public Loader getLoader() {
176 public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
177 throws AAIException {
179 if (this.entityName == null) {
180 this.topEntityName = obj.getDbName();
181 this.topEntity = obj;
183 this.entityName = obj.getDbName();
185 this.parentList = (List<Object>)this.previous.getValue(obj.getName());
186 this.parentList.add(entity.getUnderlyingObject());
188 for (String key : uriKeys.keySet()) {
189 entity.setValue(key, uriKeys.getFirst(key));
192 if (relatedObjects.containsKey(entity.getObjectId())) {
193 Introspector relatedObject = relatedObjects.get(entity.getObjectId());
194 String nameProp = relatedObject.getMetadata(ObjectMetadata.NAME_PROPS);
195 if (nameProp == null) {
198 if (nameProp != null && !nameProp.equals("")) {
199 String[] nameProps = nameProp.split(",");
200 for (String prop : nameProps) {
201 entity.setValue(prop, relatedObject.getValue(prop));
205 } catch (UnsupportedEncodingException e) {
207 this.previous = entity;
210 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
211 boolean isFinalContainer) throws AAIException {
214 if (this.entity != null) {
215 this.entity.setValue(obj.getName(), obj.getUnderlyingObject());
218 this.topEntity = obj;