From 0c54db816bcadb231b007ce56c5c90d7b96d0706 Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 1 Feb 2023 19:28:28 +0000 Subject: Validate service input default values against constraints Signed-off-by: Vasyl Razinkov Change-Id: Ifd4e3cc5c8dd93282233e4c6bb77fa763d52f922 Issue-ID: SDC-4366 --- .../openecomp/sdc/be/components/impl/InputsBusinessLogic.java | 11 +++++++---- .../utils/PropertyValueConstraintValidationUtil.java | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index 44fecb311b..12a6936895 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -290,6 +290,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { Either 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 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 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()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java index 903c0dd58e..46bd763ec0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java @@ -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; } -- cgit 1.2.3-korg