2 * This Sample test program is useful in getting started with working with Arvados Java SDK.
3 * Please also see arvadso
8 import org.arvados.sdk.java.Arvados;
10 import org.json.simple.JSONObject;
11 import org.json.simple.parser.JSONParser;
14 import java.io.BufferedWriter;
15 import java.io.FileWriter;
16 import java.util.HashMap;
17 import java.util.List;
20 public class ArvadosSDKJavaExample {
21 /** Make sure the following environment variables are set before using Arvados:
22 * ARVADOS_API_TOKEN, ARVADOS_API_HOST, ARVADOS_API_HOST_INSECURE
24 public static void main(String[] args) throws Exception {
25 String apiName = "arvados";
26 String apiVersion = "v1";
28 Arvados arv = new Arvados(apiName, apiVersion);
30 // Make a users.list call
31 System.out.println("Making an arvados users.list api call");
33 Map<String, Object> params = new HashMap<String, Object>();
35 String response = arv.call("users", "list", params);
36 System.out.println("Arvados users.list:\n" + response);
38 // get uuid of the first user from the response
39 JSONParser parser = new JSONParser();
40 Object obj = parser.parse(response);
41 JSONObject jsonObject = (JSONObject) obj;
42 List items = (List)jsonObject.get("items");
44 JSONObject firstUser = (JSONObject)items.get(0);
45 String userUuid = (String)firstUser.get("uuid");
47 // Make a users.get call on the uuid obtained above
48 System.out.println("Making a users.get call for " + userUuid);
49 params = new HashMap<String, Object>();
50 params.put("uuid", userUuid);
51 response = arv.call("users", "get", params);
52 System.out.println("Arvados users.get:\n" + response);
54 // Make a users.create call
55 System.out.println("Making a users.create call.");
57 params = new HashMap<String, Object>();
58 params.put("user", "{}");
59 response = arv.call("users", "create", params);
60 System.out.println("Arvados users.create:\n" + response);
62 // delete the newly created user
63 parser = new JSONParser();
64 obj = parser.parse(response);
65 jsonObject = (JSONObject) obj;
66 userUuid = (String)jsonObject.get("uuid");
67 params = new HashMap<String, Object>();
68 params.put("uuid", userUuid);
69 response = arv.call("users", "delete", params);
71 // Make a pipeline_templates.list call
72 System.out.println("Making a pipeline_templates.list call.");
74 params = new HashMap<String, Object>();
75 response = arv.call("pipeline_templates", "list", params);
77 System.out.println("Arvados pipelinetempates.list:\n" + response);