Fix constraint validation for yaml values 37/133337/3
authorMichaelMorris <michael.morris@est.tech>
Fri, 17 Feb 2023 17:10:51 +0000 (17:10 +0000)
committerJEFF VAN DAM <jeff.van.dam@est.tech>
Wed, 22 Feb 2023 14:08:01 +0000 (14:08 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-4401
Change-Id: I955b12b099c1f72641d97b274864c33288ba88ad

catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java

index 966f13c..5e127f4 100644 (file)
@@ -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) {