be49535f3eb57c5aef5bd389bd803c1b44b73c86
[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.AAIObjectName;
25 import org.onap.aaiclient.client.aai.AAIObjectPlurals;
26 import org.onap.aaiclient.client.aai.AAIObjectType;
27 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
28
29
30 public class AAIUriFactory {
31
32
33     public static final AAIFluentTypeReverseLookup reverseLookup = new AAIFluentTypeReverseLookup();
34
35     /**
36      * values are filled into the URI template specified in {@link AAIObjectType} in order <br>
37      *
38      * @param type
39      * @param values
40      * @return
41      */
42     public static AAIResourceUri createResourceUri(AAIObjectType type, Object... values) {
43         return new AAISimpleUri(type, values);
44     }
45
46     /**
47      * These can be retrieved without all their required keys but an HTTP call is required to do so
48      *
49      * @param type
50      * @param values
51      * @return
52      */
53     public static AAIResourceUri createResourceUri(AAISingleFragment fragment) {
54
55         if (Types.SERVICE_INSTANCE.typeName().equals(fragment.get().build().typeName())) {
56             return new ServiceInstanceUri(fragment);
57         } else if (Types.ALLOTTED_RESOURCE.typeName().equals(fragment.get().build().typeName())) {
58             return new AllottedResourceLookupUri(fragment);
59         } else {
60             return null;
61         }
62     }
63
64     public static AAIResourceUri createResourceUri(AAIFluentSingleType uri) {
65         return new AAISimpleUri(uri.build(), uri.values());
66     }
67
68     protected static NodesSingleUri createNodesUri(AAIObjectType type, Object... values) {
69         return new NodesSingleUri(type, values);
70     }
71
72     public static NodesSingleUri createNodesUri(AAISingleFragment fragment) {
73         return new NodesSingleUri(fragment.get().build(), fragment.get().values());
74     }
75
76     public static NodesPluralUri createNodesUri(AAIPluralFragment fragment) {
77         return new NodesPluralUri(fragment.get().build());
78
79     }
80
81     /**
82      * This method should only be used to wrap a URI retrieved from A&AI contained within an object response
83      * 
84      * @param type
85      * @param uri
86      * @return
87      */
88     public static AAISimpleUri createResourceFromExistingURI(AAIObjectName name, URI uri) {
89         AAIObjectType type = reverseLookup.fromName(name.typeName(), uri.toString());
90         return new AAISimpleUri(type, uri);
91     }
92
93
94     /**
95      * creates an AAIResourceUri from a parentUri
96      * 
97      * @param parentUri
98      * @param childType
99      * @param childValues
100      * @return
101      */
102     public static AAISimpleUri createResourceFromParentURI(AAIResourceUri parentUri, AAISingleFragment fragment) {
103
104         return new AAISimpleUri(parentUri, fragment.get().build(), fragment.get().values());
105     }
106
107     public static AAISimplePluralUri createResourceFromParentURI(AAIResourceUri parentUri, AAIPluralFragment fragment) {
108
109         return new AAISimplePluralUri(parentUri, fragment.get().build());
110     }
111
112     public static AAISimplePluralUri createResourceUri(AAIFluentPluralType uri) {
113
114         return new AAISimplePluralUri(uri.build(), uri.values());
115
116     }
117
118     /**
119      * Creates a uri for a plural type e.g. /cloud-infrastructure/pservers
120      * 
121      * @param type
122      * @return
123      */
124     public static AAISimplePluralUri createResourceUri(AAIObjectPlurals type) {
125
126         return new AAISimplePluralUri(type);
127
128     }
129
130     /**
131      * Creates a uri for a plural type with values e.g. /cloud-infrastructure/pservers
132      * 
133      * @param type
134      * @return
135      */
136     public static AAISimplePluralUri createResourceUri(AAIObjectPlurals type, Object... values) {
137
138         return new AAISimplePluralUri(type, values);
139
140     }
141 }