From 865692e5607193510a2cafbfee3a7f02560463d8 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Wed, 8 Jun 2022 19:29:41 +0100 Subject: Fix getToscaFunction validation for property value Issue-ID: SDC-4039 Signed-off-by: KrupaNagabhushan Change-Id: I75c7c8338490df235c2b43db88f708dc649a9667 --- .../impl/ComponentInstanceBusinessLogic.java | 26 +++++++++++++++++ .../ToscaGetFunctionExceptionSupplier.java | 34 +++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'catalog-be/src/main/java/org') 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 ec4535a27d..ab01b99957 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 @@ -2369,6 +2369,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { private void validateToscaGetFunction(T property, Component parentComponent) { final ToscaGetFunctionDataDefinition toscaGetFunction = property.getToscaGetFunction(); + validateGetToscaFunctionAttributes(toscaGetFunction); validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource()); if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) { validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel()); @@ -2471,6 +2472,31 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } + private void validateGetToscaFunctionAttributes(final ToscaGetFunctionDataDefinition toscaGetFunction) { + if (toscaGetFunction.getFunctionType() == null) { + throw ToscaGetFunctionExceptionSupplier.targetFunctionTypeNotFound().get(); + } + if (toscaGetFunction.getPropertySource() == null) { + throw ToscaGetFunctionExceptionSupplier.targetPropertySourceNotFound(toscaGetFunction.getFunctionType()).get(); + } + if (CollectionUtils.isEmpty(toscaGetFunction.getPropertyPathFromSource())) { + throw ToscaGetFunctionExceptionSupplier + .targetSourcePathNotFound(toscaGetFunction.getFunctionType()).get(); + } + if (StringUtils.isEmpty(toscaGetFunction.getSourceName()) || StringUtils.isBlank(toscaGetFunction.getSourceName())) { + throw ToscaGetFunctionExceptionSupplier.sourceNameNotFound(toscaGetFunction.getPropertySource()).get(); + } + if (StringUtils.isEmpty(toscaGetFunction.getSourceUniqueId()) || StringUtils.isBlank(toscaGetFunction.getSourceUniqueId())) { + throw ToscaGetFunctionExceptionSupplier.sourceIdNotFound(toscaGetFunction.getPropertySource()).get(); + } + if (StringUtils.isEmpty(toscaGetFunction.getPropertyName()) || StringUtils.isBlank(toscaGetFunction.getPropertyName())) { + throw ToscaGetFunctionExceptionSupplier.propertyNameNotFound(toscaGetFunction.getPropertySource()).get(); + } + if (StringUtils.isEmpty(toscaGetFunction.getPropertyUniqueId()) || StringUtils.isBlank(toscaGetFunction.getPropertyUniqueId())) { + throw ToscaGetFunctionExceptionSupplier.propertyIdNotFound(toscaGetFunction.getPropertySource()).get(); + } + } + private ResponseFormat updateInputOnContainerComponent(ComponentInstanceInput input, String newValue, Component containerComponent, ComponentInstance foundResourceInstance) { StorageOperationStatus status; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java index 5e1d005bfa..44d6f50740 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java @@ -26,6 +26,7 @@ import java.util.function.Supplier; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.PropertySource; import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; @@ -37,13 +38,44 @@ public class ToscaGetFunctionExceptionSupplier { final String errorMsg = String.format("%s on %s", toscaGetFunctionType.getFunctionName(), propertySource.getName()); return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, errorMsg); } - public static Supplier propertyNotFoundOnTarget(final String propertyName, final PropertySource propertySource, final ToscaGetFunctionType functionType) { return propertyNotFoundOnTarget(List.of(propertyName), propertySource, functionType); } + public static Supplier targetFunctionTypeNotFound() { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "function type"); + } + + public static Supplier targetPropertySourceNotFound(final ToscaGetFunctionType toscaGetFunctionType) { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property source of " + toscaGetFunctionType); + } + + public static Supplier targetSourcePathNotFound(final ToscaGetFunctionType toscaGetFunctionType) { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source path of " + toscaGetFunctionType); + } + + public static Supplier propertyNameNotFound(final PropertySource propertySource) { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property name of source " + + propertySource); + } + + public static Supplier propertyIdNotFound(final PropertySource propertySource) { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property id of source " + + propertySource); + } + + public static Supplier sourceNameNotFound(final PropertySource propertySource) { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source name of " + + propertySource); + } + + public static Supplier sourceIdNotFound(final PropertySource propertySource) { + return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source id of " + + propertySource); + } + public static Supplier propertyNotFoundOnTarget(final List propertyPathFromSource, final PropertySource propertySource, final ToscaGetFunctionType functionType) { -- cgit 1.2.3-korg