Merge branch '8784-dir-listings'
[arvados.git] / sdk / java / ArvadosSDKJavaExample.java
index 3c47f668b785b30b49b6182852481ee6b3b45b66..ded6ce99dde1fb049ff3b96afbdcd40b6baac97e 100644 (file)
@@ -1,16 +1,21 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
 /**
  * This Sample test program is useful in getting started with working with Arvados Java SDK.
- * Please also see arvadso 
  * @author radhika
  *
  */
 
-import org.arvados.sdk.java.Arvados;
+import org.arvados.sdk.Arvados;
 
 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 +41,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 +55,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 +64,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());
+      }
+    }
   }
 }