Validate service input default values against constraints 25/133125/2
authorvasraz <vasyl.razinkov@est.tech>
Wed, 1 Feb 2023 19:28:28 +0000 (19:28 +0000)
committerMichael Morris <michael.morris@est.tech>
Tue, 7 Feb 2023 17:21:24 +0000 (17:21 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Ifd4e3cc5c8dd93282233e4c6bb77fa763d52f922
Issue-ID: SDC-4366

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java
catalog-ui/src/app/ng2/components/logic/inputs-table/inputs-table.component.ts

index 44fecb3..12a6936 100644 (file)
@@ -290,6 +290,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
             Either<Boolean, ResponseFormat> constraintValidatorResponse = validateInputValueConstraint(inputs, component.getModel());
             if (constraintValidatorResponse.isRight()) {
                 log.error("Failed validation value and constraint of property: {}", constraintValidatorResponse.right().value());
+                unlockComponent(true, component);
                 return Either.right(constraintValidatorResponse.right().value());
             }
             validateCanWorkOnComponent(component, userId);
@@ -301,8 +302,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
                 if (currInput == null) {
                     ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND;
                     log.debug("Failed to found newInput {} under component {}, error: {}", newInput.getUniqueId(), componentId, actionStatus);
-                    result = Either.right(componentsUtils.getResponseFormat(actionStatus));
-                    return result;
+                    unlockComponent(true, component);
+                    return Either.right(componentsUtils.getResponseFormat(actionStatus));
                 }
                 String updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes);
                 currInput.setDefaultValue(updateInputObjectValue);
@@ -317,8 +318,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
                 Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currInput);
                 if (status.isRight()) {
                     ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value());
-                    result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
-                    return result;
+                    unlockComponent(true, component);
+                    return Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
                 } else {
                     returnInputs.add(status.left().value());
                 }
@@ -341,9 +342,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
         List<InputDefinition> inputDefinitions = new ArrayList<>();
         for (InputDefinition inputDefinition : inputs) {
             InputDefinition inputDef = new InputDefinition();
+            inputDef.setName(inputDefinition.getName());
             inputDef.setDefaultValue(inputDefinition.getDefaultValue());
             inputDef.setInputPath(inputDefinition.getSubPropertyInputPath());
             inputDef.setType(inputDefinition.getType());
+            inputDef.setConstraints(inputDefinition.getConstraints());
             if (Objects.nonNull(inputDefinition.getParentPropertyType())) {
                 ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
                 propertyDefinition.setType(inputDefinition.getParentPropertyType());
index 903c0dd..46bd763 100644 (file)
@@ -413,8 +413,10 @@ public class PropertyValueConstraintValidationUtil {
             propertyDefinition.setType(inputDefinition.getType());
             propertyDefinition.setValue(inputDefinition.getDefaultValue());
             propertyDefinition.setName(inputDefinition.getName());
+            propertyDefinition.setConstraints(inputDefinition.getConstraints());
         } else if (Objects.nonNull(inputDefinition.getInputPath())) {
             propertyDefinition = evaluateComplexTypeInputs(inputDefinition);
+            propertyDefinition.setConstraints(inputDefinition.getConstraints());
         }
         return propertyDefinition;
     }
index 8ba6da5..3017a05 100644 (file)
@@ -78,7 +78,7 @@ public class EqualConstraint extends AbstractComparablePropertyConstraint {
 
     @Override
     public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
-        return getErrorMessage(toscaType, e, propertyName, "%s property value must be %s", String.valueOf(equal));
+        return getErrorMessage(toscaType, e, propertyName, "'%s' value must be %s", String.valueOf(equal));
     }
 
     @Override
index 9120535..c0311c8 100644 (file)
@@ -64,7 +64,7 @@ public class GreaterOrEqualConstraint<T> extends AbstractComparablePropertyConst
 
     @Override
     public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
-        return getErrorMessage(toscaType, e, propertyName, "%s property value must be greater than or equal to %s", String.valueOf(greaterOrEqual));
+        return getErrorMessage(toscaType, e, propertyName, "'%s' value must be greater than or equal to %s", String.valueOf(greaterOrEqual));
     }
 
     @Override
index 7ecec8a..3da45e1 100644 (file)
@@ -64,7 +64,7 @@ public class GreaterThanConstraint<T> extends AbstractComparablePropertyConstrai
 
     @Override
     public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
-        return getErrorMessage(toscaType, e, propertyName, "%s property value must be greater than %s", String.valueOf(greaterThan));
+        return getErrorMessage(toscaType, e, propertyName, "'%s' value must be greater than %s", String.valueOf(greaterThan));
     }
 
     @Override
index ece5e40..86b1d27 100644 (file)
@@ -64,7 +64,7 @@ public class LessOrEqualConstraint<T> extends AbstractComparablePropertyConstrai
 
     @Override
     public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
-        return getErrorMessage(toscaType, e, propertyName, "%s property value must be less than or equal to %s", String.valueOf(lessOrEqual));
+        return getErrorMessage(toscaType, e, propertyName, "'%s' value must be less than or equal to %s", String.valueOf(lessOrEqual));
     }
 
     @Override
index b2f5a47..8307184 100644 (file)
@@ -64,7 +64,7 @@ public class LessThanConstraint<T> extends AbstractComparablePropertyConstraint
 
     @Override
     public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
-        return getErrorMessage(toscaType, e, propertyName, "%s value must be less than %s", String.valueOf(lessThan));
+        return getErrorMessage(toscaType, e, propertyName, "'%s' value must be less than %s", String.valueOf(lessThan));
     }
 
     @Override
index bf979fe..1fd1adf 100644 (file)
@@ -118,7 +118,7 @@ public class ValidValuesConstraint extends AbstractPropertyConstraint {
 
     @Override
     public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
-        return getErrorMessage(toscaType, e, propertyName, "%s valid value must be one of the following: [%s]", String.join(",", String.valueOf(validValues)));
+        return getErrorMessage(toscaType, e, propertyName, "'%s' value must be one of the following: [%s]", String.join(",", String.valueOf(validValues)));
     }
 
     public boolean validateValueType(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
index ec18767..c2a872f 100644 (file)
@@ -180,7 +180,7 @@ export class InputsTableComponent {
 
     public updateProperty = (inputProperty: InputFEModel): void => {
         let modelProperty : PropertyModel = this.createPropertyModel(inputProperty);
-        if (inputProperty.instanceUniqueId != null && this.componentInstancePropertyMap != null && modelProperty.constraints == null) {
+        if (inputProperty.instanceUniqueId != null && this.componentInstancePropertyMap != null && modelProperty.constraints == null && this.componentInstancePropertyMap[inputProperty.instanceUniqueId]) {
             this.componentInstancePropertyMap[inputProperty.instanceUniqueId].forEach(tempProperty => {
                 modelProperty.constraints = tempProperty.constraints;
             });