Skip to content

Commit 40ba5a1

Browse files
author
mckeea
committed
generate_query_template() update
1 parent 4daff1d commit 40ba5a1

File tree

3 files changed

+80
-10
lines changed

3 files changed

+80
-10
lines changed

R/client.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ Client <- R6::R6Class("Client",
432432
if (!is.na(param_meta$comment)) {
433433
obj <- c(obj, setNames(param_meta$comment, paste0("_comment_", param)))
434434
}
435+
if (!is.na(param_meta$possible_values)) {
436+
obj <- c(obj, setNames(param_meta$possible_values, paste0("_values_", param)))
437+
}
435438
}
436439

437440
if (to_json) {

R/utils.R

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ is_placeholder <- function(value) {
1212
extract_param_meta_for_string <- function(meta) {
1313
value <- NULL
1414
comment <- NA
15+
possible_values <- NA
1516

1617
if (exists("default", where = meta)) {
1718
value <- meta$default
@@ -37,11 +38,18 @@ extract_param_meta_for_string <- function(meta) {
3738

3839
if (exists("oneOf", where = meta) && length(meta$oneOf) > 0) {
3940
possible_values <- sapply(meta$oneOf, function(x) x$const)
40-
value <- paste(possible_values, collapse = " , ")
41-
comment <- paste0("One of")
41+
value <- possible_values[[1]]
42+
43+
if (length(possible_values) == 1) {
44+
possible_values <- I(list(list(possible_values)))
45+
} else {
46+
possible_values <- I(list(possible_values))
47+
}
48+
49+
comment <- "One of"
4250
}
4351

44-
data.frame(value = value, comment = comment)
52+
data.frame(value = value, comment = comment, possible_values = possible_values)
4553
}
4654

4755
extract_param_meta_for_number <- function(meta) {
@@ -67,7 +75,7 @@ extract_param_meta_for_number <- function(meta) {
6775
comment <- description
6876
}
6977

70-
data.frame(value = value, comment = comment)
78+
data.frame(value = value, comment = comment, possible_values = NA)
7179
}
7280

7381
extract_param_meta_for_array <- function(meta) {
@@ -86,7 +94,7 @@ extract_param_meta_for_array <- function(meta) {
8694
}
8795
}
8896

89-
data.frame(value = I(value), comment = NA)
97+
data.frame(value = I(value), comment = NA, possible_values = NA)
9098
}
9199

92100
extract_param_metadata <- function(meta) {
@@ -104,6 +112,7 @@ strip_off_template_placeholders <- function(template) {
104112
for (param in names(t))
105113
{
106114
if (startsWith(param, "_comment_")) next
115+
if (startsWith(param, "_values_")) next
107116
value <- t[[param]]
108117
if (!is_placeholder(value)) {
109118
output[[param]] <- value

vignettes/hdar.Rmd

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,21 @@ query_template
262262
"itemsPerPage": 11,
263263
"startIndex": 0,
264264
"uid": "__### Value of string type with pattern: [\\w-]+",
265-
"productType": "PPI , QFLAG",
265+
"productType": "PPI",
266266
"_comment_productType": "One of",
267+
"_values_productType": ["PPI", "QFLAG"],
267268
"platformSerialIdentifier": "S2A, S2B",
268269
"_comment_platformSerialIdentifier": "One of",
270+
"_values_platformSerialIdentifier": [
271+
"S2A, S2B"
272+
],
269273
"tileId": "__### Value of string type with pattern: [\\w-]+",
270274
"productVersion": "__### Value of string type with pattern: [\\w-]+",
271275
"resolution": "10",
272276
"_comment_resolution": "One of",
277+
"_values_resolution": [
278+
"10"
279+
],
273280
"processingDate": "__### Value of string type with format: date-time",
274281
"start": "__### Value of string type with format: date-time",
275282
"end": "__### Value of string type with format: date-time",
@@ -288,6 +295,8 @@ You can and should customize the generated query template to fit your specific n
288295

289296
Placeholders are used when there is no way to derive the value from the metadata endpoint, while comment fields appear when the field has a value already defined, offering additional context for customizing the query.
290297

298+
Furthermore, fields prefixed with `_values_` contain all possible values for a specific field. This allows you to programmatically reference them in your code with ease, simplifying customization and ensuring that you have access to valid options when configuring the query.
299+
291300
To modify the query, it is often easier to transform the JSON into an R list using the `jsonlite::fromJSON()` function:
292301

293302
```{r, eval = FALSE}
@@ -298,15 +307,33 @@ query_template
298307
$dataset_id
299308
[1] "EO:EEA:DAT:CLMS_HRVPP_ST"
300309
310+
$itemsPerPage
311+
[1] 11
312+
313+
$startIndex
314+
[1] 0
315+
301316
$uid
302317
[1] "__### Value of string type with pattern: [\\w-]+"
303318
304319
$productType
305320
[1] "PPI"
306321
322+
$`_comment_productType`
323+
[1] "One of"
324+
325+
$`_values_productType`
326+
[1] "PPI" "QFLAG"
327+
307328
$platformSerialIdentifier
308329
[1] "S2A, S2B"
309330
331+
$`_comment_platformSerialIdentifier`
332+
[1] "One of"
333+
334+
$`_values_platformSerialIdentifier`
335+
[1] "S2A, S2B"
336+
310337
$tileId
311338
[1] "__### Value of string type with pattern: [\\w-]+"
312339
@@ -316,14 +343,20 @@ $productVersion
316343
$resolution
317344
[1] "10"
318345
346+
$`_comment_resolution`
347+
[1] "One of"
348+
349+
$`_values_resolution`
350+
[1] "10"
351+
319352
$processingDate
320-
[1] "__### Value of string"
353+
[1] "__### Value of string type with format: date-time"
321354
322355
$start
323-
[1] "__### Value of string"
356+
[1] "__### Value of string type with format: date-time"
324357
325358
$end
326-
[1] "__### Value of string"
359+
[1] "__### Value of string type with format: date-time"
327360
328361
$bbox
329362
[1] -180 -90 180 90
@@ -339,18 +372,37 @@ query_template$bbox <- c(11.1090, 46.6210, 11.2090, 46.7210)
339372
query_template$start <- "2018-03-01T00:00:00.000Z"
340373
query_template$end <- "2018-05-31T00:00:00.000Z"
341374
query_template
375+
342376
$dataset_id
343377
[1] "EO:EEA:DAT:CLMS_HRVPP_ST"
344378
379+
$itemsPerPage
380+
[1] 11
381+
382+
$startIndex
383+
[1] 0
384+
345385
$uid
346386
[1] "__### Value of string type with pattern: [\\w-]+"
347387
348388
$productType
349389
[1] "PPI"
350390
391+
$`_comment_productType`
392+
[1] "One of"
393+
394+
$`_values_productType`
395+
[1] "PPI" "QFLAG"
396+
351397
$platformSerialIdentifier
352398
[1] "S2A, S2B"
353399
400+
$`_comment_platformSerialIdentifier`
401+
[1] "One of"
402+
403+
$`_values_platformSerialIdentifier`
404+
[1] "S2A, S2B"
405+
354406
$tileId
355407
[1] "__### Value of string type with pattern: [\\w-]+"
356408
@@ -360,8 +412,14 @@ $productVersion
360412
$resolution
361413
[1] "10"
362414
415+
$`_comment_resolution`
416+
[1] "One of"
417+
418+
$`_values_resolution`
419+
[1] "10"
420+
363421
$processingDate
364-
[1] "__### Value of string"
422+
[1] "__### Value of string type with format: date-time"
365423
366424
$start
367425
[1] "2018-03-01T00:00:00.000Z"

0 commit comments

Comments
 (0)