From a1ba3abf29613ee9e576a7c96a76ceb921086044 Mon Sep 17 00:00:00 2001 From: imamSidero Date: Wed, 12 Apr 2023 16:02:46 +0100 Subject: Support for addition of INDEX token to tosca functions Providing the capability to add the index token to th tosca function of all types Issue-ID: SDC-4472 Signed-off-by: Imam hussain Change-Id: Ib7ac80f31710101f50de76bdb7c79abdc637cfe3 --- .../csar/ToscaFunctionYamlParsingHandler.java | 28 ++++++++++++++++++---- .../impl/ComponentInstanceBusinessLogic.java | 4 ++-- .../validation/ToscaFunctionValidatorImpl.java | 4 ++-- 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java index 2a7af62a0c..0b9432b3a1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java @@ -23,8 +23,11 @@ package org.openecomp.sdc.be.components.csar; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaConcatFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaCustomFunction; @@ -51,7 +54,9 @@ public class ToscaFunctionYamlParsingHandler { } final List functionParameters; try { - functionParameters = (List) functionValueObj; + functionParameters = ((List) functionValueObj).stream() + .map(object -> Objects.toString(object, null)) + .collect(Collectors.toList()); } catch (final ClassCastException ignored) { return Optional.empty(); } @@ -66,7 +71,14 @@ public class ToscaFunctionYamlParsingHandler { toscaGetFunction.setPropertySource(PropertySource.INSTANCE); toscaGetFunction.setSourceName(propertySourceType); } - toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(1, functionParameters.size())); + List propertySourceIndex = functionParameters.subList(1, functionParameters.size()); + String toscaIndexValue = propertySourceIndex.get((propertySourceIndex.size() - 1)); + if (propertySourceIndex.size() > 1 && (toscaIndexValue.equalsIgnoreCase("INDEX") || StringUtils.isNumeric(toscaIndexValue))) { + toscaGetFunction.setPropertyPathFromSource(propertySourceIndex.subList(0,(propertySourceIndex.size() - 1))); + toscaGetFunction.setToscaIndex(toscaIndexValue); + } else { + toscaGetFunction.setPropertyPathFromSource(propertySourceIndex); + } final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1); toscaGetFunction.setPropertyName(propertyName); return Optional.of(toscaGetFunction); @@ -85,11 +97,19 @@ public class ToscaFunctionYamlParsingHandler { } else { final List functionParameters; try { - functionParameters = (List) functionValueObj; + functionParameters = ((List) functionValueObj).stream() + .map(object -> Objects.toString(object, null)) + .collect(Collectors.toList()); } catch (final ClassCastException ignored) { return Optional.empty(); } - toscaGetFunction.setPropertyPathFromSource(functionParameters); + String toscaIndexValue = functionParameters.get((functionParameters.size() - 1)); + if (functionParameters.size() > 1 && (toscaIndexValue.equalsIgnoreCase("INDEX") || StringUtils.isNumeric(toscaIndexValue))) { + toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(0,(functionParameters.size() - 1))); + toscaGetFunction.setToscaIndex(toscaIndexValue); + } else { + toscaGetFunction.setPropertyPathFromSource(functionParameters); + } } final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1); toscaGetFunction.setPropertyName(propertyName); 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 f43f7de860..16ec9ade96 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 @@ -2543,11 +2543,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { referredProperty = findSubProperty(referredProperty, toscaGetFunction, model); } - if (!property.getType().equals(referredProperty.getType())) { + if (!property.getType().equals(referredProperty.getType()) && !"list".equalsIgnoreCase(referredProperty.getType())) { throw ToscaGetFunctionExceptionSupplier .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get(); } - if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { + if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { throw ToscaGetFunctionExceptionSupplier .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java index 083a03fb42..1e485d9b27 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java @@ -129,11 +129,11 @@ public class ToscaFunctionValidatorImpl implements ToscaFunctionValidator { referredProperty = findSubProperty(referredProperty, toscaGetFunction, model); } - if (!property.getType().equals(referredProperty.getType())) { + if (!property.getType().equals(referredProperty.getType()) && !"list".equalsIgnoreCase(referredProperty.getType())) { throw ToscaGetFunctionExceptionSupplier .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get(); } - if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { + if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { throw ToscaGetFunctionExceptionSupplier .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get(); } -- cgit 1.2.3-korg