Provide index token to tosca function for nested lists
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / ToscaGetFunctionDataDefinition.java
index 9396188..5bd9fe3 100644 (file)
@@ -44,7 +44,7 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
     private String sourceName;
     private ToscaGetFunctionType functionType;
     private List<String> propertyPathFromSource = new ArrayList<>();
-    private Object toscaIndex;
+    private List<Object> toscaIndexList;
 
     public ToscaGetFunctionDataDefinition() {
         //necessary for JSON conversions
@@ -89,10 +89,13 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
             );
         }
         if (propertySource == PropertySource.SELF) {
-            if (toscaIndex != null) {
-                Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex;
+            if (toscaIndexList.size() > 0) {
+                List<Object> parsedIndexList = new ArrayList<Object>();
+                toscaIndexList.forEach((obj) -> {
+                    parsedIndexList.add(StringUtils.isNumeric(obj.toString()) ? Integer.parseInt(obj.toString()) : obj);
+                });
                 return Map.of(functionType.getFunctionName(),
-                    Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList())
+                    Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),parsedIndexList.stream())).collect(Collectors.toList())
                 );
             }
             return Map.of(functionType.getFunctionName(),
@@ -105,10 +108,13 @@ 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;
+            if (toscaIndexList.size() > 0) {
+                List<Object> parsedIndexList = new ArrayList<Object>();
+                toscaIndexList.forEach((obj) -> {
+                    parsedIndexList.add(StringUtils.isNumeric(obj.toString()) ? Integer.parseInt(obj.toString()) : obj);
+                });
                 return Map.of(functionType.getFunctionName(),
-                    Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList())
+                    Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),parsedIndexList.stream())).collect(Collectors.toList())
                 );
             }
             return Map.of(functionType.getFunctionName(),
@@ -123,10 +129,9 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
         List<Object> propertySourceCopy = new ArrayList<Object>(this.propertyPathFromSource);
         List<Object> propertySourceOneCopy = new ArrayList<>();
         propertySourceOneCopy.add(this.propertyPathFromSource.get(0));
-        if (toscaIndex != null) {
-            Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex;
-            propertySourceCopy.add(toscaIndexValue);
-            propertySourceOneCopy.add(toscaIndexValue);
+        if (toscaIndexList.size() > 0) {
+            propertySourceCopy.addAll(toscaIndexList);
+            propertySourceOneCopy.addAll(toscaIndexList);
         }
         if (this.propertyPathFromSource.size() == 1) {
             return Map.of(this.functionType.getFunctionName(), propertySourceOneCopy);