# Generated by roxygen2: do not edit by hand
-S3method(print,Arvados)
S3method(print,ArvadosFile)
S3method(print,Collection)
S3method(print,Subcollection)
+export(ApiClient)
+export(ApiClientAuthorization)
+export(ApiClientAuthorizationList)
+export(ApiClientList)
export(Arvados)
export(ArvadosFile)
+export(AuthorizedKey)
+export(AuthorizedKeyList)
export(Collection)
+export(CollectionList)
+export(Container)
+export(ContainerList)
+export(ContainerRequest)
+export(ContainerRequestList)
+export(Group)
+export(GroupList)
+export(Human)
+export(HumanList)
+export(Job)
+export(JobList)
+export(JobTask)
+export(JobTaskList)
+export(KeepDisk)
+export(KeepDiskList)
+export(KeepService)
+export(KeepServiceList)
+export(Link)
+export(LinkList)
+export(Log)
+export(LogList)
+export(Node)
+export(NodeList)
+export(PipelineInstance)
+export(PipelineInstanceList)
+export(PipelineTemplate)
+export(PipelineTemplateList)
+export(Repository)
+export(RepositoryList)
+export(Specimen)
+export(SpecimenList)
export(Subcollection)
+export(Trait)
+export(TraitList)
+export(User)
+export(UserAgreement)
+export(UserAgreementList)
+export(UserList)
+export(VirtualMachine)
+export(VirtualMachineList)
+export(Workflow)
+export(WorkflowList)
+export(generateAPI)
+++ /dev/null
-source("./R/RESTService.R")
-source("./R/HttpRequest.R")
-source("./R/HttpParser.R")
-
-#' Arvados
-#'
-#' Arvados class gives users ability to manipulate collections and projects.
-#'
-#' @section Usage:
-#' \preformatted{arv = Arvados$new(authToken = NULL, hostName = NULL, numRetries = 0)}
-#'
-#' @section Arguments:
-#' \describe{
-#' \item{authToken}{Authentification token. If not specified ARVADOS_API_TOKEN environment variable will be used.}
-#' \item{hostName}{Host name. If not specified ARVADOS_API_HOST environment variable will be used.}
-#' \item{numRetries}{Number which specifies how many times to retry failed service requests.}
-#' }
-#'
-#' @section Methods:
-#' \describe{
-#' \item{getToken()}{Returns authentification token currently in use.}
-#' \item{getHostName()}{Returns host name currently in use.}
-#' \item{getNumRetries()}{Returns number which specifies how many times to retry failed service requests.}
-#' \item{setNumRetries(newNumOfRetries)}{Sets number which specifies how many times to retry failed service requests.}
-#' \item{getCollection(uuid)}{Get collection with specified UUID.}
-#' \item{listCollections(filters = NULL, limit = 100, offset = 0)}{Returns list of collections based on filters parameter.}
-#' \item{listAllCollections(filters = NULL)}{Lists all collections, based on filters parameter, even if the number of items is greater than maximum API limit.}
-#' \item{deleteCollection(uuid)}{Deletes collection with specified UUID.}
-#' \item{updateCollection(uuid, newContent)}{Updates collection with specified UUID.}
-#' \item{createCollection(content)}{Creates new collection.}
-#' \item{getProject(uuid)}{Get project with specified UUID.}
-#' \item{listProjects(filters = NULL, limit = 100, offset = 0)}{Returns list of projects based on filters parameter.}
-#' \item{listAllProjects(filters = NULL)}{Lists all projects, based on filters parameter, even if the number of items is greater than maximum API limit.}
-#' \item{deleteProject(uuid)}{Deletes project with specified UUID.}
-#' \item{updateProject(uuid, newContent)}{Updates project with specified UUID.}
-#' \item{createProject(content)}{Creates new project.}
-#' }
-#'
-#' @name Arvados
-#' @examples
-#' \dontrun{
-#' arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
-#'
-#' collection <- arv$getCollection("uuid")
-#'
-#' collectionList <- arv$listCollections(list(list("name", "like", "Test%")))
-#' collectionList <- arv$listAllCollections(list(list("name", "like", "Test%")))
-#'
-#' deletedCollection <- arv$deleteCollection("uuid")
-#'
-#' updatedCollection <- arv$updateCollection("uuid", list(name = "New name",
-#' description = "New description"))
-#'
-#' createdCollection <- arv$createCollection(list(name = "Example",
-#' description = "This is a test collection"))
-#' }
-NULL
-
-#' @export
-Arvados <- R6::R6Class(
-
- "Arvados",
-
- public = list(
-
- initialize = function(authToken = NULL, hostName = NULL, numRetries = 0)
- {
- if(!is.null(hostName))
- Sys.setenv(ARVADOS_API_HOST = hostName)
-
- if(!is.null(authToken))
- Sys.setenv(ARVADOS_API_TOKEN = authToken)
-
- hostName <- Sys.getenv("ARVADOS_API_HOST");
- token <- Sys.getenv("ARVADOS_API_TOKEN");
-
- if(hostName == "" | token == "")
- stop(paste("Please provide host name and authentification token",
- "or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
- "environment variables."))
-
- private$numRetries <- numRetries
- private$REST <- RESTService$new(token, hostName,
- HttpRequest$new(), HttpParser$new(),
- numRetries)
-
- private$token <- private$REST$token
- private$host <- private$REST$hostName
- },
-
- getToken = function() private$REST$token,
- getHostName = function() private$REST$hostName,
- getWebDavHostName = function() private$REST$getWebDavHostName(),
- getRESTService = function() private$REST,
- setRESTService = function(newRESTService) private$REST <- newRESTService,
-
- getNumRetries = function() private$REST$numRetries,
- setNumRetries = function(newNumOfRetries)
- {
- private$REST$setNumRetries(newNumOfRetries)
- },
-
- getCollection = function(uuid)
- {
- collection <- private$REST$getResource("collections", uuid)
- collection
- },
-
- listCollections = function(filters = NULL, limit = 100, offset = 0)
- {
- if(!is.null(filters))
- names(filters) <- c("collection")
-
- collections <- private$REST$listResources("collections", filters,
- limit, offset)
- collections
- },
-
- listAllCollections = function(filters = NULL)
- {
- if(!is.null(filters))
- names(filters) <- c("collection")
-
- collectionURL <- paste0(private$host, "collections")
- allCollection <- private$REST$fetchAllItems(collectionURL, filters)
- allCollection
- },
-
- deleteCollection = function(uuid)
- {
- removedCollection <- private$REST$deleteResource("collections", uuid)
- removedCollection
- },
-
- updateCollection = function(uuid, newContent)
- {
- body <- list(list())
- names(body) <- c("collection")
- body$collection <- newContent
-
- updatedCollection <- private$REST$updateResource("collections",
- uuid, body)
- updatedCollection
- },
-
- createCollection = function(content)
- {
- body <- list(list())
- names(body) <- c("collection")
- body$collection <- content
-
- newCollection <- private$REST$createResource("collections", body)
- newCollection
- },
-
- getProject = function(uuid)
- {
- project <- private$REST$getResource("groups", uuid)
- project
- },
-
- createProject = function(content)
- {
- body <- list(list())
- names(body) <- c("group")
- body$group <- c("group_class" = "project", content)
-
- newProject <- private$REST$createResource("groups", body)
- newProject
- },
-
- updateProject = function(uuid, newContent)
- {
- body <- list(list())
- names(body) <- c("group")
- body$group <- newContent
-
- updatedProject <- private$REST$updateResource("groups", uuid, body)
- updatedProject
- },
-
- listProjects = function(filters = NULL, limit = 100, offset = 0)
- {
- if(!is.null(filters))
- names(filters) <- c("groups")
-
- filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
- projects <- private$REST$listResources("groups", filters, limit, offset)
- projects
- },
-
- listAllProjects = function(filters = NULL)
- {
- if(!is.null(filters))
- names(filters) <- c("groups")
-
- filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
- projectURL <- paste0(private$host, "groups")
-
- result <- private$REST$fetchAllItems(projectURL, filters)
- result
- },
-
- deleteProject = function(uuid)
- {
- removedProject <- private$REST$deleteResource("groups", uuid)
- removedProject
- }
- ),
-
- private = list(
-
- token = NULL,
- host = NULL,
- REST = NULL,
- numRetries = NULL
- ),
-
- cloneable = FALSE
-)
-
-#' print.Arvados
-#'
-#' Custom print function for Arvados class
-#'
-#' @param x Instance of Arvados class
-#' @param ... Optional arguments.
-#' @export
-print.Arvados = function(x, ...)
-{
- cat(paste0("Type: ", "\"", "Arvados", "\""), sep = "\n")
- cat(paste0("Host: ", "\"", x$getHostName(), "\""), sep = "\n")
- cat(paste0("Token: ", "\"", x$getToken(), "\""), sep = "\n")
-}
public = list(
- api = NULL,
- uuid = NULL,
-
- initialize = function(api, uuid)
+ uuid = NULL,
+ etag = NULL,
+ owner_uuid = NULL,
+ created_at = NULL,
+ modified_by_client_uuid = NULL,
+ modified_by_user_uuid = NULL,
+ modified_at = NULL,
+ portable_data_hash = NULL,
+ replication_desired = NULL,
+ replication_confirmed_at = NULL,
+ replication_confirmed = NULL,
+ updated_at = NULL,
+ manifest_text = NULL,
+ name = NULL,
+ description = NULL,
+ properties = NULL,
+ delete_at = NULL,
+ file_names = NULL,
+ trash_at = NULL,
+ is_trashed = NULL,
+
+ initialize = function(uuid = NULL, etag = NULL, owner_uuid = NULL,
+ created_at = NULL, modified_by_client_uuid = NULL,
+ modified_by_user_uuid = NULL, modified_at = NULL,
+ portable_data_hash = NULL, replication_desired = NULL,
+ replication_confirmed_at = NULL,
+ replication_confirmed = NULL, updated_at = NULL,
+ manifest_text = NULL, name = NULL, description = NULL,
+ properties = NULL, delete_at = NULL, file_names = NULL,
+ trash_at = NULL, is_trashed = NULL)
{
- self$api <- api
- private$REST <- api$getRESTService()
-
- self$uuid <- uuid
-
- private$fileContent <- private$REST$getCollectionContent(uuid)
- private$tree <- CollectionTree$new(private$fileContent, self)
+ self$uuid <- uuid
+ self$etag <- etag
+ self$owner_uuid <- owner_uuid
+ self$created_at <- created_at
+ self$modified_by_client_uuid <- modified_by_client_uuid
+ self$modified_by_user_uuid <- modified_by_user_uuid
+ self$modified_at <- modified_at
+ self$portable_data_hash <- portable_data_hash
+ self$replication_desired <- replication_desired
+ self$replication_confirmed_at <- replication_confirmed_at
+ self$replication_confirmed <- replication_confirmed
+ self$updated_at <- updated_at
+ self$manifest_text <- manifest_text
+ self$name <- name
+ self$description <- description
+ self$properties <- properties
+ self$delete_at <- delete_at
+ self$file_names <- file_names
+ self$trash_at <- trash_at
+ self$is_trashed <- is_trashed
+
+ private$classFields <- c("uuid", "etag", "owner_uuid",
+ "created_at", "modified_by_client_uuid",
+ "modified_by_user_uuid", "modified_at",
+ "portable_data_hash", "replication_desired",
+ "replication_confirmed_at",
+ "replication_confirmed", "updated_at",
+ "manifest_text", "name", "description",
+ "properties", "delete_at", "file_names",
+ "trash_at", "is_trashed")
},
add = function(content, relativePath = "")
{
+ if(is.null(private$tree))
+ private$genereateCollectionTreeStructure()
+
if(relativePath == "" ||
relativePath == "." ||
relativePath == "./")
if("ArvadosFile" %in% class(content) ||
"Subcollection" %in% class(content))
{
-
if(content$getName() == "")
stop("Content has invalid name.")
create = function(fileNames, relativePath = "")
{
+ if(is.null(private$tree))
+ private$genereateCollectionTreeStructure()
+
if(relativePath == "" ||
relativePath == "." ||
relativePath == "./")
remove = function(paths)
{
+ if(is.null(private$tree))
+ private$genereateCollectionTreeStructure()
+
if(is.character(paths))
{
sapply(paths, function(filePath)
move = function(content, newLocation)
{
+ if(is.null(private$tree))
+ private$genereateCollectionTreeStructure()
+
content <- trimFromEnd(content, "/")
elementToMove <- self$get(content)
getFileListing = function()
{
+ if(is.null(private$tree))
+ private$genereateCollectionTreeStructure()
+
content <- private$REST$getCollectionContent(self$uuid)
content[order(tolower(content))]
},
get = function(relativePath)
{
+ if(is.null(private$tree))
+ private$genereateCollectionTreeStructure()
+
private$tree$getElement(relativePath)
},
REST = NULL,
tree = NULL,
- fileContent = NULL
+ fileContent = NULL,
+ classFields = NULL,
+
+ genereateCollectionTreeStructure = function()
+ {
+ if(is.null(self$uuid))
+ stop("Collection uuid is not defined.")
+
+ if(is.null(private$REST))
+ stop("REST service is not defined.")
+
+ private$fileContent <- private$REST$getCollectionContent(self$uuid)
+ private$tree <- CollectionTree$new(private$fileContent, self)
+ }
),
cloneable = FALSE
config = headers, times = retryTimes + 1)
},
+ exec = function(verb, url, headers = NULL, body = NULL, queryParams = NULL,
+ retryTimes = 0)
+ {
+ if(!(verb %in% self$validVerbs))
+ stop("Http verb is not valid.")
+
+ headers <- httr::add_headers(unlist(headers))
+ urlQuery <- self$genQuery(queryParams)
+ url <- paste0(url, urlQuery)
+
+ # times = 1 regular call + numberOfRetries
+ response <- httr::RETRY(verb, url = url, body = body,
+ config = headers, times = retryTimes + 1)
+ },
+
createQuery = function(filters, limit, offset)
{
finalQuery <- NULL
finalQuery <- paste0("/?", finalQuery)
finalQuery
+ },
+
+ genQuery = function(queryParams)
+ {
+ queryParams <- Filter(Negate(is.null), queryParams)
+
+ query <- sapply(queryParams, function(param)
+ {
+ if(is.list(param) || length(param) > 1)
+ param <- RListToPythonList(param, ",")
+
+ URLencode(as.character(param), reserved = T, repeated = T)
+
+ }, USE.NAMES = TRUE)
+
+ if(length(query) > 0)
+ {
+ query <- paste0(names(query), "=", query, collapse = "&")
+
+ return(paste0("/?", query))
+ }
+
+ return("")
}
),
public = list(
- hostName = NULL,
token = NULL,
http = NULL,
httpParser = NULL,
numRetries = NULL,
- initialize = function(token, hostName,
+ initialize = function(token, rawHost,
http, httpParser,
numRetries = 0,
webDavHostName = NULL)
{
- version <- "v1"
+ self$token <- token
+ self$http <- http
+ self$httpParser <- httpParser
+ self$numRetries <- numRetries
- self$token <- token
- self$hostName <- paste0("https://", hostName,
- "/arvados/", version, "/")
- self$http <- http
- self$httpParser <- httpParser
- self$numRetries <- numRetries
-
- private$rawHostName <- hostName
+ private$rawHostName <- rawHost
private$webDavHostName <- webDavHostName
},
private$webDavHostName
},
- getResource = function(resource, uuid)
- {
- resourceURL <- paste0(self$hostName, resource, "/", uuid)
- headers <- list(Authorization = paste("OAuth2", self$token))
-
- serverResponse <- self$http$execute("GET", resourceURL, headers,
- retryTimes = self$numRetries)
-
- resource <- self$httpParser$parseJSONResponse(serverResponse)
-
- if(!is.null(resource$errors))
- stop(resource$errors)
-
- resource
- },
-
- listResources = function(resource, filters = NULL, limit = 100, offset = 0)
- {
- resourceURL <- paste0(self$hostName, resource)
- headers <- list(Authorization = paste("OAuth2", self$token))
- body <- NULL
-
- serverResponse <- self$http$execute("GET", resourceURL, headers, body,
- filters, limit, offset,
- self$numRetries)
-
- resources <- self$httpParser$parseJSONResponse(serverResponse)
-
- if(!is.null(resources$errors))
- stop(resources$errors)
-
- resources
- },
-
+ #Move this to utility
fetchAllItems = function(resourceURL, filters)
{
headers <- list(Authorization = paste("OAuth2", self$token))
items
},
- deleteResource = function(resource, uuid)
- {
- collectionURL <- paste0(self$hostName, resource, "/", uuid)
- headers <- list("Authorization" = paste("OAuth2", self$token),
- "Content-Type" = "application/json")
-
- serverResponse <- self$http$execute("DELETE", collectionURL, headers,
- retryTimes = self$numRetries)
-
- removedResource <- self$httpParser$parseJSONResponse(serverResponse)
-
- if(!is.null(removedResource$errors))
- stop(removedResource$errors)
-
- removedResource
- },
-
- updateResource = function(resource, uuid, newContent)
- {
- resourceURL <- paste0(self$hostName, resource, "/", uuid)
- headers <- list("Authorization" = paste("OAuth2", self$token),
- "Content-Type" = "application/json")
-
- newContent <- jsonlite::toJSON(newContent, auto_unbox = T)
-
- serverResponse <- self$http$execute("PUT", resourceURL, headers, newContent,
- retryTimes = self$numRetries)
-
- updatedResource <- self$httpParser$parseJSONResponse(serverResponse)
-
- if(!is.null(updatedResource$errors))
- stop(updatedResource$errors)
-
- updatedResource
- },
-
- createResource = function(resource, content)
- {
- resourceURL <- paste0(self$hostName, resource)
- headers <- list("Authorization" = paste("OAuth2", self$token),
- "Content-Type" = "application/json")
-
- content <- jsonlite::toJSON(content, auto_unbox = T)
-
- serverResponse <- self$http$execute("POST", resourceURL, headers, content,
- retryTimes = self$numRetries)
-
- newResource <- self$httpParser$parseJSONResponse(serverResponse)
-
- if(!is.null(newResource$errors))
- stop(newResource$errors)
-
- newResource
- },
-
create = function(files, uuid)
{
sapply(files, function(filePath)
--- /dev/null
+#TODO: Some methods do the same thing like collecion.index and collection.list.
+# Make one implementation of the method and make other reference to it.
+
+getAPIDocument <- function(){
+ url <- "https://4xphq.arvadosapi.com/discovery/v1/apis/arvados/v1/rest"
+ serverResponse <- httr::RETRY("GET", url = url)
+
+ httr::content(serverResponse, as = "parsed", type = "application/json")
+}
+
+#' @export
+generateAPI <- function()
+{
+ JSONDocument <- getAPIDocument()
+
+ generateArvadosClasses(JSONDocument)
+ generateArvadosAPIClass(JSONDocument)
+}
+
+generateArvadosAPIClass <- function(discoveryDocument)
+{
+ classMetaData <- discoveryDocument$schemas
+ functionResources <- discoveryDocument$resources
+ resourceNames <- names(functionResources)
+
+ arvadosAPIHeader <- generateAPIClassHeader()
+ arvadosAPIFooter <- generateAPIClassFooter()
+
+ arvadosMethods <- Map(function(resource, resourceName)
+ {
+ methodNames <- names(resource$methods)
+
+ functions <- Map(function(methodMetaData, methodName)
+ {
+ methodName <- paste0(resourceName, ".", methodName)
+ createFunction(methodName, methodMetaData, classMetaData)
+
+ }, resource$methods, methodNames)
+
+ unlist(unname(functions))
+
+ }, functionResources, resourceNames)
+
+ arvadosClass <- c(arvadosAPIHeader, arvadosMethods, arvadosAPIFooter)
+
+ #TODO: Save to a file or load in memory?
+ fileConn <- file("./R/Arvados.R", "w")
+ writeLines(unlist(arvadosClass), fileConn)
+ close(fileConn)
+ NULL
+}
+
+getFunctionName <- function(functionMetaData)
+{
+ stringr::str_replace(functionMetaData$id, "arvados.", "")
+}
+
+#TODO: Make sure that arguments that are required always go first.
+# This is not the case if request$required is false.
+getFunctionArguments <- function(functionMetaData)
+{
+ request <- functionMetaData$request
+ requestArgument <- NULL
+
+ if(!is.null(request))
+ if(request$required)
+ requestArgument <- names(request$properties)[1]
+ else
+ requestArgument <- paste(names(request$properties)[1], "=", "NULL")
+
+ argNames <- names(functionMetaData$parameters)
+
+ args <- sapply(argNames, function(argName)
+ {
+ arg <- functionMetaData$parameters[[argName]]
+
+ if(!arg$required)
+ {
+ if(!is.null(arg$default))
+ return(paste0(argName, " = ", "\"", arg$default, "\""))
+ else
+ return(paste(argName, "=", "NULL"))
+ }
+
+ argName
+ })
+
+ paste0(c(requestArgument, args), collapse = ", ")
+}
+
+getFunctionBody <- function(functionMetaData, classMetaData)
+{
+ url <- getRequestURL(functionMetaData)
+ headers <- getRequestHeaders()
+ requestQueryList <- getRequestQueryList(functionMetaData)
+ requestBody <- getRequestBody(functionMetaData)
+ request <- getRequest(functionMetaData)
+ response <- getResponse(functionMetaData)
+ returnObject <- getReturnObject(functionMetaData, classMetaData)
+
+ body <- c(url, headers, requestQueryList, requestBody, request, response, returnObject)
+ paste0("\t\t\t", body)
+}
+
+getRequestBody <- function(functionMetaData)
+{
+ request <- functionMetaData$request
+
+ if(is.null(request) || !request$required)
+ return("body <- NULL")
+
+ requestParameterName <- names(request$properties)[1]
+ paste0("body <- ", requestParameterName, "$toJSON()")
+}
+
+getRequestHeaders <- function()
+{
+ paste0("headers <- list(Authorization = paste(\"OAuth2\", private$token), ",
+ "\"Content-Type\" = \"application/json\")")
+}
+
+getReturnObject <- function(functionMetaData, classMetaData)
+{
+ returnClass <- functionMetaData$response[["$ref"]]
+ classArguments <- getReturnClassArguments(returnClass, classMetaData)
+
+ if(returnClass == "Collection")
+ return(c(paste0("collection <- ", returnClass, "$new(", classArguments, ")"),
+ "collection$setRESTService(private$REST)",
+ "collection"))
+
+ c(paste0(returnClass, "$new(", classArguments, ")"))
+}
+
+getReturnClassArguments <- function(className, classMetaData)
+{
+ classArguments <- unique(names(classMetaData[[className]]$properties))
+
+ arguments <- sapply(classArguments, function(arg)
+ {
+ paste0(arg, " = resource$", arg)
+ })
+
+ paste0(arguments, collapse = ", ")
+}
+
+getRequest <- function(functionMetaData)
+{
+ method <- functionMetaData$httpMethod
+ paste0("response <- private$REST$http$exec(\"", method, "\", url, headers, body, queryArgs)")
+}
+
+getResponse <- function(functionMetaData)
+{
+ "resource <- private$REST$httpParser$parseJSONResponse(response)"
+}
+
+getRequestURL <- function(functionMetaData)
+{
+ endPoint <- functionMetaData$path
+ endPoint <- stringr::str_replace_all(endPoint, "\\{", "${")
+ url <- c(paste0("endPoint <- stringr::str_interp(\"", endPoint, "\")"),
+ paste0("url <- paste0(private$host, endPoint)"))
+ url
+}
+
+getRequestQueryList <- function(functionMetaData)
+{
+ argNames <- names(functionMetaData$parameters)
+
+ if(length(argNames) == 0)
+ return("queryArgs <- NULL")
+
+ queryListContent <- sapply(argNames, function(arg) paste0(arg, " = ", arg))
+
+ paste0("queryArgs <- list(", paste0(queryListContent, collapse = ', ') , ")")
+}
+
+createFunction <- function(functionName, functionMetaData, classMetaData)
+{
+ args <- getFunctionArguments(functionMetaData)
+ aditionalArgs <-
+ body <- getFunctionBody(functionMetaData, classMetaData)
+
+ functionString <- c(paste0("\t\t", functionName, " = function(", args, ")"),
+ "\t\t{",
+ body,
+ "\t\t},\n")
+
+ functionString
+}
+
+generateAPIClassHeader <- function()
+{
+ c("#' @export",
+ "Arvados <- R6::R6Class(",
+ "",
+ "\t\"Arvados\",",
+ "",
+ "\tpublic = list(",
+ "",
+ "\t\tinitialize = function(authToken = NULL, hostName = NULL, numRetries = 0)",
+ "\t\t{",
+ "\t\t\tif(!is.null(hostName))",
+ "\t\t\t\tSys.setenv(ARVADOS_API_HOST = hostName)",
+ "",
+ "\t\t\tif(!is.null(authToken))",
+ "\t\t\t\tSys.setenv(ARVADOS_API_TOKEN = authToken)",
+ "",
+ "\t\t\thostName <- Sys.getenv(\"ARVADOS_API_HOST\")",
+ "\t\t\ttoken <- Sys.getenv(\"ARVADOS_API_TOKEN\")",
+ "",
+ "\t\t\tif(hostName == \"\" | token == \"\")",
+ "\t\t\t\tstop(paste(\"Please provide host name and authentification token\",",
+ "\t\t\t\t\t\t \"or set ARVADOS_API_HOST and ARVADOS_API_TOKEN\",",
+ "\t\t\t\t\t\t \"environment variables.\"))",
+ "",
+ "\t\t\tprivate$token <- token",
+ "\t\t\tprivate$host <- paste0(\"https://\", hostName, \"/arvados/v1/\")",
+ "\t\t\tprivate$numRetries <- numRetries",
+ "\t\t\tprivate$REST <- RESTService$new(token, hostName,",
+ "\t\t\t HttpRequest$new(), HttpParser$new(),",
+ "\t\t\t numRetries)",
+ "",
+ "\t\t},\n")
+}
+
+generateAPIClassFooter <- function()
+{
+ c("\t\tgetHostName = function() private$host,",
+ "\t\tgetToken = function() private$token,",
+ "\t\tsetRESTService = function(newREST) private$REST <- newREST",
+ "\t),",
+ "",
+ "\tprivate = list(",
+ "",
+ "\t\ttoken = NULL,",
+ "\t\thost = NULL,",
+ "\t\tREST = NULL,",
+ "\t\tnumRetries = NULL",
+ "\t),",
+ "",
+ "\tcloneable = FALSE",
+ ")")
+}
+
+generateArvadosClasses <- function(resources)
+{
+ classes <- sapply(resources$schemas, function(classSchema)
+ {
+ #NOTE: Collection is implemented manually.
+ if(classSchema$id != "Collection")
+ getArvadosClass(classSchema)
+
+ }, USE.NAMES = TRUE)
+
+ unlist(unname(classes))
+
+ fileConn <- file("./R/ArvadosClasses.R", "w")
+ writeLines(unlist(classes), fileConn)
+ close(fileConn)
+ NULL
+}
+
+getArvadosClass <- function(classSchema)
+{
+ name <- classSchema$id
+ fields <- unique(names(classSchema$properties))
+ fieldsList <- paste0("c(", paste0("\"", fields, "\"", collapse = ", "), ")")
+ constructorArgs <- paste0(fields, " = NULL", collapse = ", ")
+
+ classString <- c("#' @export",
+ paste0(name, " <- R6::R6Class("),
+ "",
+ paste0("\t\"", name, "\","),
+ "",
+ "\tpublic = list(",
+ paste0("\t\t", fields, " = NULL,"),
+ "",
+ paste0("\t\tinitialize = function(", constructorArgs, ") {"),
+ paste0("\t\t\tself$", fields, " <- ", fields),
+ "\t\t\t",
+ paste0("\t\t\tprivate$classFields <- ", fieldsList),
+ "\t\t},",
+ "",
+ "\t\ttoJSON = function() {",
+ "\t\t\tfields <- sapply(private$classFields, function(field)",
+ "\t\t\t{",
+ "\t\t\t\tself[[field]]",
+ "\t\t\t}, USE.NAMES = TRUE)",
+ "\t\t\t",
+ paste0("\t\t\tjsonlite::toJSON(list(\"", tolower(name), "\" = Filter(Negate(is.null), fields)), auto_unbox = TRUE)"),
+ "\t\t}",
+ "\t),",
+ "",
+ "\tprivate = list(",
+ "\t\tclassFields = NULL",
+ "\t),",
+ "",
+ "\tcloneable = FALSE",
+ ")",
+ "")
+}
+++ /dev/null
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{Arvados}
-\alias{Arvados}
-\title{Arvados}
-\description{
-Arvados class gives users ability to manipulate collections and projects.
-}
-\section{Usage}{
-
-\preformatted{arv = Arvados$new(authToken = NULL, hostName = NULL, numRetries = 0)}
-}
-
-\section{Arguments}{
-
-\describe{
- \item{authToken}{Authentification token. If not specified ARVADOS_API_TOKEN environment variable will be used.}
- \item{hostName}{Host name. If not specified ARVADOS_API_HOST environment variable will be used.}
- \item{numRetries}{Number which specifies how many times to retry failed service requests.}
-}
-}
-
-\section{Methods}{
-
-\describe{
- \item{getToken()}{Returns authentification token currently in use.}
- \item{getHostName()}{Returns host name currently in use.}
- \item{getNumRetries()}{Returns number which specifies how many times to retry failed service requests.}
- \item{setNumRetries(newNumOfRetries)}{Sets number which specifies how many times to retry failed service requests.}
- \item{getCollection(uuid)}{Get collection with specified UUID.}
- \item{listCollections(filters = NULL, limit = 100, offset = 0)}{Returns list of collections based on filters parameter.}
- \item{listAllCollections(filters = NULL)}{Lists all collections, based on filters parameter, even if the number of items is greater than maximum API limit.}
- \item{deleteCollection(uuid)}{Deletes collection with specified UUID.}
- \item{updateCollection(uuid, newContent)}{Updates collection with specified UUID.}
- \item{createCollection(content)}{Creates new collection.}
- \item{getProject(uuid)}{Get project with specified UUID.}
- \item{listProjects(filters = NULL, limit = 100, offset = 0)}{Returns list of projects based on filters parameter.}
- \item{listAllProjects(filters = NULL)}{Lists all projects, based on filters parameter, even if the number of items is greater than maximum API limit.}
- \item{deleteProject(uuid)}{Deletes project with specified UUID.}
- \item{updateProject(uuid, newContent)}{Updates project with specified UUID.}
- \item{createProject(content)}{Creates new project.}
-}
-}
-
-\examples{
-\dontrun{
-arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
-
-collection <- arv$getCollection("uuid")
-
-collectionList <- arv$listCollections(list(list("name", "like", "Test\%")))
-collectionList <- arv$listAllCollections(list(list("name", "like", "Test\%")))
-
-deletedCollection <- arv$deleteCollection("uuid")
-
-updatedCollection <- arv$updateCollection("uuid", list(name = "New name",
- description = "New description"))
-
-createdCollection <- arv$createCollection(list(name = "Example",
- description = "This is a test collection"))
-}
-}
+++ /dev/null
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{print.Arvados}
-\alias{print.Arvados}
-\title{print.Arvados}
-\usage{
-\method{print}{Arvados}(x, ...)
-}
-\arguments{
-\item{x}{Instance of Arvados class}
-
-\item{...}{Optional arguments.}
-}
-\description{
-Custom print function for Arvados class
-}
+++ /dev/null
-context("Arvados API")
-
-source("fakes/FakeRESTService.R")
-
-test_that("Constructor will use environment variables if no parameters are passed to it", {
-
- Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
- Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
-
- arv <- Arvados$new()
-
- Sys.unsetenv("ARVADOS_API_HOST")
- Sys.unsetenv("ARVADOS_API_TOKEN")
-
- expect_that("https://environment_api_host/arvados/v1/",
- equals(arv$getHostName()))
-
- expect_that("environment_api_token",
- equals(arv$getToken()))
-})
-
-test_that("Constructor preferes constructor fields over environment variables", {
-
- Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
- Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
-
- arv <- Arvados$new("constructor_api_token", "constructor_api_host")
-
- Sys.unsetenv("ARVADOS_API_HOST")
- Sys.unsetenv("ARVADOS_API_TOKEN")
-
- expect_that("https://constructor_api_host/arvados/v1/",
- equals(arv$getHostName()))
-
- expect_that("constructor_api_token",
- equals(arv$getToken()))
-})
-
-test_that("Constructor raises exception if fields and environment variables are not provided", {
-
- expect_that(Arvados$new(),
- throws_error(paste0("Please provide host name and authentification token",
- " or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
- " environment variables.")))
-})
-
-test_that("getCollection delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- arv$getCollection(collectionUUID)
-
- expect_that(fakeREST$getResourceCallCount, equals(1))
-})
-
-test_that("listCollections delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
-
- arv$listCollections()
-
- expect_that(fakeREST$listResourcesCallCount, equals(1))
-})
-
-test_that("listCollections filter paramerter must be named 'collection'", {
-
- filters <- list(list("name", "like", "MyCollection"))
- names(filters) <- c("collection")
- fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$listCollections(list(list("name", "like", "MyCollection")))
-
- expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-})
-
-test_that("listAllCollections delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
-
- arv$listAllCollections()
-
- expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
-})
-
-test_that("listAllCollections filter paramerter must be named 'collection'", {
-
- filters <- list(list("name", "like", "MyCollection"))
- names(filters) <- c("collection")
- fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$listAllCollections(list(list("name", "like", "MyCollection")))
-
- expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-})
-
-test_that("deleteCollection delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- arv$deleteCollection(collectionUUID)
-
- expect_that(fakeREST$deleteResourceCallCount, equals(1))
-})
-
-test_that("updateCollection delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- newCollectionContent <- list(newName = "Brand new shiny name")
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- arv$updateCollection(collectionUUID, newCollectionContent)
-
- expect_that(fakeREST$updateResourceCallCount, equals(1))
-})
-
-test_that("updateCollection adds content to request parameter named 'collection'", {
-
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- body <- list(list())
- names(body) <- c("collection")
- body$collection <- list(name = "MyCollection", desc = "No description")
- fakeREST <- FakeRESTService$new(returnContent = body)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$updateCollection(collectionUUID,
- list(name = "MyCollection", desc = "No description"))
-
- expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-})
-
-test_that("createCollection delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- collectionContent <- list(newName = "Brand new shiny name")
-
- arv$createCollection(collectionContent)
-
- expect_that(fakeREST$createResourceCallCount, equals(1))
-})
-
-test_that("createCollection adds content to request parameter named 'collection'", {
-
- body <- list(list())
- names(body) <- c("collection")
- body$collection <- list(name = "MyCollection", desc = "No description")
- fakeREST <- FakeRESTService$new(returnContent = body)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$createCollection(list(name = "MyCollection", desc = "No description"))
-
- expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-})
-
-test_that("getProject delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- arv$getCollection(projectUUID)
-
- expect_that(fakeREST$getResourceCallCount, equals(1))
-})
-
-test_that("listProjects delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
-
- arv$listCollections()
-
- expect_that(fakeREST$listResourcesCallCount, equals(1))
-})
-
-test_that("listProjects filter contains additional 'group_class' field by default", {
-
- filters <- list(list("name", "like", "MyProject"))
- names(filters) <- c("groups")
- filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
- fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$listProjects(list(list("name", "like", "MyProject")))
-
- expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-})
-
-test_that("listAllProjects delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
-
- arv$listAllProjects()
-
- expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
-})
-
-test_that("listAllProjects filter contains additional 'group_class' field by default", {
-
- filters <- list(list("name", "like", "MyProject"))
- names(filters) <- c("groups")
- filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
- fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$listAllProjects(list(list("name", "like", "MyProject")))
-
- expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-})
-
-test_that("deleteProject delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- arv$deleteCollection(projectUUID)
-
- expect_that(fakeREST$deleteResourceCallCount, equals(1))
-})
-
-test_that("updateProject delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- newProjectContent <- list(newName = "Brand new shiny name")
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- arv$updateCollection(projectUUID, newProjectContent)
-
- expect_that(fakeREST$updateResourceCallCount, equals(1))
-})
-
-test_that("updateProject adds content to request parameter named 'group'", {
-
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- body <- list(list())
- names(body) <- c("group")
- body$group <- list(name = "MyProject", desc = "No description")
-
- fakeREST <- FakeRESTService$new(returnContent = body)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$updateProject(projectUUID,
- list(name = "MyProject", desc = "No description"))
-
- expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-})
-
-test_that("createProject delegates operation to RESTService class", {
-
- arv <- Arvados$new("token", "hostName")
- fakeREST <- FakeRESTService$new()
- arv$setRESTService(fakeREST)
- projectContent <- list(newName = "Brand new shiny name")
-
- arv$createCollection(projectContent)
-
- expect_that(fakeREST$createResourceCallCount, equals(1))
-})
-
-test_that("createProject request body contains 'goup_class' filed", {
-
- body <- list(list())
- names(body) <- c("group")
- body$group <- c("group_class" = "project",
- list(name = "MyProject", desc = "No description"))
-
- fakeREST <- FakeRESTService$new(returnContent = body)
- arv <- Arvados$new("token", "hostName")
- arv$setRESTService(fakeREST)
-
- arv$createProject(list(name = "MyProject", desc = "No description"))
-
- expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-})
returnSize <- 100
fakeREST <- FakeRESTService$new(collectionContent, returnSize)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
resourceSize <- fish$getSizeInBytes()
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
expect_that(fish$read(contentType = "text", offset = -1),
readContent <- "my file"
fakeREST <- FakeRESTService$new(collectionContent, readContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
fileContent <- fish$read("text")
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
connection <- fish$connection("r")
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
connection <- fish$connection("w")
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
connection <- fish$connection("w")
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
fileContent <- fish$write("new file content")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
-
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
dog <- collection$get("animal/dog")
expect_that(dog$move("objects/dog"),
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
dog <- collection$get("animal/dog")
expect_that(dog$move("dog"),
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
dog <- collection$get("animal/dog")
dog$move("dog")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
root <- collection$get("")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
newNumber <- 10
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
newPen <- ArvadosFile$new("pen")
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
rootFolder <- Subcollection$new("")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
newDog <- ArvadosFile$new("dog")
collection$add(newDog, "animal")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
expect_that(collection$create(10),
throws_error("Expected character vector, got (numeric).",
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
newPen <- ArvadosFile$new("pen")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
files <- c("dog", "cat")
collection$create(files, "animal")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
expect_that(collection$remove(10),
throws_error("Expected character vector, got (numeric).",
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
expect_that(collection$remove(""),
throws_error("You can't delete root folder.", fixed = TRUE))
collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/cat", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
collection$remove(c("animal/dog", "animal/cat"))
collectionContent <- c("animal", "animal/dog", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
collection$move("animal/dog", "dog")
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
expect_that(collection$move("fish", "object"),
throws_error("Content you want to move doesn't exist in the collection.",
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
contentMatchExpected <- all(collection$getFileListing() ==
c("animal", "animal/fish", "ball"))
collectionContent <- c("animal", "animal/fish", "ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
fishIsNotNull <- !is.null(fish)
expect_that("https://myWebDavServer.com", equals(REST$getWebDavHostName()))
})
-test_that("getResource calls REST service properly", {
-
- serverResponse <- NULL
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
- REST <- RESTService$new("token", "host",
- httpRequest, FakeHttpParser$new(),
- 0, "webDavHost")
-
- REST$getResource("collections", resourceUUID)
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
-})
-
-test_that("getResource parses server response", {
-
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- httpParser <- FakeHttpParser$new()
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(), httpParser,
- 0, "webDavHost")
-
- REST$getResource("collections", resourceUUID)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("getResource raises exception if response contains errors field", {
-
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- serverResponse <- list(errors = 404)
-
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(NULL, serverResponse),
- FakeHttpParser$new(),
- 0, "webDavHost")
-
- expect_that(REST$getResource("collections", resourceUUID), throws_error("404", fixed = TRUE))
-})
-
-test_that("listResources calls REST service properly", {
-
- serverResponse <- NULL
- expectedURL <- paste0("https://host/arvados/v1/collections")
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
- REST <- RESTService$new("token", "host",
- httpRequest, FakeHttpParser$new(),
- 0, "webDavHost")
-
- REST$listResources("collections")
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
-})
-
-test_that("listResources parses server response", {
-
- httpParser <- FakeHttpParser$new()
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(), httpParser,
- 0, "webDavHost")
-
- REST$listResources("collections")
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("listResources raises exception if response contains errors field", {
-
- serverResponse <- list(errors = 404)
-
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(NULL, serverResponse),
- FakeHttpParser$new(),
- 0, "webDavHost")
-
- expect_that(REST$listResources("collections"), throws_error("404", fixed = TRUE))
-})
-
test_that("fetchAllItems always returns all resource items from server", {
expectedURL <- NULL
expect_that(httpParser$parserCallCount, equals(3))
})
-test_that("deleteResource calls REST service properly", {
-
- serverResponse <- NULL
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
- REST <- RESTService$new("token", "host",
- httpRequest, FakeHttpParser$new(),
- 0, "webDavHost")
-
- REST$deleteResource("collections", resourceUUID)
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfDELETERequests, equals(1))
-})
-
-test_that("deleteCollection parses server response", {
-
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- httpParser <- FakeHttpParser$new()
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(), httpParser,
- 0, "webDavHost")
-
- REST$deleteResource("collections", resourceUUID)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("deleteCollection raises exception if response contains errors field", {
-
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- serverResponse <- list(errors = 404)
-
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(NULL, serverResponse),
- FakeHttpParser$new(),
- 0, "webDavHost")
-
- expect_that(REST$deleteResource("collections", resourceUUID), throws_error("404", fixed = TRUE))
-})
-
-test_that("updateResource calls REST service properly", {
-
- serverResponse <- NULL
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0("https://host/arvados/v1/collections/", resourceUUID)
- newResourceContent <- list(newName = "Brand new shiny name")
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
- REST <- RESTService$new("token", "host",
- httpRequest, FakeHttpParser$new(),
- 0, "webDavHost")
-
- REST$updateResource("collections", resourceUUID, newResourceContent)
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
- expect_that(httpRequest$numberOfPUTRequests, equals(1))
-})
-
-test_that("updateResource parses server response", {
-
- newResourceContent <- list(newName = "Brand new shiny name")
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- httpParser <- FakeHttpParser$new()
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(), httpParser,
- 0, "webDavHost")
-
- REST$updateResource("collections", resourceUUID, newResourceContent)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("updateResource raises exception if response contains errors field", {
-
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- serverResponse <- list(errors = 404)
- newResourceContent <- list(newName = "Brand new shiny name")
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(NULL, serverResponse),
- FakeHttpParser$new(),
- 0, "webDavHost")
-
- expect_that(REST$updateResource("collections", resourceUUID, newResourceContent),
- throws_error("404", fixed = TRUE))
-})
-
-test_that("createResource calls REST service properly", {
-
- resourceContent <- list(name = "My favorite collection")
- serverResponse <- NULL
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- "https://host/arvados/v1/collections"
- newResourceContent <- list(newName = "Brand new shiny name")
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
- REST <- RESTService$new("token", "host",
- httpRequest, FakeHttpParser$new(),
- 0, "webDavHost")
-
- REST$createResource("collections", resourceContent)
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
- expect_that(httpRequest$numberOfPOSTRequests, equals(1))
-})
-
-test_that("createResource parses server response", {
-
- resourceContent <- list(newName = "Brand new shiny name")
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- httpParser <- FakeHttpParser$new()
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(), httpParser,
- 0, "webDavHost")
-
- REST$createResource("collections", resourceContent)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("createResource raises exception if response contains errors field", {
-
- resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- serverResponse <- list(errors = 404)
- resourceContent <- list(newName = "Brand new shiny name")
- REST <- RESTService$new("token", "host",
- FakeHttpRequest$new(NULL, serverResponse),
- FakeHttpParser$new(),
- 0, "webDavHost")
-
- expect_that(REST$createResource("collections", resourceContent),
- throws_error("404", fixed = TRUE))
-})
-
test_that("create calls REST service properly", {
uuid <- "aaaaa-j7d0g-ccccccccccccccc"
collectionContent <- c("animal", "animal/fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
animal <- collection$get("animal")
dog <- ArvadosFile$new("dog")
collectionContent <- c("animal", "animal/fish", "animal/dog")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
animal <- collection$get("animal")
animal$remove("fish")
"fish")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
expect_that(fish$move("fish"),
"ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
-
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
expect_that(fish$move("objects/dog"),
"ball")
fakeREST <- FakeRESTService$new(collectionContent)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
fish <- collection$get("animal/fish")
fish$move("fish")
returnSize <- 100
fakeREST <- FakeRESTService$new(collectionContent, returnSize)
- api <- Arvados$new("myToken", "myHostName")
- api$setRESTService(fakeREST)
- collection <- Collection$new(api, "myUUID")
+ collection <- Collection$new("fakeUUID")
+ collection$setRESTService(fakeREST)
animal <- collection$get("animal")
resourceSize <- animal$getSizeInBytes()