Methods listCollections and listProjects now work properly
authorFuad Muhic <fmuhic@capeannenterprises.com>
Fri, 22 Dec 2017 10:12:39 +0000 (11:12 +0100)
committerFuad Muhic <fmuhic@capeannenterprises.com>
Fri, 22 Dec 2017 10:12:39 +0000 (11:12 +0100)
when called without parameters. Removed old comments.

Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic@capeannenterprises.com>

sdk/R/R/Arvados.R
sdk/R/R/ArvadosFile.R
sdk/R/R/CollectionTree.R
sdk/R/R/HttpParser.R
sdk/R/R/HttpRequest.R
sdk/R/R/Subcollection.R

index 3236ab7930f535823b3163610a7935d13e9b2875..c051313286a080e5e3e78c6b0285a1b3ca2346e9 100644 (file)
@@ -27,9 +27,11 @@ Arvados <- R6::R6Class(
             token <- Sys.getenv("ARVADOS_API_TOKEN");
 
             if(host == "" | token == "")
-                stop("Please provide host name and authentification token or set ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
+                stop("Please provide host name and authentification token or set
+                     ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
 
-            discoveryDocumentURL <- paste0("https://", host, "/discovery/v1/apis/arvados/v1/rest")
+            discoveryDocumentURL <- paste0("https://", host,
+                                           "/discovery/v1/apis/arvados/v1/rest")
 
             version <- "v1"
             host  <- paste0("https://", host, "/arvados/", version, "/")
@@ -50,7 +52,6 @@ Arvados <- R6::R6Class(
         getToken    = function() private$token,
         getHostName = function() private$host,
 
-        #Todo(Fudo): Hardcoded credentials to WebDAV server. Remove them later
         getWebDavHostName = function() private$webDavHostName,
 
         getCollection = function(uuid) 
@@ -73,9 +74,12 @@ Arvados <- R6::R6Class(
             collectionURL <- paste0(private$host, "collections")
             headers <- list(Authorization = paste("OAuth2", private$token))
 
-            names(filters) <- c("collection")
+            if(!is.null(filters))
+                names(filters) <- c("collection")
+
+            serverResponse <- private$http$GET(collectionURL, headers, filters,
+                                               limit, offset)
 
-            serverResponse <- private$http$GET(collectionURL, headers, filters, limit, offset)
             collection <- private$httpParser$parseJSONResponse(serverResponse)
 
             if(!is.null(collection$errors))
@@ -206,10 +210,14 @@ Arvados <- R6::R6Class(
             projectURL <- paste0(private$host, "groups")
             headers <- list(Authorization = paste("OAuth2", private$token))
 
-            names(filters) <- c("groups")
+            if(!is.null(filters))
+                names(filters) <- c("groups")
+
             filters[[length(filters) + 1]] <- list("group_class", "=", "project")
 
-            serverResponse <- private$http$GET(projectURL, headers, filters, limit, offset)
+            serverResponse <- private$http$GET(projectURL, headers, filters,
+                                               limit, offset)
+
             projects <- private$httpParser$parseJSONResponse(serverResponse)
 
             if(!is.null(projects$errors))
index 84e76af4517200b756b2b393b78913aa423459d8..c5fa1832565cb7ef3564a2d4f256df89f0bcffb0 100644 (file)
@@ -25,7 +25,8 @@ ArvadosFile <- R6::R6Class(
 
         getSizeInBytes = function()
         {
-            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid))
+            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(),
+                                              "c=", private$collection$uuid))
             fileURL <- paste0(collectionURL, "/", self$getRelativePath());
 
             headers = list("Authorization" = paste("OAuth2", private$collection$api$getToken()))
@@ -82,11 +83,13 @@ ArvadosFile <- R6::R6Class(
             if(length > 0)
                 range = paste0(range, offset + length - 1)
             
-            fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
+            fileURL = paste0(private$collection$api$getWebDavHostName(),
+                             "c=", private$collection$uuid, "/", self$getRelativePath());
 
             if(offset == 0 && length == 0)
             {
-                headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken())) 
+                headers <- list(Authorization = paste("OAuth2",
+                                                      private$collection$api$getToken())) 
             }
             else
             {
@@ -108,7 +111,8 @@ ArvadosFile <- R6::R6Class(
             if(is.null(private$collection))
                 stop("ArvadosFile doesn't belong to any collection.")
 
-            fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
+            fileURL = paste0(private$collection$api$getWebDavHostName(), 
+                             "c=", private$collection$uuid, "/", self$getRelativePath());
             headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()), 
                             "Content-Type" = contentType)
             body <- content
@@ -129,7 +133,8 @@ ArvadosFile <- R6::R6Class(
 
             if(endsWith(newLocation, paste0(private$name, "/")))
             {
-                newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
+                newLocation <- substr(newLocation, 0,
+                                      nchar(newLocation) - nchar(paste0(private$name, "/")))
             }
             else if(endsWith(newLocation, private$name))
             {
@@ -147,7 +152,8 @@ ArvadosFile <- R6::R6Class(
                 stop("Unable to get destination subcollection.")
             }
 
-            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(), paste0(newParent$getRelativePath(), "/", self$getName()))
+            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
+                                                                            paste0(newParent$getRelativePath(), "/", self$getName()))
 
             private$attachToParent(newParent)
 
index 82c6eb8f9e16011a2b82c753e2e672ed15387d0e..3bf89e5f5a3bd48eeb23e5283fd66512068f2aca 100644 (file)
@@ -88,7 +88,6 @@ CollectionTree <- R6::R6Class(
             if(is.null(child))
             {
                 container$add(node)
-                #todo add it to collection
             }
             else
             {
index e7407b1a0df0b915b20602dd58cdb66ae97e52ee..82b7109fc61f63368093617e1b5ef57685b64830 100644 (file)
@@ -11,7 +11,9 @@ HttpParser <- R6::R6Class(
 
         parseJSONResponse = function(serverResponse) 
         {
-            parsed_response <- httr::content(serverResponse, as = "parsed", type = "application/json")
+            parsed_response <- httr::content(serverResponse,
+                                             as = "parsed",
+                                             type = "application/json")
         },
 
         parseWebDAVResponse = function(response, uri)
index 2f172683b39e6a4157dc8a946a788572de07d123..20ad7ea81b5d5772f4855929bc0e47f3d62c9cf5 100644 (file)
@@ -71,8 +71,6 @@ HttpRequest <- R6::R6Class(
 
     private = list(
 
-        #Todo(Fudo): Refactor this and find a better way to build
-        # Python array from R list (recursion?)
         createQuery = function(filters, limit, offset)
         {
             finalQuery <- NULL
@@ -115,7 +113,6 @@ HttpRequest <- R6::R6Class(
 
                 encodedQuery <- URLencode(filters, reserved = T, repeated = T)
 
-                #Todo(Fudo): This is a hack for now. Find a proper solution.
                 encodedQuery <- stringr::str_replace_all(encodedQuery, "%2B", "+")
 
                 finalQuery <- c(finalQuery, paste0("filters=", encodedQuery))
index 76bec2e64fc2117dedb461970bdad316845ac989..62c62d457e519434a7aa32543a9267ae6172ad59 100644 (file)
@@ -26,11 +26,14 @@ Subcollection <- R6::R6Class(
 
                 childWithSameName <- private$getChild(content$getName())
                 if(!is.null(childWithSameName))
-                stop("Subcollection already contains ArvadosFile or Subcollection with same name.")
+                    stop("Subcollection already contains ArvadosFile
+                          or Subcollection with same name.")
 
                 if(!is.null(private$collection))
                 {       
-                    contentPath <- paste0(self$getRelativePath(), "/", content$getFileList())
+                    contentPath <- paste0(self$getRelativePath(),
+                                          "/", content$getFileList())
+
                     private$collection$.__enclos_env__$private$createFilesOnREST(contentPath)
                     content$.__enclos_env__$private$addToCollection(private$collection)
                 }
@@ -42,7 +45,8 @@ Subcollection <- R6::R6Class(
             }
             else
             {
-                stop(paste("Expected AravodsFile or Subcollection object, got", class(content), "."))
+                stop(paste("Expected AravodsFile or Subcollection object, got",
+                           class(content), "."))
             }
         },
 
@@ -54,7 +58,8 @@ Subcollection <- R6::R6Class(
             if(private$name == "")
                 stop("Unable to delete root folder.")
 
-            collectionList <- paste0(self$getRelativePath(), "/", self$getFileList(fullpath = FALSE))
+            collectionList <- paste0(self$getRelativePath(),
+                                     "/", self$getFileList(fullpath = FALSE))
             sapply(collectionList, function(file)
             {
                 private$collection$.__enclos_env__$private$deleteFromREST(file)
@@ -89,7 +94,8 @@ Subcollection <- R6::R6Class(
 
         getSizeInBytes = function()
         {
-            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid))
+            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(),
+                                              "c=", private$collection$uuid))
             subcollectionURL <- paste0(collectionURL, "/", self$getRelativePath(), "/");
 
             headers = list("Authorization" = paste("OAuth2", private$collection$api$getToken()))
@@ -109,7 +115,6 @@ Subcollection <- R6::R6Class(
             relativePath <- c(private$name)
             parent <- private$parent
 
-            #Recurse back to root
             while(!is.null(parent))
             {
                 relativePath <- c(parent$getName(), relativePath)
@@ -127,11 +132,13 @@ Subcollection <- R6::R6Class(
 
             if(endsWith(newLocation, paste0(private$name, "/")))
             {
-                newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
+                newLocation <- substr(newLocation, 0,
+                                      nchar(newLocation) - nchar(paste0(private$name, "/")))
             }
             else if(endsWith(newLocation, private$name))
             {
-                newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(private$name))
+                newLocation <- substr(newLocation, 0,
+                                      nchar(newLocation) - nchar(private$name))
             }
             else
             {
@@ -145,7 +152,8 @@ Subcollection <- R6::R6Class(
                 stop("Unable to get destination subcollection.")
             }
 
-            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(), paste0(newParent$getRelativePath(), "/", self$getName()))
+            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
+                                                                            paste0(newParent$getRelativePath(), "/", self$getName()))
 
             private$attachToParent(newParent)