summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
authoreschcam <cameron.scholes@est.tech>2023-05-29 16:45:58 +0100
committerMichael Morris <michael.morris@est.tech>2023-06-13 10:47:13 +0000
commit762545c2f1ba3480d900d39adde3b1afe3823303 (patch)
tree255449f969854cee81eaf653b917bb28b0ae72d9 /catalog-model/src/main/java
parent89fb96bf935063fdffedafc10a13923dcf02e460 (diff)
[BUG] Fix error when adding valid_values constraint
Issue-ID: SDC-4515 Signed-off-by: eschcam <cameron.scholes@est.tech> Change-Id: Id8f951053581337504b8d75c76d2409ebd71940e
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java25
1 files changed, 21 insertions, 4 deletions
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<Object> 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<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
+ Map<String, Object> 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);