when called without parameters. Removed old comments.
Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic@capeannenterprises.com>
token <- Sys.getenv("ARVADOS_API_TOKEN");
if(host == "" | token == "")
- stop("Please provide host name and authentification token or set ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
+ stop("Please provide host name and authentification token or set
+ ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
- discoveryDocumentURL <- paste0("https://", host, "/discovery/v1/apis/arvados/v1/rest")
+ discoveryDocumentURL <- paste0("https://", host,
+ "/discovery/v1/apis/arvados/v1/rest")
version <- "v1"
host <- paste0("https://", host, "/arvados/", version, "/")
getToken = function() private$token,
getHostName = function() private$host,
- #Todo(Fudo): Hardcoded credentials to WebDAV server. Remove them later
getWebDavHostName = function() private$webDavHostName,
getCollection = function(uuid)
collectionURL <- paste0(private$host, "collections")
headers <- list(Authorization = paste("OAuth2", private$token))
- names(filters) <- c("collection")
+ if(!is.null(filters))
+ names(filters) <- c("collection")
+
+ serverResponse <- private$http$GET(collectionURL, headers, filters,
+ limit, offset)
- serverResponse <- private$http$GET(collectionURL, headers, filters, limit, offset)
collection <- private$httpParser$parseJSONResponse(serverResponse)
if(!is.null(collection$errors))
projectURL <- paste0(private$host, "groups")
headers <- list(Authorization = paste("OAuth2", private$token))
- names(filters) <- c("groups")
+ if(!is.null(filters))
+ names(filters) <- c("groups")
+
filters[[length(filters) + 1]] <- list("group_class", "=", "project")
- serverResponse <- private$http$GET(projectURL, headers, filters, limit, offset)
+ serverResponse <- private$http$GET(projectURL, headers, filters,
+ limit, offset)
+
projects <- private$httpParser$parseJSONResponse(serverResponse)
if(!is.null(projects$errors))
getSizeInBytes = function()
{
- collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid))
+ collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(),
+ "c=", private$collection$uuid))
fileURL <- paste0(collectionURL, "/", self$getRelativePath());
headers = list("Authorization" = paste("OAuth2", private$collection$api$getToken()))
if(length > 0)
range = paste0(range, offset + length - 1)
- fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
+ fileURL = paste0(private$collection$api$getWebDavHostName(),
+ "c=", private$collection$uuid, "/", self$getRelativePath());
if(offset == 0 && length == 0)
{
- headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()))
+ headers <- list(Authorization = paste("OAuth2",
+ private$collection$api$getToken()))
}
else
{
if(is.null(private$collection))
stop("ArvadosFile doesn't belong to any collection.")
- fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
+ fileURL = paste0(private$collection$api$getWebDavHostName(),
+ "c=", private$collection$uuid, "/", self$getRelativePath());
headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()),
"Content-Type" = contentType)
body <- content
if(endsWith(newLocation, paste0(private$name, "/")))
{
- newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
+ newLocation <- substr(newLocation, 0,
+ nchar(newLocation) - nchar(paste0(private$name, "/")))
}
else if(endsWith(newLocation, private$name))
{
stop("Unable to get destination subcollection.")
}
- status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(), paste0(newParent$getRelativePath(), "/", self$getName()))
+ status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
+ paste0(newParent$getRelativePath(), "/", self$getName()))
private$attachToParent(newParent)
if(is.null(child))
{
container$add(node)
- #todo add it to collection
}
else
{
parseJSONResponse = function(serverResponse)
{
- parsed_response <- httr::content(serverResponse, as = "parsed", type = "application/json")
+ parsed_response <- httr::content(serverResponse,
+ as = "parsed",
+ type = "application/json")
},
parseWebDAVResponse = function(response, uri)
private = list(
- #Todo(Fudo): Refactor this and find a better way to build
- # Python array from R list (recursion?)
createQuery = function(filters, limit, offset)
{
finalQuery <- NULL
encodedQuery <- URLencode(filters, reserved = T, repeated = T)
- #Todo(Fudo): This is a hack for now. Find a proper solution.
encodedQuery <- stringr::str_replace_all(encodedQuery, "%2B", "+")
finalQuery <- c(finalQuery, paste0("filters=", encodedQuery))
childWithSameName <- private$getChild(content$getName())
if(!is.null(childWithSameName))
- stop("Subcollection already contains ArvadosFile or Subcollection with same name.")
+ stop("Subcollection already contains ArvadosFile
+ or Subcollection with same name.")
if(!is.null(private$collection))
{
- contentPath <- paste0(self$getRelativePath(), "/", content$getFileList())
+ contentPath <- paste0(self$getRelativePath(),
+ "/", content$getFileList())
+
private$collection$.__enclos_env__$private$createFilesOnREST(contentPath)
content$.__enclos_env__$private$addToCollection(private$collection)
}
}
else
{
- stop(paste("Expected AravodsFile or Subcollection object, got", class(content), "."))
+ stop(paste("Expected AravodsFile or Subcollection object, got",
+ class(content), "."))
}
},
if(private$name == "")
stop("Unable to delete root folder.")
- collectionList <- paste0(self$getRelativePath(), "/", self$getFileList(fullpath = FALSE))
+ collectionList <- paste0(self$getRelativePath(),
+ "/", self$getFileList(fullpath = FALSE))
sapply(collectionList, function(file)
{
private$collection$.__enclos_env__$private$deleteFromREST(file)
getSizeInBytes = function()
{
- collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid))
+ collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(),
+ "c=", private$collection$uuid))
subcollectionURL <- paste0(collectionURL, "/", self$getRelativePath(), "/");
headers = list("Authorization" = paste("OAuth2", private$collection$api$getToken()))
relativePath <- c(private$name)
parent <- private$parent
- #Recurse back to root
while(!is.null(parent))
{
relativePath <- c(parent$getName(), relativePath)
if(endsWith(newLocation, paste0(private$name, "/")))
{
- newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
+ newLocation <- substr(newLocation, 0,
+ nchar(newLocation) - nchar(paste0(private$name, "/")))
}
else if(endsWith(newLocation, private$name))
{
- newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(private$name))
+ newLocation <- substr(newLocation, 0,
+ nchar(newLocation) - nchar(private$name))
}
else
{
stop("Unable to get destination subcollection.")
}
- status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(), paste0(newParent$getRelativePath(), "/", self$getName()))
+ status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
+ paste0(newParent$getRelativePath(), "/", self$getName()))
private$attachToParent(newParent)