diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-04-15 10:03:58 +0100 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-04-19 15:49:05 +0000 |
commit | 82ee153edbf6ffca0d69bd450b48037ee0465191 (patch) | |
tree | ad3892d4f8cdb5f4acd8b905fce10572dc218877 /catalog-model/src/main | |
parent | aaf0b66c894b0a05fa3ce6a08a71047909e5a913 (diff) |
Fix 'Unable to save changed attributes default value'
Implements missing functionality to save changed attribute
Change-Id: I1bc828ef133c8a2bf2fd6333a51fb46fc41b6547
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3562
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java | 33 |
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); + } + } |