2525: improve response printing in the examples for readability.
authorradhika <radhika@curoverse.com>
Wed, 7 May 2014 10:47:47 +0000 (06:47 -0400)
committerradhika <radhika@curoverse.com>
Wed, 7 May 2014 10:47:47 +0000 (06:47 -0400)
sdk/java/ArvadosSDKJavaExample.java
sdk/java/ArvadosSDKJavaExampleWithPrompt.java

index 050eaa69f0c4bd37473c14256beabcb87c455d89..3c6578ca33912d3081304c9d8ed2728272ed97aa 100644 (file)
@@ -10,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:
@@ -35,8 +37,19 @@ 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");
+    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());
+      }
+    }
+    
     // get uuid of the first user from the response
     List items = (List)response.get("items");
 
@@ -48,7 +61,18 @@ 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");
+    entrySet = (Set<Entry<String,Object>>)response.entrySet();
+    for (Map.Entry<String, Object> entry : entrySet) {
+      if ("items".equals(entry.getKey())) {
+        items = (List)entry.getValue();
+        for (Object item : items) {
+          System.out.println("    " + item);
+        }            
+      } else {
+        System.out.println(entry.getKey() + " = " + entry.getValue());
+      }
+    }
 
     // Make a pipeline_templates list call
     System.out.println("\n\n\nMaking a pipeline_templates.list call.");
@@ -56,6 +80,17 @@ 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");
+    entrySet = (Set<Entry<String,Object>>)response.entrySet();
+    for (Map.Entry<String, Object> entry : entrySet) {
+      if ("items".equals(entry.getKey())) {
+        items = (List)entry.getValue();
+        for (Object item : items) {
+          System.out.println("    " + item);
+        }            
+      } else {
+        System.out.println(entry.getKey() + " = " + entry.getValue());
+      }
+    }
   }
 }
index f3328692b17c6cb7b4dccbcc3e8a25e44dde6486..b87c00f503ae7a9279bda5c6e51fe6fb0965baf3 100644 (file)
@@ -13,7 +13,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;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 
@@ -76,7 +77,18 @@ public class ArvadosSDKJavaExampleWithPrompt {
       try {
         System.out.println ("Making a call for " + resourceName + " " + methodName);
         Map response = arv.call(resourceName, methodName, paramsMap);
-        System.out.println(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());
+          }
+        }
       } catch (Exception e){
         System.out.println (e.getMessage());
         System.out.println ("\nStart over");