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