[ARVADOS] updated: 1.1.2-98-g2d3726d

Git user git at public.curoverse.com
Tue Jan 9 11:22:06 EST 2018


Summary of changes:
 README.md                                          |  14 +-
 build/check-copyright-notices                      | 301 ++++++++--------
 build/run-build-docker-jobs-image.sh               |  20 +-
 build/run-build-packages-one-target.sh             |   6 +-
 build/run-build-packages.sh                        |   2 +
 build/run-library.sh                               |   9 +-
 build/run-tests.sh                                 |  19 +-
 cmd/arvados-client/.gitignore                      |   1 +
 cmd/arvados-client/cmd.go                          |  79 +++++
 cmd/arvados-client/cmd_test.go                     |  41 +++
 doc/api/methods/users.html.textile.liquid          |  13 +
 .../install-slurm.html.textile.liquid              |   2 +
 doc/user/cwl/bwa-mem/bwa-mem.cwl                   |   4 +-
 lib/cli/external.go                                | 124 +++++++
 lib/cli/flags.go                                   |  33 ++
 lib/cli/get.go                                     |  75 ++++
 lib/cli/get_test.go                                |  33 ++
 lib/cmd/cmd.go                                     | 116 +++++++
 lib/cmd/cmd_test.go                                |  62 ++++
 lib/cmdtest/leakcheck.go                           |  54 +++
 sdk/R/DESCRIPTION                                  |   1 +
 sdk/R/R/Arvados.R                                  |  34 +-
 sdk/R/R/ArvadosFile.R                              |  83 +++--
 sdk/R/R/Collection.R                               |  84 ++---
 sdk/R/R/CollectionTree.R                           |  28 +-
 sdk/R/R/HttpRequest.R                              |   8 +-
 sdk/R/R/Subcollection.R                            | 173 +++++-----
 sdk/R/tests/testthat.R                             |   4 +
 sdk/R/tests/testthat/HttpRequestStub.R             |  52 +++
 sdk/R/tests/testthat/test-Arvados.R                |  35 ++
 sdk/cwl/arvados_cwl/arvworkflow.py                 |   5 +-
 sdk/cwl/arvados_cwl/runner.py                      |  15 +-
 sdk/cwl/tests/arvados-tests.yml                    |   5 +
 .../cwl/tests/secondary/dir/hg19.fa                |   0
 .../cwl/tests/secondary/dir/hg19.fa.amb            |   0
 .../cwl/tests/secondary/dir/hg19.fa.ann            |   0
 .../cwl/tests/secondary/dir/hg19.fa.fai            |   0
 sdk/cwl/tests/secondary/ls.cwl                     |  11 +
 sdk/cwl/tests/secondary/sub.cwl                    |  17 +
 sdk/cwl/tests/secondary/wf-job.yml                 |   3 +
 sdk/cwl/tests/secondary/wf.cwl                     |  23 ++
 sdk/go/arvados/collection_fs.go                    |   4 +
 sdk/go/arvados/collection_fs_test.go               |  24 ++
 sdk/go/arvadostest/fixtures.go                     |   1 +
 .../app/controllers/arvados/v1/users_controller.rb |  17 +-
 services/api/app/models/user.rb                    |  26 ++
 services/api/config/routes.rb                      |   1 +
 .../test/fixtures/api_client_authorizations.yml    |   8 +-
 services/api/test/fixtures/containers.yml          |   3 +-
 .../functional/arvados/v1/users_controller_test.rb |  21 ++
 services/api/test/unit/container_test.rb           |   2 +-
 services/api/test/unit/user_test.rb                |  79 +++++
 services/arv-git-httpd/arvados-git-httpd.service   |   9 +-
 .../crunch-dispatch-slurm.service                  |   9 +-
 services/crunch-run/crunchrun.go                   |  19 +-
 services/crunch-run/crunchrun_test.go              |   2 +-
 services/crunch-run/logging.go                     |   6 +-
 .../dockercleaner/arvados-docker-cleaner.service   |   9 +-
 services/fuse/arvados_fuse/__init__.py             |   5 +-
 services/fuse/tests/test_inodes.py                 |   2 +-
 services/health/arvados-health.service             |  27 ++
 services/keep-balance/keep-balance.service         |   9 +-
 services/keep-web/cadaver_test.go                  |  11 +
 services/keep-web/keep-web.service                 |   9 +-
 services/keepproxy/keepproxy.service               |   9 +-
 services/keepstore/keepstore.service               |   9 +-
 services/ws/arvados-ws.service                     |   9 +-
 vendor/vendor.json                                 | 384 ++++++++++++++++++++-
 68 files changed, 1884 insertions(+), 419 deletions(-)
 create mode 100644 cmd/arvados-client/.gitignore
 create mode 100644 cmd/arvados-client/cmd.go
 create mode 100644 cmd/arvados-client/cmd_test.go
 create mode 100644 lib/cli/external.go
 create mode 100644 lib/cli/flags.go
 create mode 100644 lib/cli/get.go
 create mode 100644 lib/cli/get_test.go
 create mode 100644 lib/cmd/cmd.go
 create mode 100644 lib/cmd/cmd_test.go
 create mode 100644 lib/cmdtest/leakcheck.go
 create mode 100644 sdk/R/tests/testthat.R
 create mode 100644 sdk/R/tests/testthat/HttpRequestStub.R
 create mode 100644 sdk/R/tests/testthat/test-Arvados.R
 copy tools/crunchstat-summary/tests/__init__.py => sdk/cwl/tests/secondary/dir/hg19.fa (100%)
 copy tools/crunchstat-summary/tests/__init__.py => sdk/cwl/tests/secondary/dir/hg19.fa.amb (100%)
 copy tools/crunchstat-summary/tests/__init__.py => sdk/cwl/tests/secondary/dir/hg19.fa.ann (100%)
 copy tools/crunchstat-summary/tests/__init__.py => sdk/cwl/tests/secondary/dir/hg19.fa.fai (100%)
 create mode 100644 sdk/cwl/tests/secondary/ls.cwl
 create mode 100644 sdk/cwl/tests/secondary/sub.cwl
 create mode 100644 sdk/cwl/tests/secondary/wf-job.yml
 create mode 100644 sdk/cwl/tests/secondary/wf.cwl
 create mode 100644 services/health/arvados-health.service

       via  2d3726dd11046146731f7f7391659a5eaf44702b (commit)
       via  7b76c49887aecdb2bf0be7eecf8f5b271d5f0c38 (commit)
       via  3cca12f9fb5452831a826964656f48e427d8edcd (commit)
       via  b5a8d7052ff461073496627aef8e2e0c29901a19 (commit)
       via  9f842eecf59f293fd800ece28be2730ff3a39487 (commit)
       via  9e74f69b3ae6abbbc497c8fd2adeef41c96de251 (commit)
       via  8daddfe53514b71ef229e9c2985e116fa6614858 (commit)
       via  d246f53c1d991f1572d6701569aa8c7eac4d722d (commit)
       via  2a3daf14afb93de4d65108019a7a1d35aa1052ad (commit)
       via  ee03454bfec20bfb3b743bbd79ccd73f20301f00 (commit)
       via  27ae43f3b4d700a1a35db514130fb17824ae9c80 (commit)
       via  680ffd64dac92aec8ad94454334db9ae69b95b56 (commit)
       via  13d6ff884079f23613c0592cfead88cc92e0bbb3 (commit)
       via  cf8c09785fece3f454af5bc012c5143e44c9342b (commit)
       via  4726a67ad33df26cb84ee9bf4fca6c774ab7ced2 (commit)
       via  4ad076c659f9245494aa46609fa7741dd94c94a9 (commit)
       via  4b9a74f8ce269ebd19b8cfa77c7ebb74df125429 (commit)
       via  a5da28efdbc8d9f2673a1b200a14297447b04664 (commit)
       via  b9851a978e1a1deb8853f7cd5b02acf7c55a24c8 (commit)
       via  02001807b3a68526f3f1a5de9f4cc87e59993b2a (commit)
       via  3d8da9e64df7c0dd0302b7d2f4d188a9ede9099c (commit)
       via  8f8a0ac695f4440412de0245fc748c2792cb1496 (commit)
       via  cd9b6605e5ad6fb90c531fb4f1c98e113f0498ba (commit)
       via  7bc8466abceb800872bb6f687111f9ebe526e141 (commit)
       via  086b27a27c844178ee52a9c4186d970689147628 (commit)
       via  eae6972da6ffbf73d31fd47138cb49c13fed77de (commit)
       via  87647b5d3d72ae0c291fcdf1ee3b4a46b3af91c0 (commit)
       via  456b1c4ef6229c15d80f704647a396da7819139b (commit)
       via  a6ee0e990641973aa4d79e550821eb42eab25ca4 (commit)
       via  51bb28e3e62563fa0921f003b8d11ce8740f3a68 (commit)
       via  e7f41c4af1298b91106f9b1d8fb87a68e46a3f64 (commit)
       via  6def96daca7a5ec60dc067c04864bc58bd4aaf5c (commit)
       via  243f15e69ed3a5514be89115d3ec231551d31cb8 (commit)
       via  9c4901c09e0395899b268f9a734514ae7be4f9c9 (commit)
       via  6ac835d8869876955d85a86a4b6d35c12b0d63ac (commit)
       via  13273a566ce37e8426cb851e464ace152d4f02df (commit)
       via  4749f9394bacea3782c701b9bc98f2b9e4995a73 (commit)
       via  987457b7e545f4ad1e32c7a07c00c29c24326421 (commit)
       via  f6d560c1a46b05802ad81dc4a815d28a50c5b8f4 (commit)
       via  5b819f447743fbd8281dcf26143ad556cd710cad (commit)
       via  c152ee1d170bf419ef49241cbde030e8fce68882 (commit)
       via  b3efaa37f1e3c52b5a126ba3416856ceba21549a (commit)
       via  b8ffcc224f73c5c856c6d5993ba06255892a789f (commit)
       via  11377b3b6eb9544b9d9bcabab8de495f6e6fcaa4 (commit)
       via  cf5e73998da0cac4a00d29f6004ea58d11c7acd4 (commit)
       via  08fcef34fae00ecb34d34d4d34dbbb2cec98ced8 (commit)
      from  b37da0c1488f68491f40bbe5bfbe2e00a12137e9 (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 2d3726dd11046146731f7f7391659a5eaf44702b
Merge: 7b76c49 3cca12f
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Tue Jan 9 17:21:49 2018 +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 7b76c49887aecdb2bf0be7eecf8f5b271d5f0c38
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Tue Jan 9 17:21:18 2018 +0100

    Added support for unit testing.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/DESCRIPTION b/sdk/R/DESCRIPTION
index 0e586e9..ce96f05 100644
--- a/sdk/R/DESCRIPTION
+++ b/sdk/R/DESCRIPTION
@@ -17,3 +17,4 @@ Imports:
     jsonlite,
     curl,
     XML
+Suggests: testthat
diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
index e08ce61..b58b287 100644
--- a/sdk/R/R/Arvados.R
+++ b/sdk/R/R/Arvados.R
@@ -30,9 +30,6 @@ Arvados <- R6::R6Class(
                 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")
-
             version <- "v1"
             host  <- paste0("https://", host, "/arvados/", version, "/")
 
@@ -40,22 +37,31 @@ Arvados <- R6::R6Class(
             private$httpParser <- HttpParser$new()
             private$token      <- token
             private$host       <- host
-            
-            headers <- list(Authorization = paste("OAuth2", private$token))
-
-            serverResponse <- private$http$GET(discoveryDocumentURL, headers)
-
-            discoveryDocument <- private$httpParser$parseJSONResponse(serverResponse)
-            private$webDavHostName <- discoveryDocument$keepWebServiceUrl
-
-            if(is.null(private$webDavHostName))
-                stop("Unable to find WebDAV server.")
         },
 
         getToken    = function() private$token,
         getHostName = function() private$host,
 
-        getWebDavHostName = function() private$webDavHostName,
+        getWebDavHostName = function()
+        {
+            if(is.null(private$webDavHostName))
+            {
+                discoveryDocumentURL <- paste0("https://", host,
+                                               "/discovery/v1/apis/arvados/v1/rest")
+
+                headers <- list(Authorization = paste("OAuth2", private$token))
+
+                serverResponse <- private$http$GET(discoveryDocumentURL, headers)
+
+                discoveryDocument <- private$httpParser$parseJSONResponse(serverResponse)
+                private$webDavHostName <- discoveryDocument$keepWebServiceUrl
+
+                if(is.null(private$webDavHostName))
+                    stop("Unable to find WebDAV server.")
+            }
+
+            private$webDavHostName
+        },
 
         getCollection = function(uuid) 
         {
diff --git a/sdk/R/tests/testthat.R b/sdk/R/tests/testthat.R
new file mode 100644
index 0000000..18ef411
--- /dev/null
+++ b/sdk/R/tests/testthat.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(ArvadosR)
+
+test_check("ArvadosR")
diff --git a/sdk/R/tests/testthat/HttpRequestStub.R b/sdk/R/tests/testthat/HttpRequestStub.R
new file mode 100644
index 0000000..31f8759
--- /dev/null
+++ b/sdk/R/tests/testthat/HttpRequestStub.R
@@ -0,0 +1,52 @@
+HttpRequest <- R6::R6Class(
+
+    "HttrRequestStub",
+
+    public = list(
+
+        validContentTypes = NULL,
+
+        content = NULL,
+
+        initialize = function(returnContent) 
+        {
+            self$validContentTypes <- c("text", "raw")
+            self$content <- returnContent
+        },
+
+        GET = function(url, headers = NULL, queryFilters = NULL, limit = NULL, offset = NULL)
+        {
+            return self$content
+        },
+
+        PUT = function(url, headers = NULL, body = NULL,
+                       queryFilters = NULL, limit = NULL, offset = NULL)
+        {
+            return self$content
+        },
+
+        POST = function(url, headers = NULL, body = NULL,
+                        queryFilters = NULL, limit = NULL, offset = NULL)
+        {
+            return self$content
+        },
+
+        DELETE = function(url, headers = NULL, body = NULL,
+                          queryFilters = NULL, limit = NULL, offset = NULL)
+        {
+            return self$content
+        },
+
+        PROPFIND = function(url, headers = NULL)
+        {
+            return self$content
+        },
+
+        MOVE = function(url, headers = NULL)
+        {
+            return self$content
+        }
+    ),
+
+    cloneable = FALSE
+)
diff --git a/sdk/R/tests/testthat/test-Arvados.R b/sdk/R/tests/testthat/test-Arvados.R
new file mode 100644
index 0000000..35b4152
--- /dev/null
+++ b/sdk/R/tests/testthat/test-Arvados.R
@@ -0,0 +1,35 @@
+context("Arvados API")
+
+test_that("Arvados constructor will use environment variables if no parameters are passed to it", {
+
+    Sys.setenv(ARVADOS_API_HOST  = "environment_api_host")
+    Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
+
+    arv <- Arvados$new()
+
+    Sys.unsetenv("ARVADOS_API_HOST")
+    Sys.unsetenv("ARVADOS_API_TOKEN")
+
+    expect_that("https://environment_api_host/arvados/v1/",
+                equals(arv$getHostName())) 
+
+    expect_that("environment_api_token",
+                equals(arv$getToken())) 
+}) 
+
+test_that("Arvados constructor preferes constructor fields over environment variables", {
+
+    Sys.setenv(ARVADOS_API_HOST  = "environment_api_host")
+    Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
+
+    arv <- Arvados$new("constructor_api_token", "constructor_api_host")
+
+    Sys.unsetenv("ARVADOS_API_HOST")
+    Sys.unsetenv("ARVADOS_API_TOKEN")
+
+    expect_that("https://constructor_api_host/arvados/v1/",
+                equals(arv$getHostName())) 
+
+    expect_that("constructor_api_token",
+                equals(arv$getToken())) 
+}) 

commit 8daddfe53514b71ef229e9c2985e116fa6614858
Merge: d246f53 b37da0c
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Tue Jan 9 15:31:19 2018 +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 d246f53c1d991f1572d6701569aa8c7eac4d722d
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Tue Jan 9 15:28:42 2018 +0100

    Collection classes no longer use each others private state.
    
    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 3be24c4..8c2e9e2 100644
--- a/sdk/R/R/ArvadosFile.R
+++ b/sdk/R/R/ArvadosFile.R
@@ -37,17 +37,21 @@ ArvadosFile <- R6::R6Class(
             as.numeric(sizes)
         },
 
-        removeFromCollection = function()
+        get = function(fileLikeObjectName)
         {
-            if(is.null(private$collection))
-                stop("ArvadosFile doesn't belong to any collection.")
-            
-            private$collection$.__enclos_env__$private$deleteFromREST(self$getRelativePath())
+            return(NULL)
+        },
 
-            private$addToCollection(NULL)
-            private$detachFromParent()
+        getFirst = function()
+        {
+            return(NULL)
+        },
 
-            "Content removed successfully."
+        getCollection = function() private$collection,
+
+        setCollection = function(collection)
+        {
+            private$collection <- collection
         },
 
         getRelativePath = function()
@@ -67,6 +71,8 @@ ArvadosFile <- R6::R6Class(
 
         getParent = function() private$parent,
 
+        setParent = function(newParent) private$parent <- newParent,
+
         read = function(contentType = "raw", offset = 0, length = 0)
         {
             if(is.null(private$collection))
@@ -128,17 +134,21 @@ ArvadosFile <- R6::R6Class(
 
         move = function(newLocation)
         {
+            #todo test if file can be moved
+
             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, "/")))
+                                      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
             {
@@ -152,10 +162,25 @@ ArvadosFile <- R6::R6Class(
                 stop("Unable to get destination subcollection.")
             }
 
-            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
-                                                                            paste0(newParent$getRelativePath(), "/", self$getName()))
+            childWithSameName <- newParent$get(private$name)
+
+            if(!is.null(childWithSameName))
+                stop("Destination already contains file with same name.")
 
-            private$attachToParent(newParent)
+            status <- private$collection$moveOnREST(self$getRelativePath(),
+                                                    paste0(newParent$getRelativePath(),
+                                                           "/", self$getName()))
+
+            #Note: We temporary set parents collection to NULL. This will ensure that
+            #      add method doesn't post file on REST server.
+            parentsCollection <- newParent$getCollection()
+            newParent$setCollection(NULL, setRecursively = FALSE)
+
+            newParent$add(self)
+
+            newParent$setCollection(parentsCollection, setRecursively = FALSE)
+
+            private$parent <- newParent
 
             "Content moved successfully."
         }
@@ -168,37 +193,7 @@ ArvadosFile <- R6::R6Class(
         parent     = NULL,
         collection = NULL,
         http       = NULL,
-        httpParser = NULL,
-
-        getChild = function(name)
-        {
-            return(NULL)
-        },
-
-        getFirstChild = function()
-        {
-            return(NULL)
-        },
-
-        addToCollection = function(collection)
-        {
-            private$collection <- collection
-        },
-
-        detachFromParent = function()
-        {
-            if(!is.null(private$parent))
-            {
-                private$parent$.__enclos_env__$private$removeChild(private$name)
-                private$parent <- NULL
-            }
-        },
-
-        attachToParent = function(parent)
-        {
-            parent$.__enclos_env__$private$children <- c(parent$.__enclos_env__$private$children, self)
-            private$parent <- parent
-        }
+        httpParser = NULL
     ),
     
     cloneable = FALSE
diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index 8e6895e..8bd4655 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -37,7 +37,7 @@ Collection <- R6::R6Class(
                relativePath == "." ||
                relativePath == "./")
             {
-                subcollection <- private$tree$.__enclos_env__$private$tree
+                subcollection <- private$tree$getTree()
             }
             else
             {
@@ -71,7 +71,7 @@ Collection <- R6::R6Class(
                relativePath == "." ||
                relativePath == "./")
             {
-                subcollection <- private$tree$.__enclos_env__$private$tree
+                subcollection <- private$tree$getTree()
             }
             else
             {
@@ -89,6 +89,10 @@ Collection <- R6::R6Class(
                 arvadosFiles <- NULL
                 sapply(fileNames, function(fileName)
                 {
+                    childWithSameName <- subcollection$get(fileName)
+                    if(!is.null(childWithSameName))
+                        stop("Destination already contains file with same name.")
+
                     newFile <- ArvadosFile$new(fileName)
                     subcollection$add(newFile)
 
@@ -122,14 +126,15 @@ Collection <- R6::R6Class(
                     if(is.null(file))
                         stop(paste("File", filePath, "doesn't exist."))
 
-                    file$removeFromCollection()
+                    parent <- file$getParent()
+                    parent$remove(filePath)
                 })
             }
             else if("ArvadosFile"   %in% class(content) ||
                     "Subcollection" %in% class(content))
             {
-                if(is.null(content$.__enclos_env__$private$collection) || 
-                   content$.__enclos_env__$private$collection$uuid != self$uuid)
+                if(is.null(content$getCollection()) || 
+                   content$getCollection()$uuid != self$uuid)
                     stop("Subcollection doesn't belong to this collection.")
 
                 content$removeFromCollection()
@@ -154,44 +159,14 @@ Collection <- R6::R6Class(
         get = function(relativePath)
         {
             private$tree$getElement(relativePath)
-        }
-    ),
-
-    private = list(
-
-        http       = NULL,
-        httpParser = NULL,
-        tree       = NULL,
-
-        fileContent = NULL,
-
-        getCollectionContent = function()
-        {
-            collectionURL <- URLencode(paste0(self$api$getWebDavHostName(), "c=", self$uuid))
-
-            headers = list("Authorization" = paste("OAuth2", self$api$getToken()))
-
-            response <- private$http$PROPFIND(collectionURL, headers)
-
-            parsedResponse <- private$httpParser$parseWebDAVResponse(response, collectionURL)
-            parsedResponse[-1]
         },
-
+        
+        #Todo: Move these methods to another class.
         createFilesOnREST = function(files)
         {
             sapply(files, function(filePath)
             {
-                private$createNewFile(filePath, NULL, "text/html")
-            })
-        },
-        
-        generateTree = function(content)
-        {
-            treeBranches <- sapply(collectionContent, function(filePath)
-            {
-                splitPath <- unlist(strsplit(filePath$name, "/", fixed = TRUE))
-
-                branch = private$createBranch(splitPath, filePath$fileSize)      
+                self$createNewFile(filePath, NULL, "text/html")
             })
         },
 
@@ -209,7 +184,7 @@ Collection <- R6::R6Class(
 
             print(paste("File created:", relativePath))
         },
-        
+
         deleteFromREST = function(relativePath)
         {
             fileURL <- paste0(self$api$getWebDavHostName(), "c=", self$uuid, "/", relativePath);
@@ -241,5 +216,36 @@ Collection <- R6::R6Class(
         }
     ),
 
+    private = list(
+
+        http       = NULL,
+        httpParser = NULL,
+        tree       = NULL,
+
+        fileContent = NULL,
+
+        getCollectionContent = function()
+        {
+            collectionURL <- URLencode(paste0(self$api$getWebDavHostName(), "c=", self$uuid))
+
+            headers = list("Authorization" = paste("OAuth2", self$api$getToken()))
+
+            response <- private$http$PROPFIND(collectionURL, headers)
+
+            parsedResponse <- private$httpParser$parseWebDAVResponse(response, collectionURL)
+            parsedResponse[-1]
+        },
+
+        generateTree = function(content)
+        {
+            treeBranches <- sapply(collectionContent, function(filePath)
+            {
+                splitPath <- unlist(strsplit(filePath$name, "/", fixed = TRUE))
+
+                branch = private$createBranch(splitPath, filePath$fileSize)      
+            })
+        }
+    ),
+
     cloneable = FALSE
 )
diff --git a/sdk/R/R/CollectionTree.R b/sdk/R/R/CollectionTree.R
index 3bf89e5..e024f5e 100644
--- a/sdk/R/R/CollectionTree.R
+++ b/sdk/R/R/CollectionTree.R
@@ -21,7 +21,7 @@ CollectionTree <- R6::R6Class(
             treeBranches <- sapply(fileContent, function(filePath)
             {
                 splitPath <- unlist(strsplit(filePath, "/", fixed = TRUE))
-                branch = private$createBranch(splitPath)      
+                branch <- private$createBranch(splitPath)      
             })
 
             root <- Subcollection$new("")
@@ -31,7 +31,7 @@ CollectionTree <- R6::R6Class(
                 private$addBranch(root, branch)
             })
 
-            root$.__enclos_env__$private$addToCollection(collection)
+            root$setCollection(collection)
             private$tree <- root
         },
 
@@ -41,18 +41,20 @@ CollectionTree <- R6::R6Class(
                 relativePath <- substr(relativePath, 0, nchar(relativePath) - 1)
 
             splitPath <- unlist(strsplit(relativePath, "/", fixed = TRUE))
-            returnElement = private$tree
+            returnElement <- private$tree
 
             for(pathFragment in splitPath)
             {
-                returnElement = returnElement$.__enclos_env__$private$getChild(pathFragment)
+                returnElement <- returnElement$get(pathFragment)
 
                 if(is.null(returnElement))
                     return(NULL)
             }
 
             returnElement
-        }
+        },
+
+        getTree = function() private$tree
     ),
 
     private = list(
@@ -68,13 +70,13 @@ CollectionTree <- R6::R6Class(
             {
                 if(elementIndex == lastElementIndex)
                 {
-                    branch = ArvadosFile$new(splitPath[[elementIndex]])
+                    branch <- ArvadosFile$new(splitPath[[elementIndex]])
                 }
                 else
                 {
-                    newFolder = Subcollection$new(splitPath[[elementIndex]])
+                    newFolder <- Subcollection$new(splitPath[[elementIndex]])
                     newFolder$add(branch)
-                    branch = newFolder
+                    branch <- newFolder
                 }
             }
             
@@ -83,7 +85,7 @@ CollectionTree <- R6::R6Class(
 
         addBranch = function(container, node)
         {
-            child = container$.__enclos_env__$private$getChild(node$getName())
+            child <- container$get(node$getName())
 
             if(is.null(child))
             {
@@ -96,18 +98,18 @@ CollectionTree <- R6::R6Class(
                     child = private$replaceFileWithSubcollection(child)
                 }
 
-                private$addBranch(child, node$.__enclos_env__$private$getFirstChild())
+                private$addBranch(child, node$getFirst())
             }
         },
 
         replaceFileWithSubcollection = function(arvadosFile)
         {
             subcollection <- Subcollection$new(arvadosFile$getName())
-            fileParent <- arvadosFile$.__enclos_env__$private$parent
-            fileParent$.__enclos_env__$private$removeChild(arvadosFile$getName())
+            fileParent <- arvadosFile$getParent()
+            fileParent$remove(arvadosFile$getName())
             fileParent$add(subcollection)
 
-            arvadosFile$.__enclos_env__$private$parent <- NULL
+            arvadosFile$setParent(NULL)
 
             subcollection
         }
diff --git a/sdk/R/R/HttpRequest.R b/sdk/R/R/HttpRequest.R
index a1e1f61..ad153a0 100644
--- a/sdk/R/R/HttpRequest.R
+++ b/sdk/R/R/HttpRequest.R
@@ -21,17 +21,18 @@ HttpRequest <- R6::R6Class(
         },
 
         PUT = function(url, headers = NULL, body = NULL,
-                       queryFilters = NULL, limit = 100, offset = 0)
+                       queryFilters = NULL, limit = NULL, offset = NULL)
         {
             headers <- httr::add_headers(unlist(headers))
             query <- private$createQuery(queryFilters, limit, offset)
             url <- paste0(url, query)
+            print(url)
 
             serverResponse <- httr::PUT(url = url, config = headers, body = body)
         },
 
         POST = function(url, headers = NULL, body = NULL,
-                        queryFilters = NULL, limit = 100, offset = 0)
+                        queryFilters = NULL, limit = NULL, offset = NULL)
         {
             headers <- httr::add_headers(unlist(headers))
             query <- private$createQuery(queryFilters, limit, offset)
@@ -141,7 +142,8 @@ HttpRequest <- R6::R6Class(
                 finalQuery <- paste0(finalQuery, collapse = "&")
             }
 
-            finalQuery <- paste0("/?", finalQuery)
+            if(!is.null(finalQuery))
+                finalQuery <- paste0("/?", finalQuery)
 
             finalQuery
         }
diff --git a/sdk/R/R/Subcollection.R b/sdk/R/R/Subcollection.R
index 296cb92..06df7c4 100644
--- a/sdk/R/R/Subcollection.R
+++ b/sdk/R/R/Subcollection.R
@@ -15,31 +15,48 @@ Subcollection <- R6::R6Class(
             private$http       <- HttpRequest$new()
             private$httpParser <- HttpParser$new()
         },
+
+        getName = function() private$name,
         
+        getRelativePath = function()
+        {
+            relativePath <- c(private$name)
+            parent <- private$parent
+
+            while(!is.null(parent))
+            {
+                relativePath <- c(parent$getName(), relativePath)
+                parent <- parent$getParent()
+            }
+
+            relativePath <- relativePath[relativePath != ""]
+            paste0(relativePath, collapse = "/")
+        },
+
         add = function(content)
         {
             if("ArvadosFile"   %in% class(content) ||
                "Subcollection" %in% class(content))
             {
-                if(!is.null(content$.__enclos_env__$private$collection))
-                    stop("ArvadosFile/Subcollection already belongs to a collection.")
-
-                childWithSameName <- private$getChild(content$getName())
+                childWithSameName <- self$get(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$getFileListing())
-
-                    private$collection$.__enclos_env__$private$createFilesOnREST(contentPath)
-                    content$.__enclos_env__$private$addToCollection(private$collection)
+                    if(self$getRelativePath() != "")
+                        contentPath <- paste0(self$getRelativePath(),
+                                              "/", content$getFileListing())
+                    else
+                        contentPath <- content$getFileListing()
+
+                    private$collection$createFilesOnREST(contentPath)
+                    content$setCollection(private$collection)
                 }
 
                 private$children <- c(private$children, content)
-                content$.__enclos_env__$private$parent = self
+                content$setParent(self)
 
                 "Content added successfully."
             }
@@ -50,25 +67,31 @@ Subcollection <- R6::R6Class(
             }
         },
 
-        removeFromCollection = function()
+        remove = function(name)
         {
-            if(is.null(private$collection))
-                stop("Subcollection doesn't belong to any collection.")
+            if(is.character(name))
+            {
+                child <- self$get(name)
 
-            if(private$name == "")
-                stop("Unable to delete root folder.")
+                if(is.null(child))
+                    stop("Subcollection doesn't contains ArvadosFile
+                          or Subcollection with same name.")
 
-            collectionList <- paste0(self$getRelativePath(),
-                                     "/", self$getFileListing(fullpath = FALSE))
-            sapply(collectionList, function(file)
-            {
-                private$collection$.__enclos_env__$private$deleteFromREST(file)
-            })
+                if(!is.null(private$collection))
+                {
+                    private$collection$deleteFromREST(child$getRelativePath())
+                    child$setCollection(NULL)
+                }
 
-            private$addToCollection(NULL)
-            private$dettachFromParent()
+                private$removeChild(name)
+                child$setParent(NULL)
 
-            "Content removed successfully."
+                "Content removed"
+            }
+            else
+            {
+                stop(paste("Expected character, got", class(content), "."))
+            }
         },
 
         getFileListing = function(fullpath = TRUE)
@@ -108,23 +131,6 @@ Subcollection <- R6::R6Class(
             sum(sizes)
         },
 
-        getName = function() private$name,
-
-        getRelativePath = function()
-        {
-            relativePath <- c(private$name)
-            parent <- private$parent
-
-            while(!is.null(parent))
-            {
-                relativePath <- c(parent$getName(), relativePath)
-                parent <- parent$getParent()
-            }
-
-            relativePath <- relativePath[relativePath != ""]
-            paste0(relativePath, collapse = "/")
-        },
-
         move = function(newLocation)
         {
             if(is.null(private$collection))
@@ -152,27 +158,25 @@ 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$moveOnREST(self$getRelativePath(),
+                                                    paste0(newParent$getRelativePath(),
+                                                           "/", self$getName()))
 
-            private$attachToParent(newParent)
+            #Note: We temporary set parents collection to NULL. This will ensure that
+            #      add method doesn't post file on REST server.
+            parentsCollection <- newParent$getCollection()
+            newParent$setCollection(NULL, setRecursively = FALSE)
 
-            "Content moved successfully."
-        },
+            newParent$add(self)
 
-        getParent = function() private$parent
-    ),
+            newParent$setCollection(parentsCollection, setRecursively = FALSE)
 
-    private = list(
+            private$parent <- newParent
 
-        name       = NULL,
-        children   = NULL,
-        parent     = NULL,
-        collection = NULL,
-        http       = NULL,
-        httpParser = NULL,
+            "Content moved successfully."
+        },
 
-        getChild = function(name)
+        get = function(name)
         {
             for(child in private$children)
             {
@@ -183,7 +187,7 @@ Subcollection <- R6::R6Class(
             return(NULL)
         },
 
-        getFirstChild = function()
+        getFirst = function()
         {
             if(length(private$children) == 0)
                return(NULL)
@@ -191,6 +195,33 @@ Subcollection <- R6::R6Class(
             private$children[[1]]
         },
 
+        setCollection = function(collection, setRecursively = TRUE)
+        {
+            private$collection = collection
+
+            if(setRecursively)
+            {
+                for(child in private$children)
+                    child$setCollection(collection)
+            }
+        },
+
+        getCollection = function() private$collection,
+
+        getParent = function() private$parent,
+
+        setParent = function(newParent) private$parent <- newParent
+    ),
+
+    private = list(
+
+        name       = NULL,
+        children   = NULL,
+        parent     = NULL,
+        collection = NULL,
+        http       = NULL,
+        httpParser = NULL,
+
         removeChild = function(name)
         {
             numberOfChildren = length(private$children)
@@ -205,34 +236,6 @@ Subcollection <- R6::R6Class(
                     }
                 }
             }
-        },
-
-        addToCollection = function(collection)
-        {
-            for(child in private$children)
-                child$.__enclos_env__$private$addToCollection(collection)
-
-            private$collection = collection
-        },
-
-        dettachFromParent = function()
-        {
-            if(!is.null(private$parent))
-            {
-                private$parent$.__enclos_env__$private$removeChild(private$name)
-                private$parent <- NULL
-            }
-            else
-                stop("Parent doesn't exists.")
-        },
-
-        attachToParent = function(parent)
-        {
-            if(private$name != "")
-            {
-                parent$.__enclos_env__$private$children <- c(parent$.__enclos_env__$private$children, self)
-                private$parent <- parent
-            }
         }
     ),
     

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list