From 866ddf8eaaec0fe7f7f7261930e2f1ad258f9ce2 Mon Sep 17 00:00:00 2001 From: eblondel Date: Mon, 2 Jan 2023 18:54:05 +0100 Subject: [PATCH] #298 i18n support for Rights --- R/geoflow_right.R | 6 +++++- inst/actions/geometa_create_iso_19115.R | 8 ++++---- inst/metadata/entity/entity_handler_df.R | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/R/geoflow_right.R b/R/geoflow_right.R index b396854b..f55faa3f 100644 --- a/R/geoflow_right.R +++ b/R/geoflow_right.R @@ -29,11 +29,15 @@ geoflow_right <- R6Class("geoflow_right", #'@description Initializes an object of class \link{geoflow_right} #'@param str character string to initialize from using key-based syntax - initialize = function(str = NULL){ + #'@param kvp an object of class \link{geoflow_kvp} + initialize = function(str = NULL, kvp = NULL){ if(!is.null(str)){ right <- extract_kvp(str) self$setKey(right$key) self$setValue(paste(right$values, collapse=",")) + }else if(!is.null(kvp)){ + self$setKey(kvp$key) + self$setValue(kvp$values) } }, diff --git a/inst/actions/geometa_create_iso_19115.R b/inst/actions/geometa_create_iso_19115.R index bde9dd14..8d162af3 100644 --- a/inst/actions/geometa_create_iso_19115.R +++ b/inst/actions/geometa_create_iso_19115.R @@ -377,13 +377,13 @@ function(action, entity, config){ if(length(licenses)>0){ legal_constraints$addUseConstraint("license") for(license in licenses){ - legal_constraints$addUseLimitation(license) + legal_constraints$addUseLimitation(license$value, locales = geoflow::get_locales_from(license$value)) } } #use limitation - uses <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "use"})] + uses <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) %in% c("use","uselimitation")})] if(length(uses)>0){ - for(use in uses) legal_constraints$addUseLimitation(use$value) + for(use in uses) legal_constraints$addUseLimitation(use$value, locales = geoflow::get_locales_from(use$value)) } #use constraints useConstraints <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "useconstraint"})] @@ -398,7 +398,7 @@ function(action, entity, config){ #other constraints otherConstraints <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "otherconstraint"})] if(length(otherConstraints)>0){ - for(otherConstraint in otherConstraints) legal_constraints$addOtherConstraint(otherConstraint$value) + for(otherConstraint in otherConstraints) legal_constraints$addOtherConstraint(otherConstraint$value, locales = geoflow::get_locales_from(otherConstraint$value)) } ident$addResourceConstraints(legal_constraints) } diff --git a/inst/metadata/entity/entity_handler_df.R b/inst/metadata/entity/entity_handler_df.R index a01729ae..4d2237aa 100644 --- a/inst/metadata/entity/entity_handler_df.R +++ b/inst/metadata/entity/entity_handler_df.R @@ -250,10 +250,11 @@ handle_entities_df <- function(config, source){ src_rights <- sanitize_str(source_entity[,"Rights"]) rights <- if(!is.na(src_rights)) extract_cell_components(src_rights) else list() if(length(rights)>0){ - invisible(lapply(rights, function(right){ - right_obj <- geoflow_right$new(str = right) + kvps <- extract_kvps(rights) + for(kvp in kvps){ + right_obj <- geoflow_right$new(kvp = kvp) entity$addRight(right_obj) - })) + } } #Provenance