[ARVADOS] updated: f7f61eca36d66a723b02ac34db888f5fbdc63fc8
git at public.curoverse.com
git at public.curoverse.com
Wed May 7 11:59:07 EDT 2014
Summary of changes:
sdk/java/ArvadosSDKJavaExampleWithPrompt.java | 108 +++++++++++---------
.../main/java/org/arvados/sdk/java/Arvados.java | 39 +++++--
2 files changed, 89 insertions(+), 58 deletions(-)
via f7f61eca36d66a723b02ac34db888f5fbdc63fc8 (commit)
from a3cd0039e84373541d6648b76647457be5a7e098 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit f7f61eca36d66a723b02ac34db888f5fbdc63fc8
Author: radhika <radhika at curoverse.com>
Date: Wed May 7 11:58:23 2014 -0400
2525: Expand prompt example to list the available resources and methods. This can help enhance user experience.
diff --git a/sdk/java/ArvadosSDKJavaExampleWithPrompt.java b/sdk/java/ArvadosSDKJavaExampleWithPrompt.java
index a6efd80..64a7760 100644
--- a/sdk/java/ArvadosSDKJavaExampleWithPrompt.java
+++ b/sdk/java/ArvadosSDKJavaExampleWithPrompt.java
@@ -38,67 +38,79 @@ public class ArvadosSDKJavaExampleWithPrompt {
System.out.println("When entering parameters, you may enter a simple string or a well-formed json.");
System.out.println("For example to get a user you may enter: user, zzzzz-12345-67890");
System.out.println("Or to filter links, you may enter: filters, [[ \"name\", \"=\", \"can_manage\"]]");
-
+
System.out.println("\nEnter ^C when you want to quit");
// use configured env variables for API TOKEN, HOST and HOST_INSECURE
Arvados arv = new Arvados(apiName, apiVersion);
while (true) {
- // prompt for resource
- System.out.println("\n\nEnter Resource name (for example users)");
- System.out.print("\n>>> ");
+ try {
+ // prompt for resource
+ System.out.println("\n\nEnter Resource name (for example users)");
+ System.out.println("\nAvailable resources are: " + arv.getAvailableResourses());
+ System.out.print("\n>>> ");
- // read resource name
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String resourceName = in.readLine().trim();
+ // read resource name
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ String resourceName = in.readLine().trim();
+ if ("".equals(resourceName)) {
+ throw (new Exception("No resource name entered"));
+ }
+ // read method name
+ System.out.println("\nEnter method name (for example get)");
+ System.out.println("\nAvailable methods are: " + arv.getAvailableMethodsForResourse(resourceName));
+ System.out.print("\n>>> ");
+ String methodName = in.readLine().trim();
+ if ("".equals(methodName)) {
+ throw (new Exception("No method name entered"));
+ }
- // read method name
- System.out.println("\nEnter method name (for example get)");
- System.out.print("\n>>> ");
- String methodName = in.readLine().trim();
+ // read method parameters
+ System.out.println("\nEnter parameter name, value (for example uuid, uuid-value)");
+ System.out.print("\n>>> ");
+ Map paramsMap = new HashMap();
+ String param = "";
+ try {
+ do {
+ param = in.readLine();
+ if (param.isEmpty())
+ break;
+ int index = param.indexOf(","); // first comma
+ String paramName = param.substring(0, index);
+ String paramValue = param.substring(index+1);
+ paramsMap.put(paramName.trim(), paramValue.trim());
- // read method parameters
- System.out.println("\nEnter parameter name, value (for example uuid, uuid-value)");
- System.out.print("\n>>> ");
- Map paramsMap = new HashMap();
- String param = "";
- try {
- do {
- param = in.readLine();
- if (param.isEmpty())
- break;
- int index = param.indexOf(","); // first comma
- String paramName = param.substring(0, index);
- String paramValue = param.substring(index+1);
- paramsMap.put(paramName.trim(), paramValue.trim());
+ System.out.println("\nEnter parameter name, value (for example uuid, uuid-value)");
+ System.out.print("\n>>> ");
+ } while (!param.isEmpty());
+ } catch (Exception e) {
+ System.out.println (e.getMessage());
+ System.out.println ("\nSet up a new call");
+ continue;
+ }
- System.out.println("\nEnter parameter name, value (for example uuid, uuid-value)");
- System.out.print("\n>>> ");
- } while (!param.isEmpty());
- } catch (Exception e) {
- System.out.println (e.getMessage());
- System.out.println ("\nSet up a new call");
- continue;
- }
+ // Make a "call" for the given resource name and method name
+ try {
+ System.out.println ("Making a call for " + resourceName + " " + methodName);
+ Map response = arv.call(resourceName, methodName, paramsMap);
- // Make a "call" for the given resource name and method name
- try {
- System.out.println ("Making a call for " + resourceName + " " + methodName);
- Map response = arv.call(resourceName, methodName, paramsMap);
-
- Set<Entry<String,Object>> entrySet = (Set<Entry<String,Object>>)response.entrySet();
- for (Map.Entry<String, Object> entry : entrySet) {
- if ("items".equals(entry.getKey())) {
- List items = (List)entry.getValue();
- for (Object item : items) {
- System.out.println(" " + item);
- }
- } else {
- System.out.println(entry.getKey() + " = " + entry.getValue());
+ Set<Entry<String,Object>> entrySet = (Set<Entry<String,Object>>)response.entrySet();
+ for (Map.Entry<String, Object> entry : entrySet) {
+ if ("items".equals(entry.getKey())) {
+ List items = (List)entry.getValue();
+ for (Object item : items) {
+ System.out.println(" " + item);
+ }
+ } else {
+ System.out.println(entry.getKey() + " = " + entry.getValue());
+ }
}
+ } catch (Exception e){
+ System.out.println (e.getMessage());
+ System.out.println ("\nSet up a new call");
}
- } catch (Exception e){
+ } catch (Exception e) {
System.out.println (e.getMessage());
System.out.println ("\nSet up a new call");
}
diff --git a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
index 4a395e1..298ee77 100644
--- a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
+++ b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.log4j.Logger;
import org.json.simple.JSONArray;
@@ -160,6 +161,16 @@ public class Arvados {
}
}
+ public Set<String> getAvailableResourses() {
+ return (restDescription.getResources().keySet());
+ }
+
+ public Set<String> getAvailableMethodsForResourse(String resourceName)
+ throws Exception {
+ Map<String, RestMethod> methodMap = getMatchingMethodMap (resourceName);
+ return (methodMap.keySet());
+ }
+
private HashMap<String, Object> loadParameters(Map<String, Object> paramsMap,
RestMethod method) throws Exception {
HashMap<String, Object> parameters = Maps.newHashMap();
@@ -204,20 +215,12 @@ public class Arvados {
private RestMethod getMatchingMethod(String resourceName, String methodName)
throws Exception {
- if (resourceName == null) {
- error("missing resource name");
- }
+ Map<String, RestMethod> methodMap = getMatchingMethodMap(resourceName);
+
if (methodName == null) {
error("missing method name");
}
- Map<String, RestMethod> methodMap = null;
- Map<String, RestResource> resources = restDescription.getResources();
- RestResource resource = resources.get(resourceName);
- if (resource == null) {
- error("resource not found");
- }
- methodMap = resource.getMethods();
RestMethod method =
methodMap == null ? null : methodMap.get(methodName);
if (method == null) {
@@ -227,6 +230,22 @@ public class Arvados {
return method;
}
+ private Map<String, RestMethod> getMatchingMethodMap(String resourceName)
+ throws Exception {
+ if (resourceName == null) {
+ error("missing resource name");
+ }
+
+ Map<String, RestMethod> methodMap = null;
+ Map<String, RestResource> resources = restDescription.getResources();
+ RestResource resource = resources.get(resourceName);
+ if (resource == null) {
+ error("resource not found");
+ }
+ methodMap = resource.getMethods();
+ return methodMap;
+ }
+
/**
* Not thread-safe. So, create for each request.
* @param apiName
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list