1 source("./R/Subcollection.R")
2 source("./R/ArvadosFile.R")
4 #' Arvados Collection Object
8 #' @examples arv = Collection$new(api, uuid)
9 #' @export CollectionTree
10 CollectionTree <- R6::R6Class(
16 initialize = function(fileContent, collection)
18 self$pathsList <- fileContent
20 treeBranches <- sapply(fileContent, function(filePath)
22 splitPath <- unlist(strsplit(filePath, "/", fixed = TRUE))
23 branch = private$createBranch(splitPath)
26 root <- Subcollection$new("")
28 sapply(treeBranches, function(branch)
30 private$addBranch(root, branch)
33 root$.__enclos_env__$private$addToCollection(collection)
37 getElement = function(relativePath)
39 splitPath <- unlist(strsplit(relativePath, "/", fixed = TRUE))
40 returnElement = private$tree
42 for(pathFragment in splitPath)
44 returnElement = returnElement$.__enclos_env__$private$getChild(pathFragment)
46 if(is.null(returnElement))
58 createBranch = function(splitPath)
61 lastElementIndex <- length(splitPath)
63 for(elementIndex in lastElementIndex:1)
65 if(elementIndex == lastElementIndex)
67 branch = ArvadosFile$new(splitPath[[elementIndex]])
71 newFolder = Subcollection$new(splitPath[[elementIndex]])
80 addBranch = function(container, node)
82 child = container$.__enclos_env__$private$getChild(node$getName())
87 #todo add it to collection
91 if("ArvadosFile" %in% class(child))
93 child = private$replaceFileWithSubcollection(child)
96 private$addBranch(child, node$.__enclos_env__$private$getFirstChild())
100 replaceFileWithSubcollection = function(arvadosFile)
102 subcollection <- Subcollection$new(arvadosFile$getName())
103 fileParent <- arvadosFile$.__enclos_env__$private$parent
104 fileParent$.__enclos_env__$private$removeChild(arvadosFile$getName())
105 fileParent$add(subcollection)
107 arvadosFile$.__enclos_env__$private$parent <- NULL