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 --- .../elements/ToscaFunctionJsonDeserializer.java | 17 +++++++++++++++ .../elements/ToscaGetFunctionDataDefinition.java | 25 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'common-be/src/main') diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java index ec3459989e..2e57a4158a 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java @@ -113,6 +113,7 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer @@ -145,6 +146,22 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer propertyPathFromSource = new ArrayList<>(); + private Object toscaIndex; public ToscaGetFunctionDataDefinition() { //necessary for JSON conversions @@ -87,6 +89,12 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct ); } if (propertySource == PropertySource.SELF) { + if (toscaIndex != null) { + Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex; + return Map.of(functionType.getFunctionName(), + Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList()) + ); + } return Map.of(functionType.getFunctionName(), Stream.concat(Stream.of(PropertySource.SELF.getName()), propertyPathFromSource.stream()).collect(Collectors.toList()) ); @@ -97,6 +105,12 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct String.format("sourceName is required in order to generate the %s from INSTANCE value", functionType.getFunctionName()) ); } + if (toscaIndex != null) { + Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex; + return Map.of(functionType.getFunctionName(), + Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList()) + ); + } return Map.of(functionType.getFunctionName(), Stream.concat(Stream.of(sourceName), propertyPathFromSource.stream()).collect(Collectors.toList()) ); @@ -106,10 +120,17 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct } private Map buildGetInputFunctionValue() { + List propertySourceCopy = new ArrayList(this.propertyPathFromSource); + List propertySourceOneCopy = new ArrayList<>(); + propertySourceOneCopy.add(this.propertyPathFromSource.get(0)); + if (toscaIndex != null) { + propertySourceCopy.add(toscaIndex); + propertySourceOneCopy.add(toscaIndex); + } if (this.propertyPathFromSource.size() == 1) { - return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource.get(0)); + return Map.of(this.functionType.getFunctionName(), propertySourceOneCopy); } - return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource); + return Map.of(this.functionType.getFunctionName(), propertySourceCopy); } @Override -- cgit 1.2.3-korg