# Generated by roxygen2: do not edit by hand
export(Arvados)
-export(Collection)
+exportClasses(Collection)
"Arvados",
fields = list(
- token = "ANY",
- host = "ANY"
+
+ getToken = "function",
+ getHostName = "function",
+
+ #Todo(Fudo): These are hardcoded and for debug only. Remove them later on.
+ getWebDavToken = "function",
+ getWebDavHostName = "function",
+
+ collection_get = "function",
+ collection_list = "function",
+ collection_create = "function",
+ collection_update = "function",
+ collection_delete = "function"
),
methods = list(
initialize = function(auth_token = NULL, host_name = NULL)
{
- version <- "v1"
- #Todo(Fudo): Set environment variables
- token <<- auth_token
- host <<- paste0("https://", host_name, "/arvados/", version, "/")
- }
- )
-)
+ # Private state
+ if(!is.null(host_name))
+ Sys.setenv(ARVADOS_API_HOST = host_name)
-#' collection_get
-#'
-#' Get Arvados collection
-#'
-#' @name collection_get
-#' @field uuid UUID of the given collection
-#' @examples arv = Arvados("token", "hostName")
-#' @examples arv$collection_get("uuid")
-Arvados$methods(
-
- collection_get = function(uuid)
- {
- collection_relative_url <- paste0("collections/", uuid)
- http_request <- HttpRequest("GET", token, host, collection_relative_url)
- server_response <- http_request$execute()
-
- httpParser <- HttpParser()
- collection <- httpParser$parseCollectionGet(server_response)
+ if(!is.null(auth_token))
+ Sys.setenv(ARVADOS_API_TOKEN = auth_token)
- if(!is.null(collection$errors))
- stop(collection$errors)
+ host <- Sys.getenv("ARVADOS_API_HOST");
+ token <- Sys.getenv("ARVADOS_API_TOKEN");
- class(collection) <- "ArvadosCollection"
+ if(host == "" | token == "")
+ stop("Please provide host name and authentification token or set ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
- return(collection)
- }
-)
-
-#' collection_list
-#'
-#' Retreive list of collections based on provided filter.
-#'
-#' @name collection_list
-#' @field filters List of filters we want to use to retreive list of collections.
-#' @field limit Limits the number of result returned by server.
-#' @field offset Offset from beginning of the result set.
-#' @examples arv = Arvados("token", "hostName")
-#' @examples arv$collection_list(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"))
-Arvados$methods(
+ version <- "v1"
+ host <- paste0("https://", host, "/arvados/", version, "/")
- collection_list = function(filters = NULL, limit = NULL, offset = NULL)
- {
- #Todo(Fudo): Implement limit and offset
- collection_relative_url <- "collections"
- http_request <- HttpRequest("GET", token, host, collection_relative_url,
- body = NULL, filters, limit, offset)
+ # Public methods
+ getToken <<- function() { token }
+ getHostName <<- function() { host }
- server_response <- http_request$execute()
+ #Todo(Fudo): Hardcoded credentials to WebDAV server. Remove them later
+ getWebDavToken <<- function() { "4invqy35tf70t7hmvdc83ges8ug9cklhgqq1l8gj2cjn18teuq" }
+ getWebDavHostName <<- function() { "https://collections.4xphq.arvadosapi.com/c=4xphq-4zz18-9d5b0qm4fgijeyi/_/" }
- httpParser <- HttpParser()
- collection <- httpParser$parseCollectionGet(server_response)
+ collection_get <<- function(uuid)
+ {
+ collection_url <- paste0(host, "collections/", uuid)
+ headers <- list(Authorization = paste("OAuth2", token))
- if(!is.null(collection$errors))
- stop(collection$errors)
+ http <- HttpRequest()
+ serverResponse <- http$GET(collection_url, headers)
- class(collection) <- "ArvadosCollectionList"
+ httpParser <- HttpParser()
+ collection <- httpParser$parseJSONResponse(serverResponse)
- return(collection)
- }
-)
+ if(!is.null(collection$errors))
+ stop(collection$errors)
-#' collection_create
-#'
-#' Create Arvados collection
-#'
-#' @name collection_create
-#' @field body Structure of the collection we want to create.
-#' @examples arv = Arvados("token", "hostName")
-#' @examples arv$collection_create(list(collection = list(name = "myCollection")))
-Arvados$methods(
+ collection
+ }
- collection_create = function(body)
- {
- collection_relative_url <- paste0("collections/", "/?alt=json")
- body = jsonlite::toJSON(body, auto_unbox = T)
+ collection_list <<- function(filters = NULL, limit = 100, offset = 0)
+ {
+ collection_url <- paste0(host, "collections")
+ headers <- list(Authorization = paste("OAuth2", token))
- http_request <- HttpRequest("POST", token, host, collection_relative_url, body)
- server_response <- http_request$execute()
+ http <- HttpRequest()
+ serverResponse <- http$GET(collection_url, headers, NULL, filters, limit, offset)
- httpParser <- HttpParser()
- collection <- httpParser$parseCollectionGet(server_response)
+ httpParser <- HttpParser()
+ collection <- httpParser$parseJSONResponse(serverResponse)
- if(!is.null(collection$errors))
- stop(collection$errors)
+ if(!is.null(collection$errors))
+ stop(collection$errors)
- class(collection) <- "ArvadosCollection"
+ collection
+ }
- return(collection)
- }
-)
+ collection_delete <<- function(uuid)
+ {
+ collection_url <- paste0(host, "collections/", uuid)
+ headers <- list("Authorization" = paste("OAuth2", token),
+ "Content-Type" = "application/json")
-#' collection_delete
-#'
-#' Delete Arvados collection
-#'
-#' @name collection_delete
-#' @field uuid UUID of the collection we want to delete.
-#' @examples arv = Arvados("token", "hostName")
-#' @examples arv$collection_delete(uuid = "aaaaa-bbbbb-ccccccccccccccc")
-Arvados$methods(
+ http <- HttpRequest()
+ serverResponse <- http$DELETE(collection_url, headers)
- collection_delete = function(uuid)
- {
- collection_relative_url <- paste0("collections/", uuid, "/?alt=json")
+ httpParser <- HttpParser()
+ collection <- httpParser$parseJSONResponse(serverResponse)
- http_request <- HttpRequest("DELETE", token, host, collection_relative_url)
- server_response <- http_request$execute()
+ if(!is.null(collection$errors))
+ stop(collection$errors)
- httpParser <- HttpParser()
- collection <- httpParser$parseCollectionGet(server_response)
+ collection
+ }
- if(!is.null(collection$errors))
- stop(collection$errors)
+ collection_update <<- function(uuid, body)
+ {
+ collection_url <- paste0(host, "collections/", uuid)
+ headers <- list("Authorization" = paste("OAuth2", token),
+ "Content-Type" = "application/json")
+ body <- jsonlite::toJSON(body, auto_unbox = T)
- class(collection) <- "ArvadosCollection"
+ http <- HttpRequest()
+ serverResponse <- http$PUT(collection_url, headers, body)
- return(collection)
- }
-)
+ httpParser <- HttpParser()
+ collection <- httpParser$parseJSONResponse(serverResponse)
-#' collection_update
-#'
-#' Update Arvados collection
-#'
-#' @name collection_update
-#' @field uuid UUID of the collection we want to update.
-#' @field body New structure of the collection.
-#' @examples arv = Arvados("token", "hostName")
-#' @examples arv$collection_update(uuid = "aaaaa-bbbbb-ccccccccccccccc", list(collection = list(name = "newName")))
-Arvados$methods(
+ if(!is.null(collection$errors))
+ stop(collection$errors)
- collection_update = function(uuid, body)
- {
- collection_relative_url <- paste0("collections/", uuid, "/?alt=json")
- body = jsonlite::toJSON(body, auto_unbox = T)
+ collection
+ }
- http_request <- HttpRequest("PUT", token, host, collection_relative_url, body)
- server_response <- http_request$execute()
+ collection_create <<- function(body)
+ {
+ collection_url <- paste0(host, "collections")
+ headers <- list("Authorization" = paste("OAuth2", token),
+ "Content-Type" = "application/json")
+ body <- jsonlite::toJSON(body, auto_unbox = T)
- httpParser <- HttpParser()
- collection <- httpParser$parseCollectionGet(server_response)
+ http <- HttpRequest()
+ serverResponse <- http$POST(collection_url, headers, body)
- if(!is.null(collection$errors))
- stop(collection$errors)
+ httpParser <- HttpParser()
+ collection <- httpParser$parseJSONResponse(serverResponse)
- class(collection) <- "ArvadosCollection"
+ if(!is.null(collection$errors))
+ stop(collection$errors)
- return(collection)
- }
+ collection
+ }
+ }
+ )
)
"Collection",
- #NOTE(Fudo): Fix types!
fields = list(uuid = "ANY",
items = "ANY",
etag = "ANY",
file_names = "ANY",
trash_at = "ANY",
is_trashed = "ANY",
- arvados_api = "Arvados"
+
+ getCollectionContent = "function"
),
methods = list(
initialize = function(api, uuid)
{
- arvados_api <<- api
- result <- arvados_api$collection_get(uuid)
+
+ result <- api$collection_get(uuid)
+ # Private members
uuid <<- result$uuid
etag <<- result$etag
owner_uuid <<- result$owner_uuid
trash_at <<- result$trash_at
is_trashed <<- result$is_trashed
- items <<- getCollectionContent()
- },
- getCollectionContent = function()
- {
- #IMPORTANT(Fudo): This url is hardcoded for now. Fix it later.
- uri <- URLencode("https://collections.4xphq.arvadosapi.com/c=4xphq-4zz18-9d5b0qm4fgijeyi/_/")
+ #Public methods
- # fetch directory listing via curl and parse XML response
- h <- curl::new_handle()
- curl::handle_setopt(h, customrequest = "PROPFIND")
+ # Private methods
+ getCollectionContent <<- function()
+ {
+ #TODO(Fudo): Use proper URL here.
+ uri <- URLencode(api$getWebDavHostName())
- #IMPORTANT(Fudo): Token is hardcoded as well. Write it properly.
- curl::handle_setheaders(h, "Authorization" = paste("OAuth2 4invqy35tf70t7hmvdc83ges8ug9cklhgqq1l8gj2cjn18teuq"))
- response <- curl::curl_fetch_memory(uri, h)
+ # fetch directory listing via curl and parse XML response
+ h <- curl::new_handle()
+ curl::handle_setopt(h, customrequest = "PROPFIND")
- HttpParser()$parseWebDAVResponse(response, uri)
+ #TODO(Fudo): Use proper token here.
+ curl::handle_setheaders(h, "Authorization" = paste("OAuth2", api$getWebDavToken()))
+ response <- curl::curl_fetch_memory(uri, h)
+
+ HttpParser()$parseWebDAVResponse(response, uri)
+ }
+
+ items <<- getCollectionContent()
}
)
)
#Todo(Fudo): Create new Collection object and populate it
},
+ parseJSONResponse = function(server_response)
+ {
+ parsed_response <- httr::content(server_response, as = "parsed", type = "application/json")
+
+ #Todo(Fudo): Create new Collection object and populate it
+ },
+
parseWebDAVResponse = function(response, uri)
{
#Todo(Fudo): Move this to HttpParser.
base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
result <- unlist(
XML::xpathApply(doc, "//D:response/D:href", function(node) {
- sub(base, "", URLdecode(xmlValue(node)), fixed=TRUE)
+ sub(base, "", URLdecode(XML::xmlValue(node)), fixed=TRUE)
})
)
result[result != ""]
"HttrRequest",
fields = list(
- send_method = "character",
- server_base_url = "character",
- server_relative_url = "character",
- auth_token = "character",
- allowed_methods = "list",
- request_body = "ANY",
- query_filters = "ANY",
- response_limit = "ANY",
- query_offset = "ANY"
+
+ GET = "function",
+ PUT = "function",
+ POST = "function",
+ DELETE = "function"
),
methods = list(
- initialize = function(method,
- token,
- base_url,
- relative_url,
- body = NULL,
- filters = NULL,
- limit = 100,
- offset = 0)
- {
- send_method <<- method
- auth_token <<- token
- server_base_url <<- base_url
- server_relative_url <<- relative_url
- request_body <<- body
- query_filters <<- filters
- response_limit <<- limit
- query_offset <<- offset
- },
-
- execute = function()
+ initialize = function()
{
- #Todo(Fudo): Get rid of the switch and make this module more general.
- http_method <- switch(send_method,
- "GET" = .self$getRequest,
- "POST" = .self$postRequest,
- "PUT" = .self$putRequest,
- "DELETE" = .self$deleteRequest,
- "PATCH" = .self$pathcRequest)
- http_method()
- },
-
- getRequest = function()
- {
- requestHeaders <- httr::add_headers(Authorization = .self$getAuthHeader())
- requestQuery <- .self$generateQuery()
- url <- paste0(server_base_url, server_relative_url, requestQuery)
-
- server_data <- httr::GET(url = url,
- config = requestHeaders)
- },
+ # Public methods
+ GET <<- function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = 100, offset = 0)
+ {
+ print(limit)
+ headers <- httr::add_headers(unlist(headers))
+ query <- .createQuery(queryFilters, limit, offset)
+ url <- paste0(url, query)
+ print(url)
- #Todo(Fudo): Try to make this more generic
- postRequest = function()
- {
- url <- paste0(server_base_url, server_relative_url)
- requestHeaders <- httr::add_headers("Authorization" = .self$getAuthHeader(),
- "Content-Type" = "application/json")
- response <- POST(url, body = request_body, config = requestHeaders)
- },
+ serverResponse <- httr::GET(url = url, config = headers)
+ }
- putRequest = function()
- {
- url <- paste0(server_base_url, server_relative_url)
- requestHeaders <- httr::add_headers("Authorization" = .self$getAuthHeader(),
- "Content-Type" = "application/json")
+ PUT <<- function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = 100, offset = 0)
+ {
+ headers <- httr::add_headers(unlist(headers))
+ query <- .createQuery(queryFilters, limit, offset)
+ url <- paste0(url, query)
- response <- PUT(url, body = request_body, config = requestHeaders)
- },
+ serverResponse <- httr::PUT(url = url, config = headers, body = body)
+ }
- deleteRequest = function()
- {
- url <- paste0(server_base_url, server_relative_url)
- requestHeaders <- httr::add_headers("Authorization" = .self$getAuthHeader(),
- "Content-Type" = "application/json")
- response <- DELETE(url, config = requestHeaders)
- },
+ POST <<- function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = 100, offset = 0)
+ {
+ headers <- httr::add_headers(unlist(headers))
+ query <- .createQuery(queryFilters, limit, offset)
+ url <- paste0(url, query)
- pathcRequest = function()
- {
- #Todo(Fudo): Implement this later on.
- print("PATCH method")
- },
+ serverResponse <- httr::POST(url = url, config = headers, body = body)
+ }
- getAuthHeader = function()
- {
- auth_method <- "OAuth2"
- auth_header <- paste(auth_method, auth_token)
- },
+ DELETE <<- function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = 100, offset = 0)
+ {
+ headers <- httr::add_headers(unlist(headers))
+ query <- .createQuery(queryFilters, limit, offset)
+ url <- paste0(url, query)
- generateQuery = function()
- {
- #Todo(Fudo): This function is a mess, refactor it
- finalQuery <- "?alt=json"
+ serverResponse <- httr::DELETE(url = url, config = headers)
+ }
- if(!is.null(query_filters))
+ # Private methods
+ .createQuery <- function(filters, limit, offset)
{
- filters <- sapply(query_filters, function(filter)
+ finalQuery <- "?alt=json"
+
+ if(!is.null(filters))
{
- if(length(filter) != 3)
- stop("Filter list must have exacthey 3 elements.")
+ filters <- sapply(filters, function(filter)
+ {
+ if(length(filter) != 3)
+ stop("Filter list must have exacthey 3 elements.")
- attributeAndOperator = filter[c(1, 2)]
- filterList = filter[[3]]
- filterListIsPrimitive = TRUE
- if(length(filterList) > 1)
- filterListIsPrimitive = FALSE
+ attributeAndOperator = filter[c(1, 2)]
+ filterList = filter[[3]]
+ filterListIsPrimitive = TRUE
+ if(length(filterList) > 1)
+ filterListIsPrimitive = FALSE
- attributeAndOperator <- sapply(attributeAndOperator, function(component) {
- component <- paste0("\"", component, "\"")
- })
+ attributeAndOperator <- sapply(attributeAndOperator, function(component) {
+ component <- paste0("\"", component, "\"")
+ })
- filterList <- sapply(unlist(filterList), function(filter) {
- filter <- paste0("\"", filter, "\"")
- })
+ filterList <- sapply(unlist(filterList), function(filter) {
+ filter <- paste0("\"", filter, "\"")
+ })
- filterList <- paste(filterList, collapse = ",+")
+ filterList <- paste(filterList, collapse = ",+")
- if(!filterListIsPrimitive)
- filterList <- paste0("[", filterList, "]")
+ if(!filterListIsPrimitive)
+ filterList <- paste0("[", filterList, "]")
- filter <- c(attributeAndOperator, filterList)
+ filter <- c(attributeAndOperator, filterList)
- queryParameter <- paste(filter, collapse = ",+")
- queryParameter <- paste0("[", queryParameter, "]")
-
- })
+ queryParameter <- paste(filter, collapse = ",+")
+ queryParameter <- paste0("[", queryParameter, "]")
+
+ })
- filters <- paste(filters, collapse = ",+")
- filters <- paste0("[", filters, "]")
+ filters <- paste(filters, collapse = ",+")
+ filters <- paste0("[", filters, "]")
- encodedQuery <- URLencode(filters, reserved = T, repeated = T)
+ encodedQuery <- URLencode(filters, reserved = T, repeated = T)
- finalQuery <- paste0(finalQuery, "&filters=", encodedQuery)
+ finalQuery <- paste0(finalQuery, "&filters=", encodedQuery)
- #Todo(Fudo): This is a hack for now. Find a proper solution.
- finalQuery <- stringr::str_replace_all(finalQuery, "%2B", "+")
- }
+ #Todo(Fudo): This is a hack for now. Find a proper solution.
+ finalQuery <- stringr::str_replace_all(finalQuery, "%2B", "+")
+ }
- if(!is.null(response_limit))
- {
- if(!is.numeric(response_limit))
- stop("Limit must be a numeric type.")
-
- finalQuery <- paste0(finalQuery, "&limit=", response_limit)
- }
+ if(!is.null(limit))
+ {
+ if(!is.numeric(limit))
+ stop("Limit must be a numeric type.")
+
+ finalQuery <- paste0(finalQuery, "&limit=", limit)
+ }
- if(!is.null(query_offset))
- {
- if(!is.numeric(query_offset))
- stop("Offset must be a numeric type.")
-
- finalQuery <- paste0(finalQuery, "&offset=", query_offset)
- }
+ if(!is.null(offset))
+ {
+ if(!is.numeric(offset))
+ stop("Offset must be a numeric type.")
+
+ finalQuery <- paste0(finalQuery, "&offset=", offset)
+ }
- finalQuery
+ finalQuery
+ }
}
)
)
-#Study(Fudo): For some reason this doesnt seem to work,
-#see what seems to be a problem.
-
-setOldClass("characterOrNULL")
-setClassUnion("characterOrNULL", c("character", "NULL"))
-
-setClassUnion("listOrNULL", c("list", "NULL"))
-setOldClass("listOrNULL")
-
-setOldClass("numericOrNULL")
-setClassUnion("numericOrNULL", c("numeric", "NULL"))
+setClassUnion("characterOrNull", c("character", "NULL"))
+setClassUnion("listOrNull", c("list", "NULL"))
+setClassUnion("numericOrNull", c("numeric", "NULL"))
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/arvados_objects.R
-\name{Collection}
+% Please edit documentation in R/Collection.R
+\docType{class}
+\name{Collection-class}
+\alias{Collection-class}
\alias{Collection}
\title{Collection Object}
-\usage{
-Collection(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)
-}
\arguments{
\item{uuid}{Object ID}
\item{is_trashed}{No description}
}
-\value{
-Collection object
-}
\description{
Collection Object
}
Todo: Update description
Collection
}
-\concept{Collection functions}
+
+++ /dev/null
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{collection_create}
-\alias{collection_create}
-\title{collection_create}
-\description{
-Create Arvados collection
-}
-\section{Fields}{
-
-\describe{
-\item{\code{body}}{Structure of the collection we want to create.}
-}}
-
-\examples{
-arv = Arvados("token", "host_name")
-arv$collection_create(list(collection = list(name = "myCollection")))
-}
+++ /dev/null
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{collection_delete}
-\alias{collection_delete}
-\title{collection_delete}
-\description{
-Delete Arvados collection
-
-Delete Arvados collection
-}
-\section{Fields}{
-
-\describe{
-\item{\code{uuid}}{UUID of the collection we want to delete.}
-
-\item{\code{uuid}}{UUID of the collection we want to delete.}
-}}
-
-\examples{
-arv = Arvados("token", "host_name")
-arv$collection_delete(uuid = "aaaaa-bbbbb-ccccccccccccccc")
-arv = Arvados("token", "host_name")
-arv$collection_delete(uuid = "aaaaa-bbbbb-ccccccccccccccc")
-}
+++ /dev/null
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{collection_get}
-\alias{collection_get}
-\title{collection_get}
-\description{
-Get Arvados collection
-}
-\section{Fields}{
-
-\describe{
-\item{\code{uuid}}{UUID of the given collection}
-}}
-
-\examples{
-arv = Arvados("token", "host_name")
-arv$collection_get("uuid")
-}
+++ /dev/null
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{collection_list}
-\alias{collection_list}
-\title{collection_list}
-\description{
-Retreive list of collections based on provided filter.
-}
-\section{Fields}{
-
-\describe{
-\item{\code{filters}}{List of filters we want to use to retreive list of collections.}
-
-\item{\code{limit}}{Limits the number of result returned by server.}
-
-\item{\code{offset}}{Offset from beginning of the result set.}
-}}
-
-\examples{
-arv = Arvados("token", "host_name")
-arv$collection_list(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"))
-}