[SDC-146] support get_input in all list cases
Change-Id: I6a4b867de15908e6d06e6c7393ed710f65fc244f
Signed-off-by: Ester Rotstein <er767y@att.com>
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
index 9c39b30..0d16092 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.toscaparser.api.functions;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -91,47 +92,53 @@
// :param raw_function: The raw function as dict.
// :return: Template function as Function instance or the raw_function if
// parsing was unsuccessful.
-
- if(isFunction(rawFunctionObj)) {
- if(rawFunctionObj instanceof LinkedHashMap) {
- LinkedHashMap<String,Object> rawFunction = (LinkedHashMap<String,Object>)rawFunctionObj;
- String funcName = (new ArrayList<String>(rawFunction.keySet())).get(0);
- if(functionMappings.keySet().contains(funcName)) {
- String funcType = functionMappings.get(funcName);
- Object oargs = (new ArrayList<Object>(rawFunction.values())).get(0);
- ArrayList<Object> funcArgs;
- if(oargs instanceof ArrayList) {
- funcArgs = (ArrayList<Object>)oargs;
- }
- else {
- funcArgs = new ArrayList<>();
- funcArgs.add(oargs);
- }
+ if (rawFunctionObj instanceof LinkedHashMap) {
+ return getFunctionForObjectItem(ttpl, context, rawFunctionObj);
+ } else if (rawFunctionObj instanceof ArrayList) {
+ ArrayList<Object> rawFunctionObjList = new ArrayList<>();
+ for (Object rawFunctionObjItem: (ArrayList) rawFunctionObj) {
+ rawFunctionObjList.add(getFunctionForObjectItem(ttpl, context, rawFunctionObjItem));
+ }
+ return rawFunctionObjList;
+ }
- if(funcType.equals("GetInput")) {
- return new GetInput(ttpl,context,funcName,funcArgs);
- }
- else if(funcType.equals("GetAttribute")) {
- return new GetAttribute(ttpl,context,funcName,funcArgs);
- }
- else if(funcType.equals("GetProperty")) {
- return new GetProperty(ttpl,context,funcName,funcArgs);
- }
- else if(funcType.equals("GetOperationOutput")) {
- return new GetOperationOutput(ttpl,context,funcName,funcArgs);
- }
- else if(funcType.equals("Concat")) {
- return new Concat(ttpl,context,funcName,funcArgs);
- }
- else if(funcType.equals("Token")) {
- return new Token(ttpl,context,funcName,funcArgs);
- }
- }
- }
- }
return rawFunctionObj;
}
+ private static Object getFunctionForObjectItem(TopologyTemplate ttpl, Object context, Object rawFunctionObjItem) {
+ if(isFunction(rawFunctionObjItem)) {
+ LinkedHashMap<String, Object> rawFunction = (LinkedHashMap<String, Object>) rawFunctionObjItem;
+ String funcName = (new ArrayList<String>(rawFunction.keySet())).get(0);
+ if (functionMappings.keySet().contains(funcName)) {
+ String funcType = functionMappings.get(funcName);
+ Object oargs = (new ArrayList<Object>(rawFunction.values())).get(0);
+ ArrayList<Object> funcArgs;
+ if (oargs instanceof ArrayList) {
+ funcArgs = (ArrayList<Object>) oargs;
+ } else {
+ funcArgs = new ArrayList<>();
+ funcArgs.add(oargs);
+ }
+
+ if (funcType.equals("GetInput")) {
+ return new GetInput(ttpl, context, funcName, funcArgs);
+ } else if (funcType.equals("GetAttribute")) {
+ return new GetAttribute(ttpl, context, funcName, funcArgs);
+ } else if (funcType.equals("GetProperty")) {
+ return new GetProperty(ttpl, context, funcName, funcArgs);
+ } else if (funcType.equals("GetOperationOutput")) {
+ return new GetOperationOutput(ttpl, context, funcName, funcArgs);
+ } else if (funcType.equals("Concat")) {
+ return new Concat(ttpl, context, funcName, funcArgs);
+ } else if (funcType.equals("Token")) {
+ return new Token(ttpl, context, funcName, funcArgs);
+ }
+ }
+ }
+
+ return rawFunctionObjItem;
+ }
+
@Override
public String toString() {
String argsStr = args.size() > 1 ? args.toString() : args.get(0).toString();
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java
index 62f2b39..dd6c05c 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java
@@ -48,9 +48,15 @@
LinkedHashMap<String,Object> ttinp = (LinkedHashMap<String,Object>)toscaTpl.getTpl().get("inputs");
LinkedHashMap<String,Object> ttinpinp = (LinkedHashMap<String,Object>)ttinp.get(getInputName());
String type = (String)ttinpinp.get("type");
-
- return DataEntity.validateDatatype(
+
+ Object value = DataEntity.validateDatatype(
type, toscaTpl.getParsedParams().get(getInputName()),null,null,null);
+
+ if (value instanceof ArrayList && args.size() == 2 && args.get(1) instanceof Integer) {
+ return ((ArrayList) value).get((Integer)args.get(1));
+ }
+
+ return value;
}
Input inputDef = null;