From 995950edb07fa6ef7a756f71c5b499e631ab20a7 Mon Sep 17 00:00:00 2001 From: Lukas Forer Date: Sat, 9 Dec 2023 10:48:21 +0100 Subject: [PATCH] Add support of lists in binded variables --- .../cloudgene/mapred/util/JSONConverter.java | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/main/java/cloudgene/mapred/util/JSONConverter.java b/src/main/java/cloudgene/mapred/util/JSONConverter.java index ded765e7..8e520bd3 100644 --- a/src/main/java/cloudgene/mapred/util/JSONConverter.java +++ b/src/main/java/cloudgene/mapred/util/JSONConverter.java @@ -30,12 +30,12 @@ public class JSONConverter { public static JSONObject convert(AbstractJob job) { JsonConfig config = new JsonConfig(); - config.setExcludes(new String[] { "user", "inputParams", "output", "error", "s3Url", "task", "config", + config.setExcludes(new String[]{"user", "inputParams", "output", "error", "s3Url", "task", "config", "mapReduceJob", "job", "step", "context", "hdfsWorkspace", "localWorkspace", "logOutFiles", "removeHdfsWorkspace", "settings", "setupComplete", "stdOutFile", "workingDirectory", "parameter", "logOutFile", "map", "reduce", "mapProgress", "reduceProgress", "jobId", "makeAbsolute", "mergeOutput", "removeHeader", "value", "autoExport", "download", "tip", "apiToken", "parameterId", "count", - "username" }); + "username"}); // create tree for (CloudgeneParameterOutput param : job.getOutputParams()) { @@ -122,18 +122,14 @@ public static JSONObject convert(WdlParameterInput input, List apps) { valuesObject.put("key", "apps@" + app.getId()); valuesObject.put("label", app.getName()); // TODO: check null and instance of map - Map values = (Map) app.getProperties().get(property); - JSONArray array2 = new JSONArray(); - for (Object key : values.keySet()) { - JSONObject valuesObject2 = new JSONObject(); - String value = values.get(key).toString(); - valuesObject2.put("key", key.toString()); - valuesObject2.put("value", value); - valuesObject2.put("enabled", false); - array2.add(valuesObject2); + Object values = app.getProperties().get(property); + if (values instanceof Map){ + JSONArray array2 = buildFromMap((Map)values); + valuesObject.put("values", array2); + } else if (values instanceof List){ + JSONArray array2 = buildFromList((List)values); + valuesObject.put("values", array2); } - - valuesObject.put("values", array2); array.add(valuesObject); } @@ -270,4 +266,31 @@ public static JSONObject convert(Application application) { return object; } + private static JSONArray buildFromMap(Map values){ + JSONArray array = new JSONArray(); + for(Object key :values.keySet()){ + JSONObject valuesObject2 = new JSONObject(); + String value = values.get(key).toString(); + valuesObject2.put("key", key.toString()); + valuesObject2.put("value", value); + valuesObject2.put("enabled", false); + array.add(valuesObject2); + } + return array; + } + + private static JSONArray buildFromList(List values){ + JSONArray array = new JSONArray(); + for (Map object : values) { + if (object.containsKey("id") && object.containsKey("name")) { + JSONObject valuesObject2 = new JSONObject(); + valuesObject2.put("key",object.get("id").toString()); + valuesObject2.put("value", object.get("name").toString()); + valuesObject2.put("enabled", false); + array.add(valuesObject2); + } + } + return array; + } + }