2 * This Sample test program is useful in getting started with using Arvados Java SDK.
3 * This program creates an Arvados instance using the configured environment variables.
4 * It then provides a prompt to input method name and input parameters.
5 * The program them invokes the API server to execute the specified method.
10 import org.arvados.sdk.java.Arvados;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.Map.Entry;
18 import java.io.BufferedReader;
19 import java.io.InputStreamReader;
21 public class ArvadosSDKJavaExampleWithPrompt {
23 * Make sure the following environment variables are set before using Arvados:
24 * ARVADOS_API_TOKEN, ARVADOS_API_HOST and ARVADOS_API_HOST_INSECURE Set
25 * ARVADOS_API_HOST_INSECURE to true if you are using self-singed certificates
26 * in development and want to bypass certificate validations.
28 * Please refer to http://doc.arvados.org/api/index.html for a complete list
29 * of the available API methods.
31 public static void main(String[] args) throws Exception {
32 String apiName = "arvados";
33 String apiVersion = "v1";
35 System.out.print("Welcome to Arvados Java SDK");
36 System.out.println("You can use this example to call API methods");
37 System.out.println("Enter ^C when you want to quit");
39 // use configured env variables for API TOKEN, HOST and HOST_INSECURE
40 Arvados arv = new Arvados(apiName, apiVersion);
43 // prompt for resource
44 System.out.println("\n\nEnter Resource name (for example users): ");
47 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
48 String resourceName = in.readLine().trim();
51 System.out.println("\nEnter method name (for example get): ");
52 String methodName = in.readLine().trim();
54 // read method parameters
55 System.out.println("\nEnter parameter name, value (for example uuid, uuid-value): ");
56 Map paramsMap = new HashMap();
60 param = in.readLine();
63 int index = param.indexOf(","); // first comma
64 String paramName = param.substring(0, index);
65 String paramValue = param.substring(index);
66 System.out.println(paramName + " " + paramValue);
67 paramsMap.put(paramName.trim(), paramValue.trim());
69 System.out.println("\nEnter parameter name, value (for example uuid, uuid-value): ");
70 } while (!param.isEmpty());
71 } catch (Exception e) {
72 System.out.println (e.getMessage());
73 System.out.println ("\nStart over");
77 // Make a "call" for the given resource name and method name
79 System.out.println ("Making a call for " + resourceName + " " + methodName);
80 Map response = arv.call(resourceName, methodName, paramsMap);
82 Set<Entry<String,Object>> entrySet = (Set<Entry<String,Object>>)response.entrySet();
83 for (Map.Entry<String, Object> entry : entrySet) {
84 if ("items".equals(entry.getKey())) {
85 List items = (List)entry.getValue();
86 for (Object item : items) {
87 System.out.println(" " + item);
90 System.out.println(entry.getKey() + " = " + entry.getValue());
93 } catch (Exception e){
94 System.out.println (e.getMessage());
95 System.out.println ("\nStart over");