2525: return map instead of json string for the call method.
[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.io.BufferedWriter;
12 import java.io.FileWriter;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16
17 public class ArvadosSDKJavaExample {
18   /** Make sure the following environment variables are set before using Arvados:
19    *      ARVADOS_API_TOKEN, ARVADOS_API_HOST, ARVADOS_API_HOST_INSECURE
20    */
21   public static void main(String[] args) throws Exception {
22     String apiName = "arvados";
23     String apiVersion = "v1";
24
25     Arvados arv = new Arvados(apiName, apiVersion);
26
27     // Make a users.list call
28     System.out.println("Making an arvados users.list api call");
29
30     Map<String, Object> params = new HashMap<String, Object>();
31
32     Map response = arv.call("users", "list", params);
33     System.out.println("Arvados users.list:\n" + response);
34
35     // get uuid of the first user from the response
36     List items = (List)response.get("items");
37
38     Map firstUser = (Map)items.get(0);
39     String userUuid = (String)firstUser.get("uuid");
40     
41     // Make a users.get call on the uuid obtained above
42     System.out.println("Making a users.get call for " + userUuid);
43     params = new HashMap<String, Object>();
44     params.put("uuid", userUuid);
45     response = arv.call("users", "get", params);
46     System.out.println("Arvados users.get:\n" + response);
47
48     // Make a users.create call
49     System.out.println("Making a users.create call.");
50     
51     params = new HashMap<String, Object>();
52     params.put("user", "{}");
53     response = arv.call("users", "create", params);
54     System.out.println("Arvados users.create:\n" + response);
55
56     // delete the newly created user
57     userUuid = (String)response.get("uuid");
58     params = new HashMap<String, Object>();
59     params.put("uuid", userUuid);
60     response = arv.call("users", "delete", params);
61
62     // Make a pipeline_templates.list call
63     System.out.println("Making a pipeline_templates.list call.");
64
65     params = new HashMap<String, Object>();
66     response = arv.call("pipeline_templates", "list", params);
67
68     System.out.println("Arvados pipelinetempates.list:\n" + response);
69   }
70 }