Skip to content

Commit

Permalink
#298 multiple rights i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 3, 2023
1 parent 866ddf8 commit 63b2ddf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
29 changes: 20 additions & 9 deletions R/geoflow_right.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' \dontrun{
#' right <- geoflow_right$new()
#' right$setKey("use")
#' right$setValue("No restrictions")
#' right$setValues("No restrictions")
#' }
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
Expand All @@ -24,8 +24,8 @@ geoflow_right <- R6Class("geoflow_right",
public = list(
#'@field key right key
key = NULL,
#'@field value right value
value = NULL,
#'@field values right values
values = list(),

#'@description Initializes an object of class \link{geoflow_right}
#'@param str character string to initialize from using key-based syntax
Expand All @@ -34,10 +34,21 @@ geoflow_right <- R6Class("geoflow_right",
if(!is.null(str)){
right <- extract_kvp(str)
self$setKey(right$key)
self$setValue(paste(right$values, collapse=","))
self$setValues(right$values)
}else if(!is.null(kvp)){
self$setKey(kvp$key)
self$setValue(kvp$values)
values = lapply(1:length(kvp$values), function(i){
right = kvp$values[[i]]
attributes(right) <- NULL
val_locale_attrs <- attributes(kvp$values)
for(attr_name in names(val_locale_attrs)){
locale_value <- val_locale_attrs[[attr_name]][[i]]
attributes(locale_value) <- NULL
attr(right, attr_name) <- locale_value
}
return(right)
})
self$setValues(values)
}
},

Expand All @@ -47,10 +58,10 @@ geoflow_right <- R6Class("geoflow_right",
self$key <- key
},

#'@description Sets value
#'@param value value
setValue = function(value){
self$value <- value
#'@description Sets values
#'@param values values
setValues = function(values){
self$values <- c(self$values, values)
}
)
)
16 changes: 13 additions & 3 deletions inst/actions/geometa_create_iso_19115.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,19 @@ function(action, entity, config){
if(length(licenses)>0){
legal_constraints$addUseConstraint("license")
for(license in licenses){
legal_constraints$addUseLimitation(license$value, locales = geoflow::get_locales_from(license$value))
for(value in license$values){
legal_constraints$addUseLimitation(value, locales = geoflow::get_locales_from(value))
}
}
}
#use limitation
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, locales = geoflow::get_locales_from(use$value))
for(use in uses){
for(value in use$values){
legal_constraints$addUseLimitation(value, locales = geoflow::get_locales_from(value))
}
}
}
#use constraints
useConstraints <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "useconstraint"})]
Expand All @@ -398,7 +404,11 @@ 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, locales = geoflow::get_locales_from(otherConstraint$value))
for(otherConstraint in otherConstraints){
for(value in otherConstraint$values){
legal_constraints$addOtherConstraint(value, locales = geoflow::get_locales_from(value))
}
}
}
ident$addResourceConstraints(legal_constraints)
}
Expand Down

0 comments on commit 63b2ddf

Please sign in to comment.