Skip to content

Commit 395992f

Browse files
authored
Merge pull request nationalparkservice#161 from RobLBaker/main
add test_content_units
2 parents d743e15 + 88dd6b4 commit 395992f

File tree

16 files changed

+227
-7
lines changed

16 files changed

+227
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Imports:
3333
httr,
3434
jsonlite,
3535
QCkit,
36+
EMLeditor,
3637
lifecycle
3738
Remotes:
3839
https://github.com/NCEAS/arcticdatautils,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(load_data)
77
export(load_metadata)
88
export(run_congruence_checks)
99
export(test_attribute_defs)
10+
export(test_content_units)
1011
export(test_creator)
1112
export(test_cui_dissemination)
1213
export(test_datatable_urls)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# DPchecker 1.0.1 (under development)
2+
## 2025-03-07
3+
* Add `test_content_units()` function to test for the presence of NPS content unit links. Add `test_content_units()` function to list of functions run by `run_congruence_checks()`. Add unit tests for `test_content_units()`. Add documentation about `test_content_units()` to the Articles.
4+
* Add EMLeditor as a dependency to support unit tests for `test_content_units()`.
25
## 2025-02-25
36
* Update `CONTRIBUTING.md`
47
## 2025-02-22

R/optional_eml_elements.R

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ test_public_points <- function(metadata = load_metadata(directory)){
496496
cli::cli_inform(c("v" = "CUI is set to PUBLIC and all GPS coordinates will be publicly available."))
497497
}
498498
else {
499-
# if CUI is not public, warn the user that GPS coordiantes will be public.
499+
# if CUI is not public, warn the user that GPS coordinates will be public.
500500
cli::cli_warn(c("!" = "CUI is not set to PUBLIC. GPS coordinates detected in metadata will be publicly available. Are you sure?"))
501501
}
502502
}
@@ -545,7 +545,7 @@ test_project <- function (metadata = load_metadata(directory)) {
545545
proj_test <- unlist(proj)
546546
DS_proj <- "id" %in% names(proj_test)
547547
if (!DS_proj) {
548-
msg <- paste0("No project associated with the metadata. ",
548+
msg <- paste0("No DataStore project associated with the metadata. ",
549549
"To add a DataStore project, use ",
550550
"{.fun EMLeditor::set_project}.")
551551
cli::cli_warn(c("!" = msg))
@@ -554,5 +554,70 @@ test_project <- function (metadata = load_metadata(directory)) {
554554

555555
msg <- "The metadata contains at least one DataStore Project reference."
556556
cli::cli_inform(c("v" = msg))
557+
return(invisible(metadata))
557558
}
558559

560+
#' Test for content unit links
561+
#'
562+
#' @inheritParams test_pub_date
563+
#'
564+
#' @return invisible(metadata)
565+
#' @export
566+
#'
567+
#' @examples
568+
#' \dontrun{
569+
#' test_content_units()
570+
#' }
571+
test_content_units <- function(metadata = load_metadata(directory)) {
572+
#check whether EML is schema valid
573+
is_eml(metadata)
574+
575+
#get geographic coverage from metadata
576+
geo_cov <- metadata[["dataset"]][["coverage"]][["geographicCoverage"]]
577+
578+
#drop `@context` item from geo_cov
579+
geo_cov$`@context` <- NULL
580+
581+
# If there's only geographic coverage element, geo_cov ends up with one less level of nesting. Re-nest it so that the rest of the code works consistently
582+
if ("geographicDescription" %in% names(geo_cov)) {
583+
geo_cov <- list(geo_cov)
584+
}
585+
586+
#test for existence of geography; if absent warn and suggest solution
587+
if (is.null(geo_cov)) {
588+
msg1 <- "Metadata does not contain park content unit links."
589+
msg <- "to add content unit links."
590+
cli::cli_warn(
591+
c("!" = "{msg1}, Use {.fn EMLeditor::set_content_units} {msg}"))
592+
}
593+
594+
#if geography is present:
595+
else {
596+
units <- FALSE
597+
for (i in 1:length(seq_along(geo_cov))) {
598+
#test for content unit links:
599+
if (grepl("NPS Content Unit Link:",
600+
geo_cov[[i]]$geographicDescription)) {
601+
units <- TRUE
602+
}
603+
# exit the for-loop after the first instance of a content unit:
604+
if (units == TRUE) {
605+
break
606+
}
607+
}
608+
# if content units are present, pass the test
609+
if (units) {
610+
cli::cli_inform(c("v" = "Metadata contains NPS content unit links."))
611+
}
612+
#if content units are not present, fail with a warning and suggest solution
613+
if (!units) {
614+
msg1 <- "Metadata does not contain park content unit links."
615+
msg <- "to add content unit links."
616+
cli::cli_warn(
617+
c("!" = "{msg1}, Use {.fn EMLeditor::set_content_units} {msg}"))
618+
619+
}
620+
}
621+
622+
return(invisible(metadata))
623+
}

R/run_checks.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ run_congruence_checks <- function(directory = here::here(),
143143
warn_count <<- warn_count + 1
144144
cli::cli_bullets(c(w$message, w$body))
145145
})
146+
tryCatch(test_content_units(metadata),
147+
error = function(e) {
148+
err_count <<- err_count + 1
149+
cli::cli_bullets(c(e$message, e$body))
150+
},
151+
warning = function(w) {
152+
warn_count <<- warn_count + 1
153+
cli::cli_bullets(c(w$message, w$body))
154+
})
146155
tryCatch(test_doi(metadata),
147156
error = function(e) {
148157
err_count <<- err_count + 1

docs/articles/DPchecker.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/news/index.html

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pkgdown: 2.1.1
33
pkgdown_sha: ~
44
articles:
55
DPchecker: DPchecker.html
6-
last_built: 2025-02-25T21:14Z
6+
last_built: 2025-03-07T18:37Z

docs/reference/index.html

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/run_congruence_checks.html

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)