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