Backend support for operation milestones with activities
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / enums / ComponentTypeEnum.java
1 /*-
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 package org.openecomp.sdc.be.datatypes.enums;
16
17 import lombok.AllArgsConstructor;
18 import lombok.Getter;
19
20 @Getter
21 @AllArgsConstructor
22 public enum ComponentTypeEnum {
23     RESOURCE("Resource"),
24     SERVICE("Service"),
25     RESOURCE_INSTANCE("Resource Instance"),
26     PRODUCT("Product"),
27     SERVICE_INSTANCE("Service Instance");
28
29     // Those values cannot be another field in enum, because they are needed as constants for Swagger allowedValues param
30     public static final String RESOURCE_PARAM_NAME = "resources";
31     public static final String SERVICE_PARAM_NAME = "services";
32     public static final String PRODUCT_PARAM_NAME = "products";
33     private final String value;
34
35     public static ComponentTypeEnum findByValue(String value) {
36         ComponentTypeEnum ret = null;
37         for (ComponentTypeEnum curr : ComponentTypeEnum.values()) {
38             if (curr.getValue().equals(value)) {
39                 ret = curr;
40                 return ret;
41             }
42         }
43         return ret;
44     }
45
46     public static ComponentTypeEnum findByParamName(String paramName) {
47         ComponentTypeEnum ret = null;
48         switch (paramName) {
49             case RESOURCE_PARAM_NAME:
50                 ret = RESOURCE;
51                 break;
52             case SERVICE_PARAM_NAME:
53                 ret = SERVICE;
54                 break;
55             case PRODUCT_PARAM_NAME:
56                 ret = PRODUCT;
57                 break;
58             default:
59                 break;
60         }
61         return ret;
62     }
63
64     public static String findParamByType(ComponentTypeEnum type) {
65         String ret = null;
66         if (type == null) {
67             return ret;
68         }
69         switch (type) {
70             case RESOURCE:
71                 ret = RESOURCE_PARAM_NAME;
72                 break;
73             case SERVICE:
74                 ret = SERVICE_PARAM_NAME;
75                 break;
76             case PRODUCT:
77                 ret = PRODUCT_PARAM_NAME;
78                 break;
79             default:
80                 break;
81         }
82         return ret;
83     }
84
85     public NodeTypeEnum getNodeType() {
86         switch (this) {
87             case RESOURCE:
88                 return NodeTypeEnum.Resource;
89             case SERVICE:
90                 return NodeTypeEnum.Service;
91             case PRODUCT:
92                 return NodeTypeEnum.Product;
93             case RESOURCE_INSTANCE:
94                 return NodeTypeEnum.ResourceInstance;
95             default:
96                 throw new UnsupportedOperationException("No nodeType is defined for: " + this.getValue());
97         }
98     }
99 }