From aa92493c97b43075c18696d79f7d1bf62aa4805a Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Tue, 6 Dec 2022 11:40:17 +0000 Subject: Fix resource property constraint values mutable in Service design Issue-ID: SDC-4290 Signed-off-by: JvD_Ericsson Change-Id: Ica942b7a8bb1f03cbf6baec709135287e31def06 --- .../files/default/error-configuration.yaml | 9 ++++++++- .../impl/ComponentInstanceBusinessLogic.java | 18 ++++++++++++++++++ .../src/main/resources/config/error-configuration.yaml | 9 ++++++++- .../impl/ComponentInstanceBusinessLogicTest.java | 10 ++++++++++ .../config/catalog-be/error-configuration.yaml | 9 ++++++++- 5 files changed, 52 insertions(+), 3 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml index a9df460cf2..0530298219 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml @@ -2862,4 +2862,11 @@ errors: CAPABILITY_NOT_FOUND: code: 404 message: "Capability '%1' was not found for model '%2'." - messageId: "SVC4014" \ No newline at end of file + messageId: "SVC4014" + + #---------SVC4015----------------------------- + CANNOT_CHANGE_CONSTRAINTS: { + code: 400, + message: "Cannot change this properties constraints as the resource is an instance.", + messageId: "SVC4015" + } \ No newline at end of file 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 fe6ea03562..64c66c5d79 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 @@ -104,6 +104,7 @@ import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.PolicyDefinition; +import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.RelationshipInfo; import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; @@ -1975,6 +1976,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { for (ComponentInstanceProperty property : properties) { validateMandatoryFields(property); validatePropertyExistsOnComponent(property, containerComponent, foundResourceInstance); + validatePropertyConstraintsNotChanged(properties, foundResourceInstance); String propertyParentUniqueId = property.getParentUniqueId(); if (property.isToscaFunction()) { toscaFunctionValidator.validate(property, containerComponent); @@ -3993,6 +3995,22 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } + private void validatePropertyConstraintsNotChanged(List newProperties, ComponentInstance originalResourceInstance) { + for (ComponentInstanceProperty newProperty : newProperties) { + Optional originalProperty = originalResourceInstance.getProperties().stream() + .filter(prop -> prop.getUniqueId().equals(newProperty.getUniqueId())).findAny(); + if (originalProperty.isPresent()) { + List originalConstraints = originalProperty.get().getConstraints(); + List newConstraints = newProperty.getConstraints(); + if (!Objects.equals(originalConstraints, newConstraints)) { + throw new ByActionStatusComponentException(ActionStatus.CANNOT_CHANGE_CONSTRAINTS); + } + } else { + throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, newProperty.getUniqueId()); + } + } + } + private Either validatePropertyValueConstraint(List properties, final String componentId) { try { String propertyModel = propertyBusinessLogic.getComponentModelByComponentId(componentId); diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml index c53efc21b1..56dd54c5e4 100644 --- a/catalog-be/src/main/resources/config/error-configuration.yaml +++ b/catalog-be/src/main/resources/config/error-configuration.yaml @@ -2862,4 +2862,11 @@ errors: CAPABILITY_NOT_FOUND: code: 404 message: "Capability '%1' was not found for model '%2'." - messageId: "SVC4014" \ No newline at end of file + messageId: "SVC4014" + + #---------SVC4015----------------------------- + CANNOT_CHANGE_CONSTRAINTS: { + code: 400, + message: "Cannot change this properties constraints as the resource is an instance.", + messageId: "SVC4015" + } \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index f22b346052..f6a86ac02f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -319,6 +319,7 @@ class ComponentInstanceBusinessLogicTest { property.setName("property"); property.setValue("newVal"); property.setType("string"); + property.setUniqueId("propId"); properties.add(property); List origProperties = new ArrayList<>(); @@ -328,6 +329,14 @@ class ComponentInstanceBusinessLogicTest { origProperty.setType("string"); origProperties.add(origProperty); + List ciProperties = new ArrayList<>(); + PropertyDefinition ciProperty = new ComponentInstanceProperty(); + ciProperty.setName("property"); + ciProperty.setValue("value"); + ciProperty.setType("string"); + ciProperty.setUniqueId("propId"); + ciProperties.add(ciProperty); + Map types = new HashMap<>(); DataTypeDefinition dataTypeDef = new DataTypeDefinition(); types.put("string", dataTypeDef); @@ -340,6 +349,7 @@ class ComponentInstanceBusinessLogicTest { component.setComponentInstancesProperties(componentInstanceProps); ComponentInstance ci = createComponentInstance("ci1"); ci.setUniqueId("resourceId"); + ci.setProperties(ciProperties); component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"), createComponentInstance(componentInstanceID))); diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml index b3df674126..fc4e7d33b7 100644 --- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml +++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml @@ -2848,4 +2848,11 @@ errors: CAPABILITY_NOT_FOUND: code: 404 message: "Capability '%1' was not found for model '%2'." - messageId: "SVC4014" \ No newline at end of file + messageId: "SVC4014" + + #---------SVC4015----------------------------- + CANNOT_CHANGE_CONSTRAINTS: { + code: 400, + message: "Cannot change this properties constraints as the resource is an instance.", + messageId: "SVC4015" + } \ No newline at end of file -- cgit 1.2.3-korg