Skip to content

Commit

Permalink
#390 support file upload, metadata deactivated for now (XML filetype …
Browse files Browse the repository at this point in the history
…not supported for upload)
  • Loading branch information
eblondel committed Jun 11, 2024
1 parent 0c47b6f commit 02f4dba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/geoflow_action.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
Expand Down
31 changes: 31 additions & 0 deletions inst/actions/metadataeditr_create_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -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){

Expand Down Expand Up @@ -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)
# )
# }
}
}

0 comments on commit 02f4dba

Please sign in to comment.