aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorEster Rotstein <er767y@att.com>2017-07-23 12:59:51 +0300
committerEster Rotstein <er767y@att.com>2017-07-23 12:59:51 +0300
commiteaabcf9464592d1481d8c5d56b1b9802481debf9 (patch)
tree7e4e2d03f5ac28c332e17227be416282d1ba81da /src/main/java/org
parent0810bec2516b1841bfb5500103329b1d578f443f (diff)
[SDC-146] support get_input in all list cases
Change-Id: I6a4b867de15908e6d06e6c7393ed710f65fc244f Signed-off-by: Ester Rotstein <er767y@att.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java83
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java10
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<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(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<Object> 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<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 @@ public class GetInput extends Function {
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;