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.onap.aaiclient.client.aai.entities.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;
30 public class AAIUriFactory {
33 public static final AAIFluentTypeReverseLookup reverseLookup = new AAIFluentTypeReverseLookup();
36 * values are filled into the URI template specified in {@link AAIObjectType} in order <br>
42 public static AAIResourceUri createResourceUri(AAIObjectType type, Object... values) {
43 return new AAISimpleUri(type, values);
47 * These can be retrieved without all their required keys but an HTTP call is required to do so
53 public static AAIResourceUri createResourceUri(AAISingleFragment fragment) {
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);
64 public static AAIResourceUri createResourceUri(AAIFluentSingleType uri) {
65 return new AAISimpleUri(uri.build(), uri.values());
68 protected static NodesSingleUri createNodesUri(AAIObjectType type, Object... values) {
69 return new NodesSingleUri(type, values);
72 public static NodesSingleUri createNodesUri(AAISingleFragment fragment) {
73 return new NodesSingleUri(fragment.get().build(), fragment.get().values());
76 public static NodesPluralUri createNodesUri(AAIPluralFragment fragment) {
77 return new NodesPluralUri(fragment.get().build());
82 * This method should only be used to wrap a URI retrieved from A&AI contained within an object response
88 public static AAISimpleUri createResourceFromExistingURI(AAIObjectName name, URI uri) {
89 AAIObjectType type = reverseLookup.fromName(name.typeName(), uri.toString());
90 return new AAISimpleUri(type, uri);
95 * creates an AAIResourceUri from a parentUri
102 public static AAISimpleUri createResourceFromParentURI(AAIResourceUri parentUri, AAISingleFragment fragment) {
104 return new AAISimpleUri(parentUri, fragment.get().build(), fragment.get().values());
107 public static AAISimplePluralUri createResourceFromParentURI(AAIResourceUri parentUri, AAIPluralFragment fragment) {
109 return new AAISimplePluralUri(parentUri, fragment.get().build());
112 public static AAISimplePluralUri createResourceUri(AAIFluentPluralType uri) {
114 return new AAISimplePluralUri(uri.build(), uri.values());
119 * Creates a uri for a plural type e.g. /cloud-infrastructure/pservers
124 public static AAISimplePluralUri createResourceUri(AAIObjectPlurals type) {
126 return new AAISimplePluralUri(type);
131 * Creates a uri for a plural type with values e.g. /cloud-infrastructure/pservers
136 public static AAISimplePluralUri createResourceUri(AAIObjectPlurals type, Object... values) {
138 return new AAISimplePluralUri(type, values);