From c29a4519545ff509c038c9a19781ef210b2ee14f Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Wed, 11 Jan 2023 18:41:05 +0000 Subject: Constraint validation - Policy Properties in a Service Issue-ID: SDC-4320 Signed-off-by: KrupaNagabhushan Change-Id: I5f04b630f89b96d7a662fbab8894961670502f52 --- .../sdc/be/components/impl/PolicyBusinessLogic.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java index 3d971663b1..113f8ba4dc 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java @@ -41,11 +41,13 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator; import org.openecomp.sdc.be.components.validation.PolicyUtils; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.datamodel.utils.PropertyValueConstraintValidationUtil; import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType; @@ -60,6 +62,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation; @@ -690,10 +693,26 @@ public class PolicyBusinessLogic extends BaseBusinessLogic { final PropertyDataDefinition currentProperty = oldProperties.get(newProperty.getName()); currentProperty.setValue(newPropertyValueEither); currentProperty.setToscaFunction(newProperty.getToscaFunction()); + validatePropertyValueWithConstraints(currentProperty, policyOwnerComponent); } return policy; } + private void validatePropertyValueWithConstraints(final PropertyDataDefinition property, final Component component) { + PropertyDefinition propertyDefinition = new PropertyDefinition(property); + if (!propertyDefinition.isToscaFunction()) { + List propertyDefinitionList = new ArrayList<>(); + propertyDefinitionList.add(propertyDefinition); + PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil = new PropertyValueConstraintValidationUtil(); + Either isPropertyContraintsValid = propertyValueConstraintValidationUtil + .validatePropertyConstraints(propertyDefinitionList, applicationDataTypeCache, + component.getModel()); + if (isPropertyContraintsValid.isRight()) { + throw new ByResponseFormatComponentException(isPropertyContraintsValid.right().value()); + } + } + } + private String updatePropertyValue(final Component policyOwnerComponent, final T property) { Either isValid = propertyOperation .validateAndUpdatePropertyValue(policyOwnerComponent, property, -- cgit 1.2.3-korg