Skip to content

Commit dcb3861

Browse files
authored
Merge pull request #156 from RobLBaker/main
add the function set_project, updates to set_int_rights, update from Rest API v6 to v7
2 parents 033b976 + b2cae70 commit dcb3861

File tree

118 files changed

+7715
-25637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+7715
-25637
lines changed

.github/workflows/R-CMD-check.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Workflow derived from: https://github.com/r-lib/actions/tree/v2/examples
2-
# Need help debugging build failures? Start at:
3-
# https://github.com/r-lib/actions#where-to-find-help
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
43
# unix build check fix applied from:
54
# https://forum.posit.co/t/libraptor2-dev-depends-libcurl4-gnutls-dev-but-it-is-not-installable-in-r-lib-actions-setup-r-dependencies-v2/181572/4
6-
75
on:
86
push:
97
branches: [main, master]

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: EMLeditor
22
Title: View and Edit EML Metadata
3-
Version: 0.1.5
3+
Version: 0.1.6
44
Authors@R: c(
55
person(given="Robert", family="Baker", email="robert_baker@nps.gov",
66
role = c("aut", "cre"),

NEWS.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
# EMLeditor v0.1.6 (in progress)
1+
# EMLeditor v0.1.6
2+
## 2024-08-29
3+
* Update readme: add R-CMD-CHECK badge; use pak to install instead of devtools
4+
* Update licenseName field on restricted references to read, "Unlicensed (not for public dissemination)"
5+
* add github actions: build check
6+
* add `set_project` to the EMLscript template (.Rmd) and the github.io documentation pages.
7+
* update `set_project` so that it adds projects instead of replacing them.
8+
* update `set_project` to use cli errors/warnings
9+
* add minimal unit test for `set_project`
210
## 2024-08-21
311
* add id tag to projects to help DataStore identify DataStore projects vs. other projects.
412
## 2024-08-20

R/editEMLfunctions.R

+73-37
Original file line numberDiff line numberDiff line change
@@ -1496,14 +1496,12 @@ set_protocol <- function(eml_object,
14961496
return(eml_object)
14971497
}
14981498

1499-
#' Adds a reference to the DataStore Project housing the data package
1499+
#' Adds a reference to a DataStore Project housing the data package
15001500
#'
15011501
#' @description
1502-
#' The function will add the project title and URL to the metadata corresponding to the DataStore Project reference that the data package should be linked to. Upon EML extraction on DataStore, the data package will automatically be added to the project indicated.
1502+
#' The function will add a single project title and URL to the metadata corresponding to the DataStore Project reference that the data package should be linked to. Upon EML extraction on DataStore, the data package will automatically be added/linked to the DataStore project indicated.
15031503
#'
1504-
#' @details The person uploading and extracting the EML must be an owner on both the data package and project references in order to have the correct permissions for DataStore to create the desired link. If you have set NPS = TRUE and force = FALSE (the default settings), the function will also test whether you have owner-level permissions for the project which is necessary for DataStore to automatically connect your data package with the project.
1505-
#'
1506-
#' Currently, the function only supports one project. Using the function will replace an project(s) currently in metadata, not add to them. If you want your data package linked to multiple projects, you will have to manually perform the additional linkages via the DataStore web GUI.
1504+
#' @details This function will only add a project; it will not overwrite existing projects. To add a DataStore project to your metadata, the project must be publicly available. If you add multiple DataStore projects to metadata, only the first DataStore project will be used by DataStore. The person uploading and extracting the EML must be an owner on both the data package and project references in order to have the correct permissions for DataStore to create the desired link. If you have set NPS = TRUE and force = FALSE (the default settings), the function will also test whether you have owner-level permissions for the project which is necessary for DataStore to automatically connect your data package with the project.
15071505
#'
15081506
#' DataStore only add links between data packages and projects. DataStore cannot not remove data packages from projects. If need to remove a link between a data package and a project (perhaps you supplied the incorrect project reference ID at first), you will need to manually remove the connection using the DataStore web interface.
15091507
#'
@@ -1526,8 +1524,8 @@ set_project <- function(eml_object,
15261524
NPS = TRUE) {
15271525

15281526
if (nchar(project_reference_id) != 7) {
1529-
cat("You must supply a 7-digit project_reference_id")
1530-
stop()
1527+
cli::cli_abort(c("x" = "You must supply a 7-digit project_reference_id"))
1528+
return(invisible())
15311529
}
15321530

15331531
if (dev == TRUE) {
@@ -1546,7 +1544,9 @@ set_project <- function(eml_object,
15461544

15471545
status_code <- httr::stop_for_status(req)$status_code
15481546
if(!status_code == 200){
1549-
stop("ERROR: DataStore connection failed. Are you logged in to the VPN?\n")
1547+
cli::cli_abort(c("x" = "ERROR: DataStore connection failed.",
1548+
" " = "Are you connected to the internet?"))
1549+
return(invisible())
15501550
}
15511551

15521552
#get project information:
@@ -1555,19 +1555,21 @@ set_project <- function(eml_object,
15551555

15561556
# if it doesn't exist or permissions are invalid:
15571557
if (length(seq_along(rjson)) == 0) {
1558-
cat("The project reference (",
1559-
project_reference_id,
1560-
") does not exist or you do not have permissions to access it.")
1561-
stop()
1558+
cli::cli_abort(c("x" = "ERROR: Could not find the Project
1559+
{.var {project_reference_id}} on DataStore.",
1560+
"i" = "If {.var {project_reference_id}} is set to
1561+
restricted, you must set it to Public to add it to
1562+
metadata."))
1563+
return(invisible())
15621564
}
15631565

15641566
# make sure the project_reference_id is a project:
15651567
if (rjson$referenceType != "Project") {
1566-
cat("The reference you supplied",
1567-
project_reference_id,
1568-
"is not a project.")
1569-
cat("Please supply a valid project reference code.")
1570-
stop()
1568+
cli::cli_abort(c("x" = "The reference {.var {project_reference_id}}
1569+
is not a DataStore Project.",
1570+
" " = "Please supply a valid DataStore project
1571+
reference code."))
1572+
return(invisible())
15711573
}
15721574

15731575
#test whether user has ownership permissions for the project.
@@ -1577,22 +1579,26 @@ set_project <- function(eml_object,
15771579
ownership <- rjson$permissions$referenceOwners
15781580

15791581
if (sum(grepl(email, ownership)) < 1) {
1580-
cat(crayon::bold$yellow("WARNING: "),
1581-
crayon::bold$blue(email),
1582-
" is not listed as an owner for the project (reference ",
1583-
crayon::bold$blue(project_reference_id), ").",
1584-
sep = "")
1585-
alert <- paste0("The person uploading to DataStore and extracting the ",
1586-
"metadata must have ownership-level permissions to ",
1587-
"succesfully link the data package to it's project.")
1588-
cat(alert)
1589-
cat("Project owners can add new owners via the DataStore GUI")
1582+
msg <- paste0("WARNING: {.email {email}} is not listed as an owner for ",
1583+
"the project{.var {project_reference_id}}.")
1584+
info1 <- paste0("The person extracting the metadata on DataStore must ",
1585+
"have ownership-level permissions to succesfully link ",
1586+
"the data package to it's project.")
1587+
info2 <- "Project owners can add new owners via the DataStore GUI."
1588+
cli::cli_alert_warning(msg)
1589+
cli::cli_alert_info(info1)
1590+
cli::cli_alert_info(info2)
15901591
}
15911592
}
15921593

15931594
#project title
15941595
project_title <- rjson$bibliography$title
1595-
project_org <- rjson$bibliography$publisher$publisherName
1596+
1597+
if (sum(is.na(rjson$bibliography$publisher)) > 0) {
1598+
project_org <- "No publisher name supplied"
1599+
} else {
1600+
project_org <- rjson$bibliography$publisher$publisherName
1601+
}
15961602
project_role <- "a DataStore Project"
15971603

15981604
#generate URL (check whether project has DOI)
@@ -1612,7 +1618,9 @@ set_project <- function(eml_object,
16121618

16131619
status_code <- httr::stop_for_status(req2$status_code)
16141620
if (!status_code == 200) {
1615-
stop("ERROR: DataStore connection failed. Are you logged in to the VPN?\n")
1621+
cli::cli_abort("ERROR: DataStore connection failed.
1622+
Are you logged in to the VPN?\n")
1623+
return(invisible())
16161624
}
16171625

16181626
#get project information:
@@ -1626,7 +1634,7 @@ set_project <- function(eml_object,
16261634
project_url <- rjson2$referenceUrl
16271635
}
16281636

1629-
#create project:
1637+
#create DataStore project:
16301638
proj <- list(
16311639
title = project_title,
16321640
personnel = list(
@@ -1636,7 +1644,25 @@ set_project <- function(eml_object,
16361644
), id = "DataStore_project"
16371645
)
16381646

1639-
eml_object$dataset$project <- proj
1647+
#get existing projects:
1648+
existing_projects <- eml_object$dataset$project
1649+
1650+
if (is.null(existing_projects)) {
1651+
eml_object$dataset$project <- proj
1652+
} else {
1653+
#if there are multiple projects:
1654+
if (length(seq_along(existing_projects[[1]])) > 1) {
1655+
# combine new and old projects (with new DataStore project at the top)
1656+
proj <- append(list(proj), existing_projects)
1657+
# overwrite the existing projects in EML with new project list:
1658+
eml_object$dataset$project <- proj
1659+
}
1660+
#if there is only one existing project:
1661+
if (length(seq_along(existing_projects[[1]])) == 1) {
1662+
proj <- append(list(proj), list(existing_projects))
1663+
eml_object$dataset$project <- proj
1664+
}
1665+
}
16401666

16411667
# Set NPS publisher, if it doesn't already exist. Also sets byorForNPS in additionalMetadata to TRUE.
16421668
if (NPS == TRUE) {
@@ -1645,9 +1671,18 @@ set_project <- function(eml_object,
16451671
# add/update EMLeditor and version to metadata:
16461672
eml_object <- .set_version(eml_object)
16471673

1648-
return(eml_object)
1649-
1674+
if (force == FALSE) {
1675+
msg1 <- paste0("The DataStore project {.var {project_reference_id}} with ",
1676+
"the title {.var {project_title}} has been added to your ",
1677+
"metadata.")
1678+
msg2 <- paste0("Your data package will be automatically linked to this ",
1679+
"project when once it is uploaded to DataStore and the ",
1680+
"metadata are extracted.")
1681+
cli::cli_inform(c("i" = msg1))
1682+
cli::cli_inform(c("i" = msg2))
16501683
}
1684+
return(eml_object)
1685+
}
16511686

16521687

16531688
#' Set Publisher
@@ -1983,11 +2018,11 @@ set_publisher <- function(eml_object,
19832018
#'
19842019
#' @description set_int_rights allows the intellectualRights field in EML to be surgically replaced.
19852020
#'
1986-
#' @details set_int_rights requires that CUI information be listed in additionalMetadata prior to being called. The verbose `force = FALSE` option will warn the user if there is no CUI specified. set_int_rights checks to make sure the CUI code specified (see `set_cui()`) is appropriate for the license type chosen.
2021+
#' @details set_int_rights requires that CUI information be listed in additionalMetadata prior to being called. The verbose `force = FALSE` option will warn the user if there is no CUI specified. `set_int_rights` checks to make sure the CUI code specified (see `set_cui_code()`) is appropriate for the license type chosen. For must public NPS dataset, the CC0 license is appropriate.
19872022

19882023
#' @inheritParams set_title
19892024
#'
1990-
#' @param license String. Indicates the type of license to be used. The three potential options are "CC0" (CC zero), "public" and "restricted". CC0 and public can only be used if CUI is set to either PUBFUL or PUBVER. Restricted can only be used if CUI is set to any code that is NOT PUBFUL or PUBVER (see `set_cui()` for a list of codes). To view the exact text that will be inserted for each license, please see https://nationalparkservice.github.io/NPS_EML_Script/stepbystep.html#intellectual-rights
2025+
#' @param license String. Indicates the type of license to be used. The three potential options are "CC0" (CC zero), "public" and "restricted". CC0 and public can only be used if CUI is set to either PUBLIC. Restricted can only be used if CUI is set to any code that is NOT set to PUBLIC (see `set_cui_code()` for a list of codes). To view the exact text that will be inserted for each license, please see https://nationalparkservice.github.io/NPS_EML_Script/stepbystep.html#intellectual-rights
19912026
#'
19922027
#' @importFrom stats complete.cases
19932028
#'
@@ -2038,7 +2073,8 @@ set_int_rights <- function(eml_object,
20382073
if(cui2 == "PUBLIC"){
20392074
if(license == "CC0"){
20402075
eml_object$dataset$intellectualRights <- CCzero
2041-
eml_object$dataset$licensed$licenseName <- "CC0 1.0 Universal"
2076+
cc_zero <- "Creative Commons Zero v1.0 Universal"
2077+
eml_object$dataset$licensed$licenseName <- cc_zero
20422078
cat("Your license has been set to:", crayon::blue$bold("CC0"))
20432079
}
20442080
if(license == "public"){
@@ -2066,7 +2102,7 @@ set_int_rights <- function(eml_object,
20662102
if(cui2 != "PUBLIC"){
20672103
eml_object$dataset$intellectualRights <- restrict
20682104
eml_object$dataset$licensed$licenseName <-
2069-
"No License/Controlled Unclassified Information"
2105+
"Unlicensed (not for public dissemination)"
20702106
cat("Your license has been set to ",
20712107
crayon::bold$blue("Restricted"), ".", sep="")
20722108
}

README.Rmd

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ knitr::opts_chunk$set(
1818
<!-- badges: start -->
1919

2020
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) [![CodeFactor](https://www.codefactor.io/repository/github/roblbaker/emleditor/badge)](https://www.codefactor.io/repository/github/roblbaker/emleditor)
21-
21+
[![R-CMD-check](https://github.com/nationalparkservice/EMLeditor/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nationalparkservice/EMLeditor/actions/workflows/R-CMD-check.yaml)
2222
<!-- badges: end -->
2323

2424
# EMLeditor
@@ -32,14 +32,14 @@ The goal of EMLeditor is to edit EML-formatted xml files. Specifically, EMLedito
3232
You can install and update the development version of EMLeditor from [GitHub](https://github.com/) with:
3333

3434
``` r
35-
# install.packages("devtools")
36-
devtools::install_github("nationalparkservice/EMLeditor")
35+
# install.packages("pak")
36+
pak::pkg_install("nationalparkservice/EMLeditor")
3737
```
3838

3939
To install all the packages in the [NPSdataverse](https://github.com/nationalparkservice/NPSdataverse) (including EMLeditor):
4040

4141
``` r
42-
devtools::install_github("nationalparkservice/NPSdataverse")
42+
pak::pkg_install("nationalparkservice/NPSdataverse")
4343
```
4444

4545
## Workflow outline

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Lifecycle:
66
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
77
[![CodeFactor](https://www.codefactor.io/repository/github/roblbaker/emleditor/badge)](https://www.codefactor.io/repository/github/roblbaker/emleditor)
8-
8+
[![R-CMD-check](https://github.com/nationalparkservice/EMLeditor/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nationalparkservice/EMLeditor/actions/workflows/R-CMD-check.yaml)
99
<!-- badges: end -->
1010

1111
# EMLeditor
@@ -25,16 +25,16 @@ You can install and update the development version of EMLeditor from
2525
[GitHub](https://github.com/) with:
2626

2727
``` r
28-
# install.packages("devtools")
29-
devtools::install_github("nationalparkservice/EMLeditor")
28+
# install.packages("pak")
29+
pak::pkg_install("nationalparkservice/EMLeditor")
3030
```
3131

3232
To install all the packages in the
3333
[NPSdataverse](https://github.com/nationalparkservice/NPSdataverse)
3434
(including EMLeditor):
3535

3636
``` r
37-
devtools::install_github("nationalparkservice/NPSdataverse")
37+
pak::pkg_install("nationalparkservice/NPSdataverse")
3838
```
3939

4040
## Workflow outline

_pkgdown.yml

-4
This file was deleted.

0 commit comments

Comments
 (0)