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)
95 if (rw == "r" || rw == "rb")
97 REST <- private$collection$getRESTService()
98 return(REST$getConnection(private$collection$uuid,
99 self$getRelativePath(),
104 private$buffer <- textConnection(NULL, "w")
106 return(private$buffer)
112 v <- textConnectionValue(private$buffer)
113 close(private$buffer)
114 self$write(paste(v, collapse='\n'))
117 write = function(content, contentType = "text/html")
119 if(is.null(private$collection))
120 stop("ArvadosFile doesn't belong to any collection.")
122 REST <- private$collection$getRESTService()
124 writeResult <- REST$write(self$getRelativePath(),
125 private$collection$uuid,
126 content, contentType)
130 move = function(newLocation)
132 if(is.null(private$collection))
133 stop("ArvadosFile doesn't belong to any collection")
136 newLocation <- trimFromEnd(newLocation, "/")
137 nameAndPath <- splitToPathAndName(newLocation)
139 newParent <- private$collection$get(nameAndPath$path)
141 if(is.null(newParent))
143 stop("Unable to get destination subcollection")
146 childWithSameName <- newParent$get(nameAndPath$name)
148 if(!is.null(childWithSameName))
149 stop("Destination already contains content with same name.")
151 REST <- private$collection$getRESTService()
152 REST$move(self$getRelativePath(),
153 paste0(newParent$getRelativePath(), "/", nameAndPath$name),
154 private$collection$uuid)
156 private$dettachFromCurrentParent()
157 private$attachToNewParent(newParent)
159 private$name <- nameAndPath$name
161 "Content moved successfully."
175 attachToNewParent = function(newParent)
177 #Note: We temporary set parents collection to NULL. This will ensure that
178 # add method doesn't post file on REST.
179 parentsCollection <- newParent$getCollection()
180 newParent$setCollection(NULL, setRecursively = FALSE)
184 newParent$setCollection(parentsCollection, setRecursively = FALSE)
186 private$parent <- newParent
189 dettachFromCurrentParent = function()
191 #Note: We temporary set parents collection to NULL. This will ensure that
192 # remove method doesn't remove this subcollection from REST.
193 parent <- private$parent
194 parentsCollection <- parent$getCollection()
195 parent$setCollection(NULL, setRecursively = FALSE)
197 parent$remove(private$name)
199 parent$setCollection(parentsCollection, setRecursively = FALSE)