aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java10
2 files changed, 17 insertions, 4 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 ef7363a1a3..74cf8eb43f 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
@@ -96,7 +96,7 @@ public class PropertyValueConstraintValidationUtil {
if (propertyDefinition instanceof InputDefinition) {
return StringUtils.isNotEmpty(propertyDefinition.getDefaultValue());
}
- return StringUtils.isNotEmpty(propertyDefinition.getValue());
+ return StringUtils.isNotEmpty(propertyDefinition.getValue() != null ? propertyDefinition.getValue() : propertyDefinition.getDefaultValue());
}
private void evaluatePropertyTypeForConstraintValidation(PropertyDefinition propertyDefinition) {
@@ -155,7 +155,8 @@ public class PropertyValueConstraintValidationUtil {
}
}
} else if (!isValueAToscaFunction(propertyDefinition) && ToscaType.isPrimitiveType(propertyDefinition.getType())
- && !propertyDefinition.isToscaFunction() && !toscaType.isValidValue(propertyDefinition.getValue())) {
+ && !propertyDefinition.isToscaFunction() && !toscaType.isValidValue(
+ propertyDefinition.getValue() != null ? propertyDefinition.getValue() : propertyDefinition.getDefaultValue())) {
errorMessages.add(String.format("Unsupported value provided for %s property supported value type is %s.",
getCompletePropertyName(propertyDefinition), toscaType.getType()));
}
@@ -245,7 +246,8 @@ public class PropertyValueConstraintValidationUtil {
return StringUtils.isNotEmpty(propertyDefinition.getValue()) &&
!"null".equals(propertyDefinition.getValue());
} else if (ToscaType.LIST == ToscaType.isValidType(propertyDefinition.getType())) {
- Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
+ Collection<?> list = ConstraintUtil.parseToCollection(null != propertyDefinition.getValue() ?
+ propertyDefinition.getValue() : propertyDefinition.getDefaultValue(), new TypeReference<List<?>>() {
});
return CollectionUtils.isNotEmpty(list);
} else {
@@ -323,7 +325,8 @@ public class PropertyValueConstraintValidationUtil {
if (propertyDefinition.getSchemaType() == null) {
propertyDefinition.setSchema(createStringSchema());
}
- Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
+ Collection<?> list = ConstraintUtil.parseToCollection(null != propertyDefinition.getValue() ?
+ propertyDefinition.getValue() : propertyDefinition.getDefaultValue(), new TypeReference<List<?>>() {});
final Map<String, Object> map = new HashMap<>();
int index = 0;
for (Object obj : list) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
index c58c43db52..c291522ca7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
@@ -268,6 +268,16 @@ public class ComponentPropertyServlet extends BeGenericServlet {
log.info("Property content is invalid - {}", data);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
}
+
+ //Validate value and Constraint of property and Fetch all data types from cache
+ Either<Boolean, ResponseFormat> constraintValidatorResponse = new PropertyValueConstraintValidationUtil()
+ .validatePropertyConstraints(properties.values(), applicationDataTypeCache,
+ propertyBusinessLogic.getComponentModelByComponentId(componentId));
+ if (constraintValidatorResponse.isRight()) {
+ log.error("Failed validation value and constraint of property: {}", constraintValidatorResponse.right().value());
+ return buildErrorResponse(constraintValidatorResponse.right().value());
+ }
+
Map.Entry<String, PropertyDefinition> entry = properties.entrySet().iterator().next();
PropertyDefinition newPropertyDefinition = entry.getValue();
newPropertyDefinition.setParentUniqueId(componentId);