initialize = function(name)
{
- private$name <- name
+ private$name <- name
},
getName = function() private$name,
getFileListing = function(fullPath = TRUE)
{
- content <- NULL
-
- if(fullPath)
- {
- for(child in private$children)
- content <- c(content, child$getFileListing())
-
- if(private$name != "")
- content <- unlist(paste0(private$name, "/", content))
- }
- else
- {
- for(child in private$children)
- content <- c(content, child$getName())
- }
+ content <- private$getContentAsCharVector(fullPath)
- content
+ content[order(tolower(content))]
},
getSizeInBytes = function()
return(sum(fileSizes))
},
- move = function(newLocationInCollection)
+ move = function(newLocation)
{
if(is.null(private$collection))
stop("Subcollection doesn't belong to any collection")
- newLocationInCollection <- trimFromEnd(newLocationInCollection, "/")
- newParentLocation <- trimFromEnd(newLocationInCollection, private$name)
+ newLocation <- trimFromEnd(newLocation, "/")
+ nameAndPath <- splitToPathAndName(newLocation)
- newParent <- private$collection$get(newParentLocation)
+ newParent <- private$collection$get(nameAndPath$path)
if(is.null(newParent))
{
stop("Unable to get destination subcollection")
}
- childWithSameName <- newParent$get(private$name)
+ childWithSameName <- newParent$get(nameAndPath$name)
if(!is.null(childWithSameName))
stop("Destination already contains content with same name.")
REST <- private$collection$getRESTService()
REST$move(self$getRelativePath(),
- paste0(newParent$getRelativePath(), "/", self$getName()),
+ paste0(newParent$getRelativePath(), "/", nameAndPath$name),
private$collection$uuid)
private$dettachFromCurrentParent()
private$attachToNewParent(newParent)
- "Content moved successfully"
+ private$name <- nameAndPath$name
+
+ "Content moved successfully."
},
get = function(name)
parent$remove(private$name)
parent$setCollection(parentsCollection, setRecursively = FALSE)
+ },
+
+ getContentAsCharVector = function(fullPath = TRUE)
+ {
+ content <- NULL
+
+ if(fullPath)
+ {
+ for(child in private$children)
+ content <- c(content, child$getFileListing())
+
+ if(private$name != "")
+ content <- unlist(paste0(private$name, "/", content))
+ }
+ else
+ {
+ for(child in private$children)
+ content <- c(content, child$getName())
+ }
+
+ content
+
}
),
cloneable = FALSE
)
+
+#' @export print.Subcollection
+print.Subcollection = function(subCollection)
+{
+ collection <- NULL
+ relativePath <- subCollection$getRelativePath()
+
+ if(!is.null(subCollection$getCollection()))
+ {
+ collection <- subCollection$getCollection()$uuid
+
+ if(!subCollection$getName() == "")
+ relativePath <- paste0("/", relativePath)
+ }
+
+ cat(paste0("Type: ", "\"", "Arvados Subcollection", "\""), sep = "\n")
+ cat(paste0("Name: ", "\"", subCollection$getName(), "\""), sep = "\n")
+ cat(paste0("Relative path: ", "\"", relativePath, "\"") , sep = "\n")
+ cat(paste0("Collection: ", "\"", collection, "\""), sep = "\n")
+}