From 39e1ca8af0170e9146ff1c657b1339a067451109 Mon Sep 17 00:00:00 2001 From: eblondel Date: Thu, 21 Mar 2019 22:12:03 +0100 Subject: [PATCH] #6 method to list groups --- DESCRIPTION | 2 +- R/GNManager.R | 31 +++++++++++++++++++++++++++++++ R/geonapi.R | 2 +- man/geonapi.Rd | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c291407..1d83a08 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: geonapi Type: Package Title: 'GeoNetwork' API R Interface Version: 0.3-0 -Date: 2019-01-29 +Date: 2019-03-21 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 Description: Provides an R interface to the 'GeoNetwork' API () allowing to upload and publish metadata in a 'GeoNetwork' web-application and exposte it to OGC CSW. diff --git a/R/GNManager.R b/R/GNManager.R index 92274c0..1039ee9 100644 --- a/R/GNManager.R +++ b/R/GNManager.R @@ -266,6 +266,37 @@ GNManager <- R6Class("GNManager", return(class(self)[1]) }, + #getGroups + #--------------------------------------------------------------------------- + getGroups = function(){ + out <- NULL + self$INFO("Getting user groups...") + req <- GNUtils$GET( + url = self$getUrl(), + path = "/xml.info", + token = private$token, cookies = private$cookies, + user = private$user, pwd = private$pwd, + query = list(type = "groups"), + verbose = self$verbose.debug + ) + if(status_code(req) == 200){ + self$INFO("Successfully fetched user groups!") + xml <- GNUtils$parseResponseXML(req, "UTF-8") + xml.groups <- getNodeSet(xml, "//group/group") + out <- do.call("rbind", lapply(xml.groups, function(xml.group){ + out.group <- data.frame( + id = xmlGetAttr(xml.group, "id"), + name = xmlValue(xmlChildren(xml.group)$name), + stringsAsFactors = FALSE + ) + return(out.group) + })) + }else{ + self$ERROR("Error while fetching user groups") + } + return(out) + }, + #insertMetadata #--------------------------------------------------------------------------- insertMetadata = function(xml = NULL, file = NULL, geometa = NULL, group, diff --git a/R/geonapi.R b/R/geonapi.R index 25ec219..8bb446f 100644 --- a/R/geonapi.R +++ b/R/geonapi.R @@ -15,7 +15,7 @@ #' Package: \tab geonapi\cr #' Type: \tab Package\cr #' Version: \tab 0.3-0\cr -#' Date: \tab 2019-01-29\cr +#' Date: \tab 2019-03-21\cr #' License: \tab MIT\cr #' LazyLoad: \tab yes\cr #' } diff --git a/man/geonapi.Rd b/man/geonapi.Rd index b13e299..9afd920 100644 --- a/man/geonapi.Rd +++ b/man/geonapi.Rd @@ -16,7 +16,7 @@ Web-Services (Catalogue Service for the Web). Package: \tab geonapi\cr Type: \tab Package\cr Version: \tab 0.3-0\cr - Date: \tab 2019-01-29\cr + Date: \tab 2019-03-21\cr License: \tab MIT\cr LazyLoad: \tab yes\cr }