8784: Fix test for latest firefox.
[arvados.git] / sdk / java / ArvadosSDKJavaExample.java
1 /**
2  * This Sample test program is useful in getting started with working with Arvados Java SDK.
3  * @author radhika
4  *
5  */
6
7 import org.arvados.sdk.Arvados;
8
9 import java.io.File;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Map.Entry;
14 import java.util.Set;
15
16 public class ArvadosSDKJavaExample {
17   /** Make sure the following environment variables are set before using Arvados:
18    *      ARVADOS_API_TOKEN, ARVADOS_API_HOST and ARVADOS_API_HOST_INSECURE 
19    *      Set ARVADOS_API_HOST_INSECURE to true if you are using self-singed
20    *      certificates in development and want to bypass certificate validations.
21    *
22    *  If you are not using env variables, you can pass them to Arvados constructor.
23    *
24    *  Please refer to http://doc.arvados.org/api/index.html for a complete list
25    *      of the available API methods.
26    */
27   public static void main(String[] args) throws Exception {
28     String apiName = "arvados";
29     String apiVersion = "v1";
30
31     Arvados arv = new Arvados(apiName, apiVersion);
32
33     // Make a users list call. Here list on users is the method being invoked.
34     // Expect a Map containing the list of users as the response.
35     System.out.println("Making an arvados users.list api call");
36
37     Map<String, Object> params = new HashMap<String, Object>();
38
39     Map response = arv.call("users", "list", params);
40     System.out.println("Arvados users.list:\n");
41     printResponse(response);
42     
43     // get uuid of the first user from the response
44     List items = (List)response.get("items");
45
46     Map firstUser = (Map)items.get(0);
47     String userUuid = (String)firstUser.get("uuid");
48     
49     // Make a users get call on the uuid obtained above
50     System.out.println("\n\n\nMaking a users.get call for " + userUuid);
51     params = new HashMap<String, Object>();
52     params.put("uuid", userUuid);
53     response = arv.call("users", "get", params);
54     System.out.println("Arvados users.get:\n");
55     printResponse(response);
56
57     // Make a pipeline_templates list call
58     System.out.println("\n\n\nMaking a pipeline_templates.list call.");
59
60     params = new HashMap<String, Object>();
61     response = arv.call("pipeline_templates", "list", params);
62
63     System.out.println("Arvados pipelinetempates.list:\n");
64     printResponse(response);
65   }
66   
67   private static void printResponse(Map response){
68     Set<Entry<String,Object>> entrySet = (Set<Entry<String,Object>>)response.entrySet();
69     for (Map.Entry<String, Object> entry : entrySet) {
70       if ("items".equals(entry.getKey())) {
71         List items = (List)entry.getValue();
72         for (Object item : items) {
73           System.out.println("    " + item);
74         }            
75       } else {
76         System.out.println(entry.getKey() + " = " + entry.getValue());
77       }
78     }
79   }
80 }