Merge branch 'master' of git.curoverse.com:arvados into 3408-production-datamanager
[arvados.git] / sdk / java / ArvadosSDKJavaExample.java
index 3c47f668b785b30b49b6182852481ee6b3b45b66..7c9c0138eae86206bb75a1bd5523ecfdee92f040 100644 (file)
@@ -1,6 +1,5 @@
 /**
  * This Sample test program is useful in getting started with working with Arvados Java SDK.
- * Please also see arvadso 
  * @author radhika
  *
  */
@@ -11,6 +10,8 @@ import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
 public class ArvadosSDKJavaExample {
   /** Make sure the following environment variables are set before using Arvados:
@@ -36,8 +37,9 @@ public class ArvadosSDKJavaExample {
     Map<String, Object> params = new HashMap<String, Object>();
 
     Map response = arv.call("users", "list", params);
-    System.out.println("Arvados users.list:\n" + response);
-
+    System.out.println("Arvados users.list:\n");
+    printResponse(response);
+    
     // get uuid of the first user from the response
     List items = (List)response.get("items");
 
@@ -49,7 +51,8 @@ public class ArvadosSDKJavaExample {
     params = new HashMap<String, Object>();
     params.put("uuid", userUuid);
     response = arv.call("users", "get", params);
-    System.out.println("Arvados users.get:\n" + response);
+    System.out.println("Arvados users.get:\n");
+    printResponse(response);
 
     // Make a pipeline_templates list call
     System.out.println("\n\n\nMaking a pipeline_templates.list call.");
@@ -57,6 +60,21 @@ public class ArvadosSDKJavaExample {
     params = new HashMap<String, Object>();
     response = arv.call("pipeline_templates", "list", params);
 
-    System.out.println("Arvados pipelinetempates.list:\n" + response);
+    System.out.println("Arvados pipelinetempates.list:\n");
+    printResponse(response);
+  }
+  
+  private static void printResponse(Map response){
+    Set<Entry<String,Object>> entrySet = (Set<Entry<String,Object>>)response.entrySet();
+    for (Map.Entry<String, Object> entry : entrySet) {
+      if ("items".equals(entry.getKey())) {
+        List items = (List)entry.getValue();
+        for (Object item : items) {
+          System.out.println("    " + item);
+        }            
+      } else {
+        System.out.println(entry.getKey() + " = " + entry.getValue());
+      }
+    }
   }
-}
+}
\ No newline at end of file