Skip to content

Commit

Permalink
#19 support geometa inspireValidator parameter in insert/update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 24, 2022
1 parent 421eb39 commit 36dd42a
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 37 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Package: geonapi
Type: Package
Title: 'GeoNetwork' API R Interface
Version: 0.5-1
Date: 2022-01-14
Version: 0.5-2
Date: 2022-01-24
Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762")))
Maintainer: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
Description: Provides an R interface to the 'GeoNetwork' API (<https://geonetwork-opensource.org/#api>) allowing to upload and publish metadata in a 'GeoNetwork' web-application and expose it to OGC CSW.
Depends: R (>= 3.1.0), geometa, keyring
Imports: R6, openssl, httr, XML
Remotes: geometa
Suggests: testthat, roxygen2
License: MIT + file LICENSE
URL: https://github.com/eblondel/geonapi/wiki, https://geonetwork-opensource.org
Expand Down
24 changes: 16 additions & 8 deletions R/GNLegacyAPIManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@
#' \item{\code{getCategories()}}{
#' Retrieves the list of categories available in Geonetwork
#' }
#' \item{\code{insertMetadata(xml, file, geometa, group, category, stylesheet, validate, geometa_validate, geometa_inspire)}}{
#' \item{\code{insertMetadata(xml, file, geometa, group, category, stylesheet, validate, geometa_validate,
#' geometa_inspire, geometa_inspireValidator)}}{
#' Inserts a metadata by file, XML object or \pkg{geometa} object of class
#' \code{ISOMetadata} or \code{ISOFeatureCatalogue}. If successful, returns the Geonetwork
#' metadata internal identifier (integer). Extra parameters \code{geometa_validate} (TRUE
#' by default) and \code{geometa_inspire} (FALSE by default) can be used with geometa objects
#' for perform ISO and INSPIRE validation respectively.
#' for perform ISO and INSPIRE validation respectively. In that case on object of class
#' \code{geometa::INSPIREMetadataValidator}, with a proper user API key, should be specified as
#' \code{geometa_inspireValidator} argument.
#' }
#' \item{\code{setPrivConfiguration(id, config)}}{
#' Set the privilege configuration for a metadata. 'id' is the metadata integer id.
Expand All @@ -99,11 +102,14 @@
#' \item{\code{getInfoByUUID(uuid)}}{
#' Get a metadata Info by UUID. Returns an XML document object
#' }
#' \item{\code{updateMetadata(id, xml, file, geometa, geometa_validate, geometa_inspire)}}{
#' \item{\code{updateMetadata(id, xml, file, geometa, geometa_validate,
#' geometa_inspire, geometa_inspireValidator)}}{
#' Updates a metadata by file, XML object or \pkg{geometa} object of class
#' 'ISOMetadata' or 'ISOFeatureCatalogue'. Extra parameters \code{geometa_validate} (TRUE
#' by default) and \code{geometa_inspire} (FALSE by default) can be used with geometa objects
#' for perform ISO and INSPIRE validation respectively.
#' for perform ISO and INSPIRE validation respectively. In that case on object of class
#' \code{geometa::INSPIREMetadataValidator}, with a proper user API key, should be specified as
#' \code{geometa_inspireValidator} argument.
#' }
#' \item{\code{deleteMetadata(id)}}{
#' Deletes a metadata
Expand Down Expand Up @@ -318,7 +324,7 @@ GNLegacyAPIManager <- R6Class("GNLegacyAPIManager",
#---------------------------------------------------------------------------
insertMetadata = function(xml = NULL, file = NULL, geometa = NULL, group,
category = NULL, stylesheet = NULL, validate = FALSE,
geometa_validate = TRUE, geometa_inspire = FALSE){
geometa_validate = TRUE, geometa_inspire = FALSE, geometa_inspireValidator = NULL){
self$INFO("Inserting metadata ...")
out <- NULL
data <- NULL
Expand All @@ -337,7 +343,8 @@ GNLegacyAPIManager <- R6Class("GNLegacyAPIManager",
if(!is(geometa, "ISOMetadata") & !is(geometa, "ISOFeatureCatalogue")){
stop("Object 'geometa' should be of class 'ISOMetadata' or 'ISOFeatureCatalogue")
}
data <- geometa$encode(validate = geometa_validate, inspire = geometa_inspire)
data <- geometa$encode(validate = geometa_validate,
inspire = geometa_inspire, inspireValidator = geometa_inspireValidator)
}

if(is.null(data)){
Expand Down Expand Up @@ -504,7 +511,7 @@ GNLegacyAPIManager <- R6Class("GNLegacyAPIManager",
#updateMetadata
#---------------------------------------------------------------------------
updateMetadata = function(id, xml = NULL, file = NULL, geometa = NULL,
geometa_validate = TRUE, geometa_inspire = FALSE){
geometa_validate = TRUE, geometa_inspire = FALSE, geometa_inspireValidator = NULL){

self$INFO(sprintf("Updating metadata id = %s ...", id))
out <- NULL
Expand All @@ -524,7 +531,8 @@ GNLegacyAPIManager <- R6Class("GNLegacyAPIManager",
if(!is(geometa, "ISOMetadata") & !is(geometa, "ISOFeatureCatalogue")){
stop("Object 'geometa' should be of class 'ISOMetadata' or 'ISOFeatureCatalogue")
}
data <- geometa$encode(validate = geometa_validate, inspire = geometa_inspire)
data <- geometa$encode(validate = geometa_validate,
inspire = geometa_inspire, inspireValidator = geometa_inspireValidator)
}

if(is.null(data)){
Expand Down
33 changes: 21 additions & 12 deletions R/GNOpenAPIManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,33 @@
#' \item{\code{insertRecord(xml, file, geometa, metadataType, uuidProcessing,
#' group, category, rejectIfInvalid, publishToAll,
#' transformWith, schema, extra,
#' geometa_validate, geometa_inspire)}}{
#' geometa_validate, geometa_inspire, geometa_inspireValidator)}}{
#' Inserts a record by file, XML object or \pkg{geometa} object of class \code{ISOMetadata} or \code{ISOFeatureCatalogue}.
#' Extra parameters related to \pkg{geometa} objects: \code{geometa_validate} (TRUE by default) and \code{geometa_inspire}
#' (FALSE by default) can be used to perform ISO and INSPIRE validation respectively.
#' (FALSE by default) can be used to perform ISO and INSPIRE validation respectively. In that case on object of class
#' \code{geometa::INSPIREMetadataValidator}, with a proper user API key, should be specified as \code{geometa_inspireValidator}
#' argument.
#' }
#' \item{\code{insertMetadata(xml, file, geometa, metadataType, uuidProcessing,
#' group, category, rejectIfInvalid, publishToAll,
#' transformWith, schema, extra,
#' geometa_validate, geometa_inspire)}}{
#' geometa_validate, geometa_inspire, geometa_inspireValidator)}}{
#' Inserts a metadata by file, XML object or \pkg{geometa} object of class \code{ISOMetadata} or \code{ISOFeatureCatalogue}.
#' Extra parameters related to \pkg{geometa} objects: \code{geometa_validate} (TRUE by default) and \code{geometa_inspire}
#' (FALSE by default) can be used to perform ISO and INSPIRE validation respectively.
#' (FALSE by default) can be used to perform ISO and INSPIRE validation respectively. In that case on object of class
#' \code{geometa::INSPIREMetadataValidator}, with a proper user API key, should be specified as
#' \code{geometa_inspireValidator} argument.
#' }
#' \item{\code{updateMetadata(xml, file, geometa, metadataType,
#' group, category, rejectIfInvalid, publishToAll,
#' transformWith, schema, extra,
#' geometa_validate, geometa_inspire)}}{
#' geometa_validate, geometa_inspire, geometa_inspireValidator)}}{
#' Updates a metadata by file, XML object or \pkg{geometa} object of class
#' 'ISOMetadata' or 'ISOFeatureCatalogue'. Extra parameters \code{geometa_validate} (TRUE
#' by default) and \code{geometa_inspire} (FALSE by default) can be used with geometa objects
#' for perform ISO and INSPIRE validation respectively.
#' for perform ISO and INSPIRE validation respectively. In that case on object of class
#' \code{geometa::INSPIREMetadataValidator}, with a proper user API key, should be specified as
#' \code{geometa_inspireValidator} argument.
#' }
#' \item{\code{deleteMetadata(id, withBackup)}}{
#' Deletes a metadata
Expand Down Expand Up @@ -303,7 +309,7 @@ GNOpenAPIManager <- R6Class("GNOpenAPIManager",
metadataType = "METADATA", uuidProcessing = "NOTHING",
group, category = NULL, rejectIfInvalid = FALSE, publishToAll = TRUE,
transformWith = "_none_", schema = NULL, extra = NULL,
geometa_validate = TRUE, geometa_inspire = FALSE){
geometa_validate = TRUE, geometa_inspire = FALSE, geometa_inspireValidator = NULL){

allowedMetadataTypes <- c("METADATA", "TEMPLATE", "SUB_TEMPLATE", "TEMPLATE_OF_SUB_TEMPLATE")
if(!metadataType %in% allowedMetadataTypes){
Expand Down Expand Up @@ -338,7 +344,8 @@ GNOpenAPIManager <- R6Class("GNOpenAPIManager",
tempf = tempfile(tmpdir = tempdir())
file <- paste(tempf,".xml",sep='')
isTempFile <- TRUE
geometa$save(file = file, validate = geometa_validate, inspire = geometa_inspire)
geometa$save(file = file, validate = geometa_validate,
inspire = geometa_inspire, inspireValidator = geometa_inspireValidator)
}

if(is.null(file)){
Expand Down Expand Up @@ -391,13 +398,14 @@ GNOpenAPIManager <- R6Class("GNOpenAPIManager",
metadataType = "METADATA", uuidProcessing = "NOTHING",
group, category = NULL, rejectIfInvalid = FALSE, publishToAll = TRUE,
transformWith = "_none_", schema = NULL, extra = NULL,
geometa_validate = TRUE, geometa_inspire = FALSE){
geometa_validate = TRUE, geometa_inspire = FALSE, geometa_inspireValidator = NULL){
self$INFO("Inserting metadata ...")
inserted <- self$insertRecord(xml = xml, file = file, geometa = geometa,
metadataType = metadataType, uuidProcessing = uuidProcessing,
group = group, category = category, rejectIfInvalid = rejectIfInvalid, publishToAll = publishToAll,
transformWith = transformWith, schema = schema, extra = extra,
geometa_validate = geometa_validate, geometa_inspire = geometa_inspire)
geometa_validate = geometa_validate,
geometa_inspire = geometa_inspire, geometa_inspireValidator = geometa_inspireValidator)
},

#updateMetadata
Expand All @@ -406,13 +414,14 @@ GNOpenAPIManager <- R6Class("GNOpenAPIManager",
metadataType = "METADATA",
group, category = NULL, rejectIfInvalid = FALSE, publishToAll = TRUE,
transformWith = "_none_", schema = NULL, extra = NULL,
geometa_validate = TRUE, geometa_inspire = FALSE){
geometa_validate = TRUE, geometa_inspire = FALSE, geometa_inspireValidator = NULL){
self$INFO("Updating metadata ...")
self$insertRecord(xml = xml, file = file, geometa = geometa,
metadataType = metadataType, uuidProcessing = "OVERWRITE",
group = group, category = category, rejectIfInvalid = rejectIfInvalid, publishToAll = publishToAll,
transformWith = transformWith, schema = schema, extra = extra,
geometa_validate = geometa_validate, geometa_inspire = geometa_inspire)
geometa_validate = geometa_validate,
geometa_inspire = geometa_inspire, geometa_inspireValidator = geometa_inspireValidator)
},

#deleteMetadata
Expand Down
4 changes: 2 additions & 2 deletions R/geonapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#' \tabular{ll}{
#' Package: \tab geonapi\cr
#' Type: \tab Package\cr
#' Version: \tab 0.5-1\cr
#' Date: \tab 2022-01-14\cr
#' Version: \tab 0.5-2\cr
#' Date: \tab 2022-01-24\cr
#' License: \tab MIT\cr
#' LazyLoad: \tab yes\cr
#' }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
===========

[![Build Status](https://github.com/eblondel/geonapi/actions/workflows/r-cmd-check.yml/badge.svg?branch=master)](https://github.com/eblondel/geonapi/actions/workflows/r-cmd-check.yml)
[![Github_Status_Badge](https://img.shields.io/badge/Github-0.5--1-blue.svg)](https://github.com/eblondel/geonapi)
[![Github_Status_Badge](https://img.shields.io/badge/Github-0.5--2-blue.svg)](https://github.com/eblondel/geonapi)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/geonapi)](https://cran.r-project.org/package=geonapi)
[![CRAN checks](https://cranchecks.info/badges/worst/geonapi)](https://cran.r-project.org/web/checks/check_results_geonapi.html)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1345012.svg)](https://doi.org/10.5281/zenodo.1345012)
Expand Down
14 changes: 10 additions & 4 deletions man/GNLegacyAPIManager.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions man/GNOpenAPIManager.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/geonapi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 36dd42a

Please sign in to comment.