From 02f4dba3ec5b6ad3f37cf42030a93e842abb3671 Mon Sep 17 00:00:00 2001 From: eblondel Date: Tue, 11 Jun 2024 22:20:00 +0200 Subject: [PATCH] #390 support file upload, metadata deactivated for now (XML filetype not supported for upload) --- R/geoflow_action.R | 6 +++- inst/actions/metadataeditr_create_project.R | 31 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/R/geoflow_action.R b/R/geoflow_action.R index 0159b08..5cfa083 100644 --- a/R/geoflow_action.R +++ b/R/geoflow_action.R @@ -527,7 +527,11 @@ register_actions <- function(){ target = "entity", target_dir = "metadata", packages = list("metadataeditr"), - available_options = list(), + available_options = list( + depositWithFiles = list(def = "Indicates if the action is uploading files", class = "logical", default = TRUE), + depositDataPattern = list(def = "A regular expression to filter data files to upload in metadata editor", class = "character", default = ""), + depositMetadataPattern = list(def = "A regular expression to filter metadata files to upload in metadata editor", class = "character", default = "") + ), fun = source(system.file("actions", "metadataeditr_create_project.R", package = "geoflow"))$value ) ) diff --git a/inst/actions/metadataeditr_create_project.R b/inst/actions/metadataeditr_create_project.R index 75ac3e0..42686cc 100644 --- a/inst/actions/metadataeditr_create_project.R +++ b/inst/actions/metadataeditr_create_project.R @@ -15,6 +15,11 @@ function(action, entity, config){ collection_names = as.list(strsplit(MD_EDITOR_CONFIG$properties$collection_names, ",")[[1]]) } + #options + depositWithFiles <- action$getOption("depositWithFiles") + depositDataPattern <- action$getOption("depositDataPattern") + depositMetadataPattern <- action$getOption("depositMetadataPattern") + #basic function to map a geoflow_contact to a metadata editor contact produce_md_contact = function(x){ @@ -344,4 +349,30 @@ function(action, entity, config){ ) } } + + #files + if(depositWithFiles){ + #data + data_files <- list.files(file.path(getwd(),"data"), pattern = depositDataPattern) + for(data_file in data_files){ + config$logger.info(sprintf("Upload data file '%s'", data_file)) + metadataeditr::resources_add( + idno = entity$identifiers[["id"]], + dctype = "dat", + title = data_file, + file_path = file.path(getwd(), "data", data_file) + ) + } + #metadata + # metadata_files <- list.files(file.path(getwd(),"metadata"), pattern = depositMetadataPattern) + # for(metadata_file in metadata_files){ + # config$logger.info(sprintf("Upload metadata file '%s'", metadata_file)) + # metadataeditr::resources_add( + # idno = entity$identifiers[["id"]], + # dctype = "dat", + # title = metadata_file, + # file_path = file.path(getwd(), "metadata", metadata_file) + # ) + # } + } } \ No newline at end of file