ac0aba3c365b80ae53aa3bbf6b6c817492184aae
[so.git] / common / src / main / java / org / onap / so / client / aai / entities / uri / AAIUriFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.so.client.aai.entities.uri;
22
23 import java.net.URI;
24
25 import org.onap.so.client.aai.AAIObjectPlurals;
26 import org.onap.so.client.aai.AAIObjectType;
27
28
29 public class AAIUriFactory {
30         
31         /**
32          * values are filled into the URI template specified in {@link AAIObjectType} in order
33          * <br>
34          * There are two special lookups performed on certain types when a single value is specified:
35          * <br>
36          * Service Instance and AllottedResources
37          * <br>
38          * These can be retrieved without all their required keys but an HTTP call is required to do so
39          * @param type
40          * @param values
41          * @return
42          */
43         public static AAIResourceUri createResourceUri(AAIObjectType type, Object... values) {
44                 if (AAIObjectType.SERVICE_INSTANCE.equals(type)) {
45                         return new ServiceInstanceUri(values);
46                 } else if (AAIObjectType.ALLOTTED_RESOURCE.equals(type)) {
47                         return new AllottedResourceLookupUri(values);
48                 } else {
49                         return new AAISimpleUri(type, values);
50                 }
51         }
52         
53         public static AAIResourceUri createNodesUri(AAIObjectType type, Object... values) {
54                 return new NodesUri(type, values);
55                 
56         }
57         
58         public static AAIResourceUri createNodesUri(AAIObjectPlurals type) {
59                 return new NodesUri(type);
60                 
61         }
62         
63         /**
64          * This method should only be used to wrap a URI retrieved from A&AI contained within an object response
65          * 
66          * @param type
67          * @param uri
68          * @return
69          */
70         public static AAIResourceUri createResourceFromExistingURI(AAIObjectType type, URI uri) {
71                 return new AAISimpleUri(type, uri);
72         }
73         
74         
75         /**
76          * creates an AAIResourceUri from a parentUri
77          * 
78          * @param parentUri
79          * @param childType
80          * @param childValues
81          * @return
82          */
83         public static AAIResourceUri createResourceFromParentURI(AAIResourceUri parentUri, AAIObjectType childType, Object... childValues) {
84                 
85                 return new AAISimpleUri(parentUri, childType, childValues);
86         }
87         
88         public static AAIResourceUri createResourceFromParentURI(AAIResourceUri parentUri, AAIObjectPlurals childType) {
89                 
90                 return new AAISimpleUri(parentUri, childType);
91         }
92         
93         /**
94          * Creates a uri for a plural type e.g. /cloud-infrastructure/pservers
95          * 
96          * @param type
97          * @return
98          */
99         public static AAIResourceUri createResourceUri(AAIObjectPlurals type) {
100                 
101                 return new AAISimpleUri(type);
102         
103         }
104         
105         /**
106          * Creates a uri for a plural type with values e.g. /cloud-infrastructure/pservers
107          * 
108          * @param type
109          * @return
110          */
111         public static AAIResourceUri createResourceUri(AAIObjectPlurals type, Object... values) {
112                 
113                 return new AAISimpleUri(type, values);
114         
115         }
116 }