Skip to content

Commit

Permalink
#3 working on CSW3 & trying again docker geopython/pycsw
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jul 28, 2018
1 parent ff1456c commit 5e5a047
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 55 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ before_install:
# --> GeoNetwork
- docker run --name geonetwork -d -p 8282:8080 pobsteta/docker-geonetwork:3.0.5
# --> pycsw
- docker pull axiom/docker-pycsw
- chmod 777 $TRAVIS_BUILD_DIR/tests/pycsw/database
- chmod 777 $TRAVIS_BUILD_DIR/tests/pycsw/database/cite.db
- docker run --name pycsw -v $TRAVIS_BUILD_DIR/tests/pycsw/pycsw.cfg:/opt/pycsw/default.cfg -v $TRAVIS_BUILD_DIR/tests/pycsw/database:/database -d -p 8000:8000 axiom/docker-pycsw
- docker pull geopython/pycsw:latest
- docker run --name pycsw -v $TRAVIS_BUILD_DIR/tests/pycsw/pycsw.cfg:/etc/pycsw/pycsw.cfg -d -p 8000:8000 geopython/pycsw:latest
#- chmod 777 $TRAVIS_BUILD_DIR/tests/pycsw/database
#- chmod 777 $TRAVIS_BUILD_DIR/tests/pycsw/database/cite.db
#- docker pull axiom/docker-pycsw
#- docker run --name pycsw -v $TRAVIS_BUILD_DIR/tests/pycsw/pycsw.cfg:/opt/pycsw/default.cfg -v $TRAVIS_BUILD_DIR/tests/pycsw/database:/database -d -p 8000:8000 axiom/docker-pycsw


r:
Expand Down
2 changes: 1 addition & 1 deletion R/CSWCapabilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CSWCapabilities <- R6Class("CSWCapabilities",
initialize = function(url, version, logger = NULL) {
owsVersion <- switch(version,
"2.0.2" = "1.1",
"3.0" = "2.0"
"3.0.0" = "2.0"
)
super$initialize(url, service = "CSW", serviceVersion = version,
owsVersion = owsVersion, logger = logger)
Expand Down
3 changes: 2 additions & 1 deletion R/CSWClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CSWClient <- R6Class("CSWClient",
public = list(
#initialize
initialize = function(url, serviceVersion = NULL, user = NULL, pwd = NULL, logger = NULL) {
if(startsWith(serviceVersion, "3.0")) serviceVersion <- "3.0"
if(startsWith(serviceVersion, "3.0")) serviceVersion <- "3.0.0"
super$initialize(url, service = private$serviceName, serviceVersion, user, pwd, logger)
self$capabilities = CSWCapabilities$new(self$url, self$version, logger = logger)
},
Expand Down Expand Up @@ -101,6 +101,7 @@ CSWClient <- R6Class("CSWClient",
self$ERROR(errorMsg)
stop(errorMsg)
}
query$setServiceVersion(self$getVersion())
request <- CSWGetRecords$new(op, self$getUrl(), self$getVersion(),
user = self$getUser(), pwd = self$getPwd(),
query = query, logger = self$loggerType, ...)
Expand Down
17 changes: 12 additions & 5 deletions R/CSWConstraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
#' @format \code{\link{R6Class}} object.
#' @section Methods:
#' \describe{
#' \item{\code{new(cqlText, filter, cswVersion)}}{
#' \item{\code{new(cqlText, filter, serviceVersion)}}{
#' This method is used to instantiate an CSWConstraint object.
#' }
#' }
CSWConstraint <- R6Class("CSWConstraint",
inherit = OGCAbstractObject,
private = list(
xmlElement = "Constraint",
xmlNamespaceBase = "http://www.opengis.net/cat/csw",
xmlNamespace = c(csw = "http://www.opengis.net/cat/csw")
),
public = list(
wrap = TRUE,
CqlText = NULL,
filter = NULL,
initialize = function(cqlText = NULL, filter = NULL, cswVersion = "2.0.2"){
nsName <- names(private$xmlNamespace)
private$xmlNamespace = paste(private$xmlNamespace, cswVersion, sep="/")
names(private$xmlNamespace) <- nsName
initialize = function(cqlText = NULL, filter = NULL, serviceVersion = "2.0.2"){
self$setServiceVersion(serviceVersion)
super$initialize(attrs = list(version = "1.1.0"))
if(!is.null(cqlText)) if(!is(cqlText, "character")){
stop("The argument 'cqlText' should be an object of class 'character'")
Expand All @@ -33,6 +32,14 @@ CSWConstraint <- R6Class("CSWConstraint",
}
self$CqlText = cqlText
self$filter = filter
},

#setServiceVersion
setServiceVersion = function(serviceVersion){
nsVersion <- ifelse(serviceVersion=="3.0.0", "3.0", serviceVersion)
private$xmlNamespace = paste(private$xmlNamespaceBase, nsVersion, sep="/")
names(private$xmlNamespace) <- ifelse(serviceVersion=="3.0.0", "csw30", "csw")
}

)
)
18 changes: 9 additions & 9 deletions R/CSWGetRecordById.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @section Methods:
#' \describe{
#' \item{\code{new(op, url, version, user, pwd, id, elementSetName, logger, ...)}}{
#' \item{\code{new(op, url, serviceVersion, user, pwd, id, elementSetName, logger, ...)}}{
#' This method is used to instantiate a CSWGetRecordById object
#' }
#' }
Expand All @@ -29,7 +29,7 @@ CSWGetRecordById <- R6Class("CSWGetRecordById",
public = list(
Id = NA,
ElementSetName = "full",
initialize = function(op, url, version,
initialize = function(op, url, serviceVersion = "2.0.2",
user = NULL, pwd = NULL,
id, elementSetName = "full", logger = NULL, ...) {
self$Id = id
Expand All @@ -44,17 +44,17 @@ CSWGetRecordById <- R6Class("CSWGetRecordById",
contentType = "text/xml", mimeType = "text/xml",
logger = logger, ...)

nsName <- names(private$xmlNamespace)
private$xmlNamespace = paste(private$xmlNamespace, version, sep="/")
names(private$xmlNamespace) <- nsName
nsVersion <- ifelse(serviceVersion=="3.0.0", "3.0", serviceVersion)
private$xmlNamespace = paste(private$xmlNamespace, nsVersion, sep="/")
names(private$xmlNamespace) <- ifelse(serviceVersion=="3.0.0", "csw30", "csw")

self$attrs <- private$defaultAttrs

#version
self$attrs$version = version
#serviceVersion
self$attrs$version = serviceVersion

#output schema
self$attrs$outputSchema = paste(self$attrs$outputSchema, version, sep="/")
self$attrs$outputSchema = paste(self$attrs$outputSchema, nsVersion, sep="/")
outputSchema <- list(...)$outputSchema
if(!is.null(outputSchema)){
self$attrs$outputSchema = outputSchema
Expand Down Expand Up @@ -123,7 +123,7 @@ CSWGetRecordById <- R6Class("CSWGetRecordById",
warnings(warnMsg)
self$WARN(warnMsg)
self$WARN("Dublin Core returned as R list...")
recordsXML <- getNodeSet(private$response, "//csw:Record", private$xmlNamespace[1])
recordsXML <- getNodeSet(private$response, "//csw30:Record", private$xmlNamespace[1])
if(length(recordsXML)>0){
recordXML <- recordsXML[[1]]
children <- xmlChildren(recordXML)
Expand Down
28 changes: 14 additions & 14 deletions R/CSWGetRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @section Methods:
#' \describe{
#' \item{\code{new(op, url, version, user, pwd, query, logger, ...)}}{
#' \item{\code{new(op, url, serviceVersion, user, pwd, query, logger, ...)}}{
#' This method is used to instantiate a CSWGetRecords object
#' }
#' }
Expand All @@ -32,28 +32,28 @@ CSWGetRecords <- R6Class("CSWGetRecords",
),
public = list(
Query = NULL,
initialize = function(op, url, version = "2.0.2",
initialize = function(op, url, serviceVersion = "2.0.2",
user = NULL, pwd = NULL,
query = NULL, logger = NULL, ...) {
super$initialize(op, "POST", url, request = private$xmlElement,
user = user, pwd = pwd,
contentType = "text/xml", mimeType = "text/xml",
logger = logger, ...)

nsName <- names(private$xmlNamespace)
private$xmlNamespace = paste(private$xmlNamespace, version, sep="/")
names(private$xmlNamespace) <- nsName
nsVersion <- ifelse(serviceVersion=="3.0.0", "3.0", serviceVersion)
private$xmlNamespace = paste(private$xmlNamespace, nsVersion, sep="/")
names(private$xmlNamespace) <- ifelse(serviceVersion=="3.0.0", "csw30", "csw")

self$attrs <- private$defaultAttrs

#version
self$attrs$version = version
self$attrs$version = serviceVersion

#resultsType
resultType <- list(...)$resultType
if(!is.null(resultType)){
self$attrs$resultType = resultType
}
if(serviceVersion=="3.0.0") self$attrs$resultType = NULL

#startPosition
startPosition <- list(...)$startPosition
Expand All @@ -74,7 +74,7 @@ CSWGetRecords <- R6Class("CSWGetRecords",
}

#output schema
self$attrs$outputSchema = paste(self$attrs$outputSchema, version, sep="/")
self$attrs$outputSchema = paste(self$attrs$outputSchema, nsVersion, sep="/")
outputSchema <- list(...)$outputSchema
if(!is.null(outputSchema)){
self$attrs$outputSchema = outputSchema
Expand All @@ -85,10 +85,10 @@ CSWGetRecords <- R6Class("CSWGetRecords",
"http://www.isotc211.org/2005/gmd" = "gmd:MD_Metadata",
"http://www.isotc211.org/2005/gfc" = "gfc:FC_FeatureCatalogue",
"http://www.opengis.net/cat/csw/2.0.2" = "csw:Record",
"http://www.opengis.net/cat/csw/3.0" = "csw:Record",
"http://www.opengis.net/cat/csw/3.0" = "csw30:Record",
"http://www.w3.org/ns/dcat#" = "dcat"
)
if(typeNames != "csw:Record"){
if(!(typeNames %in% c("csw:Record","csw30:Record"))){
private$xmlNamespace = c(private$xmlNamespace, ns = self$attrs$outputSchema)
names(private$xmlNamespace)[2] <- unlist(strsplit(typeNames,":"))[1]
}
Expand Down Expand Up @@ -159,12 +159,12 @@ CSWGetRecords <- R6Class("CSWGetRecords",
self$WARN("Dublin Core records returned as R lists...")
out <- private$response
resultElement <- switch(query$ElementSetName,
"full" = "csw:Record",
"brief" = "csw:BriefRecord",
"summary" = "csw:SummaryRecord"
"full" = "csw30:Record",
"brief" = "csw30:BriefRecord",
"summary" = "csw30:SummaryRecord"
)
out <- list()
recordsXML <- getNodeSet(private$response,paste0("//csw:GetRecordsResponse/csw:SearchResults/",resultElement), private$xmlNamespace[1])
recordsXML <- getNodeSet(private$response,paste0("//csw30:GetRecordsResponse/csw30:SearchResults/",resultElement), private$xmlNamespace[1])
if(length(recordsXML)>0){
out <- lapply(recordsXML, function(recordXML){
children <- xmlChildren(recordXML)
Expand Down
26 changes: 19 additions & 7 deletions R/CSWQuery.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
#' @format \code{\link{R6Class}} object.
#' @section Methods:
#' \describe{
#' \item{\code{new(filter, cswVersion)}}{
#' \item{\code{new(filter, serviceVersion)}}{
#' This method is used to instantiate an CSWQUery object.
#' }
#' }
CSWQuery <- R6Class("CSWQuery",
inherit = OGCAbstractObject,
private = list(
xmlElement = "Query",
xmlNamespace = c(csw = "http://www.opengis.net/cat/csw")
xmlNamespaceBase = "http://www.opengis.net/cat/csw",
xmlNamespace = c(csw = "http://www.opengis.net/cat/csw"),
typeNames = "csw:Record"
),
public = list(
ElementSetName = "full",
constraint = NULL,
initialize = function(elementSetName = "full", constraint = NULL,
typeNames = "csw:Record", cswVersion = "2.0.2"){
nsName <- names(private$xmlNamespace)
private$xmlNamespace = paste(private$xmlNamespace, cswVersion, sep="/")
names(private$xmlNamespace) <- nsName
super$initialize(attrs = list(typeNames = typeNames))
typeNames = "csw:Record", serviceVersion = "2.0.2"){
private$typeNames <- typeNames
self$setServiceVersion(serviceVersion)
super$initialize(attrs = list(typeNames = private$typeNames))
if(!is(elementSetName, "character")){
stop("The argument 'elementSetName' should be an object of class 'character'")
}
Expand All @@ -34,6 +35,17 @@ CSWQuery <- R6Class("CSWQuery",
stop("The argument 'constraint' should be an object of class 'OGCConstraint'")
}
self$constraint = constraint
},

#setServiceVersion
setServiceVersion = function(serviceVersion){
nsVersion <- ifelse(serviceVersion=="3.0.0", "3.0", serviceVersion)
private$xmlNamespace = paste(private$xmlNamespaceBase, nsVersion, sep="/")
names(private$xmlNamespace) <- ifelse(serviceVersion=="3.0.0", "csw30", "csw")
if(private$typeNames == "csw:Record" && serviceVersion=="3.0.0"){
private$typeNames <- paste0(names(private$xmlNamespace),":Record")
}
}

)
)
2 changes: 1 addition & 1 deletion R/OWSRequest.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ OWSRequest <- R6Class("OWSRequest",
outXML <- self$encode()

#headers
headers <- c("Content-type" = contentType)
headers <- c("Accept" = "application/xml", "Content-Type" = contentType)
if(!is.null(private$token)){
headers <- c(headers, "Authorization" = paste("Basic", private$token))
}
Expand Down
2 changes: 1 addition & 1 deletion man/CSWConstraint.Rd

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

2 changes: 1 addition & 1 deletion man/CSWGetRecordById.Rd

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

2 changes: 1 addition & 1 deletion man/CSWQuery.Rd

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

Binary file modified tests/pycsw/database/cite.db
Binary file not shown.
12 changes: 7 additions & 5 deletions tests/pycsw/pycsw.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# =================================================================
#
# Authors: Tom Kralidis <[email protected]>
# Ricardo Garcia Silva <[email protected]>
#
# Copyright (c) 2015 Tom Kralidis
# Copyright (c) 2017 Ricardo Garcia Silva
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand All @@ -28,14 +30,14 @@
# =================================================================

[server]
home=/opt/pycsw
url=http://localhost:8000/pycsw/csw.py
home=/home/pycsw
url=http://localhost/pycsw/csw.py
mimetype=application/xml; charset=UTF-8
encoding=UTF-8
language=en-US
maxrecords=10
loglevel=DEBUG
logfile=/opt/pycsw/pycsw.log
logfile=
#ogc_schemas_base=http://foo
#federatedcatalogues=http://catalog.data.gov/csw
#pretty_print=true
Expand Down Expand Up @@ -76,7 +78,7 @@ contact_role=pointOfContact

[repository]
# sqlite
database=sqlite:////database/cite.db
database=sqlite:////home/pycsw/tests/functionaltests/suites/cite/data/cite.db
# postgres
#database=postgresql://username:password@localhost/pycsw
# mysql
Expand All @@ -94,4 +96,4 @@ gemet_keywords=Utility and governmental services
conformity_service=notEvaluated
contact_name=Organization Name
contact_email[email protected]
temp_extent=YYYY-MM-DD/YYYY-MM-DD
temp_extent=YYYY-MM-DD/YYYY-MM-DD
2 changes: 1 addition & 1 deletion tests/testthat/test_CSWClient_v2_0_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ csw2 <- NULL
#--------------------------------------------------------------------------
#--> pycsw
test_that("CSW 2.0.2 - GetCapabilities | pycsw",{
csw2 <<- CSWClient$new("http://localhost:8000/csw", "2.0.2", logger="DEBUG")
csw2 <<- CSWClient$new("http://localhost:8000/csw", "2.0.2", logger="INFO")
expect_is(csw2, "CSWClient")
expect_equal(csw2$getVersion(), "2.0.2")
caps <- csw2$getCapabilities()
Expand Down
20 changes: 16 additions & 4 deletions tests/testthat/test_CSWClient_v3_0.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,23 @@ test_that("CSW 3.0 - Transaction - Delete",{
#CSW 3.0 – GetRecordById
#--------------------------------------------------------------------------
test_that("CSW 3.0 - GetRecordById",{
#TBD
record <- csw3$getRecordById(id = "urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f")
expect_is(record, "list")
})

#CSW 3.0 – GetRecords
#CSW 3.0 – GetRecords / csw30:Record (Dublin Core)
#--------------------------------------------------------------------------
test_that("CSW 3.0 - GetRecords",{
#TBD
test_that("CSW 3.0 - GetRecords - full",{
#as Dublin core records (R lists)
records <- csw3$getRecords(query = CSWQuery$new())
expect_equal(length(records), 5L)
#ignoring query param (default is CSWQuery$new())
records <- csw3$getRecords()
expect_equal(length(records), 5L)
})

test_that("CSW 3.0 - GetRecords - full / maxRecords",{
#as Dublin core records (R lists)
records <- csw3$getRecords(query = CSWQuery$new(), maxRecords = 10L)
expect_equal(length(records), 10L)
})

0 comments on commit 5e5a047

Please sign in to comment.