1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
6 * This Sample test program is useful in getting started with working with Arvados Java SDK.
11 import org.arvados.sdk.Arvados;
14 import java.util.HashMap;
15 import java.util.List;
17 import java.util.Map.Entry;
20 public class ArvadosSDKJavaExample {
21 /** Make sure the following environment variables are set before using Arvados:
22 * ARVADOS_API_TOKEN, ARVADOS_API_HOST and ARVADOS_API_HOST_INSECURE
23 * Set ARVADOS_API_HOST_INSECURE to true if you are using self-singed
24 * certificates in development and want to bypass certificate validations.
26 * If you are not using env variables, you can pass them to Arvados constructor.
28 * Please refer to http://doc.arvados.org/api/index.html for a complete list
29 * of the available API methods.
31 public static void main(String[] args) throws Exception {
32 String apiName = "arvados";
33 String apiVersion = "v1";
35 Arvados arv = new Arvados(apiName, apiVersion);
37 // Make a users list call. Here list on users is the method being invoked.
38 // Expect a Map containing the list of users as the response.
39 System.out.println("Making an arvados users.list api call");
41 Map<String, Object> params = new HashMap<String, Object>();
43 Map response = arv.call("users", "list", params);
44 System.out.println("Arvados users.list:\n");
45 printResponse(response);
47 // get uuid of the first user from the response
48 List items = (List)response.get("items");
50 Map firstUser = (Map)items.get(0);
51 String userUuid = (String)firstUser.get("uuid");
53 // Make a users get call on the uuid obtained above
54 System.out.println("\n\n\nMaking a users.get call for " + userUuid);
55 params = new HashMap<String, Object>();
56 params.put("uuid", userUuid);
57 response = arv.call("users", "get", params);
58 System.out.println("Arvados users.get:\n");
59 printResponse(response);
61 // Make a pipeline_templates list call
62 System.out.println("\n\n\nMaking a pipeline_templates.list call.");
64 params = new HashMap<String, Object>();
65 response = arv.call("pipeline_templates", "list", params);
67 System.out.println("Arvados pipelinetempates.list:\n");
68 printResponse(response);
71 private static void printResponse(Map response){
72 Set<Entry<String,Object>> entrySet = (Set<Entry<String,Object>>)response.entrySet();
73 for (Map.Entry<String, Object> entry : entrySet) {
74 if ("items".equals(entry.getKey())) {
75 List items = (List)entry.getValue();
76 for (Object item : items) {
77 System.out.println(" " + item);
80 System.out.println(entry.getKey() + " = " + entry.getValue());