-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgeoflow_software.R
845 lines (815 loc) · 42 KB
/
geoflow_software.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
#' geoflow_software
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#'
#' @name geoflow_software
#' @title Geoflow software class
#' @description This class models a software to be used by geoflow
#' @keywords software
#' @return Object of \code{\link{R6Class}} for modelling a software
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' \dontrun{
#' software<- geoflow_software$new(
#' id = "some-id",
#' type = "output",
#' software_type = "software",
#' definition = "definition",
#' packages = list(),
#' handler = function(){},
#' arguments = list(
#' url = list(def = "the software url")
#' ),
#' attributes = list(
#' workspace = list(def = "a workspace name in the software")
#' )
#' )
#' }
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
geoflow_software <- R6Class("geoflow_software",
inherit = geoflowLogger,
public = list(
#'@field id software id
id = NULL,
#'@field type software I/O type ("input" or "output")
type = NULL,
#'@field software_type type of software
software_type = NULL,
#'@field definition definition
definition = NULL,
#'@field packages list of packages required for the software functioning
packages = list(),
#'@field handler software handler function
handler = NULL,
#'@field arguments software arguments
arguments = list(),
#'@field parameters software parameters
parameters = list(),
#'@field attributes software attributes
attributes = list(),
#'@field properties software properties
properties = list(),
#'@field actions actions associated with the software
actions = list(),
#'@description Initializes a software
#'@param id id
#'@param type type "input" or "output"
#'@param software_type software type
#'@param packages list of packages required for the software functioning
#'@param definition software definition
#'@param handler software handler \code{function}
#'@param arguments software handler arguments
#'@param attributes software attributes
#'@param actions software actions
initialize = function(id = NULL, type = NULL, software_type,
packages = list(), definition, handler,
arguments, attributes = list(),
actions = list()){
self$setId(id)
if(!is.null(type)) self$setType(type)
self$setSoftwareType(software_type)
self$setPackages(packages)
self$setDefinition(definition)
self$setHandler(handler)
self$setArguments(arguments)
self$setAttributes(attributes)
self$setActions(actions)
},
#'@description Sets software ID
#'@param id id
setId = function(id){
self$id <- id
},
#'@description Set type. Either "input" or "output"
#'@param type software I/O type
setType = function(type){
if(!(type %in% c("input","output"))){
stop("The type should be either an 'input' or 'output'!")
}
self$type <- type
},
#'@description Set software type
#'@param software_type software type
setSoftwareType = function(software_type){
self$software_type <- software_type
},
#'@description Set software required packages
#'@param packages list of package names
setPackages = function(packages){
self$packages <- packages
},
#'@description Set software definition
#'@param definition software definition
setDefinition = function(definition){
self$definition <- definition
},
#'@description Set attributes. Function to call when creating an instance of \code{geoflow_software}
#'@param attributes named list of attributes
setAttributes = function(attributes){
self$attributes <- attributes
},
#'@description Set properties. Function to call to pass argument values for a given \code{geoflow_software}
#'@param props named list of properties
setProperties = function(props){
propNames <- names(props)
if(length(propNames)>0){
for(propName in propNames){
if(!(propName %in% names(self$properties))){
stop(sprintf("The property '%s' is not a valid property for software '%s'. The parameter should be among values [%s]. To see a comprehensive properties list, use the following the code: list_software_properties(\"%s\")",
paramName, self$software_type, paste(names(self$attributes), collapse=","), self$software_type))
}
self$properties[[propName]] <- props[[propName]]
}
}
},
#'@description Set software arguments. Function to call when creating an instance of \code{geoflow_software}
#'@param arguments list of software arguments
setArguments = function(arguments){
self$arguments <- arguments
},
#'@description Set parameters. Function to call to pass argument values for a given \code{geoflow_software}
#'@param params named list of parameters
setParameters = function(params){
paramNames <- names(params)
if(length(paramNames)>0){
for(paramName in paramNames){
if(!(paramName %in% names(self$arguments))){
stop(sprintf("The parameter '%s' is not a valid parameter for software '%s'. The parameter should be among values [%s]. To see a comprehensive parameters list, use the following the code: list_software_parameters(\"%s\")",
paramName, self$software_type, paste(names(self$arguments), collapse=","), self$software_type))
}
self$parameters[[paramName]] <- params[[paramName]]
}
}
},
#'@description Set software actions
#'@param actions a list of \code{geoflow_action}
setActions = function(actions){
self$actions <- actions
},
#'@description Set the software handler function
#'@param handler object of class \code{function}
setHandler = function(handler){
self$handler <- handler
},
#'@description Check that all packages required for the software are available, if yes,
#' import them in the R session, and return a \code{data.frame} giving the
#' packages names and version. If one or more packages are unavailable,
#' an error is thrown and user informed of the missing packages.
checkPackages = function(){
self$INFO(sprintf("Check package dependencies for software '%s' (%s)", self$id, self$software_type))
out_pkgs <- try(check_packages(self$packages))
if(is(out_pkgs,"try-error")){
errMsg <- sprintf("One or more packages are not imported although required for software '%s' (%s)",
self$id, self$software_type)
self$ERROR(errMsg)
stop(errMsg)
}else{
if(is.null(out_pkgs)){
self$INFO(sprintf("No additional package required for software '%s' (%s):",
self$id, self$software_type))
}else{
self$INFO(sprintf("The following packages have been imported for software '%s' (%s):",
self$id, self$software_type))
print(out_pkgs)
}
}
},
#'@description Get the software handler instance
#'@return an object instance of the software handler
getHandlerInstance = function(){
#get handler
handler_params = paste(sapply(names(self$parameters), function(paramName){
paramValue <- self$parameters[[paramName]]
if(is.character(paramValue)) paramValue <- paste0("\"",paramValue,"\"")
#manage argument handler (if defined)
argIdx = which(paramName == names(self$arguments))
if(length(argIdx)>0){
if(!is.null(self$arguments[[argIdx]]$handler)){
paramValue <- paste0("self$arguments[[",argIdx,"]]$handler", "(", paramValue, ")")
}
}
return(paste(paramName," = ",paramValue))
}),collapse=", ")
instance <- eval(parse(text=paste0("self$handler(",handler_params,")")))
return(instance)
}
)
)
#' @name register_software
#' @aliases register_software
#' @title register_software
#' @description \code{register_software} registers default geoflow software
#'
#' @usage register_software()
#'
#' @note Function called on load by geoflow
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#' @export
#'
register_software <- function(){
software <- list(
#-------------------------------------------------------------------------------------------------------
#DBI
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "dbi",
definition = "Data Base Interface powered by 'DBI' package",
packages = list("DBI", "RSQLite", "RPostgres"),
handler = try(DBI::dbConnect, silent = TRUE),
arguments = list(
drv = list(label = "DBI driver", def = "DBI driver name", class = "character", handler = try(DBI::dbDriver, silent = TRUE)),
user = list(label = "Username", def = "Username", class = "character"),
password = list(label = "Password", def = "Password", class = "character"),
host = list(label = "Hostname", def = "Hostname", class = "character"),
port = list(label = "Port number", def = "Port number", class = "integer"),
dbname = list(label = "Database name", def = "Database name", class = "character"),
options = list(label = "Options", def = "Connection options", class = "character")
),
attributes = list(
onstart_sql = list(label = "SQL 'on-start' script", def = "An SQL script to be run on workflow start", class = "character"),
onstart_r = list(label = "R 'on-start' SQL generating script", def = "R instructions to generate a SQL. It should be made of 2 properties 'script' (name
of the R script) that should include a function standardized with parameter config (being the
DBI software config) and will output a character representing the SQL. The name of the function
is to specify in 'fun' property."),
onend_sql = list(label = "SQL 'on-end' script", def = "An SQL script to be run on workflow end", class = "character"),
onend_r = list(label = "R 'on-end' SQL generating script", def = "R instructions to generate a SQL. It should be made of 2 properties 'script' (name of the R script)
that should include a function standardized with parameter config (being the DBI software config) and will output
a character representing the SQL. The name of the function is to specify in 'fun' property."),
metadata_table = list(label = "Entities metadata table", def = "Name of a metadata table to read entities from it, if no source is specified.", class = "character")
),
actions = list(
onstart = function(config, software, software_config){
if(!is.null(software_config$properties$onstart_sql) || !is.null(software_config$properties$onstart_r)){
config$logger.info(sprintf("DBI [id='%s'] Execute 'onstart' action",software_config$id))
sql <- NULL
if(!is.null(software_config$properties$onstart_sql)){
config$logger.info(sprintf("SQL script = %s", software_config$properties$onstart_sql))
sql <- paste0(readLines(get_config_resource_path(config, software_config$properties$onstart_sql)),collapse="\n")
}else if(!is.null(software_config$properties$onstart_r)){
if(is.null(software_config$properties$onstart_r$script)){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onstart' from R - Missing 'script'",software_config$id)
config$logger.error(errMsg)
stop(errMsg)
}
if(is.null(software_config$properties$onstart_r$fun)){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onstart' from R - Missing 'fun'",software_config$id)
config$logger.error(errMsg)
stop(errMsg)
}
src <- try(source(get_config_resource_path(config, software_config$properties$onstart_r$script)))
if(is(src,"try-error")){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onstart' from R - Error while sourcing script '%s'",
software_config$id, software_config$properties$onstart_r$script)
config$logger.error(errMsg)
stop(errMsg)
}
onstart_r_fun <- eval(parse(text=software_config$properties$onstart_r$fun))
sql <- try(onstart_r_fun(config, software, software_config))
if(is(sql,"try-error")){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onstart' from R - Error while executing function '%s'",
software_config$id, software_config$properties$onstart_r$fun)
config$logger.error(errMsg)
stop(errMsg)
}
}
config$logger.info(sprintf("DBI [id='%s'] Executing SQL",software_config$id))
config$logger.info(paste0("\n", sql))
#write sql to file
if (!dir.exists("sql")){
config$logger.info(sprintf("Creating 'sql' directory: %s", file.path(getwd(), "sql")))
dir.create(file.path(getwd(), "sql"))
}
sqlfilename <- paste0(software_config$id, "_onstart.sql")
config$logger.info(sprintf("DBI [id='%s'] Writing SQL file '%s' to job directory",software_config$id, sqlfilename))
writeChar(sql, file.path(getwd(), "sql", sqlfilename), eos = NULL)
#send sql to dB
out <- try(DBI::dbSendQuery(software, sql))
if(is(out,"try-error")){
errMsg <- sprintf("DBI [id='%s'] Error while executing SQL",software_config$id)
config$logger.error(errMsg)
stop(errMsg)
}
config$logger.info(sprintf("DBI [id='%s'] Successful SQL execution!",software_config$id))
}else{
config$logger.info(sprintf("DBI [id='%s'] No 'sqlonstart' property. Skipping 'onstart' action",software_config$id))
}
},
onend = function(config, software, software_config){
if(!is.null(software_config$properties$onend_sql) || !is.null(software_config$properties$onend_r)){
config$logger.info(sprintf("DBI [id='%s'] Execute 'onend' action",software_config$id))
sql <- NULL
if(!is.null(software_config$properties$onend_sql)){
config$logger.info(sprintf("SQL script = %s", software_config$properties$onend_sql))
sql <- paste0(readLines(get_config_resource_path(config, software_config$properties$onend_sql)),collapse="\n")
}else if(!is.null(software_config$properties$onend_r)){
if(is.null(software_config$properties$onend_r$script)){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onend' from R - Missing 'script'",software_config$id)
config$logger.error(errMsg)
stop(errMsg)
}
if(is.null(software_config$properties$onend_r$fun)){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onend' from R - Missing 'fun'",software_config$id)
config$logger.error(errMsg)
stop(errMsg)
}
src <- try(source(get_config_resource_path(config, software_config$properties$onend_r$script)))
if(is(src,"try-error")){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onend' from R - Error while sourcing script '%s'",
software_config$id, software_config$properties$onend_r$script)
config$logger.error(errMsg)
stop(errMsg)
}
onend_r_fun <- eval(parse(text=software_config$properties$onend_r$fun))
print(class(onend_r_fun))
sql <- try(onend_r_fun(config, software, software_config))
if(is(sql,"try-error")){
errMsg <- sprintf("DBI [id='%s'] Error to init 'onend' from R - Error while executing function '%s'",
software_config$id, software_config$properties$onend_r$fun)
config$logger.error(errMsg)
stop(errMsg)
}
}
config$logger.info(sprintf("DBI [id='%s'] Executing SQL",software_config$id))
config$logger.info(paste0("\n", sql))
#write sql to file
if (!dir.exists("sql")){
config$logger.info(sprintf("Creating 'sql' directory: %s", file.path(getwd(), "sql")))
dir.create(file.path(getwd(), "sql"))
}
sqlfilename <- paste0(software_config$id, "_onend.sql")
config$logger.info(sprintf("DBI [id='%s'] Writing SQL file '%s' to job directory",software_config$id, sqlfilename))
writeChar(sql, file.path(getwd(), "sql", sqlfilename), eos = NULL)
#send sql to dB
out <- try(DBI::dbSendQuery(software, sql))
if(is(out,"try-error")){
errMsg <- sprintf("DBI [id='%s'] Error while executing SQL",software_config$id)
config$logger.error(errMsg)
stop(errMsg)
}
config$logger.info(sprintf("DBI [id='%s'] Successful SQL execution!",software_config$id))
}else{
config$logger.info(sprintf("DBI [id='%s'] No 'onend_sql' property. Skipping 'onend' action",software_config$id))
}
}
)
),
#-------------------------------------------------------------------------------------------------------
#GOOGLE DRIVE
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "googledrive",
definition = "Google Drive access powered by 'googledrive' package",
packages = list("googledrive"),
handler = try(googledrive::drive_auth, silent = TRUE),
arguments = list(
email = list(label = "Email", def = "User email to authenticate in Google Drive", class = "character"),
path = list(label = "Path", def = "An optional path within the Google drive repository. Default will be the root", class = "character"),
token = list(label = "User token", def = "The user authentication token. To get your token in R: gargle::token_fetch()$credentials$access_token", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#INSPIRE METADATA VALIDATOR
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "inspire",
definition = "INSPIRE Metadata validator, powered by 'geometa' package",
packages = list("geometa"),
handler = try(geometa::INSPIREMetadataValidator$new, silent = TRUE),
arguments = list(
url = list(label = "INSPIRE Metadata validator URL", def = "URL of the INSPIRE metadata validator instance. By default use 'https://inspire.ec.europa.eu/validator/v2'", class = "character", default = "https://inspire.ec.europa.eu/validator/v2"),
apiKey = list(label = "API Key", def = "API user key to authenticate to INSPIRE API gateway", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#OGC CSW
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "csw",
definition = "OGC Catalogue Service for the Web (CSW) client powered by 'ows4R' package",
packages = list("ows4R"),
handler = try(ows4R::CSWClient$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "CSW service endpoint URL", class = "character"),
serviceVersion = list(label = "Service version", def = "CSW service version ('2.0.2' or '3.0')", class = "character"),
user = list(label = "Username", def = "Username for CSW authentication (optional)", class = "character"),
pwd = list(label = "Password", def = "Password for CSW authentication (optional)", class = "character"),
logger = list(label = "Logger", def = "Level for 'ows4R' logger messages (NULL,INFO or DEBUG)", class = "character", choices = c("INFO", "DEBUG"))
)
),
#-------------------------------------------------------------------------------------------------------
#OGC WFS
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "wfs",
definition = "OGC Web Feature Service (WFS) client powered by 'ows4R' package",
packages = list("ows4R"),
handler = try(ows4R::WFSClient$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "WFS service endpoint URL", class = "character"),
serviceVersion = list(label = "Service version", def = "WFS service version ('1.0.0', '1.1.1', '2.0')", class = "character"),
user = list(label = "Username", def = "Username for WFS authentication (optional)", class = "character"),
pwd = list(label = "Password", def = "Password for WFS authentication (optional)", class = "character"),
logger = list(label = "Logger", def = "Level for 'ows4R' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = c("INFO", "DEBUG"))
)
),
#-------------------------------------------------------------------------------------------------------
#OGC WPS
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "wps",
definition = "OGC Web Processing Service (WPS) client powered by 'ows4R' package",
packages = list("ows4R"),
handler = try(ows4R::WPSClient$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "WPS service endpoint URL", class = "character"),
serviceVersion = list(label = "Service version", def = "WPS service version (limited to '1.0.0')", class = "character"),
user = list(label = "Username", def = "Username for WPS authentication (optional)", class = "character"),
pwd = list(label = "Password", def = "Password for WPS authentication (optional)", class = "character"),
logger = list(label = "Logger", def = "Level for 'ows4R' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = c("INFO", "DEBUG"))
)
),
#-------------------------------------------------------------------------------------------------------
#GEONETWORK API
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "geonetwork",
definition = "GeoNetwork API Client, powered by 'geonapi' package",
packages = list("geonapi"),
handler = try(geonapi::GNManager$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "GeoNetwork catalogue URL"),
version = list(label = "Geonetwork version", def = "Geonetwork catalogue version", class = "character"),
user = list(label = "Username", def = "Username for GeoNetwork authentication", class = "character"),
pwd = list(label = "Password", def = "Password for GeoNetwork authentication", class = "character"),
logger = list(label = "Logger", def = "Level for 'geonapi' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = c("INFO", "DEBUG"))
)
),
#-------------------------------------------------------------------------------------------------------
#GEOSERVER API
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "geoserver",
definition = "GeoServer REST API Client, powered by 'geosapi' package",
packages = list("geosapi"),
handler = try(geosapi::GSManager$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "GeoServer application URL", class = "character"),
user = list(label = "Username", def = "Username for GeoServer authentication", class = "character"),
pwd = list(label = "Password", def = "Password for GeoServer authentication", class = "character"),
logger = list(label = "Logger", def = "Level for 'geosapi' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = c("INFO", "DEBUG"))
),
attributes = list(
workspace = list(label = "Workspace", def = "GeoServer workspace name", class = "character"),
store = list(label = "Store", def = "GeoServer data/coverage store name", class = "character"),
publicUrl = list(label = "Public URL", def = "Geoserver public URL", class = "character")
),
actions = list(
onstart = function(config, software, software_config){
config$logger.info("Executing GeoServer 'onstart' action")
if(!is.null(config$properties$workspace)){
ws <- software$getWorkspace(config$properties$workspace)
if(is.null(ws)){
software$createWorkspace(config$properties$workspace, paste0("http://",config$properties$workspace))
}
}
#TODO to be completed with store creation cases
},
onend = function(config, software, software_config){
config$logger.info("Executing GeoServer 'onend' action")
software$reload()
}
)
),
#-------------------------------------------------------------------------------------------------------
#ZENODO
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "zenodo",
definition = "Zenodo client powered by 'zen4R' package",
packages = list("zen4R"),
handler = try(zen4R::ZenodoManager$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "Zenodo API URL. For sandbox tests, use 'https://sandbox.zenodo.org/api'", class = "character", choices = c("https://zenodo.org/api","https://sandbox.zenodo.org/api")),
token = list(label = "User token", def = "Zenodo user authentication token.", class = "character"),
logger = list(label = "Logger", def = "Level for 'zen4R' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = c("INFO","DEBUG"))
),
attributes = list(
clean = list(label = "Clean", def = "An option, to clean draft Zenodo deposits prior to any new deposit. To clean deposits, enable 'run',
and optionally specify either a 'query' (ElasticSearch Zenodo query), a list of 'doi', or 'community' for which
you want to restrain the cleaning operation.")
)
),
#-------------------------------------------------------------------------------------------------------
#DATAVERSE SWORD CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "sword_for_dataverse",
definition = "Dataverse SWORD API Client powered by 'atom4R' package",
packages = list("atom4R"),
handler = try(atom4R::SwordDataverseClient$new, silent = TRUE),
arguments = list(
hostname = list(label = "URL", def = "Dataverse base URL", class = "character"),
token = list(label = "User token", def = "Dataverse user authentication token", class = "character"),
logger = list(label = "Logger", def = "Level for 'atom4R' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = list("INFO","DEBUG"))
),
attributes = list(
dataverse = list(label = "Dataverse ID", def = "Dataverse id where to deposit/publish records", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#DATAVERSE NATIVE API CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "dataverse",
definition = "Dataverse Native API Client powered by 'dataverse' package",
packages = list("dataverse"),
handler = list,
arguments = list(
server = list(label = "URL", def = "Dataverse server URL", class = "character")
),
attributes = list(
dataverse = list(label = "Dataverse ID", def = "Dataverse id where to deposit/publish records", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#DATAONE CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "dataone",
definition = "DataONe API Client powered by 'dataone' package",
packages = list("dataone"),
handler = try(dataone::D1Client, silent = TRUE),
arguments = list(
x = list(label = "Contributing Node URL", def = "Contributing Node URL", handler = try(dataone::CNode, silent = TRUE), class = "character"),
y = list(label = "Member Node URL", def = "Member Node URL", handler = try(dataone::MNode, silent = TRUE), class = "character"),
token = list(label = "User token", def = "User Authorization token")
),
attributes = list(),
actions = list(
onstart = function(config, software, software_config){
config$logger.info("Executing DataOne 'onstart' action")
options(dataone_test_token = software_config$parameters$token)
options(dataone_token = software_config$parameters$token)
},
onend = function(config, software, software_config){
config$logger.info("Executing DataOne 'onend' action")
options(dataone_test_token = NULL)
options(dataone_token = NULL)
}
)
),
#-------------------------------------------------------------------------------------------------------
#D4SCIENCE STORAGE HUB CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "d4storagehub",
definition = "D4science storage hub API Client powered by 'd4storagehub4R' package",
packages = list("d4storagehub4R"),
handler = try(d4storagehub4R::StoragehubManager$new, silent = TRUE),
arguments = list(
token = list(label = "User token", def = "D4Science storage hub user authentication token", class = "character"),
logger = list(label = "Logger", def = "Level for 'd4storagehub4R' logger messages (NULL, 'INFO' or 'DEBUG')", class = "character", choices = list("INFO","DEBUG"))
),
attributes = list(
workspace = list(label = "Workspace", def = "D4Science storage hub workspace name", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#GBIF CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "gbif",
definition = "Gbif API Client powered by 'rgbif' package",
packages = list("rgbif"),
handler = list,
arguments = list(
user = list(label = "Username", def = "Username for Gbif authentication", class = "character"),
pwd = list(label = "Password", def = "Password for Gbif authentication", class = "character"),
email = list(label = "Email", def = "Email address for sending notification ", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#THREDDS CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "thredds",
definition = "Thredds data server API Client powered by 'thredds' package",
packages = list("thredds"),
handler = try(thredds::CatalogNode$new, silent = TRUE),
arguments = list(
x = list(label = "Catalog URL", def = "url of top level catalog request", class = "character"),
prefix = list(label = "Namespace", def = "the namespace to examine", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#OPENAPI CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "openapi",
definition = "OpenAPI client powered by 'rapiclient' package",
packages = list("rapiclient"),
handler = try({
openapi_handler <- function(url, api_key_name = "", api_key_value = ""){
api <- rapiclient::get_api(url)
api_headers <- list()
api_headers[[api_key_name]] <- api_key_value
api_ops <- rapiclient::get_operations(api, .headers = unlist(api_headers))
return(api_ops)
}
openapi_handler
}, silent = TRUE),
arguments = list(
url = list(label = "OpenAPI URL", def = "url of the OpenAPI JSON definition (now limited to OpenAPI v2)", class = "character"),
api_key_name = list(label = "Open API key name", def = "Name of the API key for registered uses", class = "character", default = ""),
api_key_value = list(label = "Open API key value", def = "Value of the API key for registered uses (typically a token)", class = "character", default = "")
)
),
#-------------------------------------------------------------------------------------------------------
#OCS CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "ocs",
definition = "Open Collaboration Services (OCS) client powered by 'ocs4R' package",
packages = list("ocs4R"),
handler = try(ocs4R::ocsManager$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "OCS service endpoint URL", class = "character"),
user = list(label = "Username", def = "Username for user authentication", class = "character"),
pwd = list(label = "Password", def = "Password for user authentication", class = "character"),
logger = list(label = "Logger", def = "Level for 'ows4R' logger messages (NULL,INFO or DEBUG)", class = "character", choices = c("INFO", "DEBUG"))
),
attributes = list(
cloud_path = list(label = "Cloud path", def = "Cloud path", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#GEONODE CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "geonode",
definition = "GeoNode client powered by 'geonode4R' package",
packages = list("geonode4R"),
handler = try(geonode4R::GeoNodeManager$new, silent = TRUE),
arguments = list(
url = list(label = "URL", def = "GeoNode endpoint URL", class = "character"),
user = list(label = "Username", def = "Username for user authentication", class = "character"),
pwd = list(label = "Password", def = "Password for user authentication", class = "character"),
logger = list(label = "Logger", def = "Level for 'geonode4R' logger messages (NULL,INFO or DEBUG)", class = "character", choices = c("INFO", "DEBUG"))
)
),
#-------------------------------------------------------------------------------------------------------
#WORLDBANK METADATA EDITOR CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "metadataeditr",
definition = "World Bank metadata editor client powered by 'metadataeditr' package",
packages = list("metadataeditr"),
handler = try(metadataeditr:::set_api, silent = TRUE),
arguments = list(
api_url = list(label = "API URL", def = "Metadata editor API endpoint URL", class = "character"),
api_key = list(label = "API key", def = "An API user authorization key (to be generated in the Metadata editor)", class = "character"),
verbose = list(label = "verbose", def = "Whether messages should be displayed or not", class = "logical", default = FALSE)
),
attributes = list(
collection_names = list(label = "Collection_names", def = "A coma-separated list of collection names where projects will be associated with", class = "character")
)
),
#-------------------------------------------------------------------------------------------------------
#SMTP CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "smtp",
definition = "SMTP Mail client powered by 'blastula' package",
packages = list("blastula"),
handler = try(blastula::creds_envvar, silent = TRUE),
arguments = list(
user = list(label = "User", def = "User", class = "character"),
pass_envvar = list(label = "Password Env Variable", def = "Environment variable name giving the password", class = "character", default = "SMTP_PASSWORD"),
provider = list(label = "Provider", def = "Provider", class = "character"),
host = list(label = "Host", def = "Host", class = "character"),
port = list(label = "Port", def = "Port", class = "integer"),
use_ssl = list(label = "Use SSL", def = "Use SSL", class = "logical", default = TRUE)
)
),
#-------------------------------------------------------------------------------------------------------
#SPARQL CLIENT
#-------------------------------------------------------------------------------------------------------
geoflow_software$new(
software_type = "sparql",
definition = "A SPARQL endpoint client",
packages = list(),
handler = list,
arguments = list(
endpoint = list(label = "Endpoint", def = "SPARQL endpoint URL", class = "character")
)
)
)
.geoflow$software <- software
}
#' @name list_software
#' @aliases list_software
#' @title list_software
#' @description \code{list_software} lists the software supported by geoflow.
#'
#' @usage list_software(raw)
#'
#' @param raw Default value is \code{FALSE}, meaning the software will be listed as
#' \code{data.frame}. The output If \code{TRUE} the raw list of \link{geoflow_software}
#' is returned.
#'
#' @return an object of class \code{data.frame} (or \code{list} of \link{geoflow_software} if raw = FALSE)
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#' @export
#'
list_software <- function(raw = FALSE){
software <- .geoflow$software
if(raw){
return(software)
}else{
software <- do.call("rbind", lapply(software, function(obj){
obj.out <- data.frame(
software_type = obj$software_type,
definition = obj$definition,
packages = paste(obj$packages, collapse=","),
stringsAsFactors = FALSE
)
return(obj.out)
}))
}
return(software)
}
#' @name list_software_parameters
#' @aliases list_software_parameters
#' @title list_software_parameters
#' @description \code{list_software_parameters} lists the parameters of a given software supported by geoflow.
#'
#' @usage list_software_parameters(software_type, raw)
#'
#' @param software_type A software type
#' @param raw if raw list should be returned
#'
#' @return an object of class \code{data.frame} (or \code{list} if raw is TRUE) listing the software parameters
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#' @export
#'
list_software_parameters <- function(software_type, raw = FALSE){
out <- NULL
software <- .geoflow$software[sapply(.geoflow$software, function(x){x$software_type == software_type})]
if(length(software)==0) stop(sprintf("No software '%s'!", software_type))
software <- software[[1]]
if(raw) return(software$arguments)
if(length(software$arguments)>0){
out <- data.frame(
name = names(software$arguments),
label = sapply(software$arguments, function(x){x$label}),
definition = sapply(software$arguments, function(x){x$def}),
stringsAsFactors = FALSE
)
row.names(out) <- 1:nrow(out)
}else{
out <- data.frame(name = character(0), label = character(0), definition = character(0))
}
return(out)
}
#' @name list_software_properties
#' @aliases list_software_properties
#' @title list_software_properties
#' @description \code{list_software_properties} lists the properties of a given software supported by geoflow.
#'
#' @usage list_software_properties(software_type, raw)
#'
#' @param software_type A software type
#' @param raw if raw list should be returned
#'
#' @return an object of class \code{data.frame} listing the software properties
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#' @export
#'
list_software_properties <- function(software_type, raw = FALSE){
out <- NULL
software <- .geoflow$software[sapply(.geoflow$software, function(x){x$software_type == software_type})]
if(length(software)==0) stop(sprintf("No software '%s'!", software_type))
software <- software[[1]]
if(raw) return(software$attributes)
if(length(software$attributes)>0){
out <- data.frame(
name = names(software$attributes),
label = sapply(software$attributes, function(x){x$label}),
definition = sapply(software$attributes, function(x){x$def}),
stringsAsFactors = FALSE
)
row.names(out) <- 1:nrow(out)
}else{
out <- data.frame(name = character(0), label = character(0), definition = character(0))
}
return(out)
}