aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java
index 0adb90de80..f2e8c83b26 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java
@@ -315,4 +315,37 @@ public class AttributeOperation extends AbstractOperation {
private void updateAttributeValue(final AttributeDataDefinition attributeDefinition, final JsonElement jsonElement) {
attributeDefinition.set_default(jsonElement);
}
+
+ public Either<Object, Boolean> validateAndUpdateAttributeValue(final String attributeType,
+ final String value,
+ final boolean isValidate,
+ final String innerType,
+ final Map<String, DataTypeDefinition> dataTypes) {
+ log.trace("Going to validate attribute value and its type. type = {}, value = {}", attributeType, value);
+ final ToscaPropertyType type = getType(attributeType);
+ if (isValidate) {
+ if (type == null) {
+ final DataTypeDefinition dataTypeDefinition = dataTypes.get(attributeType);
+ final ImmutablePair<JsonElement, Boolean> validateResult =
+ dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes);
+ if (Boolean.FALSE.equals(validateResult.right)) {
+ log.debug(THE_VALUE_OF_ATTRIBUTE_FROM_TYPE_IS_INVALID, value, attributeType);
+ return Either.right(false);
+ }
+ return Either.left(getValueFromJsonElement(validateResult.left));
+ }
+ log.trace("before validating property type {}", attributeType);
+ if (!isValidValue(type, value, innerType, dataTypes)) {
+ log.debug(THE_VALUE_OF_ATTRIBUTE_FROM_TYPE_IS_INVALID, value, type);
+ return Either.right(false);
+ }
+ }
+ Object convertedValue = value;
+ if (!isEmptyValue(value) && isValidate) {
+ PropertyValueConverter converter = type.getConverter();
+ convertedValue = converter.convert(value, innerType, dataTypes);
+ }
+ return Either.left(convertedValue);
+ }
+
}