1 source("./R/Subcollection.R")
3 source("./R/ArvadosFile.R")
5 #' Arvados Collection Object
9 #' @examples arv = Collection$new(api, uuid)
10 #' @export CollectionTree
11 CollectionTree <- R6::R6Class(
17 initialize = function(fileContent, collection)
19 self$pathsList <- fileContent
21 treeBranches <- sapply(fileContent, function(filePath)
23 splitPath <- unlist(strsplit(filePath, "/", fixed = TRUE))
24 branch <- private$createBranch(splitPath)
27 root <- Subcollection$new("")
29 sapply(treeBranches, function(branch)
31 private$addBranch(root, branch)
34 root$setCollection(collection)
38 getElement = function(relativePath)
40 if(endsWith(relativePath, "/"))
41 relativePath <- substr(relativePath, 0, nchar(relativePath) - 1)
43 splitPath <- unlist(strsplit(relativePath, "/", fixed = TRUE))
44 returnElement <- private$tree
46 for(pathFragment in splitPath)
48 returnElement <- returnElement$get(pathFragment)
50 if(is.null(returnElement))
57 getTree = function() private$tree
64 createBranch = function(splitPath)
67 lastElementIndex <- length(splitPath)
69 for(elementIndex in lastElementIndex:1)
71 if(elementIndex == lastElementIndex)
73 branch <- ArvadosFile$new(splitPath[[elementIndex]])
77 newFolder <- Subcollection$new(splitPath[[elementIndex]])
86 addBranch = function(container, node)
88 child <- container$get(node$getName())
96 if("ArvadosFile" %in% class(child))
98 child = private$replaceFileWithSubcollection(child)
101 private$addBranch(child, node$getFirst())
105 replaceFileWithSubcollection = function(arvadosFile)
107 subcollection <- Subcollection$new(arvadosFile$getName())
108 fileParent <- arvadosFile$getParent()
109 fileParent$remove(arvadosFile$getName())
110 fileParent$add(subcollection)
112 arvadosFile$setParent(NULL)