2525: Add support for array request parameter type
[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 org.json.simple.JSONObject;
11 import org.json.simple.parser.JSONParser;
12
13 import java.io.File;
14 import java.io.BufferedWriter;
15 import java.io.FileWriter;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
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
23    */
24   public static void main(String[] args) throws Exception {
25     String apiName = "arvados";
26     String apiVersion = "v1";
27
28     Arvados arv = new Arvados(apiName, apiVersion);
29
30     // Make a users.list call
31     System.out.println("Making an arvados users.list api call");
32
33     Map<String, Object> params = new HashMap<String, Object>();
34
35     String response = arv.call("users", "list", params);
36     System.out.println("Arvados users.list:\n" + response);
37
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");
43
44     JSONObject firstUser = (JSONObject)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("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);
53
54     // Make a users.create call
55     System.out.println("Making a users.create call.");
56     
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);
61
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);
70
71     // Make a pipeline_templates.list call
72     System.out.println("Making a pipeline_templates.list call.");
73
74     params = new HashMap<String, Object>();
75     response = arv.call("pipeline_templates", "list", params);
76
77     System.out.println("Arvados pipelinetempates.list:\n" + response);
78   }
79 }