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