Skip to content

Commit 63b2ddf

Browse files
committed
#298 multiple rights i18n support
1 parent 866ddf8 commit 63b2ddf

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

R/geoflow_right.R

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' \dontrun{
1616
#' right <- geoflow_right$new()
1717
#' right$setKey("use")
18-
#' right$setValue("No restrictions")
18+
#' right$setValues("No restrictions")
1919
#' }
2020
#'
2121
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
@@ -24,8 +24,8 @@ geoflow_right <- R6Class("geoflow_right",
2424
public = list(
2525
#'@field key right key
2626
key = NULL,
27-
#'@field value right value
28-
value = NULL,
27+
#'@field values right values
28+
values = list(),
2929

3030
#'@description Initializes an object of class \link{geoflow_right}
3131
#'@param str character string to initialize from using key-based syntax
@@ -34,10 +34,21 @@ geoflow_right <- R6Class("geoflow_right",
3434
if(!is.null(str)){
3535
right <- extract_kvp(str)
3636
self$setKey(right$key)
37-
self$setValue(paste(right$values, collapse=","))
37+
self$setValues(right$values)
3838
}else if(!is.null(kvp)){
3939
self$setKey(kvp$key)
40-
self$setValue(kvp$values)
40+
values = lapply(1:length(kvp$values), function(i){
41+
right = kvp$values[[i]]
42+
attributes(right) <- NULL
43+
val_locale_attrs <- attributes(kvp$values)
44+
for(attr_name in names(val_locale_attrs)){
45+
locale_value <- val_locale_attrs[[attr_name]][[i]]
46+
attributes(locale_value) <- NULL
47+
attr(right, attr_name) <- locale_value
48+
}
49+
return(right)
50+
})
51+
self$setValues(values)
4152
}
4253
},
4354

@@ -47,10 +58,10 @@ geoflow_right <- R6Class("geoflow_right",
4758
self$key <- key
4859
},
4960

50-
#'@description Sets value
51-
#'@param value value
52-
setValue = function(value){
53-
self$value <- value
61+
#'@description Sets values
62+
#'@param values values
63+
setValues = function(values){
64+
self$values <- c(self$values, values)
5465
}
5566
)
5667
)

inst/actions/geometa_create_iso_19115.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,19 @@ function(action, entity, config){
377377
if(length(licenses)>0){
378378
legal_constraints$addUseConstraint("license")
379379
for(license in licenses){
380-
legal_constraints$addUseLimitation(license$value, locales = geoflow::get_locales_from(license$value))
380+
for(value in license$values){
381+
legal_constraints$addUseLimitation(value, locales = geoflow::get_locales_from(value))
382+
}
381383
}
382384
}
383385
#use limitation
384386
uses <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) %in% c("use","uselimitation")})]
385387
if(length(uses)>0){
386-
for(use in uses) legal_constraints$addUseLimitation(use$value, locales = geoflow::get_locales_from(use$value))
388+
for(use in uses){
389+
for(value in use$values){
390+
legal_constraints$addUseLimitation(value, locales = geoflow::get_locales_from(value))
391+
}
392+
}
387393
}
388394
#use constraints
389395
useConstraints <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "useconstraint"})]
@@ -398,7 +404,11 @@ function(action, entity, config){
398404
#other constraints
399405
otherConstraints <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "otherconstraint"})]
400406
if(length(otherConstraints)>0){
401-
for(otherConstraint in otherConstraints) legal_constraints$addOtherConstraint(otherConstraint$value, locales = geoflow::get_locales_from(otherConstraint$value))
407+
for(otherConstraint in otherConstraints){
408+
for(value in otherConstraint$values){
409+
legal_constraints$addOtherConstraint(value, locales = geoflow::get_locales_from(value))
410+
}
411+
}
402412
}
403413
ident$addResourceConstraints(legal_constraints)
404414
}

0 commit comments

Comments
 (0)