Skip to content

Commit

Permalink
#403 entity handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 6, 2025
1 parent 5f1b594 commit 07724d0
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 143 deletions.
84 changes: 71 additions & 13 deletions R/geoflow_handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ geoflow_handler <- R6Class("geoflow_handler",
public = list(
#'@field id handler id
id = NA,
#'@field type handler type (entity,contact,dictionary)
type = NULL,
#'@field funders funders
funders = list(),
#'@field authors authors
authors = list(),
#'@field maintainer maintainer
maintainer = NULL,
#'@field def handler definition
def = NA,
#'@field packages handler packages
Expand All @@ -49,32 +57,82 @@ geoflow_handler <- R6Class("geoflow_handler",
#'@field available_options available options
available_options = list(),
#'@field status status
status = "active",
status = "stable",
#'@field notes notes
notes = "",

#'@description Initializes a \link{geoflow_handler}
#'@param yaml a YAML file
#'@param id id
#'@param type type
#'@param funders funders
#'@param authors authors
#'@param maintainer maintainer
#'@param def def
#'@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
#'@param options action options
#'@param available_options available options for the action
#'@param status status (active/deprecated)
#'@param status status (experimental/stable/deprecated/superseded)
#'@param notes notes
initialize = function(id, def = "", packages = list(), fun = NULL, script = NULL,
initialize = function(yaml = NULL,
id = NULL, type = c("entity", "contact", "dictionary"),
funders = list(), authors = list(), maintainer = NULL,
def = "",
packages = list(), fun = NULL, script = NULL,
options = list(), available_options = list(),
status = "active", notes = ""){
self$id <- id
self$def <- def
self$packages <- packages
self$fun <- fun
self$script <- script
self$options <- options
self$available_options <- available_options
self$status = status
self$notes = notes
status = "stable", notes = ""){
if(!is.null(yaml)){
self$fromYAML(yaml)
}else{
self$id <- id
type = match.arg(type)
self$type = type
self$funders = funders
self$authors = authors
self$maintainer = maintainer
self$def <- def
self$packages <- packages
self$fun <- fun
self$script <- script
self$options <- options
self$available_options <- available_options
self$status = status
self$notes = notes
}
},

#'@description Reads handler properties from YAML file
#'@param file file
fromYAML = function(file){
yml = yaml::read_yaml(file)
self$id = yml$id
self$type = yml$type
self$funders = yml$funders
self$authors = yml$authors
self$maintainer = yml$maintainer
self$def = yml$def
self$packages = yml$packages
self$fun = source(system.file(paste0("metadata/", self$type), yml$fun, package = "geoflow"))$value
self$status = if(!is.null(yml$status)) yml$status else "<unknown>"
self$notes = if(!is.null(yml$notes)) yml$notes else ""
self$available_options = lapply(yml$available_options, function(opt){
if(is.null(opt$default)){
opt$default = c()
}else{
if(length(opt$default)>1){
opt$default = unlist(opt$default)
}else{
opt$default = switch(opt$default,
"NA" = NA,
"Inf" = Inf,
as(opt$default, opt$class)
)
}
}
return(opt)
})
},

#'@description Check that all packages required for the handler are available, if yes,
Expand Down
132 changes: 5 additions & 127 deletions R/geoflow_handler_entity.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,133 +11,10 @@
#' @export
#'
register_entity_handlers <- function(){
handlers <- list(
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,
available_options = list(
guess_max = list(def = "Guess max argument, see readr::read_csv", default = 0),
enrich_from_dbi = list(def = "Enrich entity data from DBI software", default = FALSE)
)
),
geoflow_handler$new(
id = "excel",
def = "Handle metadata entities from a Microsoft Excel (xls,xlsx) file",
packages = list("readxl"),
fun = source(system.file("metadata/entity", "entity_handler_excel.R", package = "geoflow"))$value,
available_options = list(
enrich_from_dbi = list(def = "Enrich entity data from DBI software", default = FALSE)
)
),
geoflow_handler$new(
id = "gsheet",
def = "Handle metadata entities from a Google spreadsheet",
packages = list("gsheet"),
fun = source(system.file("metadata/entity", "entity_handler_gsheet.R", package = "geoflow"))$value,
available_options = list(
enrich_from_dbi = list(def = "Enrich entity data from DBI software", default = FALSE)
)
),
geoflow_handler$new(
id = "dbi",
def = "Handle metadata entities from a DB source",
packages = list("DBI", "RSQLite", "RPostgres"),
fun = source(system.file("metadata/entity", "entity_handler_dbi.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "dbi_csv",
def = "Handle DBI metadata entities from a CSV file",
packages = list("DBI", "RSQLite", "RPostgres"),
fun = source(system.file("metadata/entity", "entity_handler_dbi_csv.R", package = "geoflow"))$value,
status = "deprecated",
notes = "Use 'csv' handler enabling option 'enrich_from_dbi"
),
geoflow_handler$new(
id = "dbi_excel",
def = "Handle DBI metadata entities from a Microsoft Excel (xls, xlsx) file",
packages = list("readxl"),
fun = source(system.file("metadata/entity", "entity_handler_dbi_excel.R", package = "geoflow"))$value,
status = "deprecated",
notes = "Use 'excel' handler enabling option 'enrich_from_dbi"
),
geoflow_handler$new(
id = "dbi_gsheet",
def = "Handle DBI metadata entities from a Google spreadsheet",
packages = list("gsheet"),
fun = source(system.file("metadata/entity", "entity_handler_dbi_gsheet.R", package = "geoflow"))$value,
status = "deprecated",
notes = "Use 'gsheet' handler enabling option 'enrich_from_dbi"
),
geoflow_handler$new(
id = "dataverse",
def = "Handle metadata entities built from a Dataverse source",
packages = list("dataverse"),
fun = source(system.file("metadata/entity", "entity_handler_dataverse.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "ocs",
def = "Handle metadata entities from a tabulat data source (csv or excel) hosted on an OCS cloud",
packages = list("ocs4R"),
fun = source(system.file("metadata/entity", "entity_handler_ocs.R", package = "geoflow"))$value,
available_options = list(
enrich_from_dbi = list(def = "Enrich entity data from DBI software", default = FALSE)
)
),
geoflow_handler$new(
id = "ncdf",
def = "Handle metadata entities from a Netcdf source",
packages = list("ncdf4"),
fun = source(system.file("metadata/entity", "entity_handler_ncdf.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "ncml",
def = "Handle metadata entities from a NCML source",
packages = list("XML"),
fun = source(system.file("metadata/entity", "entity_handler_ncml.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "thredds",
def = "Handle metadata entities from a Thredds server source",
packages = list("ncdf4","thredds","XML","png","curl"),
fun = source(system.file("metadata/entity", "entity_handler_thredds.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "thredds_csv",
def = "Handle metadata thredds entities from a CSV file",
fun = source(system.file("metadata/entity", "entity_handler_thredds_csv.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "thredds_excel",
def = "Handle metadata thredds entities from a Microsoft Excel (xls,xlsx) file",
packages = list("readxl"),
fun = source(system.file("metadata/entity", "entity_handler_thredds_excel.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "thredds_gsheet",
def = "Handle metadata thredds entities from a Google spreadsheet",
packages = list("gsheet"),
fun = source(system.file("metadata/entity", "entity_handler_thredds_gsheet.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "ogc_csw",
def = "Handle metadata entities from an OGC CSW endpoint",
packages = list("ows4R", "sf", "geometa"),
fun = source(system.file("metadata/entity", "entity_handler_csw.R", package = "geoflow"))$value
),
geoflow_handler$new(
id = "zenodo",
def = "Handle metadata entities built from a Zenodo source",
packages = list("zen4R"),
fun = source(system.file("metadata/entity", "entity_handler_zenodo.R", package = "geoflow"))$value,
available_options = list(
resource_type = list(def = "Type resource. By default 'deposit', use this if you are the owner of the records you fetch.
Alternative option value is 'record' that can be used for third-party record handling (as anonymous user", default = "deposit"),
source_type = list(def = "Type of source for handling Zenodo input deposits/records. Possible values are ['query': an ElasticSearch query,
'doi': one or more DOIs]", default = 'query')
)
)
)
yml_files = list.files(system.file("metadata/entity", package = "geoflow"), pattern = "yml")
handlers <- lapply(yml_files, function(file){
geoflow_handler$new(yaml = system.file("metadata/entity", file, package = "geoflow"))
})
.geoflow$entity_handlers <- handlers
}

Expand Down Expand Up @@ -169,6 +46,7 @@ list_entity_handlers <- function(raw = FALSE){
packages = paste(handler$packages, collapse=","),
status = handler$status,
notes = handler$notes,
maintainer = if(!is.null(handler$maintainer$name)){handler$maintainer$name}else{ if(handler$maintainer$orphaned) "<orphaned>" else "<unknown>" },
stringsAsFactors = FALSE
))
}))
Expand Down
23 changes: 23 additions & 0 deletions inst/metadata/entity/entity_handler_csv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
id: csv
type: entity
fun: entity_handler_csv.R
funders: []
authors:
- name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
maintainer:
name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
def: Handle metadata entities from a CSV file
status: stable
packages:
- readr
available_options:
guess_max:
def: Guess max argument, see readr::read_csv
class: integer
default: 0
enrich_from_dbi:
def: Enrich entity data from DBI software
class: logical
default: false
21 changes: 21 additions & 0 deletions inst/metadata/entity/entity_handler_csw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
id: csw
type: entity
fun: entity_handler_csw.R
funders:
- name: IRD
url: https:/www.ird.fr
- name: INRAE
url: https://www.inrae.fr
authors:
- name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
maintainer:
name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
def: Handle metadata entities from an OGC CSW endpoint
status: experimental
packages:
- ows4R
- sf
- geometa
available_options: []
15 changes: 15 additions & 0 deletions inst/metadata/entity/entity_handler_dataverse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: dbi_dataverse
type: entity
fun: entity_handler_dataverse.R
funders:
- name: INRAE
url: https://www.inrae.fr
authors:
- name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
maintainer:
orphaned: true
def: Handle metadata entities built from a Dataverse source
status: experimental
packages:
- dataverse
26 changes: 26 additions & 0 deletions inst/metadata/entity/entity_handler_dbi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
id: dbi
type: entity
fun: entity_handler_dbi.R
funders:
- name: IRD
url: https:/www.ird.fr
- name: INRAE
url: https://www.inrae.fr
authors:
- name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
maintainer:
name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
def: Handle metadata entities from a DB source
status: stable
packages:
- DBI
- RSQLite
- RPostgres
- RPostgreSQL
available_options:
enrich_from_dbi:
def: Enrich entity data from DBI software
class: logical
default: false
19 changes: 19 additions & 0 deletions inst/metadata/entity/entity_handler_dbi_csv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
id: dbi_csv
type: entity
fun: entity_handler_dbi_csv.R
funders: []
authors:
- name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
maintainer:
name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
def: Handle DBI metadata entities from a CSV file
status: superseded
notes: Use 'csv' handler enabling option 'enrich_from_dbi'
packages:
- readr
- DBI
- RSQLite
- RPostgres
- RPostgreSQL
19 changes: 19 additions & 0 deletions inst/metadata/entity/entity_handler_dbi_excel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
id: dbi_excel
type: entity
fun: entity_handler_dbi_excel.R
funders: []
authors:
- name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
maintainer:
name: Emmanuel Blondel
email: emmanuel.blondel1@gmail.com
def: Handle DBI metadata entities from a Microsoft Excel (xls, xlsx) file
status: superseded
notes: Use 'excel' handler enabling option 'enrich_from_dbi'
packages:
- readxl
- DBI
- RSQLite
- RPostgres
- RPostgreSQL
Loading

0 comments on commit 07724d0

Please sign in to comment.