-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathargument_types.R
3157 lines (2751 loc) · 103 KB
/
argument_types.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
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Parameter ====
# should also be abstract
#' Parameter class
#'
#' This class defines parameters of [Process]. They store information about the type, format and
#' pattern. A parameter class is designed to not carry any value, as opposed to an
#' [Argument].
#'
#' The parameters are parsed from the specific description and format of the JSON
#' objects returned for the parameters in processes. Find a list of openEO-specific formats here:
#' [RFC7946](https://github.com/Open-EO/openeo-processes/blob/master/meta/subtype-schemas.json)
#'
#' @name Parameter
#'
#' @return Object of [R6::R6Class()] which represents a parameter.
#'
#'
#' @section Methods:
#' \describe{
#' \item{`$new(name, description, required=FALSE)`}{}
#' \item{`$getName`}{returns the name of a parameter as string}
#' \item{`$setName(name)`}{sets the name of a parameter}
#' \item{`$getDescription()`}{returns the description of a parameter}
#' \item{`$setDescription(description)`}{sets the description of a parameter}
#' \item{`$getPattern()`}{returns a string with the pattern of a parameter description}
#' \item{`$setPattern(pattern)`}{sets the pattern (string) for a parameter}
#' \item{`$getDefault()`}{returns the parameter's default value}
#' \item{`$setDefault(default)`}{sets the default value of a parameter}
#' \item{`$matchesSchema(schema)`}{returns TRUE if the given schema - a list of the parsed openEO
#' API schema object - matches the parameter's schema, which is used for finding the corresponding parameter}
#' \item{`$getSchema()`}{returns the schema definition}
#' \item{`$asParameterInfo()`}{returns a list representation of this parameter for being sent in a JSON to the openEO service}
#' \item{`$isNullable()`}{returns TRUE if the parameter is allowed to be nullable, FALSE otherwise}
#' \item{`$isRequired()`}{returns whether a parameter is mandatory or not}
#' \item{`$isAny()`}{returns TRUE if this parameter describes a choice of parameters}
#' }
#' @section Arguments:
#' \describe{
#' \item{`name`}{character - The name of a parameter}
#' \item{`description`}{character - The description of a parameter}
#' \item{`required`}{logical - whether it is required or not }
#' \item{`pattern`}{the regexp as a string indicating how to formulate the value}
#' \item{`default`}{the regexp as a string indicating how to formulate the value}
#' \item{`schema`}{the parsed schema object of a process parameter as a list}
#' }
#'
#' @importFrom rlang is_na
NULL
Parameter = R6Class(
"Parameter",
public = list(
initialize=function(name=character(), description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = FALSE
},
getName = function() {
return(private$name)
},
setName = function(name) {
private$name = name
},
getDescription = function() {
return(private$description)
},
setDescription = function(description) {
private$description = description
invisible(self)
},
getPattern = function() {
return(private$schema$pattern)
},
setPattern = function(pattern) {
private$schema$pattern = pattern
},
getEnum = function() {
return(private$schema$enum)
},
setEnum = function(enum){
private$schema$enum = enum
},
setDefault = function(default) {
private$default = default
invisible(self)
},
getDefault = function() {
return(private$default)
},
matchesSchema = function(schema) {
sel = c("type","subtype")
if (is.null(schema$type)) schema$type = character()
if (is.null(schema$subtype)) schema$subtype = character()
if (length(schema$type) == 0 && length(schema$subtype) == 0) return(TRUE)
return(setequal(private$schema[sel], schema[sel]))
},
getSchema = function() {
return(private$schema)
},
asParameterInfo = function() {
# the function will serialize a parameter as in a process definition, which will be used
# when describing a parameter as some sort of a variable
info = list()
info$name = self$getName()
if (length(self$getDescription()) > 0) {
if (!is.na(self$getDescription()) || nchar(self$getDescription()) > 0) {
info$description = self$getDescription()
}
}
if (self$isNullable) {
info$optional = TRUE
info$default = NA
}
# if the parameter is required "optional" can be left out
if (all(c("Argument","Parameter","R6") %in% class(self)) &&
all(class(self) %in% c("Argument","Parameter","R6"))) {
# this is an object where anything goes in (Any)
info$schema = list(description = "Any data type")
} else if (all(c("anyOf","Argument","Parameter","R6") %in% class(self))) {
info$schema = lapply(self$getChoice(), function(param) {
param$asParameterInfo()
})
if (self$isNullable) {
info$schema = append(private$schema, list(list(type = "null")))
}
} else if (self$isNullable) {
info$schema$type = list(private$schema$type,"null")
} else {
info$schema = private$schema
}
info$schema = .clean_empty_fields(info$schema)
return(info)
}
),
active = list(
isNullable = function(value) {
if (missing(value)) {
return(private$nullable)
} else {
value = as.logical(value)
if (rlang::is_na(value)) {
warning("Cannot cast value to logical. Assume FALSE.")
value = FALSE
}
private$nullable = value
}
},
isRequired = function(value) {
if (missing(value)) {
return(private$required)
} else {
value = as.logical(value)
if (rlang::is_na(value)) {
warning("Cannot cast value to logical. Assume FALSE.")
value = FALSE
}
private$required = value
}
},
isAny = function() {
length(private$schema$type) == 0
}
),
private = list(
name=character(),
nullable = FALSE,
default = character(),
schema = list(
type=character(),
subtype = character(),
pattern = character(),
parameters = list(), # potential ProcessGraphParameter (variables)
# items are relevant for arrays
items = list(
type=NULL # type name, e.g. "string", "array","number","any", etc.
),
minItems = integer(),
maxItems = integer(),
enum = character()
),
required = logical(),
description = character()
)
)
# Argument ====
#' Argument class
#'
#' This class inherits all fields and functions from [Parameter] adds the functionality to
#' manage a value. This includes getter/setter, validation and serialization. Since this is the parent class
#' for the type specific argument classes, the inheriting classes implement their own version of the private
#' functions `$typeCheck()` and `$typeSerialization()`.
#'
#' @name Argument
#'
#' @return Object of [R6::R6Class()] representing an argument.
#'
#' @section Methods:
#' \describe{
#' \item{`$setValue(value)`}{Assigns a value to this argument}
#' \item{`$getValue()`}{Returns the value of this argument}
#' \item{`$serialize()`}{returns a list representation of a openEO argument}
#' \item{`$validate()`}{return TRUE if the parameter is validated positively by the type check}
#' \item{`$isEmpty()`}{returns TRUE if the value is set}
#' \item{`$getProcess()`}{returns the process this parameter belongs to}
#' \item{`$setProcess(p)`}{sets the owning process for this parameter}
#' }
#' @section Arguments:
#' \describe{
#' \item{`value`}{The value for this argument.}
#' \item{`p`}{An object of class 'Process' or inheriting like 'ProcessNode'}
#' }
#'
#' @importFrom rlang is_na
NULL
Argument = R6Class(
"Argument",
inherit=Parameter,
public = list(
setValue = function(value) {
private$value = value
},
getValue = function() {
private$value
},
serialize = function() {
# nullable / required / value = NULL
if (self$isNullable &&
(length(self$getValue()) == 0 ||
(!is.environment(self$getValue()) &&
rlang::is_na(self$getValue())))
) {
if (self$isRequired) {
return(NA)
} else {
return(NULL)
}
}
if (any(c("ProcessGraphParameter") %in% class(self$getValue()))) {
return(self$getValue()$serialize())
}
if ("ProcessNode" %in% class(self$getValue())) {
return(self$getValue()$serializeAsReference())
}
# for format specific conversion overwrite this by children
tryCatch({
return(private$typeSerialization())
}, error = function(e) {
serialization_error = paste0("Error serializing parameter '",self$getName(),
"' in process node '", self$getProcess()$getNodeId(),
"' :",e$message)
stop(serialization_error)
})
},
validate = function() {
tryCatch(
{
private$checkRequiredNotSet()
if (!self$isRequired &&
!is.environment(private$value) &&
self$isEmpty()) {
} else {
# ProcessGraphParameter -> variable
# schema$type length == 0 -> ANY
if (any(c("ProcessGraphParameter") %in% class(self$getValue()))) return(invisible(NULL))
if ("ProcessNode" %in% class(self$getValue()) && self$getValue()$getReturns()$isAny) return(invisible(NULL))
private$typeCheck()
}
invisible(NULL)
}, error = function(e) {
if (length(self$getProcess()) >0 ) {
node_id = self$getProcess()$getNodeId()
if (!is.null(node_id)) node_id = paste0("[",node_id,"] ")
message = paste0(node_id,"Parameter '",private$name,"': ",e$message)
} else {
message = e$message
}
return(message)
}
)
},
isEmpty = function() {
return(!is.environment(private$value) && !is.function(private$value) && !is.call(private$value) && (
is.null(private$value) ||
rlang::is_na(private$value) ||
length(private$value) == 0))
},
getProcess = function() {
return(private$process)
},
setProcess = function(p) {
private$process = p
return(invisible(self))
}
),
# private =====
private = list(
value=NULL,
process = NULL,
checkRequiredNotSet = function() {
if (private$required &&
!self$isNullable &&
!is.environment(private$value) &&
self$isEmpty()) stop("Argument is required, but has not been set.")
},
typeCheck = function() {
# implemented / overwritten by children
},
typeSerialization = function() {
# implemented / overwritten by children
#if nothing is done, then simply return the object
if (self$isEmpty() && !self$isRequired) return(NULL)
else return(private$value)
},
deep_clone = function(name, value) {
if (name == "process") {
return(value)
}
# this is the anyOf case
if (name == "parameter_choice") {
new_list = list()
if (is.null(names(value))) {
iterable = 1:length(value)
} else {
iterable = names(value)
}
for (list_name in iterable) {
list_elem = value[[list_name]]
if ("R6" %in% class(list_elem)) {
list_elem = list_elem$clone(deep=TRUE)
}
entry = list(list_elem)
names(entry) = list_name
new_list = append(new_list,entry)
}
return(new_list)
}
if (is.environment(value) && !is.null(value$`.__enclos_env__`)) {
return(value$clone(deep = TRUE))
}
return(value)
}
)
)
# Integer ====
#' Integer class
#'
#' Inheriting from [Argument] in order to represent a single integer value.
#'
#' @name Integer
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing an Integer
NULL
Integer = R6Class(
"integer",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "integer"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 && !is.environment(private$value)) stop("Integer cannot be an array.")
if (!rlang::is_na(private$value) && !is.integer(private$value)) {
suppressWarnings({
coerced = as.integer(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into integer."))
# correct value if you can
private$value = coerced
}
return(invisible(NULL))
},
typeSerialization = function() {
if (self$isEmpty() && !self$isRequired) return(NULL)
else return(as.integer(private$value))
}
)
)
# EPSG-Code ====
#' EPSGCode class
#'
#' Inheriting from [Argument] in order to represent an EPSG Code. Allowed values are single integer values like `4326` or a text containing 'EPSG:' like `EPSG:4326`.
#'
#' @name EPSGCode
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing an EPSG code as Integer
NULL
EPSGCode = R6Class(
"epsg-code",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "integer"
private$schema$subtype = "epsg-code"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 && !is.environment(private$value)) stop("EPSG code cannot be an array.")
if (!rlang::is_na(private$value) && !is.integer(private$value)) {
suppressWarnings({
coerced = as.integer(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) {
if (is.character(private$value) && grepl(tolower(private$value),pattern = "^epsg:")) {
coerced = as.integer(gsub(x = private$value,replacement = "",pattern = "[^0-9]"))
} else {
stop(paste0("Value '", private$value,"' cannot be coerced into integer."))
}
}
# correct value if you can
private$value = coerced
return(invisible(NULL))
}
},
typeSerialization = function() {
if (self$isEmpty() && !self$isRequired) return(NULL)
else return(as.integer(private$value))
}
)
)
# Number ====
#' Number class
#'
#' Inheriting from [Argument] in order to represent a numeric value.
#'
#' @name Number
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing a number
NULL
Number = R6Class(
"number",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "number"
},
setValue = function(value) {
process_collection = self$getProcess()$getGraph()
private$value = .checkMathConstants(value,process_collection)
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 && !is.environment(private$value)) stop("Number cannot be an array.")
if ("ProcessNode" %in% class(private$value)) {
return_value = private$value$getReturns()
if (!any(c("number","integer") %in% class(return_value)) &&
length(return_value$getSchema()$type) != 0) {
stop(paste0("Value 'ProcessNode' returns neither the ANY object nor a number."))
}
# if (!is.null(return_schema$type) && !"number" %in% unlist(return_schema$type))
} else if (!rlang::is_na(private$value) && !is.numeric(private$value)) {
suppressWarnings({
coerced = as.numeric(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a number."))
# correct value if you can
private$value = coerced
}
return(invisible(NULL))
},
typeSerialization = function() {
if ("ProcessNode" %in% class(private$value)) {
return(private$value$serialize())
} else if (self$isEmpty() && !self$isRequired) {
return(NULL)
} else {
return(as.numeric(private$value))
}
}
)
)
# String ====
#' String class
#'
#' Inheriting from [Argument] in order to represent a character string value.
#'
#' @name String
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing a string.
NULL
String = R6Class(
"string",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 && !is.environment(private$value) &&
!any(c("CubeDimension") %in% class(private$value))) stop("String cannot be an array.")
if (!rlang::is_na(private$value) && !is.character(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a character string."))
# correct value if you can
private$value = coerced
}
if (length(self$getEnum()) > 0) {
if (!private$value %in% self$getEnum()) {
stop(paste0("Enum was stated, but the value does not match any enum."))
}
}
return(invisible(NULL))
},
typeSerialization = function() {
if (length(private$value) > 1 && !is.environment(private$value) &&
!any(c("CubeDimension") %in% class(private$value))) stop("String cannot be an array.")
if (is.call(private$value)) {
return(paste(deparse(private$value),collapse = "\n"))
} else if (is.character(private$value)) {
return(private$value)
} else if (self$isEmpty() && !self$isRequired) {
return(NULL)
} else if (!is.environment(private$value) && rlang::is_na(private$value)) {
return(NA)
} else {
return(as.character(private$value))
}
}
)
)
# URI ====
URI = R6Class(
"uri",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
private$schema$subtype = "uri"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 && !is.environment(private$value)) stop("URI cannot be an array.")
if (!rlang::is_na(private$value) && !is.character(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a character string."))
# correct value if you can
private$value = coerced
}
if (!file.exists(private$value) || !grepl(private$value,pattern="\\w+:(\\/?\\/?)[^\\s]+")) stop("Value is not an URI or file.")
return(invisible(NULL))
},
typeSerialization = function() {
if (is.character(private$value)) {
if (file.exists(private$value)) {
# if valid file path open file and attach
return(readChar(private$value, file.info(private$value)$size))
} else {
return(private$value)
}
} else {
return(as.character(private$value))
}
}
)
)
# Output Format ====
#' OutputFormat class
#'
#' Inheriting from [Argument] in order to represent an output format of a back-end as a
#' character string value.
#'
#' @name OutputFormat
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing an output format of a back-end.
NULL
OutputFormat = R6Class(
"output-format",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
private$schema$subtype = "output-format"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 &&
!is.environment(private$value) &&
!"FileFormat" %in% class(private$value)) stop("Output format cannot be an array.")
if (!"FileFormat" %in% class(private$value)) {
if (!rlang::is_na(private$value) && !is.character(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a character string."))
# correct value if you can
private$value = coerced
}
}
return(invisible(NULL))
},
typeSerialization = function() {
if ("FileFormat" %in% class(private$value)) {
return(private$value$name)
} else {
return(as.character(private$value))
}
}
)
)
# CollectionId ====
#' CollectionId class
#'
#' Inheriting from [Argument] in order to represent a CollectionId on an openeo back-end.
#'
#' @name CollectionId
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing a CollectionId.
NULL
CollectionId = R6Class(
"collection-id",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
private$schema$subtype = "collection-id"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 && !is.environment(private$value) && ! "Collection" %in% class(private$value)) stop("Collection ID cannot be an array.")
if (!rlang::is_na(private$value) && !is.character(private$value)) {
if (!"Collection" %in% class(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})
if (length(private$schema$pattern) > 0) {
if (!grepl(pattern=private$schema$pattern,x=coerced,perl=TRUE)) stop(paste0("The provided regexpr pattern does not match the value: ",private$value))
}
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a character string."))
# correct value if you can
private$value = coerced
} else {
coerced = private$value$id
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("CollectionId obtained from service is not valid, please contact the openEO service support."))
}
} else {
if (length(private$schema$pattern) > 0) {
if (!grepl(pattern=private$schema$pattern,x=private$value,perl=TRUE))
stop(paste0("The provided value does not match the required pattern: ",private$value))
}
}
return(invisible(NULL))
},
typeSerialization = function() {
if (!"Collection" %in% class(private$value)) {
return(as.character(private$value))
} else {
return(private$value$id)
}
}
)
)
# JobId ====
#' JobId class
#'
#' Inheriting from [Argument] in order to represent a jobId on an openeo back-end.
#'
#' @name JobId
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing the id of a job.
NULL
JobId = R6Class(
"job-id",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
private$schema$subtype = "job-id"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 &&
!is.environment(private$value) &&
!"Job" %in% class(private$value)) stop("Job id cannot be an array.")
if (!rlang::is_na(private$value) && !is.character(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})
if (!grepl(pattern=private$schema$pattern,x=private$value, perl=TRUE)) stop(paste0("The provided regexpr pattern does not match the value: ",private$value))
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a character string."))
# correct value if you can
private$value = coerced
} else {
if (!grepl(pattern=private$schema$pattern,x=private$value,perl=TRUE)) stop(paste0("The provided value does not match the required pattern: ",private$value))
}
return(invisible(NULL))
},
typeSerialization = function() {
return(as.character(private$value))
}
)
)
# UdfRuntime argument ====
#' UdfRuntimeArgument class
#'
#' Inheriting from [Argument] in order to represent the id of an UDF runtime object as obtainable by [list_udf_runtimes()].
#'
#' @name UdfRuntimeArgument
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] representing the UDF runtime in a process argument.
NULL
UdfRuntimeArgument = R6Class(
"udf-runtime",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
private$schema$subtype = "udf-runtime"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 &&
!is.environment(private$value) &&
!"UdfRuntime" %in% class(private$value)) stop("UDF runtime cannot be an array.")
if (!rlang::is_na(private$value) && !is.character(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})
if (is.null(coerced) ||
rlang::is_na(coerced) ||
length(coerced) == 0) stop(paste0("Value '", private$value,"' cannot be coerced into a runtime id."))
# correct value if you can
private$value = coerced
}
return(invisible(NULL))
},
typeSerialization = function() {
return(as.character(private$value))
}
)
)
# UdfRuntimeVersion argument ====
#' UdfRuntimeVersionArgument class
#'
#' Inheriting from [Argument] in order to represent the id of a UDF runtime object as obtainable by [list_udf_runtimes()].
#'
#' @name UdfRuntimeVersionArgument
#'
#' @seealso [Array], [Integer], [EPSGCode], [String], [Number],
#' [Date], [DataCube], [ProcessGraphArgument],
#' [ProcessGraphParameter], [OutputFormatOptions], [GeoJson],
#' [Boolean], [DateTime], [Time], [BoundingBox], [Kernel],
#' [TemporalInterval], [TemporalIntervals], [CollectionId], [OutputFormat],
#' [AnyOf], [ProjDefinition], [UdfCodeArgument], [UdfRuntimeArgument] and
#' [UdfRuntimeVersionArgument], [MetadataFilter]
#'
#' @return Object of [R6::R6Class()] is an argument that expects a UDF runtime version or character as value.
NULL
UdfRuntimeVersionArgument = R6Class(
"udf-runtime-version",
inherit=Argument,
public = list(
initialize=function(name=character(),description=character(),required=FALSE) {
private$name = name
private$description = description
private$required = required
private$schema$type = "string"
private$schema$subtype = "udf-runtime-version"
}
),
private = list(
typeCheck = function() {
if (length(private$value) > 1 &&
!is.environment(private$value) &&
!"UdfRuntimeVersion" %in% class(private$value)) stop("UDF runtime version cannot be an array.")
if (!rlang::is_na(private$value) && !is.character(private$value)) {
suppressWarnings({
coerced = as.character(private$value)
})