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.so.client.aai;
23 import java.util.HashMap;
26 import org.onap.aai.annotations.Metadata;
27 import org.onap.aai.domain.yang.AllottedResource;
28 import org.onap.aai.domain.yang.CloudRegion;
29 import org.onap.aai.domain.yang.Collection;
30 import org.onap.aai.domain.yang.Configuration;
31 import org.onap.aai.domain.yang.Customer;
32 import org.onap.aai.domain.yang.GenericVnf;
33 import org.onap.aai.domain.yang.InstanceGroup;
34 import org.onap.aai.domain.yang.L3Network;
35 import org.onap.aai.domain.yang.LinesOfBusiness;
36 import org.onap.aai.domain.yang.ModelVer;
37 import org.onap.aai.domain.yang.NetworkPolicy;
38 import org.onap.aai.domain.yang.OperationalEnvironment;
39 import org.onap.aai.domain.yang.OwningEntity;
40 import org.onap.aai.domain.yang.PInterface;
41 import org.onap.aai.domain.yang.PhysicalLink;
42 import org.onap.aai.domain.yang.Platform;
43 import org.onap.aai.domain.yang.Project;
44 import org.onap.aai.domain.yang.Pserver;
45 import org.onap.aai.domain.yang.RouteTableReferences;
46 import org.onap.aai.domain.yang.ServiceInstance;
47 import org.onap.aai.domain.yang.ServiceSubscription;
48 import org.onap.aai.domain.yang.Tenant;
49 import org.onap.aai.domain.yang.TunnelXconnect;
50 import org.onap.aai.domain.yang.VfModule;
51 import org.onap.aai.domain.yang.VlanTag;
52 import org.onap.aai.domain.yang.Vce;
53 import org.onap.aai.domain.yang.Vnfc;
54 import org.onap.aai.domain.yang.VolumeGroup;
55 import org.onap.aai.domain.yang.VpnBinding;
56 import org.onap.aai.domain.yang.Vserver;
57 import org.onap.so.client.graphinventory.GraphInventoryObjectType;
59 import com.google.common.base.CaseFormat;
61 public enum AAIObjectType implements GraphInventoryObjectType {
63 DEFAULT_CLOUD_REGION(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, "/cloud-regions/cloud-region/att-aic/{cloud-region-id}"),
64 CUSTOMER(AAINamespaceConstants.BUSINESS, Customer.class),
65 GENERIC_QUERY("/search", "/generic-query"),
66 BULK_PROCESS("/bulkprocess", ""),
67 GENERIC_VNF(AAINamespaceConstants.NETWORK, GenericVnf.class),
68 VF_MODULE(AAIObjectType.GENERIC_VNF.uriTemplate(), VfModule.class),
69 L3_NETWORK(AAINamespaceConstants.NETWORK, L3Network.class),
70 NETWORK_POLICY(AAINamespaceConstants.NETWORK, NetworkPolicy.class),
71 NODES_QUERY("/search", "/nodes-query"),
72 CUSTOM_QUERY("/query", ""),
73 ROUTE_TABLE_REFERENCE(AAINamespaceConstants.NETWORK, RouteTableReferences.class),
74 DEFAULT_TENANT(AAINamespaceConstants.CLOUD_INFRASTRUCTURE + "/cloud-regions/cloud-region/att-aic/AAIAIC25", "/tenants/tenant/{tenant-id}"),
75 VCE(AAINamespaceConstants.NETWORK, Vce.class),
76 VPN_BINDING(AAINamespaceConstants.NETWORK, VpnBinding.class),
77 VPN_BINDINGS(AAINamespaceConstants.NETWORK, "/vpn-bindings"),
78 CONFIGURATION(AAINamespaceConstants.NETWORK, Configuration.class),
79 PSERVER(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Pserver.class),
80 SERVICE_SUBSCRIPTION(AAIObjectType.CUSTOMER.uriTemplate(), ServiceSubscription.class),
81 SERVICE_INSTANCE(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), ServiceInstance.class),
82 PROJECT(AAINamespaceConstants.BUSINESS, Project.class),
83 LINE_OF_BUSINESS(AAINamespaceConstants.BUSINESS, LinesOfBusiness.class),
84 PLATFORM(AAINamespaceConstants.BUSINESS, Platform.class),
85 OWNING_ENTITY(AAINamespaceConstants.BUSINESS, OwningEntity.class),
86 ALLOTTED_RESOURCE(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), AllottedResource.class),
87 PNF(AAINamespaceConstants.NETWORK, "/pnfs/pnf/{pnf-name}"),
88 OPERATIONAL_ENVIRONMENT(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, OperationalEnvironment.class),
89 CLOUD_REGION(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, CloudRegion.class),
90 TENANT(AAIObjectType.CLOUD_REGION.uriTemplate(), Tenant.class),
91 VOLUME_GROUP(AAIObjectType.CLOUD_REGION.uriTemplate(), VolumeGroup.class),
92 VSERVER(AAIObjectType.TENANT.uriTemplate(), Vserver.class),
93 MODEL_VER(AAINamespaceConstants.SERVICE_DESIGN_AND_CREATION + "/models/model/{model-invariant-id}", ModelVer.class),
94 TUNNEL_XCONNECT(AAIObjectType.ALLOTTED_RESOURCE.uriTemplate(), TunnelXconnect.class),
95 P_INTERFACE(AAIObjectType.PSERVER.uriTemplate(), PInterface.class),
96 PHYSICAL_LINK(AAINamespaceConstants.NETWORK, PhysicalLink.class),
97 INSTANCE_GROUP(AAINamespaceConstants.NETWORK, InstanceGroup.class),
98 COLLECTION(AAINamespaceConstants.NETWORK, Collection.class),
99 VNFC(AAINamespaceConstants.NETWORK, Vnfc.class),
100 VLAN_TAG(AAINamespaceConstants.NETWORK, VlanTag.class),
103 private final String uriTemplate;
104 private final String parentUri;
105 private final String partialUri;
106 private final Class<?> aaiObjectClass;
107 private static Map<String, AAIObjectType> map = new HashMap<>();
108 private AAIObjectType(String parentUri, String partialUri) {
109 this.parentUri = parentUri;
110 this.partialUri = partialUri;
111 this.uriTemplate = parentUri + partialUri;
112 this.aaiObjectClass = null;
115 private AAIObjectType(String parentUri, Class<?> aaiObjectClass) {
116 this.parentUri = parentUri;
117 this.partialUri = removeParentUri(aaiObjectClass, parentUri);
118 this.uriTemplate = parentUri + partialUri;
119 this.aaiObjectClass = aaiObjectClass;
123 public String toString() {
124 return this.uriTemplate();
127 public static AAIObjectType fromTypeName(String name) {
129 for (AAIObjectType type : AAIObjectType.values()) {
130 map.put(type.typeName(), type);
134 if (map.containsKey(name)) {
135 return map.get(name);
137 return AAIObjectType.UNKNOWN;
141 public String typeName() {
142 return this.typeName(CaseFormat.LOWER_HYPHEN);
145 public String typeName(CaseFormat format) {
146 String enumName = this.name();
147 if (this.equals(AAIObjectType.DEFAULT_CLOUD_REGION) || this.equals(AAIObjectType.DEFAULT_TENANT)) {
148 enumName = enumName.replace("DEFAULT_", "");
151 return CaseFormat.UPPER_UNDERSCORE.to(format, enumName);
155 public String uriTemplate() {
156 return this.uriTemplate;
160 public String partialUri() {
161 return this.partialUri;
164 protected String removeParentUri(Class<?> aaiObjectClass, String parentUri) {
165 return aaiObjectClass.getAnnotation(Metadata.class).uriTemplate().replace(parentUri, "");