Improve test coverage
[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
16 package org.openecomp.sdc.be.datatypes.enums;
17
18 import lombok.AllArgsConstructor;
19 import lombok.Getter;
20
21 @Getter
22 @AllArgsConstructor
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     // Those values cannot be another field in enum, because they are needed
31     // as constants for Swagger allowedValues param
32     public static final String RESOURCE_PARAM_NAME = "resources";
33     public static final String SERVICE_PARAM_NAME = "services";
34     public static final String PRODUCT_PARAM_NAME = "products";
35     private final String value;
36
37     public static ComponentTypeEnum findByValue(String value) {
38         ComponentTypeEnum ret = null;
39         for (ComponentTypeEnum curr : ComponentTypeEnum.values()) {
40             if (curr.getValue().equals(value)) {
41                 ret = curr;
42                 return ret;
43             }
44         }
45         return ret;
46     }
47
48     public static ComponentTypeEnum findByParamName(String paramName) {
49         ComponentTypeEnum ret = null;
50         switch (paramName) {
51             case RESOURCE_PARAM_NAME:
52                 ret = RESOURCE;
53                 break;
54             case SERVICE_PARAM_NAME:
55                 ret = SERVICE;
56                 break;
57             case PRODUCT_PARAM_NAME:
58                 ret = PRODUCT;
59                 break;
60             default:
61                 break;
62         }
63         return ret;
64     }
65
66     public static String findParamByType(ComponentTypeEnum type) {
67         String ret = null;
68         if (type == null) {
69             return ret;
70         }
71
72         switch (type) {
73             case RESOURCE:
74                 ret = RESOURCE_PARAM_NAME;
75                 break;
76             case SERVICE:
77                 ret = SERVICE_PARAM_NAME;
78                 break;
79             case PRODUCT:
80                 ret = PRODUCT_PARAM_NAME;
81                 break;
82             default:
83                 break;
84         }
85         return ret;
86     }
87
88     public NodeTypeEnum getNodeType() {
89
90         switch (this) {
91             case RESOURCE:
92                 return NodeTypeEnum.Resource;
93             case SERVICE:
94                 return NodeTypeEnum.Service;
95             case PRODUCT:
96                 return NodeTypeEnum.Product;
97             case RESOURCE_INSTANCE:
98                 return NodeTypeEnum.ResourceInstance;
99             default:
100                 throw new UnsupportedOperationException("No nodeType is defined for: " + this.getValue());
101         }
102     }
103 }