Constraint validation for instance attributes in a service 22/131422/3
authorimamSidero <imam.hussain@est.tech>
Tue, 11 Oct 2022 08:56:47 +0000 (09:56 +0100)
committerMichael Morris <michael.morris@est.tech>
Mon, 24 Oct 2022 13:05:56 +0000 (13:05 +0000)
Validating the attributes of instance in a service against it's constraints

Signed-off-by: imamSidero <imam.hussain@est.tech>
Issue-ID: SDC-4209
Change-Id: I7f28f1bd2b209c2d765687e06350711ef9be3c6d

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java

index 0b3610a..e867d06 100644 (file)
@@ -2086,6 +2086,22 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
         }
         final ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
 
+        // Validate instance attributes against it's constraints
+        List<PropertyDefinition> 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<Boolean, ResponseFormat> 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<Boolean, ResponseFormat> validatePropertyValueConstraint(List<ComponentInstanceProperty> properties, final String componentId) {
+    private Either<Boolean, ResponseFormat> validatePropertyValueConstraint(List<? extends PropertyDefinition> properties, final String componentId) {
         try {
             String propertyModel = propertyBusinessLogic.getComponentModelByComponentId(componentId);
             PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil = new PropertyValueConstraintValidationUtil();