diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/main')
5 files changed, 145 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; - } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitFrequency.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitFrequency.java new file mode 100644 index 0000000000..8ec246555a --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitFrequency.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.heat.datatypes; + +/** + * This enum is responsible for defining properties that have scalar values measured in units per second. + */ +public enum ToscaScalarUnitFrequency { + + HZ, KHZ, MHZ, GHZ + +} diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitSize.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitSize.java new file mode 100644 index 0000000000..12f6a176a3 --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitSize.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.heat.datatypes; + +/** + * This enum is responsible for defining properties that have scalar values measured in size units. + */ +public enum ToscaScalarUnitSize { + + B, KB, KIB, MB, MIB, GB, GIB, TB, TIB + +} diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitTime.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitTime.java new file mode 100644 index 0000000000..0a41a63ed1 --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitTime.java @@ -0,0 +1,30 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.heat.datatypes; + + +/** + * This enum is responsible for defining properties that have scalar values measured in size units. + */ +public enum ToscaScalarUnitTime { + + D, H, M, S, MS, US, NS + +} diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitTypes.java new file mode 100644 index 0000000000..05cc97c8dc --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/ToscaScalarUnitTypes.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.heat.datatypes; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * This enum is responsible for defining all Tosca Scalar Unit types Supported. + */ +@Getter +@AllArgsConstructor +public enum ToscaScalarUnitTypes { + + SCALAR_UNIT_SIZE("scalar-unit.size"), + SCALAR_UNIT_TIME("scalar-unit.time"), + SCALAR_UNIT_FREQUENCY("scalar-unit.frequency"); + + private String type; +} |