aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2023-02-17 17:10:51 +0000
committerJEFF VAN DAM <jeff.van.dam@est.tech>2023-02-22 14:08:01 +0000
commit8aa94a97ebfff1205e85470d78202f598632dbd6 (patch)
tree03abbfbee8a98317b18ba166d9ae76ac54835d04
parent3a7add7ec56db4a7c0d62e2c86150f9a216ad041 (diff)
Fix constraint validation for yaml values
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4401 Change-Id: I955b12b099c1f72641d97b274864c33288ba88ad
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java17
1 files changed, 10 insertions, 7 deletions
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) {