From 762545c2f1ba3480d900d39adde3b1afe3823303 Mon Sep 17 00:00:00 2001 From: eschcam Date: Mon, 29 May 2023 16:45:58 +0100 Subject: [BUG] Fix error when adding valid_values constraint Issue-ID: SDC-4515 Signed-off-by: eschcam Change-Id: Id8f951053581337504b8d75c76d2409ebd71940e --- .../tosca/constraints/ValidValuesConstraint.java | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'catalog-model/src/main/java/org/openecomp') 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 ea7642b459..569294d0b8 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 @@ -120,12 +120,27 @@ public class ValidValuesConstraint extends AbstractPropertyConstraint { try { Collection valuesToValidate; if (ToscaType.LIST == toscaType) { - valuesToValidate = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {}); + if (propertyDefinition.getValue() != null) { + valuesToValidate = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {}); + } else { + valuesToValidate = ConstraintUtil.parseToCollection(propertyDefinition.getDefaultValue(), new TypeReference<>() {}); + } } else if (ToscaType.MAP == toscaType) { - final Map map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {}); + Map map; + + if (propertyDefinition.getValue() != null) { + map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {}); + } else { + map = ConstraintUtil.parseToCollection(propertyDefinition.getDefaultValue(), new TypeReference<>() {}); + } + valuesToValidate = map.values(); } else { - valuesToValidate = Collections.singleton(propertyDefinition.getValue()); + if (propertyDefinition.getValue() != null) { + valuesToValidate = Collections.singleton(propertyDefinition.getValue()); + } else { + valuesToValidate = Collections.singleton(propertyDefinition.getDefaultValue()); + } } if (propertyDefinition.getSubPropertyToscaFunctions() != null) { propertyDefinition.getSubPropertyToscaFunctions().forEach(subPropToscaFunction -> { @@ -134,7 +149,9 @@ public class ValidValuesConstraint extends AbstractPropertyConstraint { } ToscaType valuesType = getValuesType(toscaType, propertyDefinition.getSchema()); for (final Object value: valuesToValidate) { - validate(valuesType, value.toString()); + if (value != null) { + validate(valuesType, value.toString()); + } } } catch (ConstraintValueDoNotMatchPropertyTypeException exception) { throw new ConstraintViolationException("Value cannot be parsed to a list", exception); -- cgit 1.2.3-korg