From e3f5545168163fdbf0d83314ee9dd51983e4bcc8 Mon Sep 17 00:00:00 2001 From: imamSidero Date: Thu, 18 May 2023 17:56:32 +0100 Subject: Provide index token to tosca function for nested lists Index token capability is provided in tosca function for all nested levels of list and custom types Issue-ID: SDC-4505 Signed-off-by: Imam hussain Change-Id: If21c0078e0d17c44b5a31b00d6fac3e18ff6831d --- .../csar/ToscaFunctionYamlParsingHandler.java | 54 ++++++++++++++++------ .../impl/ComponentInstanceBusinessLogic.java | 2 +- .../validation/ToscaFunctionValidatorImpl.java | 2 +- 3 files changed, 43 insertions(+), 15 deletions(-) (limited to 'catalog-be/src/main/java/org/openecomp') 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 80608a82db..40604322d6 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 @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.csar; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,7 +29,6 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.config.Configuration; @@ -77,13 +77,27 @@ public class ToscaFunctionYamlParsingHandler { toscaGetFunction.setSourceName(propertySourceType); } 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); + List propertySourcePath = new ArrayList<>(); + propertySourcePath.add((String)propertySourceIndex.get(0)); + if (propertySourceIndex.size() > 1 ) { + List indexParsedList = new ArrayList(); + List indexObjectList = propertySourceIndex.subList(1,propertySourceIndex.size()); + boolean loopFlag = true; + for (String indexValue : indexObjectList) { + if (!indexValue.equalsIgnoreCase("INDEX") && !StringUtils.isNumeric(indexValue) && loopFlag) { + propertySourcePath.add(indexValue); + } else { + loopFlag = false; + if (StringUtils.isNumeric(indexValue)) { + indexParsedList.add(Integer.parseInt(indexValue)); + } else { + indexParsedList.add(indexValue); + } + } + } + toscaGetFunction.setToscaIndexList(indexParsedList); } + toscaGetFunction.setPropertyPathFromSource(propertySourcePath); final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1); toscaGetFunction.setPropertyName(propertyName); return Optional.of(toscaGetFunction); @@ -108,13 +122,27 @@ public class ToscaFunctionYamlParsingHandler { } catch (final ClassCastException ignored) { return Optional.empty(); } - 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); + List propertySourcePath = new ArrayList<>(); + propertySourcePath.add((String)functionParameters.get(0)); + if (functionParameters.size() > 1 ) { + List indexParsedList = new ArrayList(); + List indexObjectList = functionParameters.subList(1,functionParameters.size()); + boolean loopFlag = true; + for (String indexValue : indexObjectList) { + if (!indexValue.equalsIgnoreCase("INDEX") && !StringUtils.isNumeric(indexValue) && loopFlag) { + propertySourcePath.add(indexValue); + } else { + loopFlag = false; + if (StringUtils.isNumeric(indexValue)) { + indexParsedList.add(Integer.parseInt(indexValue)); + } else { + indexParsedList.add(indexValue); + } + } + } + toscaGetFunction.setToscaIndexList(indexParsedList); } + toscaGetFunction.setPropertyPathFromSource(propertySourcePath); } 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 16ec9ade96..c6007a3608 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 @@ -2547,7 +2547,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { throw ToscaGetFunctionExceptionSupplier .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get(); } - if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { + if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !"list".equalsIgnoreCase(referredProperty.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 1e485d9b27..b76ae596a1 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 @@ -133,7 +133,7 @@ public class ToscaFunctionValidatorImpl implements ToscaFunctionValidator { throw ToscaGetFunctionExceptionSupplier .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get(); } - if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { + if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !"list".equalsIgnoreCase(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { throw ToscaGetFunctionExceptionSupplier .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get(); } -- cgit 1.2.3-korg