From ad23e435a1048c3c2cfe02f86a07eae6bca7a118 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 2 Jul 2015 09:18:34 +0300 Subject: [PATCH] Enhancing the APIClient This patch adds the getListMapStrValue that returns a list of maps and a helper method to create a map from json list, it also adds a stub method for CQL queries. Signed-off-by: Amnon Heiman --- .../com/cloudius/urchin/api/APIClient.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/com/cloudius/urchin/api/APIClient.java b/src/main/java/com/cloudius/urchin/api/APIClient.java index f7f1c7e..780c210 100644 --- a/src/main/java/com/cloudius/urchin/api/APIClient.java +++ b/src/main/java/com/cloudius/urchin/api/APIClient.java @@ -156,6 +156,17 @@ public class APIClient { return res; } + public static Map mapStrFromJArr(JsonArray arr) { + Map res = new HashMap(); + for (int i = 0; i < arr.size(); i++) { + JsonObject obj = arr.getJsonObject(i); + if (obj.containsKey("key") && obj.containsKey("value")) { + res.put(obj.getString("key"), obj.getString("value")); + } + } + return res; + } + public static String join(String[] arr, String joiner) { String res = ""; if (arr != null) { @@ -426,4 +437,23 @@ public class APIClient { public JsonArray getJsonArray(String string) { return getJsonArray(string, null); } + + public List> getListMapStrValue(String string, + MultivaluedMap queryParams) { + JsonArray arr = getJsonArray(string, queryParams); + List> res = new ArrayList>(); + for (int i = 0; i < arr.size(); i++) { + res.add(mapStrFromJArr(arr.getJsonArray(i))); + } + return res; + } + + public List> getListMapStrValue(String string) { + return getListMapStrValue(string, null); + } + + public TabularData getCQLResult(String string) { + // TODO Auto-generated method stub + return null; + } }