[ARVADOS] updated: 1.1.1-271-g5c5ec11

Git user git at public.curoverse.com
Thu Dec 14 11:26:51 EST 2017


Summary of changes:
 sdk/R/.RData                                       | Bin 399721 -> 321963 bytes
 sdk/R/R/Arvados.R                                  |   9 ++-
 sdk/R/R/ArvadosFile.R                              |  41 +++++++------
 sdk/R/R/Collection.R                               |  67 +++++++++++++++++----
 sdk/R/R/FileTree.R                                 |  12 +++-
 sdk/R/R/HttpRequest.R                              |  12 +++-
 sdk/R/R/Subcollection.R                            |   6 +-
 sdk/R/README                                       |  24 +++++++-
 .../api/app/controllers/application_controller.rb  |   2 +-
 services/api/test/integration/cross_origin_test.rb |   2 +-
 10 files changed, 128 insertions(+), 47 deletions(-)

       via  5c5ec11a744d47f7235e5a1862d2d22288ffe90f (commit)
       via  8b29c17f3dcbfa2601b6be4921316340967af17b (commit)
       via  6d4667c55fb00fba62df76e64c10a87ebb522eaf (commit)
       via  335b2d29f9953f6e7767223cb71d1d0f313c9043 (commit)
      from  f67c59f3fea793ed3ccea7f5a8106014ec2dc108 (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 5c5ec11a744d47f7235e5a1862d2d22288ffe90f
Merge: 8b29c17 6d4667c
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Thu Dec 14 17:26:32 2017 +0100

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


commit 8b29c17f3dcbfa2601b6be4921316340967af17b
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Thu Dec 14 17:22:01 2017 +0100

    Added feature to create new file in a particular collection.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/.RData b/sdk/R/.RData
index 4f88320..5745e7d 100644
Binary files a/sdk/R/.RData and b/sdk/R/.RData differ
diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
index c768e49..7d61d77 100644
--- a/sdk/R/R/Arvados.R
+++ b/sdk/R/R/Arvados.R
@@ -34,10 +34,10 @@ Arvados <- R6::R6Class(
             version <- "v1"
             host  <- paste0("https://", host, "/arvados/", version, "/")
 
-            private$http <- HttpRequest$new()
+            private$http       <- HttpRequest$new()
             private$httpParser <- HttpParser$new()
-            private$token <- token
-            private$host <- host
+            private$token      <- token
+            private$host       <- host
             
             headers <- list(Authorization = paste("OAuth2", private$token))
 
@@ -73,8 +73,7 @@ Arvados <- R6::R6Class(
             collectionURL <- paste0(private$host, "collections")
             headers <- list(Authorization = paste("OAuth2", private$token))
 
-            serverResponse <- private$http$GET(collectionURL, headers, NULL, filters, limit, offset)
-
+            serverResponse <- private$http$GET(collectionURL, headers, filters, limit, offset)
             collection <- private$httpParser$parseJSONResponse(serverResponse)
 
             if(!is.null(collection$errors))
diff --git a/sdk/R/R/ArvadosFile.R b/sdk/R/R/ArvadosFile.R
index da8692d..563eaa2 100644
--- a/sdk/R/R/ArvadosFile.R
+++ b/sdk/R/R/ArvadosFile.R
@@ -45,11 +45,11 @@ ArvadosFile <- R6::R6Class(
             if(serverResponse$status_code != 206)
                 stop(paste("Server code:", serverResponse$status_code))
 
-            collection
-            parsed_response <- httr::content(serverResponse, "raw")
+            parsedServerResponse <- httr::content(serverResponse, "raw")
+            parsedServerResponse
         },
         
-        write = function(content, contentType)
+        write = function(content, contentType = "text/html")
         {
             fileURL = paste0(private$api$getWebDavHostName(), "c=", private$collection$uuid, "/", private$relativePath);
             headers <- list(Authorization = paste("OAuth2", private$api$getToken()), 
@@ -61,23 +61,10 @@ ArvadosFile <- R6::R6Class(
             if(serverResponse$status_code != 201)
                 stop(paste("Server code:", serverResponse$status_code))
 
-            #Note(Fudo): Everything went well we need to update file size 
-            # in collection tree.
+            private$notifyCollectionThatFileSizeChanges()
 
-            #Todo(Fudo): Move this into HttpRequest
-            uri <- URLencode(paste0(private$api$getWebDavHostName(), "c=", private$collection$uuid))
-            h <- curl::new_handle()
-            curl::handle_setopt(h, customrequest = "PROPFIND")
-
-            curl::handle_setheaders(h, "Authorization" = paste("OAuth2", private$api$getToken()))
-            propfindResponse <- curl::curl_fetch_memory(fileURL, h)
-
-            fileInfo <- private$httpParser$parseWebDAVResponse(propfindResponse, uri)
-
-            private$size <- fileInfo[[1]]$fileSize
-            private$collection$update(self, "File size changed")
-
-            parsed_response <- httr::content(serverResponse, "text")
+            parsedServerResponse <- httr::content(serverResponse, "text")
+            parsedServerResponse
         }
     ),
 
@@ -90,7 +77,21 @@ ArvadosFile <- R6::R6Class(
         api          = NULL,
         collection   = NULL,
         http         = NULL,
-        httpParser   = NULL
+        httpParser   = NULL,
+
+        notifyCollectionThatFileSizeChanges = function()
+        {
+            collectionURL <- URLencode(paste0(private$api$getWebDavHostName(), "c=", private$collection$uuid))
+            fileURL = paste0(collectionURL, "/", private$relativePath);
+            headers = list("Authorization" = paste("OAuth2", private$api$getToken()))
+
+            propfindResponse <- private$http$PROPFIND(fileURL, headers)
+
+            fileInfo <- private$httpParser$parseWebDAVResponse(propfindResponse, collectionURL)
+
+            private$size <- fileInfo[[1]]$fileSize
+            private$collection$update(self, "File size changed")
+        }
     ),
     
     cloneable = FALSE
diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index c29f8f0..0ebaed8 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -1,6 +1,8 @@
 source("./R/Subcollection.R")
 source("./R/ArvadosFile.R")
 source("./R/FileTree.R")
+source("./R/HttpRequest.R")
+source("./R/HttpParser.R")
 
 #' Arvados Collection Object
 #'
@@ -62,9 +64,12 @@ Collection <- R6::R6Class(
             self$trash_at                 <- result$trash_at                           
             self$is_trashed               <- result$is_trashed                         
 
-            private$fileItems <- private$getCollectionContent()
+            private$http <- HttpRequest$new()
+            private$httpParser <- HttpParser$new()
 
+            private$fileItems <- private$getCollectionContent()
             private$fileTree <- FileTree$new(private$fileItems)
+
         },
 
         printFileContent = function()
@@ -100,6 +105,29 @@ Collection <- R6::R6Class(
             }
         },
 
+        createNewFile = function(relativePath, content, contentType)
+        {
+            node <- private$fileTree$getNode(relativePath)
+
+            if(is.null(node))
+                stop("File already exists")
+
+            fileURL <- paste0(private$api$getWebDavHostName(), "c=", self$uuid, "/", relativePath);
+            headers <- list(Authorization = paste("OAuth2", private$api$getToken()), 
+                            "Content-Type" = contentType)
+            body <- content
+
+            serverResponse <- private$http$PUT(fileURL, headers, body)
+
+            if(serverResponse$status_code != 201)
+                stop(paste("Server code:", serverResponse$status_code))
+
+            fileSize = private$getNewFileSize(relativePath)
+            private$fileTree$addNode(relativePath, fileSize)
+
+            paste0("File created (size = ", fileSize , ")")
+        },
+
         update = function(subcollection, event)
         {
             #Todo(Fudo): Add some king of check here later on.
@@ -125,13 +153,19 @@ Collection <- R6::R6Class(
     
     private = list(
 
-        fileItems = NULL,
-        api       = NULL,
-        fileTree  = NULL,
+        fileItems  = NULL,
+        api        = NULL,
+        fileTree   = NULL,
+        http       = NULL,
+        httpParser = NULL,
 
         handleFileSizeChange = function(filePath, newSize)
         {
             node <- private$fileTree$getNode(filePath)
+
+            if(is.null(node))
+                stop("File doesn't exits")
+
             node$size <- newSize
         },
 
@@ -160,19 +194,28 @@ Collection <- R6::R6Class(
 
         getCollectionContent = function()
         {
-            uri <- URLencode(paste0(private$api$getWebDavHostName(), "c=", self$uuid))
+            collectionURL <- URLencode(paste0(private$api$getWebDavHostName(), "c=", self$uuid))
 
-            # fetch directory listing via curl and parse XML response
-            h <- curl::new_handle()
-            curl::handle_setopt(h, customrequest = "PROPFIND")
+            headers = list("Authorization" = paste("OAuth2", private$api$getToken()))
 
-            curl::handle_setheaders(h, "Authorization" = paste("OAuth2", private$api$getToken()))
-            response <- curl::curl_fetch_memory(uri, h)
+            response <- private$http$PROPFIND(collectionURL, headers)
 
-            parsedResponse <- HttpParser$new()$parseWebDAVResponse(response, uri)
+            parsedResponse <- private$httpParser$parseWebDAVResponse(response, collectionURL)
             parsedResponse[-1]
-        }
+        },
 
+        getNewFileSize = function(relativePath)
+        {
+            collectionURL <- URLencode(paste0(private$api$getWebDavHostName(), "c=", self$uuid))
+            fileURL = paste0(collectionURL, "/", relativePath);
+            headers = list("Authorization" = paste("OAuth2", private$api$getToken()))
+
+            propfindResponse <- private$http$PROPFIND(fileURL, headers)
+
+            fileInfo <- private$httpParser$parseWebDAVResponse(propfindResponse, collectionURL)
+
+            fileInfo[[1]]$fileSize
+        }
     ),
 
     cloneable = FALSE
diff --git a/sdk/R/R/FileTree.R b/sdk/R/R/FileTree.R
index ee54bd9..4b21fda 100644
--- a/sdk/R/R/FileTree.R
+++ b/sdk/R/R/FileTree.R
@@ -70,13 +70,23 @@ FileTree <- R6::R6Class(
                 for(pathFragment in splitPath)
                 {
                     child = node$getChild(pathFragment)
+
                     if(is.null(child))
-                        stop("Subcollection/ArvadosFile you are looking for doesn't exist.")
+                        return(NULL)
+
                     node = child
                 }
 
                 node
             })
+        },
+
+        addNode = function(relativePathToNode, size)
+        {
+            splitPath <- unlist(strsplit(relativePathToNode, "/", fixed = TRUE))
+
+            branch <- private$createBranch(splitPath, size)
+            private$addBranch(private$tree, branch)
         }
     ),
 
diff --git a/sdk/R/R/HttpRequest.R b/sdk/R/R/HttpRequest.R
index 6dd8e4c..f5c11a1 100644
--- a/sdk/R/R/HttpRequest.R
+++ b/sdk/R/R/HttpRequest.R
@@ -8,8 +8,7 @@ HttpRequest <- R6::R6Class(
         {
         },
 
-        GET = function(url, headers = NULL, body = NULL,
-                       queryFilters = NULL, limit = NULL, offset = NULL)
+        GET = function(url, headers = NULL, queryFilters = NULL, limit = NULL, offset = NULL)
         {
             headers <- httr::add_headers(unlist(headers))
             query <- private$createQuery(queryFilters, limit, offset)
@@ -46,6 +45,15 @@ HttpRequest <- R6::R6Class(
             url <- paste0(url, query)
 
             serverResponse <- httr::DELETE(url = url, config = headers)
+        },
+
+        PROPFIND = function(url, headers = NULL)
+        {
+            h <- curl::new_handle()
+            curl::handle_setopt(h, customrequest = "PROPFIND")
+            curl::handle_setheaders(h, .list = headers)
+
+            propfindResponse <- curl::curl_fetch_memory(url, h)
         }
     ),
 
diff --git a/sdk/R/R/Subcollection.R b/sdk/R/R/Subcollection.R
index 1d8c8a7..4fd2d3c 100644
--- a/sdk/R/R/Subcollection.R
+++ b/sdk/R/R/Subcollection.R
@@ -34,10 +34,10 @@ Subcollection <- R6::R6Class(
 
     private = list(
 
-        name = NULL,
+        name         = NULL,
         relativePath = NULL,
-        children = NULL,
-        parent = NULL
+        children     = NULL,
+        parent       = NULL
     ),
     
     cloneable = FALSE
diff --git a/sdk/R/README b/sdk/R/README
index 344deab..c611c04 100644
--- a/sdk/R/README
+++ b/sdk/R/README
@@ -73,7 +73,7 @@ arvadosFile <- collection$get("location/to/my/file.cpp")
 
 #or
 
-arvadosSubcollection <- collection.get("location/to/my/directory/")
+arvadosSubcollection <- collection$get("location/to/my/directory/")
 
 --------------------------------------------------------------------------------------------------------------------------------
 
@@ -83,9 +83,29 @@ fileContent <- arvadosFile$read(offset = 1024, length = 512)
 
 --------------------------------------------------------------------------------------------------------------------------------
 
-#Get ArvadosFile or Subcollection size
+#Get ArvadosFile or Subcollection size 
 
 size <- arvadosFile$getSizeInBytes()
 size <- arvadosSubcollection$getSizeInBytes()
 
 --------------------------------------------------------------------------------------------------------------------------------
+
+#Create new file in a collection
+
+#Call structure
+
+collection$createNewFile("relativePath", "fileContent", "fileContentType")
+
+#Example
+
+collection$createNewFile("cpp/src/main.cpp", "#include<iostream>", "text/html")
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Write to existing file (Override current content of the file)
+
+arvadosFile <- collection$get("location/to/my/file.cpp")
+
+arvadosFile$write("This is new file content")
+
+--------------------------------------------------------------------------------------------------------------------------------

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list