[ARVADOS] updated: 1.1.2-44-g3d51cb8

Git user git at public.curoverse.com
Thu Dec 21 08:14:37 EST 2017


Summary of changes:
 sdk/R/R/ArvadosFile.R   | 67 +++++++++++++++++++++++++++++++------------------
 sdk/R/R/Collection.R    |  8 +++---
 sdk/R/R/HttpRequest.R   |  3 +++
 sdk/R/R/Subcollection.R | 28 +++++++++++++++------
 sdk/R/README            |  4 ++-
 5 files changed, 74 insertions(+), 36 deletions(-)

       via  3d51cb80240a582a901855d7a7e79b70dcf28bab (commit)
       via  c65dfd0d76b9432b1ca305d2bf39d8bb309124a2 (commit)
      from  082df78ff6abc6ecb5fb817649111e7e6ef967a2 (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 3d51cb80240a582a901855d7a7e79b70dcf28bab
Merge: c65dfd0 082df78
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Thu Dec 21 14:09:47 2017 +0100

    Merge branch '11876-r-sdk' of git.curoverse.com:arvados into 11876-r-sdk
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>


commit c65dfd0d76b9432b1ca305d2bf39d8bb309124a2
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Thu Dec 21 13:57:51 2017 +0100

    Fixed some bugs and improved error handling.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/ArvadosFile.R b/sdk/R/R/ArvadosFile.R
index 85d11c7..84e76af 100644
--- a/sdk/R/R/ArvadosFile.R
+++ b/sdk/R/R/ArvadosFile.R
@@ -11,9 +11,9 @@ ArvadosFile <- R6::R6Class(
 
         initialize = function(name)
         {
-            private$name       <- name
-            private$http       <- HttpRequest$new()
-            private$httpParser <- HttpParser$new()
+            private$name             <- name
+            private$http             <- HttpRequest$new()
+            private$httpParser       <- HttpParser$new()
         },
 
         getName = function() private$name,
@@ -39,13 +39,14 @@ ArvadosFile <- R6::R6Class(
         removeFromCollection = function()
         {
             if(is.null(private$collection))
-                stop("Subcollection doesn't belong to any collection.")
+                stop("ArvadosFile doesn't belong to any collection.")
             
             private$collection$.__enclos_env__$private$deleteFromREST(self$getRelativePath())
 
-            #todo rename this add to a collection
             private$addToCollection(NULL)
             private$detachFromParent()
+
+            "Content removed successfully."
         },
 
         getRelativePath = function()
@@ -53,7 +54,6 @@ ArvadosFile <- R6::R6Class(
             relativePath <- c(private$name)
             parent <- private$parent
 
-            #Recurse back to root
             while(!is.null(parent))
             {
                 relativePath <- c(parent$getName(), relativePath)
@@ -66,11 +66,16 @@ ArvadosFile <- R6::R6Class(
 
         getParent = function() private$parent,
 
-        read = function(offset = 0, length = 0)
+        read = function(contentType = "raw", offset = 0, length = 0)
         {
-            #todo range is wrong fix it
+            if(is.null(private$collection))
+                stop("ArvadosFile doesn't belong to any collection.")
+
             if(offset < 0 || length < 0)
-            stop("Offset and length must be positive values.")
+                stop("Offset and length must be positive values.")
+
+            if(!(contentType %in% private$http$validContentTypes))
+                stop("Invalid contentType. Please use text or raw.")
 
             range = paste0("bytes=", offset, "-")
 
@@ -78,20 +83,31 @@ ArvadosFile <- R6::R6Class(
                 range = paste0(range, offset + length - 1)
             
             fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
-            headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()), 
-                            Range = range)
+
+            if(offset == 0 && length == 0)
+            {
+                headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken())) 
+            }
+            else
+            {
+                headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()), 
+                                Range = range)
+            }
 
             serverResponse <- private$http$GET(fileURL, headers)
 
-            if(serverResponse$status_code != 206)
+            if(serverResponse$status_code < 200 || serverResponse$status_code >= 300)
                 stop(paste("Server code:", serverResponse$status_code))
 
-            parsedServerResponse <- httr::content(serverResponse, "raw")
+            parsedServerResponse <- httr::content(serverResponse, contentType)
             parsedServerResponse
         },
         
         write = function(content, contentType = "text/html")
         {
+            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());
             headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()), 
                             "Content-Type" = contentType)
@@ -99,7 +115,7 @@ ArvadosFile <- R6::R6Class(
 
             serverResponse <- private$http$PUT(fileURL, headers, body)
 
-            if(serverResponse$status_code != 201)
+            if(serverResponse$status_code < 200 || serverResponse$status_code >= 300)
                 stop(paste("Server code:", serverResponse$status_code))
 
             parsedServerResponse <- httr::content(serverResponse, "text")
@@ -108,6 +124,9 @@ ArvadosFile <- R6::R6Class(
 
         move = function(newLocation)
         {
+            if(is.null(private$collection))
+                stop("ArvadosFile doesn't belong to any collection.")
+
             if(endsWith(newLocation, paste0(private$name, "/")))
             {
                 newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
@@ -125,25 +144,25 @@ ArvadosFile <- R6::R6Class(
 
             if(is.null(newParent))
             {
-                stop("Unable to get destination subcollectin")
+                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)
 
-            paste("Status code :", status$status_code)
+            "Content moved successfully."
         }
     ),
 
     private = list(
 
-        name         = NULL,
-        size         = NULL,
-        parent       = NULL,
-        collection   = NULL,
-        http         = NULL,
-        httpParser   = NULL,
+        name       = NULL,
+        size       = NULL,
+        parent     = NULL,
+        collection = NULL,
+        http       = NULL,
+        httpParser = NULL,
 
         getChild = function(name)
         {
@@ -157,7 +176,7 @@ ArvadosFile <- R6::R6Class(
 
         addToCollection = function(collection)
         {
-            private$collection = collection
+            private$collection <- collection
         },
 
         detachFromParent = function()
diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index ea6f692..ca26082 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -160,7 +160,7 @@ Collection <- R6::R6Class(
 
             serverResponse <- private$http$PUT(fileURL, headers, body)
 
-            if(serverResponse$status_code != 201)
+            if(serverResponse$status_code < 200 || serverResponse$status_code >= 300)
                 stop(paste("Server code:", serverResponse$status_code))
 
             print(paste("File created:", relativePath))
@@ -173,13 +173,13 @@ Collection <- R6::R6Class(
 
             serverResponse <- private$http$DELETE(fileURL, headers)
 
-            if(serverResponse$status_code != 204)
+            if(serverResponse$status_code < 200 || serverResponse$status_code >= 300)
                 stop(paste("Server code:", serverResponse$status_code))
 
-            print(paste("File deleted", relativePath))
+            print(paste("File deleted:", relativePath))
         },
 
-        moveOnRest = function(from, to)
+        moveOnREST = function(from, to)
         {
             collectionURL <- URLencode(paste0(self$api$getWebDavHostName(), "c=", self$uuid, "/"))
             fromURL <- paste0(collectionURL, from)
diff --git a/sdk/R/R/HttpRequest.R b/sdk/R/R/HttpRequest.R
index 7a399a4..8366907 100644
--- a/sdk/R/R/HttpRequest.R
+++ b/sdk/R/R/HttpRequest.R
@@ -4,8 +4,11 @@ HttpRequest <- R6::R6Class(
 
     public = list(
 
+        validContentTypes = NULL,
+
         initialize = function() 
         {
+            self$validContentTypes <- c("text", "raw")
         },
 
         GET = function(url, headers = NULL, queryFilters = NULL, limit = NULL, offset = NULL)
diff --git a/sdk/R/R/Subcollection.R b/sdk/R/R/Subcollection.R
index a1fba1a..76bec2e 100644
--- a/sdk/R/R/Subcollection.R
+++ b/sdk/R/R/Subcollection.R
@@ -24,6 +24,10 @@ Subcollection <- R6::R6Class(
                 if(!is.null(content$.__enclos_env__$private$collection))
                     stop("ArvadosFile/Subcollection already belongs to a collection.")
 
+                childWithSameName <- private$getChild(content$getName())
+                if(!is.null(childWithSameName))
+                stop("Subcollection already contains ArvadosFile or Subcollection with same name.")
+
                 if(!is.null(private$collection))
                 {       
                     contentPath <- paste0(self$getRelativePath(), "/", content$getFileList())
@@ -33,10 +37,12 @@ Subcollection <- R6::R6Class(
 
                 private$children <- c(private$children, content)
                 content$.__enclos_env__$private$parent = self
+
+                "Content added successfully."
             }
             else
             {
-                stop("Expected AravodsFile or Subcollection object, got ...")
+                stop(paste("Expected AravodsFile or Subcollection object, got", class(content), "."))
             }
         },
 
@@ -45,7 +51,7 @@ Subcollection <- R6::R6Class(
             if(is.null(private$collection))
                 stop("Subcollection doesn't belong to any collection.")
 
-            if(self$name == "")
+            if(private$name == "")
                 stop("Unable to delete root folder.")
 
             collectionList <- paste0(self$getRelativePath(), "/", self$getFileList(fullpath = FALSE))
@@ -56,6 +62,8 @@ Subcollection <- R6::R6Class(
 
             private$addToCollection(NULL)
             private$dettachFromParent()
+
+            "Content removed successfully."
         },
 
         getFileList = function(fullpath = TRUE)
@@ -114,6 +122,9 @@ Subcollection <- R6::R6Class(
 
         move = function(newLocation)
         {
+            if(is.null(private$collection))
+                stop("Subcollection doesn't belong to any collection.")
+
             if(endsWith(newLocation, paste0(private$name, "/")))
             {
                 newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
@@ -131,14 +142,14 @@ Subcollection <- R6::R6Class(
 
             if(is.null(newParent))
             {
-                stop("Unable to get destination subcollectin")
+                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)
 
-            paste("Status code :", status$status_code)
+            "Content moved successfully."
         },
 
         getParent = function() private$parent
@@ -209,8 +220,11 @@ Subcollection <- R6::R6Class(
 
         attachToParent = function(parent)
         {
-            parent$.__enclos_env__$private$children <- c(parent$.__enclos_env__$private$children, self)
-            private$parent <- parent
+            if(private$name != "")
+            {
+                parent$.__enclos_env__$private$children <- c(parent$.__enclos_env__$private$children, self)
+                private$parent <- parent
+            }
         }
     ),
     
diff --git a/sdk/R/README b/sdk/R/README
index 560be87..14a0c9b 100644
--- a/sdk/R/README
+++ b/sdk/R/README
@@ -73,7 +73,9 @@ arvadosSubcollection <- collection$get("location/to/my/directory/")
 
 #Read whole file or just a portion of it.
 
-fileContent <- arvadosFile$read(offset = 1024, length = 512)
+fileContent <- arvadosFile$read()
+fileContent <- arvadosFile$read("text")
+fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
 
 --------------------------------------------------------------------------------------------------------------------------------
 

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list