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