From eaabcf9464592d1481d8c5d56b1b9802481debf9 Mon Sep 17 00:00:00 2001 From: Ester Rotstein Date: Sun, 23 Jul 2017 12:59:51 +0300 Subject: [SDC-146] support get_input in all list cases Change-Id: I6a4b867de15908e6d06e6c7393ed710f65fc244f Signed-off-by: Ester Rotstein --- .../sdc/toscaparser/api/functions/Function.java | 83 ++++++++++++---------- .../sdc/toscaparser/api/functions/GetInput.java | 10 ++- 2 files changed, 53 insertions(+), 40 deletions(-) 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 @@ public abstract class Function { // :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 rawFunction = (LinkedHashMap)rawFunctionObj; - String funcName = (new ArrayList(rawFunction.keySet())).get(0); - if(functionMappings.keySet().contains(funcName)) { - String funcType = functionMappings.get(funcName); - Object oargs = (new ArrayList(rawFunction.values())).get(0); - ArrayList funcArgs; - if(oargs instanceof ArrayList) { - funcArgs = (ArrayList)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); - } - } - } - } + if (rawFunctionObj instanceof LinkedHashMap) { + return getFunctionForObjectItem(ttpl, context, rawFunctionObj); + } else if (rawFunctionObj instanceof ArrayList) { + ArrayList rawFunctionObjList = new ArrayList<>(); + for (Object rawFunctionObjItem: (ArrayList) rawFunctionObj) { + rawFunctionObjList.add(getFunctionForObjectItem(ttpl, context, rawFunctionObjItem)); + } + return rawFunctionObjList; + } + return rawFunctionObj; } + private static Object getFunctionForObjectItem(TopologyTemplate ttpl, Object context, Object rawFunctionObjItem) { + if(isFunction(rawFunctionObjItem)) { + LinkedHashMap rawFunction = (LinkedHashMap) rawFunctionObjItem; + String funcName = (new ArrayList(rawFunction.keySet())).get(0); + if (functionMappings.keySet().contains(funcName)) { + String funcType = functionMappings.get(funcName); + Object oargs = (new ArrayList(rawFunction.values())).get(0); + ArrayList funcArgs; + if (oargs instanceof ArrayList) { + funcArgs = (ArrayList) 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 @@ public class GetInput extends Function { LinkedHashMap ttinp = (LinkedHashMap)toscaTpl.getTpl().get("inputs"); LinkedHashMap ttinpinp = (LinkedHashMap)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; -- cgit 1.2.3-korg