/
GSAbstractDataStore.R
88 lines (82 loc) · 3.47 KB
/
GSAbstractDataStore.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#' Geoserver REST API DataStore
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords geoserver rest api DataStore
#' @return Object of \code{\link{R6Class}} for modelling a GeoServer dataStore
#' @format \code{\link{R6Class}} object.
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
GSAbstractDataStore <- R6Class("GSAbstractDataStore",
inherit = GSAbstractStore,
private = list(
STORE_TYPE = "dataStore"
),
public = list(
#'@field connectionParameters the list of connection parameters
connectionParameters = NULL,
#'@description initializes an abstract data store
#'@param xml an object of class \link{xml_node-class} to create object from XML
#'@param type the type of coverage store
#'@param name coverage store name
#'@param description coverage store description
#'@param enabled whether the store should be enabled or not. Default is \code{TRUE}
#'@param connectionParameters the list of connection parameters
initialize = function(xml = NULL, type = NULL,
name = NULL, description = "", enabled = TRUE,
connectionParameters){
super$initialize(xml = xml, storeType = private$STORE_TYPE, type = type,
name = name, description = description, enabled = enabled)
if(!missing(xml) & !is.null(xml)){
if(!any(class(xml) %in% c("xml_document","xml_node"))){
stop("The argument 'xml' is not a valid XML object")
}
self$decode(xml)
}else{
self$connectionParameters = GSRESTEntrySet$new(rootName = "connectionParameters")
if(!missing(connectionParameters)){
if(!is.list(connectionParameters)) stop("Connection parameters should be provided as named list")
self$connectionParameters$setEntryset(connectionParameters)
}
}
},
#'@description Decodes a data store from XML
#'@param xml an object of class \link{xml_node-class}
#'@return an object of class \link{GSAbstractDataStore}
decode = function(xml){
xml = xml2::as_xml_document(xml)
super$decode(xml)
self$connectionParameters = GSRESTEntrySet$new(rootName = "connectionParameters", xml)
},
#'@description Set list connection parameters. The argument should be an object
#' of class \code{GSRESTEntrySet} giving a list of key/value parameter entries.
#'@param parameters an object of class \link{GSRESTEntrySet}
setConnectionParameters = function(parameters){
self$connectionParameters = parameters
},
#'@description Adds a connection parameter
#'@param key connection parameter key
#'@param value connection parameter value
#'@return \code{TRUE} if added, \code{FALSE} otherwise
addConnectionParameter = function(key, value){
added <- self$connectionParameters$addEntry(key, value)
return(added)
},
#'@description Sets a connection parameter
#'@param key connection parameter key
#'@param value connection parameter value
setConnectionParameter = function(key, value){
self$connectionParameters$setEntry(key, value)
},
#'@description Removes a connection parameter
#'@param key connection parameter key
#'@param value connection parameter value
#'@return \code{TRUE} if removed, \code{FALSE} otherwise
delConnectionParameter = function(key){
deleted <- self$connectionParameters$delEntry(key)
return(deleted)
}
)
)