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 com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aai.exceptions.AAIException;
25 import org.onap.aai.introspection.Introspector;
26 import org.onap.aai.introspection.Loader;
27 import org.onap.aai.introspection.Version;
28 import org.onap.aai.schema.enums.ObjectMetadata;
29 import org.onap.aai.serialization.db.EdgeType;
31 import javax.ws.rs.core.MultivaluedMap;
32 import java.io.UnsupportedEncodingException;
34 import java.util.HashMap;
35 import java.util.List;
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 {
47 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(URIToObject.class);
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) {
206 LOGGER.error(e.getMessage(),e);
208 this.previous = entity;
211 public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
212 boolean isFinalContainer) throws AAIException {
215 if (this.entity != null) {
216 this.entity.setValue(obj.getName(), obj.getUnderlyingObject());
219 this.topEntity = obj;