[ARVADOS] updated: ee056b0ceb9ce569e0ee9a64b41ead728636772a

git at public.curoverse.com git at public.curoverse.com
Sun May 4 14:16:11 EDT 2014


Summary of changes:
 sdk/java/ArvadosSDKJavaExample.java                |   16 ++----
 .../main/java/org/arvados/sdk/java/Arvados.java    |   53 ++++++++++------
 .../java/org/arvados/sdk/java/ArvadosTest.java     |   62 ++++++++++----------
 services/api/app/models/link.rb                    |    2 +-
 services/api/test/test_helper.rb                   |   11 ++-
 services/api/test/unit/log_test.rb                 |    7 --
 services/api/test/unit/permission_test.rb          |   17 +++++
 7 files changed, 93 insertions(+), 75 deletions(-)
 create mode 100644 services/api/test/unit/permission_test.rb

       via  ee056b0ceb9ce569e0ee9a64b41ead728636772a (commit)
       via  3e237c89424489bad02cde9be33f715269e0c6b8 (commit)
       via  988726079e8e2f8ce4b49115c10a8a1d22040972 (commit)
      from  00ba956a67072f8b4a77fe71d3dc1e4dd8f70e98 (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 ee056b0ceb9ce569e0ee9a64b41ead728636772a
Author: radhika <radhika at curoverse.com>
Date:   Sun May 4 14:13:31 2014 -0400

    2525: Add support for array request parameter type

diff --git a/sdk/java/ArvadosSDKJavaExample.java b/sdk/java/ArvadosSDKJavaExample.java
index 8a28e25..aaffe2b 100644
--- a/sdk/java/ArvadosSDKJavaExample.java
+++ b/sdk/java/ArvadosSDKJavaExample.java
@@ -5,6 +5,11 @@
  *
  */
 
+import org.arvados.sdk.java.Arvados;
+
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
 import java.io.File;
 import java.io.BufferedWriter;
 import java.io.FileWriter;
@@ -12,12 +17,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.arvados.sdk.java.Arvados;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-
-import com.google.api.services.discovery.model.RestDescription;
-
 public class ArvadosSDKJavaExample {
   /** Make sure the following environment variables are set before using Arvados:
    *      ARVADOS_API_TOKEN, ARVADOS_API_HOST, ARVADOS_API_HOST_INSECURE
@@ -28,11 +27,6 @@ public class ArvadosSDKJavaExample {
 
     Arvados arv = new Arvados(apiName, apiVersion);
 
-    // Make a discover request. 
-    System.out.println("Making an arvados discovery api request");
-    RestDescription restDescription = arv.discover();
-    System.out.println("Arvados discovery docuemnt:\n" + restDescription);
-    
     // Make a users.list call
     System.out.println("Making an arvados users.list api 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 6c0cf97..8abb005 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
@@ -20,11 +20,13 @@ import com.google.api.services.discovery.model.RestResource;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
+import org.json.simple.JSONArray;
 
 /**
  * This class provides a java SDK interface to Arvados API server.
@@ -100,17 +102,6 @@ public class Arvados {
   }
 
   /**
-   * Make a discover call and cache the response in-memory.
-   *  Reload the document on each invocation.
-   * @return RestDescription
-   * @throws Exception
-   */
-  public RestDescription discover() throws Exception {
-    restDescription = loadArvadosApi();
-    return (restDescription);
-  }
-
-  /**
    * Make a call to API server with the provide call information.
    * @param resourceName
    * @param methodName
@@ -141,10 +132,10 @@ public class Arvados {
         if (requestBody == null) {
           error("POST method requires content object " + objectName);
         }
-        
+
         content = new ByteArrayContent("application/json", ((String)requestBody).getBytes());
       }
-      
+
       HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
 
       // make the request
@@ -184,7 +175,7 @@ public class Arvados {
     for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
       String parameterName = entry.getKey();
       Object parameterValue = entry.getValue();
-      
+
       if (parameterName.equals("contentType")) {
         if (method.getHttpMethod().equals("GET") || method.getHttpMethod().equals("DELETE")) {
           error("HTTP content type cannot be specified for this method: " + parameterName);
@@ -200,12 +191,12 @@ public class Arvados {
         putParameter(parameterName, parameters, parameterName, parameter, parameterValue);
       }
     }
-    
+
     return parameters;
   }
 
   private RestMethod getMatchingMethod(String resourceName, String methodName)
-              throws Exception {
+      throws Exception {
     if (resourceName == null) {
       error("missing resource name");      
     }
@@ -230,7 +221,7 @@ public class Arvados {
     if (method == null) {
       error("method not found: ");
     }
-    
+
     return method;
   }
 
@@ -271,10 +262,31 @@ public class Arvados {
       } else if ("integer".equals(parameter.getType())) {
         value = new BigInteger(parameterValue.toString());
       } else if ("array".equals(parameter.getType())) {
-        // TBD
+        if (parameterValue.getClass().isArray()){
+          String arrayStr = Arrays.deepToString((Object[])parameterValue);
+          arrayStr = arrayStr.substring(1, arrayStr.length()-1);
+          Object[] array = arrayStr.split(",");
+          Object[] trimmedArray = new Object[array.length];
+          for (int i=0; i<array.length; i++){
+            trimmedArray[i] = array[i].toString().trim();
+          }
+          String jsonString = JSONArray.toJSONString(Arrays.asList(trimmedArray));
+          value = "["+ jsonString +"]";
+        } else if (List.class.isAssignableFrom(parameterValue.getClass())) {
+          List paramList = (List)parameterValue;
+          Object[] array = new Object[paramList.size()];
+          String arrayStr = Arrays.deepToString(paramList.toArray(array));
+          arrayStr = arrayStr.substring(1, arrayStr.length()-1);
+          array = arrayStr.split(",");
+          Object[] trimmedArray = new Object[array.length];
+          for (int i=0; i<array.length; i++){
+            trimmedArray[i] = array[i].toString().trim();
+          }
+          String jsonString = JSONArray.toJSONString(Arrays.asList(trimmedArray));
+          value = "["+ jsonString +"]";
+        }
       }
     }
-    
     parameters.put(parameterName, value);
   }
 
@@ -284,9 +296,10 @@ public class Arvados {
     logger.debug(errorDetail);
     throw new Exception(errorDetail);
   }
-  
+
   public static void main(String[] args){
     System.out.println("Welcome to Arvados Java SDK.");
     System.out.println("Please refer to README to learn to use the SDK.");
   }
+  
 }
\ No newline at end of file
diff --git a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
index 644365c..afe9b6e 100644
--- a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
+++ b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
@@ -1,10 +1,8 @@
 package org.arvados.sdk.java;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -13,9 +11,6 @@ import org.junit.Test;
 
 import static org.junit.Assert.*;
 
-import com.google.api.services.discovery.model.RestDescription;
-import com.google.api.services.discovery.model.RestResource;
-
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 
@@ -25,28 +20,6 @@ import org.json.simple.parser.JSONParser;
 public class ArvadosTest {
 
   /**
-   * test discover method
-   * @throws Exception
-   */
-  @Test
-  public void testDiscover() throws Exception {
-    Arvados arv = new Arvados("arvados", "v1");
-
-    RestDescription restDescription = arv.discover();
-
-    // The discover method returns the supported methods
-    Map<String, RestResource> resources = restDescription.getResources();
-    assertNotNull("Expected resources", resources);
-
-    Object users = resources.get("users");
-    assertNotNull ("Expected users.list method", users);
-    assertEquals("Exepcted users.list to be a RestResource type", RestResource.class, users.getClass());
-
-    assertTrue("Root URL expected to match ARVADOS_API_HOST env paramdeter", 
-        restDescription.getRootUrl().contains(System.getenv().get("ARVADOS_API_HOST")));
-  }
-
-  /**
    * Test users.list api
    * @throws Exception
    */
@@ -405,14 +378,39 @@ public class ArvadosTest {
     String response = arv.call("links", "list", params);
     assertTrue("Expected links.list in response", response.contains("arvados#linkList"));
 
-    /*
-    String[] filters = new String[1];
-    filters[0] = "name != 'can_manage'";
+    String[] filters = new String[3];
+    filters[0] = "name";
+    filters[1] = "is_a";
+    filters[2] = "can_manage";
+    
+    params.put("filters", filters);
+    
+    response = arv.call("links", "list", params);
+    
+    assertTrue("Expected links.list in response", response.contains("arvados#linkList"));
+    assertFalse("Expected no can_manage in response", response.contains("\"name\":\"can_manage\""));
+  }
+
+  @Test
+  public void testGetLinksWithFiltersAsList() throws Exception {
+    Arvados arv = new Arvados("arvados", "v1");
+
+    Map<String, Object> params = new HashMap<String, Object>();
+
+    String response = arv.call("links", "list", params);
+    assertTrue("Expected links.list in response", response.contains("arvados#linkList"));
 
+    List<String> filters = new ArrayList<String>();
+    filters.add("name");
+    filters.add("is_a");
+    filters.add("can_manage");
+    
     params.put("filters", filters);
+    
     response = arv.call("links", "list", params);
+    
     assertTrue("Expected links.list in response", response.contains("arvados#linkList"));
-     */   
+    assertFalse("Expected no can_manage in response", response.contains("\"name\":\"can_manage\""));
   }
 
 }
\ No newline at end of file

commit 3e237c89424489bad02cde9be33f715269e0c6b8
Merge: 00ba956 9887260
Author: radhika <radhika at curoverse.com>
Date:   Sat May 3 22:18:52 2014 -0400

    Merge branch 'master' into 2525-java-sdk


-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list