-source("./R/Subcollection.R")
-source("./R/ArvadosFile.R")
-source("./R/util.R")
-
-#' Arvados Collection Object
-#'
-#' Update description
-#'
-#' @examples arv = Collection$new(api, uuid)
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
CollectionTree <- R6::R6Class(
"CollectionTree",
public = list(
initialize = function(fileContent, collection)
{
self$pathsList <- fileContent
-
- treeBranches <- sapply(fileContent, function(filePath)
- {
- splitPath <- unlist(strsplit(filePath, "/", fixed = TRUE))
- branch <- private$createBranch(splitPath)
- })
-
+ treeBranches <- sapply(fileContent, function(filePath) self$createBranch(filePath))
root <- Subcollection$new("")
-
- sapply(treeBranches, function(branch)
- {
- private$addBranch(root, branch)
- })
-
+ sapply(treeBranches, function(branch) self$addBranch(root, branch))
root$setCollection(collection)
private$tree <- root
},
- getElement = function(relativePath)
- {
- relativePath <- trimFromStart(relativePath, "./")
- relativePath <- trimFromEnd(relativePath, "/")
-
- if(endsWith(relativePath, "/"))
- relativePath <- substr(relativePath, 0, nchar(relativePath) - 1)
-
- splitPath <- unlist(strsplit(relativePath, "/", fixed = TRUE))
- returnElement <- private$tree
-
- for(pathFragment in splitPath)
- {
- returnElement <- returnElement$get(pathFragment)
-
- if(is.null(returnElement))
- return(NULL)
- }
-
- returnElement
- },
-
- getTree = function() private$tree
- ),
-
- private = list(
-
- tree = NULL,
-
- createBranch = function(splitPath)
+ createBranch = function(filePath)
{
+ splitPath <- unlist(strsplit(filePath, "/", fixed = TRUE))
branch <- NULL
lastElementIndex <- length(splitPath)
branch <- newFolder
}
}
-
+
branch
},
if(is.null(child))
{
+ # Make sure we are don't make any REST call while adding child
+ collection <- container$getCollection()
+ container$setCollection(NULL, setRecursively = FALSE)
container$add(node)
+ container$setCollection(collection, setRecursively = FALSE)
}
else
{
- # Note: REST always returns folder name alone before other folder
+ # Note: REST always returns folder name alone before other folder
# content, so in first iteration we don't know if it's a file
- # or folder since its just a name, so we assume it's a file.
- # If we encounter that same name again we know
+ # or folder since its just a name, so we assume it's a file.
+ # If we encounter that same name again we know
# it's a folder so we need to replace ArvadosFile with Subcollection.
if("ArvadosFile" %in% class(child))
- {
child = private$replaceFileWithSubcollection(child)
- }
- private$addBranch(child, node$getFirst())
+ self$addBranch(child, node$getFirst())
+ }
+ },
+
+ getElement = function(relativePath)
+ {
+ relativePath <- trimFromStart(relativePath, "./")
+ relativePath <- trimFromEnd(relativePath, "/")
+
+ if(endsWith(relativePath, "/"))
+ relativePath <- substr(relativePath, 0, nchar(relativePath) - 1)
+
+ splitPath <- unlist(strsplit(relativePath, "/", fixed = TRUE))
+ returnElement <- private$tree
+
+ for(pathFragment in splitPath)
+ {
+ returnElement <- returnElement$get(pathFragment)
+
+ if(is.null(returnElement))
+ return(NULL)
}
+
+ returnElement
},
+ getTree = function() private$tree
+ ),
+
+ private = list(
+
+ tree = NULL,
+
replaceFileWithSubcollection = function(arvadosFile)
{
subcollection <- Subcollection$new(arvadosFile$getName())