aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2019-10-01 16:47:26 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-11-19 07:48:02 +0000
commit35b5687d60558bac72c1e53ddd9044584964a3d8 (patch)
treedc2e184f2cef02c6d1aee0b5baf1585d2b7b3ffe /catalog-model/src/main/java
parent0f9257b8265404c82ccdfae6aafce940f20a2947 (diff)
Fix for scalar-unit type value.
Issue-ID: SDC-323 Change-Id: I7f19a7356e1cd34deca0a168b3cb707ef657b9cb Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java54
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatNumberConverter.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java20
3 files changed, 40 insertions, 43 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java
index f5f4d9ff2d..503cf61e70 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java
@@ -20,9 +20,23 @@
package org.openecomp.sdc.be.model.heat;
-import org.openecomp.sdc.be.model.tosca.converters.*;
-import org.openecomp.sdc.be.model.tosca.validators.*;
-
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import org.openecomp.sdc.be.model.tosca.converters.HeatBooleanConverter;
+import org.openecomp.sdc.be.model.tosca.converters.HeatCommaDelimitedListConverter;
+import org.openecomp.sdc.be.model.tosca.converters.HeatJsonConverter;
+import org.openecomp.sdc.be.model.tosca.converters.HeatNumberConverter;
+import org.openecomp.sdc.be.model.tosca.converters.HeatStringConverter;
+import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
+import org.openecomp.sdc.be.model.tosca.validators.HeatBooleanValidator;
+import org.openecomp.sdc.be.model.tosca.validators.HeatCommaDelimitedListValidator;
+import org.openecomp.sdc.be.model.tosca.validators.HeatNumberValidator;
+import org.openecomp.sdc.be.model.tosca.validators.HeatStringValidator;
+import org.openecomp.sdc.be.model.tosca.validators.PropertyTypeValidator;
+
+
+@AllArgsConstructor
+@Getter
public enum HeatParameterType {
STRING("string", HeatStringValidator.getInstance(), HeatStringConverter.getInstance()),
@@ -40,42 +54,12 @@ public enum HeatParameterType {
private PropertyTypeValidator validator;
private PropertyValueConverter converter;
- HeatParameterType(String type, PropertyTypeValidator validator, PropertyValueConverter converter) {
- this.type = type;
- this.validator = validator;
- this.converter = converter;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public PropertyTypeValidator getValidator() {
- return validator;
- }
-
- public void setValidator(PropertyTypeValidator validator) {
- this.validator = validator;
- }
-
- public PropertyValueConverter getConverter() {
- return converter;
- }
-
- public void setConverter(PropertyValueConverter converter) {
- this.converter = converter;
- }
-
- public static HeatParameterType isValidType(String typeName) {
+ public static HeatParameterType isValidType(final String typeName) {
if (typeName == null) {
return null;
}
- for (HeatParameterType type : HeatParameterType.values()) {
+ for (final HeatParameterType type : HeatParameterType.values()) {
if (type.getType().equals(typeName)) {
return type;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatNumberConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatNumberConverter.java
index 187793ee0b..b2237d0f35 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatNumberConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatNumberConverter.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.tosca.converters;
+import org.onap.sdc.tosca.datatypes.model.ScalarUnitValidator;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import java.math.BigDecimal;
@@ -33,17 +34,23 @@ public class HeatNumberConverter implements PropertyValueConverter {
return numberConverter;
}
+ private final ScalarUnitValidator scalarUnitValidator = ScalarUnitValidator.getInstance();
+
+
private HeatNumberConverter() {
}
@Override
public String convert(String original, String innerType, Map<String, DataTypeDefinition> dataTypes) {
-
if (original == null || original.isEmpty()) {
return null;
}
+ if (scalarUnitValidator.isScalarUnit(original)) {
+ return original;
+ }
+
return new BigDecimal(original).toPlainString();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java
index 0ae3f74c85..ec281c0618 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/HeatNumberValidator.java
@@ -20,27 +20,29 @@
package org.openecomp.sdc.be.model.tosca.validators;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-
import java.util.Map;
+import org.onap.sdc.tosca.datatypes.model.ScalarUnitValidator;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
public class HeatNumberValidator implements PropertyTypeValidator {
private static HeatNumberValidator numberValidator = new HeatNumberValidator();
- private static FloatValidator floatValidator = FloatValidator.getInstance();
- private static IntegerValidator integerValidator = IntegerValidator.getInstance();
+ private final FloatValidator floatValidator = FloatValidator.getInstance();
+ private final IntegerValidator integerValidator = IntegerValidator.getInstance();
+ private final ScalarUnitValidator scalarUnitValidator = ScalarUnitValidator.getInstance();
public static HeatNumberValidator getInstance() {
return numberValidator;
}
private HeatNumberValidator() {
-
}
@Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ public boolean isValid(final String value,
+ final String innerType,
+ final Map<String, DataTypeDefinition> allDataTypes) {
if (value == null || value.isEmpty()) {
return true;
@@ -51,11 +53,15 @@ public class HeatNumberValidator implements PropertyTypeValidator {
valid = floatValidator.isValid(value, null, allDataTypes);
}
+ if(!valid) {
+ valid = scalarUnitValidator.isScalarUnit(value);
+ }
+
return valid;
}
@Override
- public boolean isValid(String value, String innerType) {
+ public boolean isValid(final String value, final String innerType) {
return isValid(value, innerType, null);
}
}