2 * This Sample test program is useful in getting started with working with Arvados Java SDK.
7 import org.arvados.sdk.java.Arvados;
10 import java.util.HashMap;
11 import java.util.List;
13 import java.util.Map.Entry;
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.
22 * If you are not using env variables, you can pass them to Arvados constructor.
24 * Please refer to http://doc.arvados.org/api/index.html for a complete list
25 * of the available API methods.
27 public static void main(String[] args) throws Exception {
28 String apiName = "arvados";
29 String apiVersion = "v1";
31 Arvados arv = new Arvados(apiName, apiVersion);
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");
37 Map<String, Object> params = new HashMap<String, Object>();
39 Map response = arv.call("users", "list", params);
40 System.out.println("Arvados users.list:\n");
41 printResponse(response);
43 // get uuid of the first user from the response
44 List items = (List)response.get("items");
46 Map firstUser = (Map)items.get(0);
47 String userUuid = (String)firstUser.get("uuid");
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);
57 // Make a pipeline_templates list call
58 System.out.println("\n\n\nMaking a pipeline_templates.list call.");
60 params = new HashMap<String, Object>();
61 response = arv.call("pipeline_templates", "list", params);
63 System.out.println("Arvados pipelinetempates.list:\n");
64 printResponse(response);
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);
76 System.out.println(entry.getKey() + " = " + entry.getValue());