From 8aa94a97ebfff1205e85470d78202f598632dbd6 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 17 Feb 2023 17:10:51 +0000 Subject: Fix constraint validation for yaml values Signed-off-by: MichaelMorris Issue-ID: SDC-4401 Change-Id: I955b12b099c1f72641d97b274864c33288ba88ad --- .../utils/PropertyValueConstraintValidationUtil.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java index 966f13c952..5e127f4695 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java @@ -73,7 +73,7 @@ public class PropertyValueConstraintValidationUtil { dataTypeDefinitionCache = applicationDataTypeCache.getAll(model).left().value(); CollectionUtils.emptyIfNull(propertyDefinitionList).stream() - .filter(this::isValuePresent) + .filter(this::isNonToscaFunctionValuePresent) .forEach(this::evaluatePropertyTypeForConstraintValidation); if (CollectionUtils.isNotEmpty(errorMessages)) { final String errorMsgAsString = String.join(",", errorMessages); @@ -83,7 +83,10 @@ public class PropertyValueConstraintValidationUtil { return Either.left(Boolean.TRUE); } - private boolean isValuePresent(PropertyDefinition propertyDefinition) { + private boolean isNonToscaFunctionValuePresent(PropertyDefinition propertyDefinition) { + if (isValueAToscaFunction(propertyDefinition)) { + return false; + } if (propertyDefinition instanceof ComponentInstanceInput) { return StringUtils.isNotEmpty(propertyDefinition.getValue()); } @@ -137,7 +140,7 @@ public class PropertyValueConstraintValidationUtil { private void evaluateConstraintsOnProperty(PropertyDefinition propertyDefinition) { ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType()); - if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) { + if (!isValueAToscaFunction(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) { for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) { try { propertyConstraint.initialize(toscaType, propertyDefinition.getSchema()); @@ -148,16 +151,16 @@ public class PropertyValueConstraintValidationUtil { errorMessages.add(ie.getMessage()); } } - } else if (isPropertyNotMappedAsInput(propertyDefinition) && ToscaType.isPrimitiveType(propertyDefinition.getType()) + } else if (!isValueAToscaFunction(propertyDefinition) && ToscaType.isPrimitiveType(propertyDefinition.getType()) && !propertyDefinition.isToscaFunction() && !toscaType.isValidValue(propertyDefinition.getValue())) { errorMessages.add(String.format("Unsupported value provided for %s property supported value type is %s.", getCompletePropertyName(propertyDefinition), toscaType.getType())); } } - private boolean isPropertyNotMappedAsInput(PropertyDefinition propertyDefinition) { - return !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY) - && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE); + private boolean isValueAToscaFunction(PropertyDefinition propertyDefinition) { + return propertyDefinition.getToscaFunction() != null || propertyDefinition.getValue() != null && (propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY) + || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE)); } private void checkAndEvaluatePrimitiveProperty(PropertyDefinition propertyDefinition, DataTypeDefinition dataTypeDefinition) { -- cgit 1.2.3-korg