From e159dee791441b68d142323f7d951b0592841c7f Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Fri, 27 May 2022 11:58:10 +0100 Subject: Support of get_property for instance properties Support of get_property for INSTANCE properties, as currently only SELF properties can be selected. Change-Id: I80611002964a6ebb515134155c321f2d7f87811c Issue-ID: SDC-4026 Signed-off-by: andre.schmid --- .../impl/ComponentInstanceBusinessLogic.java | 18 +++++++++++++++--- .../exceptions/ToscaGetFunctionExceptionSupplier.java | 8 ++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) (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 1fa459da80..7ea00b1d46 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 @@ -2374,12 +2374,21 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { private void validateToscaGetFunction(T property, Component parentComponent) { final ToscaGetFunctionDataDefinition toscaGetFunction = property.getToscaGetFunction(); + validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource()); if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) { validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel()); return; } if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_PROPERTY) { - validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel()); + if (toscaGetFunction.getPropertySource() == PropertySource.SELF) { + validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel()); + } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) { + final ComponentInstance componentInstance = + parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId()) + .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName())); + validateGetFunction(property, componentInstance.getProperties(), parentComponent.getModel()); + } + return; } @@ -2396,7 +2405,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { toscaGetFunction.getFunctionType() ).get(); } - validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource()); final String getFunctionPropertyUniqueId = toscaGetFunction.getPropertyUniqueId(); T referredProperty = (T) parentProperties.stream() .filter(property1 -> getFunctionPropertyUniqueId.equals(property1.getUniqueId())) @@ -2458,7 +2466,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } private void validateGetPropertySource(final ToscaGetFunctionType functionType, final PropertySource propertySource) { - if (propertySource != PropertySource.SELF) { + if (functionType == ToscaGetFunctionType.GET_INPUT && propertySource != PropertySource.SELF) { + throw ToscaGetFunctionExceptionSupplier + .targetSourceNotSupported(functionType, propertySource).get(); + } + if (functionType == ToscaGetFunctionType.GET_PROPERTY && !List.of(PropertySource.SELF, PropertySource.INSTANCE).contains(propertySource)) { throw ToscaGetFunctionExceptionSupplier .targetSourceNotSupported(functionType, propertySource).get(); } 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 d54cb79ba5..5e1d005bfa 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 @@ -91,4 +91,12 @@ public class ToscaGetFunctionExceptionSupplier { functionType.getFunctionName(), referredPropertySchemaType, propertySchemaType ); } + + public static Supplier instanceNotFound(final String instanceName) { + return () -> new ByActionStatusComponentException( + ActionStatus.TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND, + instanceName + ); + } + } -- cgit 1.2.3-korg