8 ArvadosFile <- R6::R6Class(
14 initialize = function(name)
17 private$http <- HttpRequest$new()
18 private$httpParser <- HttpParser$new()
21 getName = function() private$name,
23 getFileListing = function(fullpath = TRUE)
28 getSizeInBytes = function()
30 if(is.null(private$collection))
33 REST <- private$collection$getRESTService()
35 fileSize <- REST$getResourceSize(self$getRelativePath(),
36 private$collection$uuid)
41 get = function(fileLikeObjectName)
51 getCollection = function() private$collection,
53 setCollection = function(collection)
55 private$collection <- collection
58 getRelativePath = function()
60 relativePath <- c(private$name)
61 parent <- private$parent
63 while(!is.null(parent))
65 relativePath <- c(parent$getName(), relativePath)
66 parent <- parent$getParent()
69 relativePath <- relativePath[relativePath != ""]
70 paste0(relativePath, collapse = "/")
73 getParent = function() private$parent,
75 setParent = function(newParent) private$parent <- newParent,
77 read = function(contentType = "raw", offset = 0, length = 0)
79 if(is.null(private$collection))
80 stop("ArvadosFile doesn't belong to any collection.")
82 if(offset < 0 || length < 0)
83 stop("Offset and length must be positive values.")
85 REST <- private$collection$getRESTService()
87 fileContent <- REST$read(self$getRelativePath(),
88 private$collection$uuid,
89 contentType, offset, length)
93 connection = function(rw)
97 return(textConnection(self$read("text")))
101 private$buffer <- textConnection(NULL, "w")
103 return(private$buffer)
109 v <- textConnectionValue(private$buffer)
110 close(private$buffer)
111 self$write(paste(v, collapse='\n'))
114 write = function(content, contentType = "text/html")
116 if(is.null(private$collection))
117 stop("ArvadosFile doesn't belong to any collection.")
119 REST <- private$collection$getRESTService()
121 writeResult <- REST$write(self$getRelativePath(),
122 private$collection$uuid,
123 content, contentType)
127 move = function(newLocationInCollection)
129 if(is.null(private$collection))
130 stop("ArvadosFile doesn't belong to any collection")
132 newLocationInCollection <- trimFromEnd(newLocationInCollection, "/")
133 newParentLocation <- trimFromEnd(newLocationInCollection, private$name)
135 newParent <- private$collection$get(newParentLocation)
137 if(is.null(newParent))
139 stop("Unable to get destination subcollection")
142 childWithSameName <- newParent$get(private$name)
144 if(!is.null(childWithSameName))
145 stop("Destination already contains content with same name.")
147 REST <- private$collection$getRESTService()
148 REST$move(self$getRelativePath(),
149 paste0(newParent$getRelativePath(), "/", self$getName()),
150 private$collection$uuid)
152 private$dettachFromCurrentParent()
153 private$attachToNewParent(newParent)
155 "Content moved successfully."
169 attachToNewParent = function(newParent)
171 #Note: We temporary set parents collection to NULL. This will ensure that
172 # add method doesn't post file on REST.
173 parentsCollection <- newParent$getCollection()
174 newParent$setCollection(NULL, setRecursively = FALSE)
178 newParent$setCollection(parentsCollection, setRecursively = FALSE)
180 private$parent <- newParent
183 dettachFromCurrentParent = function()
185 #Note: We temporary set parents collection to NULL. This will ensure that
186 # remove method doesn't remove this subcollection from REST.
187 parent <- private$parent
188 parentsCollection <- parent$getCollection()
189 parent$setCollection(NULL, setRecursively = FALSE)
191 parent$remove(private$name)
193 parent$setCollection(parentsCollection, setRecursively = FALSE)