From 5f7cec0ec24c9de5b7e476b0144b39b1c8f59818 Mon Sep 17 00:00:00 2001 From: eblondel Date: Wed, 30 Aug 2023 09:25:22 +0200 Subject: [PATCH] implement #346 --- NAMESPACE | 3 ++ R/geoflow_handler.R | 32 ++++++++++-- R/geoflow_handler_contact.R | 36 ++++++++++++++ R/geoflow_handler_dictionary.R | 36 +++++++++++++- R/geoflow_handler_entity.R | 43 +++++++++++++++- R/initWorkflow.R | 18 +++++-- R/loadMetadataHandler.R | 15 +++--- inst/metadata/contact/contact_handler_csv.R | 4 +- inst/metadata/contact/contact_handler_dbi.R | 4 +- inst/metadata/contact/contact_handler_df.R | 2 +- inst/metadata/contact/contact_handler_excel.R | 4 +- .../metadata/contact/contact_handler_gsheet.R | 4 +- inst/metadata/contact/contact_handler_ocs.R | 6 +-- .../dictionary/dictionary_handler_csv.R | 4 +- .../dictionary/dictionary_handler_dbi.R | 4 +- .../dictionary/dictionary_handler_df.R | 2 +- .../dictionary/dictionary_handler_excel.R | 4 +- .../dictionary/dictionary_handler_gsheet.R | 4 +- .../dictionary/dictionary_handler_ocs.R | 6 +-- inst/metadata/entity/entity_handler_csv.R | 6 +-- inst/metadata/entity/entity_handler_csw.R | 2 +- .../entity/entity_handler_dataverse.R | 2 +- inst/metadata/entity/entity_handler_dbi.R | 6 +-- .../entity_handler_dbi_geometry_columns.R | 2 +- inst/metadata/entity/entity_handler_df.R | 2 +- inst/metadata/entity/entity_handler_excel.R | 4 +- inst/metadata/entity/entity_handler_gsheet.R | 4 +- inst/metadata/entity/entity_handler_ncdf.R | 2 +- inst/metadata/entity/entity_handler_ncml.R | 2 +- inst/metadata/entity/entity_handler_ocs.R | 6 +-- inst/metadata/entity/entity_handler_thredds.R | 2 +- .../entity/entity_handler_thredds_csv.R | 4 +- .../entity/entity_handler_thredds_df.R | 6 +-- .../entity/entity_handler_thredds_excel.R | 4 +- .../entity/entity_handler_thredds_gsheet.R | 4 +- man/geoflow_handler.Rd | 49 +++++++++++++++++-- man/list_contact_handler_options.Rd | 22 +++++++++ man/list_dictionary_handler_options.Rd | 22 +++++++++ man/list_entity_handler_options.Rd | 22 +++++++++ man/loadMetadataHandler.Rd | 3 ++ 40 files changed, 332 insertions(+), 75 deletions(-) create mode 100644 man/list_contact_handler_options.Rd create mode 100644 man/list_dictionary_handler_options.Rd create mode 100644 man/list_entity_handler_options.Rd diff --git a/NAMESPACE b/NAMESPACE index f9514291..7321e690 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -64,9 +64,12 @@ export(initWorkflowJob) export(is_absolute_path) export(list_action_options) export(list_actions) +export(list_contact_handler_options) export(list_contact_handlers) export(list_data_accessors) +export(list_dictionary_handler_options) export(list_dictionary_handlers) +export(list_entity_handler_options) export(list_entity_handlers) export(list_registers) export(list_software) diff --git a/R/geoflow_handler.R b/R/geoflow_handler.R index 6d4365d6..7d165175 100644 --- a/R/geoflow_handler.R +++ b/R/geoflow_handler.R @@ -8,9 +8,10 @@ #' @title Geoflow handler class #' @description This class models a content handler. An handler is a method to handle #' some content (eg entity or contact). It is mainly driven by a function that takes -#' as argument a \code{config} object, as the overall configuration created by geoflow -#' \code{initWorkflow} function, and a source which identifiers the source to be handled, -#' that can be of a different type (eg a URL, a file path) depending on the handler. +#' as argument the \code{handler} considered (as self accessible object), a \code{source} +#' which identifiers the source to be handled, that can be of a different type (eg a URL, a file path) +#' depending on the handler, and a \code{config} object, as the overall configuration created by geoflow +#' \code{initWorkflow} function. #' @keywords handler #' @return Object of \code{\link{R6Class}} for modelling a handler #' @format \code{\link{R6Class}} object. @@ -21,7 +22,8 @@ #' id = "some-id", #' def = "some definition", #' packages = list(), -#' fun = function(config, source){} +#' fun = function(handler, source, config){}, +#' available_options = list() #' ) #' } #' @@ -42,6 +44,10 @@ geoflow_handler <- R6Class("geoflow_handler", fun = NA, #'@field script handler script script = NA, + #'@field options options + options = list(), + #'@field available_options available options + available_options = list(), #'@description Initializes a \link{geoflow_handler} #'@param id id @@ -49,12 +55,17 @@ geoflow_handler <- R6Class("geoflow_handler", #'@param packages list of packages required for the handler #'@param fun the handler \code{function} having 2 arguments \code{config} and \code{source} #'@param script a handler script - initialize = function(id, def = "", packages = list(), fun = NULL, script = NULL){ + #'@param options action options + #'@param available_options available options for the action + initialize = function(id, def = "", packages = list(), fun = NULL, script = NULL, + options = list(), available_options = list()){ self$id <- id self$def <- def self$packages <- packages self$fun <- fun self$script <- script + self$options <- options + self$available_options <- available_options }, #'@description Check that all packages required for the handler are available, if yes, @@ -77,6 +88,17 @@ geoflow_handler <- R6Class("geoflow_handler", print(out_pkgs) } } + }, + + #'@description Get handler option value + #'@param option option id + #'@return the option value, either specified through a workflow, or the default value + getOption = function(option){ + option_value <- self$options[[option]] + if(is.null(option_value)){ + option_value <- self$available_options[[option]]$default + } + return(option_value) } ) ) diff --git a/R/geoflow_handler_contact.R b/R/geoflow_handler_contact.R index e4aab7d3..dec73441 100644 --- a/R/geoflow_handler_contact.R +++ b/R/geoflow_handler_contact.R @@ -77,3 +77,39 @@ list_contact_handlers <- function(raw = FALSE){ } return(handlers) } + +#' @name list_contact_handler_options +#' @aliases list_contact_handler_options +#' @title list_contact_handler_options +#' @description \code{list_contact_handler_options} lists the options available for a given contact handler supported by geoflow. +#' +#' @usage list_contact_handler_options(id, raw) +#' +#' @param id An contact handler identifier +#' @param raw if raw list should be returned +#' +#' @return an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the available handler options. +#' +#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} +#' @export +#' +list_contact_handler_options <- function(id, raw = FALSE){ + out <- NULL + handlers <- list_contact_handlers(raw = TRUE) + handler <- handlers[sapply(handlers, function(x){x$id == id})] + if(length(handler)==0) stop(sprintf("No handler with id '%s'!", id)) + handler <- handler[[1]] + if(raw) return(handler$available_options) + if(length(handler$available_options)>0){ + out <- data.frame( + name = names(handler$available_options), + definition = sapply(handler$available_options, function(x){x$def}), + default = sapply(handler$available_options, function(x){paste0(x$default, collapse=",")}), + stringsAsFactors = FALSE + ) + row.names(out) <- 1:nrow(out) + }else{ + out <- data.frame(name = character(0), definition = character(0)) + } + return(out) +} \ No newline at end of file diff --git a/R/geoflow_handler_dictionary.R b/R/geoflow_handler_dictionary.R index 677bac68..36b8cd70 100644 --- a/R/geoflow_handler_dictionary.R +++ b/R/geoflow_handler_dictionary.R @@ -78,4 +78,38 @@ list_dictionary_handlers <- function(raw = FALSE){ return(handlers) } - +#' @name list_dictionary_handler_options +#' @aliases list_dictionary_handler_options +#' @title list_dictionary_handler_options +#' @description \code{list_dictionary_handler_options} lists the options available for a given dictionary handler supported by geoflow. +#' +#' @usage list_dictionary_handler_options(id, raw) +#' +#' @param id An dictionary handler identifier +#' @param raw if raw list should be returned +#' +#' @return an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the available handler options. +#' +#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} +#' @export +#' +list_dictionary_handler_options <- function(id, raw = FALSE){ + out <- NULL + handlers <- list_dictionary_handlers(raw = TRUE) + handler <- handlers[sapply(handlers, function(x){x$id == id})] + if(length(handler)==0) stop(sprintf("No handler with id '%s'!", id)) + handler <- handler[[1]] + if(raw) return(handler$available_options) + if(length(handler$available_options)>0){ + out <- data.frame( + name = names(handler$available_options), + definition = sapply(handler$available_options, function(x){x$def}), + default = sapply(handler$available_options, function(x){paste0(x$default, collapse=",")}), + stringsAsFactors = FALSE + ) + row.names(out) <- 1:nrow(out) + }else{ + out <- data.frame(name = character(0), definition = character(0)) + } + return(out) +} diff --git a/R/geoflow_handler_entity.R b/R/geoflow_handler_entity.R index e1f5974e..81649970 100644 --- a/R/geoflow_handler_entity.R +++ b/R/geoflow_handler_entity.R @@ -15,7 +15,10 @@ register_entity_handlers <- function(){ geoflow_handler$new( id = "csv", def = "Handle metadata entities from a CSV file", - fun = source(system.file("metadata/entity", "entity_handler_csv.R", package = "geoflow"))$value + fun = source(system.file("metadata/entity", "entity_handler_csv.R", package = "geoflow"))$value, + available_options = list( + guess_max = list(def = "Guess max argument, see readr::read_csv", default = 0) + ) ), geoflow_handler$new( id = "excel", @@ -123,4 +126,40 @@ list_entity_handlers <- function(raw = FALSE){ })) } return(handlers) -} \ No newline at end of file +} + +#' @name list_entity_handler_options +#' @aliases list_entity_handler_options +#' @title list_entity_handler_options +#' @description \code{list_entity_handler_options} lists the options available for a given entity handler supported by geoflow. +#' +#' @usage list_entity_handler_options(id, raw) +#' +#' @param id An entity handler identifier +#' @param raw if raw list should be returned +#' +#' @return an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the available handler options. +#' +#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} +#' @export +#' +list_entity_handler_options <- function(id, raw = FALSE){ + out <- NULL + handlers <- list_entity_handlers(raw = TRUE) + handler <- handlers[sapply(handlers, function(x){x$id == id})] + if(length(handler)==0) stop(sprintf("No handler with id '%s'!", id)) + handler <- handler[[1]] + if(raw) return(handler$available_options) + if(length(handler$available_options)>0){ + out <- data.frame( + name = names(handler$available_options), + definition = sapply(handler$available_options, function(x){x$def}), + default = sapply(handler$available_options, function(x){paste0(x$default, collapse=",")}), + stringsAsFactors = FALSE + ) + row.names(out) <- 1:nrow(out) + }else{ + out <- data.frame(name = character(0), definition = character(0)) + } + return(out) +} diff --git a/R/initWorkflow.R b/R/initWorkflow.R index 6ca094f0..5ebc2d85 100644 --- a/R/initWorkflow.R +++ b/R/initWorkflow.R @@ -277,7 +277,11 @@ initWorkflow <- function(file, dir = ".", jobDirPath = NULL, handleMetadata = TR md_dict_handler <- loadMetadataHandler(config, x, type = "dictionary") config$logger.info("Execute handler to load dictionary data structures...") - dict <- md_dict_handler(config, source = x$source) + dict <- md_dict_handler$fun( + handler = md_dict_handler, + source = x$source, + config = config + ) if(!is(dict, "geoflow_dictionary")){ errMsg <- "The output of the dictionary handler should return an object of class 'geoflow_dictionary'" @@ -392,7 +396,11 @@ initWorkflow <- function(file, dir = ".", jobDirPath = NULL, handleMetadata = TR x$source, x$handler)) md_contact_handler <- loadMetadataHandler(config, x, type = "contacts") config$logger.info("Execute contact handler to load contacts...") - contacts <- md_contact_handler(config, source = x$source) + contacts <- md_contact_handler$fun( + handler = md_contact_handler, + source = x$source, + config = config + ) if(!is(contacts, "list") | !all(sapply(contacts, is, "geoflow_contact"))){ errMsg <- "The output of the contacts handler should return a list of objects of class 'geoflow_entity_contact'" @@ -427,7 +435,11 @@ initWorkflow <- function(file, dir = ".", jobDirPath = NULL, handleMetadata = TR x$source, x$handler)) md_entity_handler <- loadMetadataHandler(config, x, type = "entities") config$logger.info("Execute handler to load entities...") - entities <- md_entity_handler(config, source = x$source) + entities <- md_entity_handler$fun( + handler = md_entity_handler, + source = x$source, + config = config + ) if(!is(entities, "list") | !all(sapply(entities, is, "geoflow_entity"))){ errMsg <- "The output of the entities handler should return a list of objects of class 'geoflow_entity'" diff --git a/R/loadMetadataHandler.R b/R/loadMetadataHandler.R index 096ad4b3..5bc1fe6c 100644 --- a/R/loadMetadataHandler.R +++ b/R/loadMetadataHandler.R @@ -8,6 +8,7 @@ #' @param config a geoflow configuration (as list). Only used to write logs, can be NULL. #' @param element a geoflow configuration metadata list element #' @param type either 'contacts', 'entities' or 'dictionnary' +#' @return an object of class \link{geoflow_handler} #' #' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com} #' @export @@ -42,7 +43,8 @@ loadMetadataHandler <- function(config, element, type){ errMsg <- sprintf("Missing 'source' for handler '%s'", h) } - md_handler <- md_default_handlers[sapply(md_default_handlers, function(x){x$id==h})][[1]]$fun + md_handler <- md_default_handlers[sapply(md_default_handlers, function(x){x$id==h})][[1]] + md_handler$options = element$options }else{ #in case handler is a script @@ -55,20 +57,21 @@ loadMetadataHandler <- function(config, element, type){ stop(errMsg) } source(h_script) #load script - md_handler <- try(eval(parse(text = h))) - if(is(md_handler,"try-error")){ + md_handler_fun <- try(eval(parse(text = h))) + if(is(md_handler_fun,"try-error")){ errMsg <- sprintf("Failed loading function '%s. Please check the script '%s'", h, h_script) if(!is.null(config)) config$logger.error(errMsg) stop(errMsg) } #check custom handler arguments - args <- names(formals(md_handler)) - if(!all(c("config", "source") %in% args)){ - errMsg <- "The handler function should at least include the parameters (arguments) 'config' and 'source'" + args <- names(formals(md_handler_fun)) + if(!all(c("handler", "source", "config") %in% args)){ + errMsg <- "The handler function should at least include the parameters (arguments) 'handler', 'source' and 'config'" if(!is.null(config)) config$logger.error(errMsg) stop(errMsg) } + md_handler = geoflow_handler$new(id = h, fun = md_handler_fun, options = element$options) } return(md_handler) } \ No newline at end of file diff --git a/inst/metadata/contact/contact_handler_csv.R b/inst/metadata/contact/contact_handler_csv.R index 70581763..6338ddfd 100644 --- a/inst/metadata/contact/contact_handler_csv.R +++ b/inst/metadata/contact/contact_handler_csv.R @@ -1,5 +1,5 @@ #handle_contacts_csv -handle_contacts_csv <- function(config, source, handle = TRUE){ +handle_contacts_csv <- function(handler, source, config, handle = TRUE){ #read csv TODO -> options management: sep, encoding etc #source <- read.csv(source) @@ -8,6 +8,6 @@ handle_contacts_csv <- function(config, source, handle = TRUE){ #apply generic handler handle_contacts_df <- source(system.file("metadata/contact", "contact_handler_df.R", package = "geoflow"))$value - contacts <- handle_contacts_df(config, source) + contacts <- handle_contacts_df(handler, source, config) return(contacts) } \ No newline at end of file diff --git a/inst/metadata/contact/contact_handler_dbi.R b/inst/metadata/contact/contact_handler_dbi.R index 717b22be..d8af68e5 100644 --- a/inst/metadata/contact/contact_handler_dbi.R +++ b/inst/metadata/contact/contact_handler_dbi.R @@ -1,5 +1,5 @@ #handle_contacts_dbi -handle_contacts_dbi <- function(config, source, handle = TRUE){ +handle_contacts_dbi <- function(handler, source, config, handle = TRUE){ dbi <- config$software$input$dbi if(is.null(dbi)){ stop("There is no database input software configured to handle contacts from DB") @@ -26,7 +26,7 @@ handle_contacts_dbi <- function(config, source, handle = TRUE){ #apply generic handler handle_contacts_df <- source(system.file("metadata/contact", "contact_handler_df.R", package = "geoflow"))$value - contacts <- handle_contacts_df(config, source) + contacts <- handle_contacts_df(handler, source, config) return(contacts) } \ No newline at end of file diff --git a/inst/metadata/contact/contact_handler_df.R b/inst/metadata/contact/contact_handler_df.R index c2f472fe..0231d7c2 100644 --- a/inst/metadata/contact/contact_handler_df.R +++ b/inst/metadata/contact/contact_handler_df.R @@ -1,5 +1,5 @@ #handle_contacts_df -handle_contacts_df <- function(config, source){ +handle_contacts_df <- function(handler, source, config){ if(!is(source, "data.frame")){ errMsg <- "Error in 'handle_contact_df': source parameter should be an object of class 'data.frame'" diff --git a/inst/metadata/contact/contact_handler_excel.R b/inst/metadata/contact/contact_handler_excel.R index d77e6f91..600e4a0a 100644 --- a/inst/metadata/contact/contact_handler_excel.R +++ b/inst/metadata/contact/contact_handler_excel.R @@ -1,5 +1,5 @@ #handle_contacts_excel -handle_contacts_excel <- function(config, source, handle = TRUE){ +handle_contacts_excel <- function(handler, source, config, handle = TRUE){ isSourceUrl <- regexpr("(http|https)[^([:blank:]|\\\"|<|&|#\n\r)]+", source) > 0 if(isSourceUrl){ @@ -16,6 +16,6 @@ handle_contacts_excel <- function(config, source, handle = TRUE){ #apply generic handler handle_contacts_df <- source(system.file("metadata/contact", "contact_handler_df.R", package = "geoflow"))$value - contacts <- handle_contacts_df(config, source) + contacts <- handle_contacts_df(handler, source, config) return(contacts) } \ No newline at end of file diff --git a/inst/metadata/contact/contact_handler_gsheet.R b/inst/metadata/contact/contact_handler_gsheet.R index 260f2519..0d931dd5 100644 --- a/inst/metadata/contact/contact_handler_gsheet.R +++ b/inst/metadata/contact/contact_handler_gsheet.R @@ -1,5 +1,5 @@ #handle_contacts_gsheet -handle_contacts_gsheet <- function(config, source, handle = TRUE){ +handle_contacts_gsheet <- function(handler, source, config, handle = TRUE){ #read gsheet URL source <- as.data.frame(gsheet::gsheet2tbl(source)) @@ -7,6 +7,6 @@ handle_contacts_gsheet <- function(config, source, handle = TRUE){ #apply generic handler handle_contacts_df <- source(system.file("metadata/contact", "contact_handler_df.R", package = "geoflow"))$value - contacts <- handle_contacts_df(config, source) + contacts <- handle_contacts_df(handler, source, config) return(contacts) } \ No newline at end of file diff --git a/inst/metadata/contact/contact_handler_ocs.R b/inst/metadata/contact/contact_handler_ocs.R index 6aeea776..86905bf6 100644 --- a/inst/metadata/contact/contact_handler_ocs.R +++ b/inst/metadata/contact/contact_handler_ocs.R @@ -1,5 +1,5 @@ #handle_contacts_ocs -handle_contacts_ocs <- function(config, source, handle = TRUE){ +handle_contacts_ocs <- function(handler, source, config, handle = TRUE){ if(!requireNamespace("ocs4R", quietly = TRUE)){ stop("The OCS handler requires the 'ocs4R' package") @@ -15,11 +15,11 @@ handle_contacts_ocs <- function(config, source, handle = TRUE){ contacts <- switch(mime::guess_type(contacts_file), "text/csv" = { handle_contacts_csv <- source(system.file("metadata/contact", "contact_handler_csv.R", package = "geoflow"))$value - handle_contacts_csv(config = config, source = contacts_file, handle = handle) + handle_contacts_csv(handler = handler, source = contacts_file, config = config, handle = handle) }, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" = { handle_contacts_excel <- source(system.file("metadata/contact", "contact_handler_excel.R", package = "geoflow"))$value - handle_contacts_excel(config = config, source = contacts_file, handle = handle) + handle_contacts_excel(handler = handler, source = contacts_file, config = config, handle = handle) } ) return(contacts) diff --git a/inst/metadata/dictionary/dictionary_handler_csv.R b/inst/metadata/dictionary/dictionary_handler_csv.R index e2637c77..b1fa4206 100644 --- a/inst/metadata/dictionary/dictionary_handler_csv.R +++ b/inst/metadata/dictionary/dictionary_handler_csv.R @@ -1,5 +1,5 @@ #handle_dictionary_csv -handle_dictionary_csv <- function(config, source, handle = TRUE){ +handle_dictionary_csv <- function(handler, source, config, handle = TRUE){ #read csv TODO -> options management: sep, encoding etc #source <- read.csv(source) @@ -8,6 +8,6 @@ handle_dictionary_csv <- function(config, source, handle = TRUE){ #apply generic handler handle_dictionary_df <- source(system.file("metadata/dictionary", "dictionary_handler_df.R", package = "geoflow"))$value - dictionary <- handle_dictionary_df(config, source) + dictionary <- handle_dictionary_df(handler, source, config) return(dictionary) } \ No newline at end of file diff --git a/inst/metadata/dictionary/dictionary_handler_dbi.R b/inst/metadata/dictionary/dictionary_handler_dbi.R index 774fe13a..761092f2 100644 --- a/inst/metadata/dictionary/dictionary_handler_dbi.R +++ b/inst/metadata/dictionary/dictionary_handler_dbi.R @@ -1,5 +1,5 @@ #handle_dictionary_dbi -handle_dictionary_dbi <- function(config, source, handle = TRUE){ +handle_dictionary_dbi <- function(handler, source, config, handle = TRUE){ dbi <- config$software$input$dbi if(is.null(dbi)){ stop("There is no database input software configured to handle dictionary from DB") @@ -26,6 +26,6 @@ handle_dictionary_dbi <- function(config, source, handle = TRUE){ #apply generic handler handle_dictionary_df <- source(system.file("metadata/dictionary", "dictionary_handler_df.R", package = "geoflow"))$value - dictionary <- handle_dictionary_df(config, source) + dictionary <- handle_dictionary_df(handler, source, config) return(dictionary) } diff --git a/inst/metadata/dictionary/dictionary_handler_df.R b/inst/metadata/dictionary/dictionary_handler_df.R index a786944f..1295368a 100644 --- a/inst/metadata/dictionary/dictionary_handler_df.R +++ b/inst/metadata/dictionary/dictionary_handler_df.R @@ -1,5 +1,5 @@ #handle_dictionary_df -handle_dictionary_df <- function(config, source){ +handle_dictionary_df <- function(handler, source, config){ source [source == ""] <- NA diff --git a/inst/metadata/dictionary/dictionary_handler_excel.R b/inst/metadata/dictionary/dictionary_handler_excel.R index 38da5901..13d7d864 100644 --- a/inst/metadata/dictionary/dictionary_handler_excel.R +++ b/inst/metadata/dictionary/dictionary_handler_excel.R @@ -1,5 +1,5 @@ #handle_dictionary_excel -handle_dictionary_excel <- function(config, source, handle = TRUE){ +handle_dictionary_excel <- function(handler, source, config, handle = TRUE){ #read excel TODO -> options management: sep, encoding etc source <- as.data.frame(readxl::read_excel(source)) @@ -7,6 +7,6 @@ handle_dictionary_excel <- function(config, source, handle = TRUE){ #apply generic handler handle_dictionary_df <- source(system.file("metadata/dictionary", "dictionary_handler_df.R", package = "geoflow"))$value - dictionary <- handle_dictionary_df(config, source) + dictionary <- handle_dictionary_df(handler, source, config) return(dictionary) } \ No newline at end of file diff --git a/inst/metadata/dictionary/dictionary_handler_gsheet.R b/inst/metadata/dictionary/dictionary_handler_gsheet.R index fbf7d66f..f37663d9 100644 --- a/inst/metadata/dictionary/dictionary_handler_gsheet.R +++ b/inst/metadata/dictionary/dictionary_handler_gsheet.R @@ -1,5 +1,5 @@ #handle_dictionary_gsheet -handle_dictionary_gsheet <- function(config, source, handle = TRUE){ +handle_dictionary_gsheet <- function(handler, source, config, handle = TRUE){ #read gsheet URL source <- read.csv(text = gsheet::gsheet2text(source)) @@ -7,6 +7,6 @@ handle_dictionary_gsheet <- function(config, source, handle = TRUE){ #apply generic handler handle_dictionary_df <- source(system.file("metadata/dictionary", "dictionary_handler_df.R", package = "geoflow"))$value - dictionary <- handle_dictionary_df(config, source) + dictionary <- handle_dictionary_df(handler, source, config) return(dictionary) } \ No newline at end of file diff --git a/inst/metadata/dictionary/dictionary_handler_ocs.R b/inst/metadata/dictionary/dictionary_handler_ocs.R index c9fd2bc0..fc578e5a 100644 --- a/inst/metadata/dictionary/dictionary_handler_ocs.R +++ b/inst/metadata/dictionary/dictionary_handler_ocs.R @@ -1,5 +1,5 @@ #handle_dictionary_ocs -handle_dictionary_ocs <- function(config, source, handle = TRUE){ +handle_dictionary_ocs <- function(handler, source, config, handle = TRUE){ if(!requireNamespace("ocs4R", quietly = TRUE)){ stop("The OCS handler requires the 'ocs4R' package") @@ -15,11 +15,11 @@ handle_dictionary_ocs <- function(config, source, handle = TRUE){ dictionary <- switch(mime::guess_type(dict_file), "text/csv" = { handle_dictionary_csv <- source(system.file("metadata/dictionary", "dictionary_handler_csv.R", package = "geoflow"))$value - handle_dictionary_csv(config = config, source = dict_file, handle = handle) + handle_dictionary_csv(handler = handler, source = dict_file, config = config, handle = handle) }, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" = { handle_dictionary_excel <- source(system.file("metadata/dictionary", "dictionary_handler_excel.R", package = "geoflow"))$value - handle_dictionary_excel(config = config, source = dict_file, handle = handle) + handle_dictionary_excel(handler = handler, source = dict_file, config = config, handle = handle) } ) return(dictionary) diff --git a/inst/metadata/entity/entity_handler_csv.R b/inst/metadata/entity/entity_handler_csv.R index 8dbaf304..bb37811c 100644 --- a/inst/metadata/entity/entity_handler_csv.R +++ b/inst/metadata/entity/entity_handler_csv.R @@ -1,13 +1,13 @@ #handle_entities_csv -handle_entities_csv <- function(config, source, handle = TRUE){ +handle_entities_csv <- function(handler, source, config, handle = TRUE){ #read csv TODO -> options management: sep, encoding etc #source <- read.csv(source,stringsAsFactors = F) - source <- as.data.frame(readr::read_csv(source, guess_max = 0)) + source <- as.data.frame(readr::read_csv(source, guess_max = handler$getOption("guess_max"))) if(!handle) return(source) #apply generic handler handle_entities_df <- source(system.file("metadata/entity", "entity_handler_df.R", package = "geoflow"))$value - entities <- handle_entities_df(config, source) + entities <- handle_entities_df(handler, source, config) return(entities) } \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_csw.R b/inst/metadata/entity/entity_handler_csw.R index 7cd2b008..aee0ea5e 100644 --- a/inst/metadata/entity/entity_handler_csw.R +++ b/inst/metadata/entity/entity_handler_csw.R @@ -1,5 +1,5 @@ #handle_entities_csw -handle_entities_csw <- function(config, source, handle = TRUE){ +handle_entities_csw <- function(handler, source, config, handle = TRUE){ if(!requireNamespace("ows4R", quietly = TRUE)){ stop("The OGC CSW handler requires the 'ows4R' package") diff --git a/inst/metadata/entity/entity_handler_dataverse.R b/inst/metadata/entity/entity_handler_dataverse.R index fb753dc0..e9c07535 100644 --- a/inst/metadata/entity/entity_handler_dataverse.R +++ b/inst/metadata/entity/entity_handler_dataverse.R @@ -1,5 +1,5 @@ #handle_entities_dataverse -handle_entities_dataverse <- function(config, source, handle = TRUE){ +handle_entities_dataverse <- function(handler, source, config, handle = TRUE){ if(!requireNamespace("dataverse", quietly = TRUE)){ stop("The Dataverse handler requires the 'dataverse' package") diff --git a/inst/metadata/entity/entity_handler_dbi.R b/inst/metadata/entity/entity_handler_dbi.R index 2af5176a..ce3b7055 100644 --- a/inst/metadata/entity/entity_handler_dbi.R +++ b/inst/metadata/entity/entity_handler_dbi.R @@ -1,5 +1,5 @@ #handle_entities_dbi -handle_entities_dbi <- function(config, source, handle = TRUE){ +handle_entities_dbi <- function(handler, source, config, handle = TRUE){ dbi <- config$software$input$dbi dbi_config <- config$software$input$dbi_config if(is.null(dbi)){ @@ -50,12 +50,12 @@ handle_entities_dbi <- function(config, source, handle = TRUE){ #use a generic DBI geometry columns source = dbi_config$parameters$dbname handle_entities_dbi_geometry_columns <- source(system.file("metadata/entity", "entity_handler_dbi_geometry_columns.R", package = "geoflow"))$value - handle_entities_dbi_geometry_columns(config, source) + handle_entities_dbi_geometry_columns(handler, source, config) }else{ config$logger.info("Use default tabular entity handler") #use the df entity handler based on the SQL query/table specified as source handle_entities_df <- source(system.file("metadata/entity", "entity_handler_df.R", package = "geoflow"))$value - handle_entities_df(config, source = out_query) + handle_entities_df(handler, source = out_query, config) } return(entities) } \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_dbi_geometry_columns.R b/inst/metadata/entity/entity_handler_dbi_geometry_columns.R index b9f1a0b9..78e96d6c 100644 --- a/inst/metadata/entity/entity_handler_dbi_geometry_columns.R +++ b/inst/metadata/entity/entity_handler_dbi_geometry_columns.R @@ -1,5 +1,5 @@ #handle_entities_dbi_geometry_columns -handle_entities_dbi_geometry_columns <- function(config, source, handle = TRUE){ +handle_entities_dbi_geometry_columns <- function(handler, source, config, handle = TRUE){ dbi <- config$software$input$dbi dbi_config <- config$software$input$dbi_config dbi_user <- dbi_config$parameters$user diff --git a/inst/metadata/entity/entity_handler_df.R b/inst/metadata/entity/entity_handler_df.R index f55b51dd..ec61d1d4 100644 --- a/inst/metadata/entity/entity_handler_df.R +++ b/inst/metadata/entity/entity_handler_df.R @@ -1,5 +1,5 @@ #handle_entities_df -handle_entities_df <- function(config, source){ +handle_entities_df <- function(handler, source, config){ if(!is(source, "data.frame")){ errMsg <- "Error in 'handle_entities_df': source parameter should be an object of class 'data.frame'" diff --git a/inst/metadata/entity/entity_handler_excel.R b/inst/metadata/entity/entity_handler_excel.R index 69d9765b..1bd42e3d 100644 --- a/inst/metadata/entity/entity_handler_excel.R +++ b/inst/metadata/entity/entity_handler_excel.R @@ -1,5 +1,5 @@ #handle_entities_excel -handle_entities_excel <- function(config, source, handle = TRUE){ +handle_entities_excel <- function(handler, source, config, handle = TRUE){ isSourceUrl <- regexpr("(http|https)[^([:blank:]|\\\"|<|&|#\n\r)]+", source) > 0 if(isSourceUrl){ @@ -16,6 +16,6 @@ handle_entities_excel <- function(config, source, handle = TRUE){ #apply generic handler handle_entities_df <- source(system.file("metadata/entity", "entity_handler_df.R", package = "geoflow"))$value - entities <- handle_entities_df(config, source) + entities <- handle_entities_df(handler, source, config) return(entities) } \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_gsheet.R b/inst/metadata/entity/entity_handler_gsheet.R index ce69f4cc..819933ff 100644 --- a/inst/metadata/entity/entity_handler_gsheet.R +++ b/inst/metadata/entity/entity_handler_gsheet.R @@ -1,5 +1,5 @@ #handle_entities_gsheets -handle_entities_gsheet <- function(config, source, handle = TRUE){ +handle_entities_gsheet <- function(handler, source, config, handle = TRUE){ #read gsheet URL source <- as.data.frame(gsheet::gsheet2tbl(source)) @@ -7,6 +7,6 @@ handle_entities_gsheet <- function(config, source, handle = TRUE){ #apply generic handler handle_entities_df <- source(system.file("metadata/entity", "entity_handler_df.R", package = "geoflow"))$value - entities <- handle_entities_df(config, source) + entities <- handle_entities_df(handler, source, config) return(entities) } \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_ncdf.R b/inst/metadata/entity/entity_handler_ncdf.R index e057b45e..17015355 100644 --- a/inst/metadata/entity/entity_handler_ncdf.R +++ b/inst/metadata/entity/entity_handler_ncdf.R @@ -1,5 +1,5 @@ #handle_entities_ncdf -handle_entities_ncdf <- function(config, source, handle = TRUE){ +handle_entities_ncdf <- function(handler, source, config, handle = TRUE){ config$logger.info("NCDF Handler") if(!requireNamespace("ncdf4", quietly = TRUE)){ diff --git a/inst/metadata/entity/entity_handler_ncml.R b/inst/metadata/entity/entity_handler_ncml.R index a5de1525..6f225cde 100644 --- a/inst/metadata/entity/entity_handler_ncml.R +++ b/inst/metadata/entity/entity_handler_ncml.R @@ -1,5 +1,5 @@ #handle_entities_ncml -handle_entities_ncml <- function(config, source, handle = TRUE){ +handle_entities_ncml <- function(handler, source, config, handle = TRUE){ config$logger.info("NCML Handle") diff --git a/inst/metadata/entity/entity_handler_ocs.R b/inst/metadata/entity/entity_handler_ocs.R index a69f3e9b..8067c8b6 100644 --- a/inst/metadata/entity/entity_handler_ocs.R +++ b/inst/metadata/entity/entity_handler_ocs.R @@ -1,5 +1,5 @@ #handle_entities_ocs -handle_entities_ocs <- function(config, source, handle = TRUE){ +handle_entities_ocs <- function(handler, source, config, handle = TRUE){ if(!requireNamespace("ocs4R", quietly = TRUE)){ stop("The OCS handler requires the 'ocs4R' package") @@ -15,11 +15,11 @@ handle_entities_ocs <- function(config, source, handle = TRUE){ entities <- switch(mime::guess_type(entities_file), "text/csv" = { handle_entities_csv <- source(system.file("metadata/entity", "entity_handler_csv.R", package = "geoflow"))$value - handle_entities_csv(config = config, source = entities_file, handle = handle) + handle_entities_csv(handler = handler, source = entities_file, config = config, handle = handle) }, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" = { handle_entities_excel <- source(system.file("metadata/entity", "entity_handler_excel.R", package = "geoflow"))$value - handle_entities_excel(config = config, source = entities_file, handle = handle) + handle_entities_excel(handler = , source = entities_file, config = config, handle = handle) } ) return(entities) diff --git a/inst/metadata/entity/entity_handler_thredds.R b/inst/metadata/entity/entity_handler_thredds.R index c8c6dc04..d58d6668 100644 --- a/inst/metadata/entity/entity_handler_thredds.R +++ b/inst/metadata/entity/entity_handler_thredds.R @@ -1,5 +1,5 @@ #handle_entities_thredds -handle_entities_thredds <- function(config, source){ +handle_entities_thredds <- function(handler, source, config){ if(!requireNamespace("thredds", quietly = TRUE)){ stop("The Thredds handler requires the 'thredds' package") diff --git a/inst/metadata/entity/entity_handler_thredds_csv.R b/inst/metadata/entity/entity_handler_thredds_csv.R index 22df9580..5cfddbcc 100644 --- a/inst/metadata/entity/entity_handler_thredds_csv.R +++ b/inst/metadata/entity/entity_handler_thredds_csv.R @@ -1,5 +1,5 @@ #handle_entities_thredds_csv -handle_entities_thredds_csv <- function(config, source, handle = TRUE){ +handle_entities_thredds_csv <- function(handler, source, config, handle = TRUE){ #read csv TODO -> options management: sep, encoding etc source <- read.csv(source,stringsAsFactors = F) @@ -7,6 +7,6 @@ handle_entities_thredds_csv <- function(config, source, handle = TRUE){ #apply generic handler handle_entities_thredds_df <- source(system.file("metadata/entity", "entity_handler_thredds_df.R", package = "geoflow"))$value - entities <- handle_entities_thredds_df(config, source) + entities <- handle_entities_thredds_df(handler, source, config) return(entities) } \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_thredds_df.R b/inst/metadata/entity/entity_handler_thredds_df.R index 40b7ce5d..bd42cce5 100644 --- a/inst/metadata/entity/entity_handler_thredds_df.R +++ b/inst/metadata/entity/entity_handler_thredds_df.R @@ -1,13 +1,13 @@ #handle_entities_thredds_df -handle_entities_thredds_df = function(config, source){ +handle_entities_thredds_df = function(handler, source, config){ - entities <- handle_entities_df(config, source) + entities <- handle_entities_df(handler, source, config) thredds_entities <- lapply(entities, function(entity){ thredds_source <- entity$data$source[[1]] - thredds_entity <- handle_entities_thredds(config, thredds_source)[[1]] + thredds_entity <- handle_entities_thredds(handle, thredds_source, config)[[1]] #identifiers (priority to df) if(is.null(entity$identifiers$doi)) if(!is.null(thredds_entity$identifiers$doi)) entity$identifiers$doi<-thredds_entity$identifiers$doi diff --git a/inst/metadata/entity/entity_handler_thredds_excel.R b/inst/metadata/entity/entity_handler_thredds_excel.R index 5edb9745..eeaecf00 100644 --- a/inst/metadata/entity/entity_handler_thredds_excel.R +++ b/inst/metadata/entity/entity_handler_thredds_excel.R @@ -1,5 +1,5 @@ #handle_entities_thredds_excel -handle_entities_thredds_excel <- function(config, source, handle = TRUE){ +handle_entities_thredds_excel <- function(handler, source, config, handle = TRUE){ #read excel TODO -> options management: sep, encoding etc source <- as.data.frame(readxl::read_excel(source)) @@ -7,6 +7,6 @@ handle_entities_thredds_excel <- function(config, source, handle = TRUE){ #apply generic handler handle_entities_thredds_df <- source(system.file("metadata/entity", "entity_handler_thredds_df.R", package = "geoflow"))$value - entities <- handle_entities_thredds_df(config, source) + entities <- handle_entities_thredds_df(handler, source, config) return(entities) } \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_thredds_gsheet.R b/inst/metadata/entity/entity_handler_thredds_gsheet.R index 08a49997..474cc134 100644 --- a/inst/metadata/entity/entity_handler_thredds_gsheet.R +++ b/inst/metadata/entity/entity_handler_thredds_gsheet.R @@ -1,5 +1,5 @@ #handle_entities_thredds_gsheet -handle_entities_thredds_gsheet <- function(config, source, handle = TRUE){ +handle_entities_thredds_gsheet <- function(handler, source, config, handle = TRUE){ #read gsheet URL source <- as.data.frame(gsheet::gsheet2tbl(source)) @@ -7,6 +7,6 @@ handle_entities_thredds_gsheet <- function(config, source, handle = TRUE){ #apply generic handler handle_entities_thredds_df <- source(system.file("metadata/entity", "entity_handler_thredds_df.R", package = "geoflow"))$value - entities <- handle_entities_thredds_df(config, source) + entities <- handle_entities_thredds_df(handler, source, config) return(entities) } \ No newline at end of file diff --git a/man/geoflow_handler.Rd b/man/geoflow_handler.Rd index 85d4d12a..56505a37 100644 --- a/man/geoflow_handler.Rd +++ b/man/geoflow_handler.Rd @@ -13,9 +13,10 @@ Object of \code{\link{R6Class}} for modelling a handler \description{ This class models a content handler. An handler is a method to handle some content (eg entity or contact). It is mainly driven by a function that takes -as argument a \code{config} object, as the overall configuration created by geoflow -\code{initWorkflow} function, and a source which identifiers the source to be handled, -that can be of a different type (eg a URL, a file path) depending on the handler. +as argument the \code{handler} considered (as self accessible object), a \code{source} +which identifiers the source to be handled, that can be of a different type (eg a URL, a file path) +depending on the handler, and a \code{config} object, as the overall configuration created by geoflow +\code{initWorkflow} function. } \details{ geoflow_handler @@ -30,7 +31,8 @@ for entities and contacts. id = "some-id", def = "some definition", packages = list(), - fun = function(config, source){} + fun = function(handler, source, config){}, + available_options = list() ) } @@ -51,6 +53,10 @@ Emmanuel Blondel \item{\code{fun}}{handler function} \item{\code{script}}{handler script} + +\item{\code{options}}{options} + +\item{\code{available_options}}{available options} } \if{html}{\out{}} } @@ -59,6 +65,7 @@ Emmanuel Blondel \itemize{ \item \href{#method-geoflow_handler-new}{\code{geoflow_handler$new()}} \item \href{#method-geoflow_handler-checkPackages}{\code{geoflow_handler$checkPackages()}} +\item \href{#method-geoflow_handler-getOption}{\code{geoflow_handler$getOption()}} \item \href{#method-geoflow_handler-clone}{\code{geoflow_handler$clone()}} } } @@ -68,7 +75,15 @@ Emmanuel Blondel \subsection{Method \code{new()}}{ Initializes a \link{geoflow_handler} \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{geoflow_handler$new(id, def = "", packages = list(), fun = NULL, script = NULL)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{geoflow_handler$new( + id, + def = "", + packages = list(), + fun = NULL, + script = NULL, + options = list(), + available_options = list() +)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -83,6 +98,10 @@ Initializes a \link{geoflow_handler} \item{\code{fun}}{the handler \code{function} having 2 arguments \code{config} and \code{source}} \item{\code{script}}{a handler script} + +\item{\code{options}}{action options} + +\item{\code{available_options}}{available options for the action} } \if{html}{\out{}} } @@ -99,6 +118,26 @@ Check that all packages required for the handler are available, if yes, \if{html}{\out{
}}\preformatted{geoflow_handler$checkPackages()}\if{html}{\out{
}} } +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-geoflow_handler-getOption}{}}} +\subsection{Method \code{getOption()}}{ +Get handler option value +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{geoflow_handler$getOption(option)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{option}}{option id} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +the option value, either specified through a workflow, or the default value +} } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/list_contact_handler_options.Rd b/man/list_contact_handler_options.Rd new file mode 100644 index 00000000..bdee7fcc --- /dev/null +++ b/man/list_contact_handler_options.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geoflow_handler_contact.R +\name{list_contact_handler_options} +\alias{list_contact_handler_options} +\title{list_contact_handler_options} +\usage{ +list_contact_handler_options(id, raw) +} +\arguments{ +\item{id}{An contact handler identifier} + +\item{raw}{if raw list should be returned} +} +\value{ +an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the available handler options. +} +\description{ +\code{list_contact_handler_options} lists the options available for a given contact handler supported by geoflow. +} +\author{ +Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} +} diff --git a/man/list_dictionary_handler_options.Rd b/man/list_dictionary_handler_options.Rd new file mode 100644 index 00000000..454ea8d2 --- /dev/null +++ b/man/list_dictionary_handler_options.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geoflow_handler_dictionary.R +\name{list_dictionary_handler_options} +\alias{list_dictionary_handler_options} +\title{list_dictionary_handler_options} +\usage{ +list_dictionary_handler_options(id, raw) +} +\arguments{ +\item{id}{An dictionary handler identifier} + +\item{raw}{if raw list should be returned} +} +\value{ +an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the available handler options. +} +\description{ +\code{list_dictionary_handler_options} lists the options available for a given dictionary handler supported by geoflow. +} +\author{ +Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} +} diff --git a/man/list_entity_handler_options.Rd b/man/list_entity_handler_options.Rd new file mode 100644 index 00000000..36895ef7 --- /dev/null +++ b/man/list_entity_handler_options.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geoflow_handler_entity.R +\name{list_entity_handler_options} +\alias{list_entity_handler_options} +\title{list_entity_handler_options} +\usage{ +list_entity_handler_options(id, raw) +} +\arguments{ +\item{id}{An entity handler identifier} + +\item{raw}{if raw list should be returned} +} +\value{ +an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the available handler options. +} +\description{ +\code{list_entity_handler_options} lists the options available for a given entity handler supported by geoflow. +} +\author{ +Emmanuel Blondel, \email{emmanuel.blondel1@gmail.com} +} diff --git a/man/loadMetadataHandler.Rd b/man/loadMetadataHandler.Rd index 9c561da4..0ee50a1b 100644 --- a/man/loadMetadataHandler.Rd +++ b/man/loadMetadataHandler.Rd @@ -13,6 +13,9 @@ loadMetadataHandler(config, element, type) \item{type}{either 'contacts', 'entities' or 'dictionnary'} } +\value{ +an object of class \link{geoflow_handler} +} \description{ \code{loadMetadataHandler} allows to load a metadata handler }