diff options
author | imamSidero <imam.hussain@est.tech> | 2023-04-12 16:02:46 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-05-09 14:33:29 +0000 |
commit | a1ba3abf29613ee9e576a7c96a76ceb921086044 (patch) | |
tree | f3f9e4d9c98c6b5bc2d8aba1be01b327dd36b31d /catalog-be/src/main/java/org | |
parent | 3bc3a5c724e9a6ea8a112dca72a9a3128eddca19 (diff) |
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 <imam.hussain@est.tech>
Change-Id: Ib7ac80f31710101f50de76bdb7c79abdc637cfe3
Diffstat (limited to 'catalog-be/src/main/java/org')
3 files changed, 28 insertions, 8 deletions
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<String> functionParameters; try { - functionParameters = (List<String>) functionValueObj; + functionParameters = ((List<Object>) 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<String> 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<String> functionParameters; try { - functionParameters = (List<String>) functionValueObj; + functionParameters = ((List<Object>) 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(); } |