From aa361f84ec4d137e7a64df8c7feaec6d2304c03e Mon Sep 17 00:00:00 2001 From: imamSidero Date: Tue, 11 Oct 2022 09:56:47 +0100 Subject: Constraint validation for instance attributes in a service Validating the attributes of instance in a service against it's constraints Signed-off-by: imamSidero Issue-ID: SDC-4209 Change-Id: I7f28f1bd2b209c2d765687e06350711ef9be3c6d --- .../impl/ComponentInstanceBusinessLogic.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 0b3610a611..e867d0639e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -2086,6 +2086,22 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } final ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value(); + // Validate instance attributes against it's constraints + List attributesToValidate = new ArrayList<>(); + attributes.forEach((componentInstanceAttribute) -> { + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setValue(componentInstanceAttribute.getValue()); + propertyDefinition.setType(componentInstanceAttribute.getType()); + propertyDefinition.setName(componentInstanceAttribute.getName()); + propertyDefinition.setUniqueId(componentInstanceAttribute.getUniqueId()); + attributesToValidate.add(propertyDefinition); + }); + Either constraintValidatorResponse = validatePropertyValueConstraint(attributesToValidate,componentId); + if (constraintValidatorResponse.isRight()) { + log.error("Failed validation value and constraint of attribute: {}", constraintValidatorResponse.right().value()); + return Either.right(constraintValidatorResponse.right().value()); + } + // lock resource final StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType()); if (lockStatus != StorageOperationStatus.OK) { @@ -3918,7 +3934,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } - private Either validatePropertyValueConstraint(List properties, final String componentId) { + private Either validatePropertyValueConstraint(List properties, final String componentId) { try { String propertyModel = propertyBusinessLogic.getComponentModelByComponentId(componentId); PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil = new PropertyValueConstraintValidationUtil(); -- cgit 1.2.3-korg