2525: Now that we have the doc page updated with Java SDK details, updated the README...
[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, ARVADOS_API_HOST_INSECURE
18    */
19   public static void main(String[] args) throws Exception {
20     String apiName = "arvados";
21     String apiVersion = "v1";
22
23     Arvados arv = new Arvados(apiName, apiVersion);
24
25     // Make a users.list call
26     System.out.println("Making an arvados users.list api call");
27
28     Map<String, Object> params = new HashMap<String, Object>();
29
30     Map response = arv.call("users", "list", params);
31     System.out.println("Arvados users.list:\n" + response);
32
33     // get uuid of the first user from the response
34     List items = (List)response.get("items");
35
36     Map firstUser = (Map)items.get(0);
37     String userUuid = (String)firstUser.get("uuid");
38     
39     // Make a users.get call on the uuid obtained above
40     System.out.println("Making a users.get call for " + userUuid);
41     params = new HashMap<String, Object>();
42     params.put("uuid", userUuid);
43     response = arv.call("users", "get", params);
44     System.out.println("Arvados users.get:\n" + response);
45
46     // Make a pipeline_templates.list call
47     System.out.println("Making a pipeline_templates.list call.");
48
49     params = new HashMap<String, Object>();
50     response = arv.call("pipeline_templates", "list", params);
51
52     System.out.println("Arvados pipelinetempates.list:\n" + response);
53   }
54 }