diff options
author | MichaelMorris <michael.morris@est.tech> | 2023-02-22 14:33:47 +0000 |
---|---|---|
committer | Francisco Javier Paradela Vila <javier.paradela.vila@est.tech> | 2023-02-24 11:31:10 +0000 |
commit | 5526028d3bc464937c9a4373a7fc6e577d781cad (patch) | |
tree | b367e438fac665cd42c4062b1829d3059be4c81a /catalog-model/src | |
parent | 96bfbbad6b2a7e6db7d4e78ed182c8be4f7c895f (diff) |
Fix valid values for list and map
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-4412
Change-Id: I672193784c51250173b7e5c4c43354a0b9852c21
Diffstat (limited to 'catalog-model/src')
5 files changed, 20 insertions, 11 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java index df961acb6e..51f0dbc67a 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java @@ -34,7 +34,7 @@ public interface PropertyConstraint { void validate(Object propertyValue) throws ConstraintViolationException; - void validate(ToscaType toscaType, SchemaDefinition schema, String propertyTextValue) throws ConstraintViolationException; + void validate(PropertyDefinition property) throws ConstraintViolationException; @JsonIgnore ConstraintType getConstraintType(); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java index 2d88f38977..dbe11a8efd 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java @@ -2464,8 +2464,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe if (rangeArray.size() != 2) { log.error("The range constraint content is invalid. value = {}", value); } else { - final String minValue = rangeArray.get(0).asText(); - final String maxValue = rangeArray.get(1).asText(); + final Object minValue = convertToType(rangeArray.get(0)); + final Object maxValue = convertToType(rangeArray.get(1)); final Comparable min = ConstraintUtil.convertToComparable( ToscaType.getToscaType(minValue.getClass().getSimpleName().toLowerCase()), String.valueOf(minValue)); final Comparable max = ConstraintUtil.convertToComparable( diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraint.java index b8e2e26660..8e09648804 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraint.java @@ -23,6 +23,7 @@ import java.util.Arrays; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.model.PropertyConstraint; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; @@ -34,8 +35,8 @@ public abstract class AbstractPropertyConstraint implements PropertyConstraint { private static final String INVALID_VALUE_ERROR_MESSAGE = "Unsupported value provided for %s property supported value type is %s."; @Override - public void validate(ToscaType toscaType, SchemaDefinition schema, String propertyTextValue) throws ConstraintViolationException { - validate(toscaType, propertyTextValue); + public void validate(PropertyDefinition property) throws ConstraintViolationException { + validate(ToscaType.isValidType(property.getType()), property.getValue()); } protected void validate(ToscaType toscaType, String propertyTextValue) throws ConstraintViolationException { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java index 4970808948..ea7642b459 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.model.tosca.constraints; import static java.util.stream.Collectors.toList; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -38,6 +39,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.model.PropertyConstraint; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; @@ -113,18 +115,24 @@ public class ValidValuesConstraint extends AbstractPropertyConstraint { } @Override - public void validate(ToscaType toscaType, SchemaDefinition schema, String propertyTextValue) throws ConstraintViolationException { + public void validate(PropertyDefinition propertyDefinition) throws ConstraintViolationException { + ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType()); try { Collection<Object> valuesToValidate; if (ToscaType.LIST == toscaType) { - valuesToValidate = ConstraintUtil.parseToCollection(propertyTextValue, new TypeReference<>() {}); + valuesToValidate = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {}); } else if (ToscaType.MAP == toscaType) { - final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyTextValue, new TypeReference<>() {}); + final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {}); valuesToValidate = map.values(); } else { - valuesToValidate = Collections.singleton(propertyTextValue); + valuesToValidate = Collections.singleton(propertyDefinition.getValue()); } - ToscaType valuesType = getValuesType(toscaType, schema); + if (propertyDefinition.getSubPropertyToscaFunctions() != null) { + propertyDefinition.getSubPropertyToscaFunctions().forEach(subPropToscaFunction -> { + valuesToValidate.remove(subPropToscaFunction.getToscaFunction().getJsonObjectValue()); + }); + } + ToscaType valuesType = getValuesType(toscaType, propertyDefinition.getSchema()); for (final Object value: valuesToValidate) { validate(valuesType, value.toString()); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java index 595437fab6..be814afa54 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java @@ -62,7 +62,7 @@ public class AbstractStringPropertyConstraintTest { @Test(expected = ConstraintViolationException.class) public void testValidateNull() throws ConstraintViolationException { // when - constraint.validate(null); + constraint.validate((String)null); } @Test(expected = ConstraintViolationException.class) |