2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.heat.datatypes;
23 import org.apache.commons.lang.math.NumberUtils;
24 import org.apache.commons.lang3.ClassUtils;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.Objects;
31 public enum DefinedHeatParameterTypes {
34 COMMA_DELIMITED_LIST("comma_delimited_list"),
38 private static Map<String, DefinedHeatParameterTypes> stringToDefinedType = new HashMap<>();
41 stringToDefinedType = new HashMap<>();
42 for (DefinedHeatParameterTypes definedHeatParameterType : DefinedHeatParameterTypes.values()) {
43 stringToDefinedType.put(definedHeatParameterType.type, definedHeatParameterType);
49 DefinedHeatParameterTypes(String type) {
53 public static DefinedHeatParameterTypes findByHeatResource(String type) {
54 return stringToDefinedType.get(type);
58 * Is value is from given type boolean.
60 * @param value the value
61 * @param parameterType the parameter type
64 public static boolean isValueIsFromGivenType(Object value, String parameterType) {
65 DefinedHeatParameterTypes definedType = findByHeatResource(parameterType);
67 if (Objects.nonNull(definedType)) {
68 switch (definedType) {
70 return NumberUtils.isNumber(String.valueOf(value));
73 return HeatBoolean.isValueBoolean(value);
75 case COMMA_DELIMITED_LIST:
76 return isValueCommaDelimitedList(value);
79 return isValueJson(value);
82 return isValueString(value);
90 public static boolean isNovaServerEnvValueIsFromRightType(Object value) {
91 return isValueIsFromGivenType(value, COMMA_DELIMITED_LIST.getType())
92 || isValueIsFromGivenType(value, STRING.getType());
95 private static boolean isValueCommaDelimitedList(Object value) {
96 return value instanceof List
97 || String.valueOf(value).contains(",")
98 || isValueIsFromGivenType(value, DefinedHeatParameterTypes.STRING.type);
101 private static boolean isValueString(Object value) {
102 return value instanceof String
103 || ClassUtils.isPrimitiveOrWrapper(value.getClass());
106 private static boolean isValueJson(Object value) {
107 return (value instanceof Map) || (value instanceof List);
110 public static boolean isEmptyValueInEnv(Object value) {
111 return Objects.isNull(value);
114 public String getType() {
118 public void setType(String type) {