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.ArrayList;
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 com.google.common.base.Joiner;
36 * Creates a Unique database key from a URI
38 * The key is of the form node-type/key(s).
40 public class URIToDBKey implements Parsable {
43 private List<String> dbKeys = new ArrayList<>();
46 * Instantiates a new URI to DB key.
48 * @param loader the loader
50 * @throws IllegalArgumentException the illegal argument exception
51 * @throws AAIException the AAI exception
52 * @throws UnsupportedEncodingException the unsupported encoding exception
54 public URIToDBKey(Loader loader, URI uri) throws IllegalArgumentException, AAIException, UnsupportedEncodingException {
56 URIParser parser = new URIParser(loader, uri);
60 public URIToDBKey(Version version, String uri) throws IllegalArgumentException {
64 context = ModelInjestor.getInstance().getContextForVersion(version);
65 if (context == null) {
66 throw new IllegalArgumentException("could not find a context for version: " + version);
69 } catch (Exception e) {
70 throw new IllegalArgumentException("uri not valid against our model: " + uri);
78 public void processObject (Introspector obj, MultivaluedMap<String, String> uriKeys) {
80 dbKeys.add(obj.getDbName());
82 for (String key : uriKeys.keySet()) {
83 dbKeys.add(uriKeys.getFirst(key).toString());
91 public void processContainer (Introspector obj, MultivaluedMap<String, String> uriKeys, boolean isFinalContainer) {
99 public void processNamespace(Introspector obj) {
107 public String getCloudRegionTransform() {
116 public Object getResult() {
117 return Joiner.on("/").join(this.dbKeys);
124 public boolean useOriginalLoader() {