diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java')
-rw-r--r-- | openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java index 600917201b..4205f0bee3 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java @@ -24,10 +24,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; - +import lombok.AllArgsConstructor; +import lombok.Getter; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.ClassUtils; +import org.onap.sdc.tosca.datatypes.model.ScalarUnitValidator; +@AllArgsConstructor +@Getter public enum DefinedHeatParameterTypes { NUMBER("number"), STRING("string"), @@ -35,22 +39,19 @@ public enum DefinedHeatParameterTypes { JSON("json"), BOOLEAN("boolean"); + private static ScalarUnitValidator scalarUnitValidator = ScalarUnitValidator.getInstance(); private static Map<String, DefinedHeatParameterTypes> stringToDefinedType; static { stringToDefinedType = new HashMap<>(); - for (DefinedHeatParameterTypes definedHeatParameterType : DefinedHeatParameterTypes.values()) { + for (final DefinedHeatParameterTypes definedHeatParameterType : DefinedHeatParameterTypes.values()) { stringToDefinedType.put(definedHeatParameterType.type, definedHeatParameterType); } } private String type; - DefinedHeatParameterTypes(String type) { - this.type = type; - } - - public static DefinedHeatParameterTypes findByHeatResource(String type) { + public static DefinedHeatParameterTypes findByHeatResource(final String type) { return stringToDefinedType.get(type); } @@ -61,12 +62,17 @@ public enum DefinedHeatParameterTypes { * @param parameterType the parameter type * @return the boolean */ - public static boolean isValueIsFromGivenType(Object value, String parameterType) { - DefinedHeatParameterTypes definedType = findByHeatResource(parameterType); + public static boolean isValueIsFromGivenType(final Object value, final String parameterType) { + final DefinedHeatParameterTypes definedType = findByHeatResource(parameterType); if (Objects.nonNull(definedType)) { switch (definedType) { case NUMBER: + if (scalarUnitValidator.isValueScalarUnit(value, ToscaScalarUnitSize.class) || + scalarUnitValidator.isValueScalarUnit(value, ToscaScalarUnitTime.class) || + scalarUnitValidator.isValueScalarUnit(value, ToscaScalarUnitFrequency.class)) { + return isValueString(value); + } return NumberUtils.isNumber(String.valueOf(value)); case BOOLEAN: @@ -87,35 +93,28 @@ public enum DefinedHeatParameterTypes { return false; } - public static boolean isNovaServerEnvValueIsFromRightType(Object value) { + public static boolean isNovaServerEnvValueIsFromRightType(final Object value) { return isValueIsFromGivenType(value, COMMA_DELIMITED_LIST.getType()) || isValueIsFromGivenType(value, STRING.getType()); } - private static boolean isValueCommaDelimitedList(Object value) { + private static boolean isValueCommaDelimitedList(final Object value) { return value instanceof List || String.valueOf(value).contains(",") || isValueIsFromGivenType(value, DefinedHeatParameterTypes.STRING.type); } - private static boolean isValueString(Object value) { + private static boolean isValueString(final Object value) { return value instanceof String || ClassUtils.isPrimitiveOrWrapper(value.getClass()); } - private static boolean isValueJson(Object value) { + private static boolean isValueJson(final Object value) { return (value instanceof Map) || (value instanceof List); } - public static boolean isEmptyValueInEnv(Object value) { + public static boolean isEmptyValueInEnv(final Object value) { return Objects.isNull(value); } - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } } |