Merge "Release 1.14.0 maven artifact"
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / parsers / uri / URIToDBKey.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.parsers.uri;
22
23 import com.google.common.base.Joiner;
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.URI;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import javax.ws.rs.core.MultivaluedMap;
31
32 import org.onap.aai.edges.enums.EdgeType;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.introspection.Introspector;
35 import org.onap.aai.introspection.Loader;
36
37 /**
38  * Creates a Unique database key from a URI
39  * 
40  * The key is of the form node-type/key(s).
41  */
42 public class URIToDBKey implements Parsable {
43
44     private List<String> dbKeys = new ArrayList<>();
45
46     /**
47      * Instantiates a new URI to DB key.
48      *
49      * @param loader the loader
50      * @param uri the uri
51      * @throws IllegalArgumentException the illegal argument exception
52      * @throws AAIException the AAI exception
53      * @throws UnsupportedEncodingException the unsupported encoding exception
54      */
55     public URIToDBKey(Loader loader, URI uri)
56             throws IllegalArgumentException, AAIException, UnsupportedEncodingException {
57         URIParser parser = new URIParser(loader, uri);
58         parser.parse(this);
59     }
60
61     /**
62      * @{inheritDoc}
63      */
64     @Override
65     public void processNamespace(Introspector obj) {
66
67     }
68
69     /**
70      * @{inheritDoc}
71      */
72     @Override
73     public String getCloudRegionTransform() {
74         return "add";
75     }
76
77     /**
78      * Gets the result.
79      *
80      * @return the result
81      */
82     public Object getResult() {
83         return Joiner.on("/").join(this.dbKeys);
84     }
85
86     /**
87      * @{inheritDoc}
88      */
89     @Override
90     public boolean useOriginalLoader() {
91         return false;
92     }
93
94     @Override
95     public void processObject(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys)
96             throws AAIException {
97
98         dbKeys.add(obj.getDbName());
99
100         for (String key : uriKeys.keySet()) {
101             dbKeys.add(uriKeys.getFirst(key).toString());
102         }
103     }
104
105     @Override
106     public void processContainer(Introspector obj, EdgeType type, MultivaluedMap<String, String> uriKeys,
107             boolean isFinalContainer) {
108     }
109 }