re base code
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / enums / ComponentTypeEnum.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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.openecomp.sdc.be.datatypes.enums;
22
23 public enum ComponentTypeEnum {
24     RESOURCE("Resource"),
25     SERVICE("Service"),
26     RESOURCE_INSTANCE("Resource Instance"),
27     PRODUCT("Product"),
28     SERVICE_INSTANCE("Service Instance");
29
30     private String value;
31
32     private ComponentTypeEnum(String value) {
33         this.value = value;
34     }
35
36     public String getValue() {
37         return value;
38     }
39
40     // Those values cannot be another field in enum, because they are needed
41     // as constants for Swagger allowedValues param
42     public static final String RESOURCE_PARAM_NAME = "resources";
43     public static final String SERVICE_PARAM_NAME = "services";
44     public static final String PRODUCT_PARAM_NAME = "products";
45
46     public NodeTypeEnum getNodeType() {
47
48         switch (this) {
49             case RESOURCE:
50                 return NodeTypeEnum.Resource;
51             case SERVICE:
52                 return NodeTypeEnum.Service;
53             case PRODUCT:
54                 return NodeTypeEnum.Product;
55             case RESOURCE_INSTANCE:
56                 return NodeTypeEnum.ResourceInstance;
57             default:
58                 throw new UnsupportedOperationException("No nodeType is defined for: " + this.getValue());
59         }
60     }
61
62     public static ComponentTypeEnum findByValue(String value) {
63         ComponentTypeEnum ret = null;
64         for (ComponentTypeEnum curr : ComponentTypeEnum.values()) {
65             if (curr.getValue().equals(value)) {
66                 ret = curr;
67                 return ret;
68             }
69         }
70         return ret;
71     }
72
73     public static ComponentTypeEnum findByParamName(String paramName) {
74         ComponentTypeEnum ret = null;
75         switch (paramName) {
76             case RESOURCE_PARAM_NAME:
77                 ret = RESOURCE;
78                 break;
79             case SERVICE_PARAM_NAME:
80                 ret = SERVICE;
81                 break;
82             case PRODUCT_PARAM_NAME:
83                 ret = PRODUCT;
84                 break;
85             default:
86                 break;
87         }
88         return ret;
89     }
90
91     public static String findParamByType(ComponentTypeEnum type) {
92         String ret = null;
93                 if (type == null) {
94                         return ret;
95                 }
96                 
97         switch (type) {
98             case RESOURCE:
99                 ret = RESOURCE_PARAM_NAME;
100                 break;
101             case SERVICE:
102                 ret = SERVICE_PARAM_NAME;
103                 break;
104             case PRODUCT:
105                 ret = PRODUCT_PARAM_NAME;
106                 break;
107             default:
108                 break;
109         }
110         return ret;
111     }
112 }