Skip to content

Commit

Permalink
Merge pull request #105 from nationalparkservice/EMLeditor_DataStore_…
Browse files Browse the repository at this point in the history
…v6_dev

DataStore v6 dev
  • Loading branch information
RobLBaker authored Sep 5, 2023
2 parents 9ebfccf + 9bf3415 commit a571af6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: EMLeditor
Title: View and Edit EML Metadata
Version: 0.1.0.7
Version: 0.1.1
Authors@R: c(
person(given="Robert", family="Baker", email="robert_baker@nps.gov",
role = c("aut", "cre"),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# EMLeditor v0.1.0.8 "Work in progress"
EMLeditor v0.1.1 "Big South Fork"

## 29 August 2023
Updated all rest API services from v4/v5 to v6. Units services remain at v2.

## 15 August 2023
* Fix bugs in `get_authors()`
Expand Down
15 changes: 6 additions & 9 deletions R/datastore_interactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ set_datastore_doi <- function(eml_object, force = FALSE, NPS = TRUE){
if(length(seq_along(doc)) == 1){
#get Datastore Reference ID:
DS_ref <- get_ds_id(eml_object)
url <- paste0("https://irmaservices.nps.gov/datastore-secure/v4/rest/ReferenceCodeSearch?q=", DS_ref)
url <- paste0(.ds_secure_api(), "ReferenceCodeSearch?q=", DS_ref)
#API call to look for an existing reference:
test_req <- httr::GET(url, httr::authenticate(":", ":", "ntlm"))
status_code <- httr::stop_for_status(test_req)$status_code
Expand Down Expand Up @@ -105,7 +105,8 @@ set_datastore_doi <- function(eml_object, force = FALSE, NPS = TRUE){
precision = ""))
bdy <- jsonlite::toJSON(mylist, pretty = TRUE, auto_unbox = TRUE)
#Create empty draft reference:
req <- httr::POST("https://irmaservices.nps.gov/datastore-secure/v4/rest/Reference/CreateDraft",
post_url <- paste0(.ds_secure_api(), "Reference/CreateDraft")
req <- httr::POST(post_url,
httr::authenticate(":", "", "ntlm"),
httr::add_headers('Content-Type'='application/json'),
body = bdy)
Expand Down Expand Up @@ -187,7 +188,7 @@ upload_data_package <- function(directory = here::here(), force = FALSE){
#list files in data package

#test whether reference already exists or the DOI:
url <- paste0("https://irmaservices.nps.gov/datastore-secure/v4/rest/ReferenceCodeSearch?q=", DS_ref)
url <- paste0(.ds_secure_api(), "ReferenceCodeSearch?q=", DS_ref)
#verbose approach:
if(force == FALSE){
#API call to look for an existing reference:
Expand Down Expand Up @@ -264,9 +265,7 @@ upload_data_package <- function(directory = here::here(), force = FALSE){
stop()
}
if(is.null(file_size_error)){
api_url <- paste0(
"https://irmaservices.nps.gov/datastore-secure/v4/rest/Reference/",
DS_ref, "/UploadFile")
api_url <- paste0(.ds_secure_api(), "Reference/", DS_ref, "/UploadFile")
#upload the files
for(i in seq_along(files)){
req <- httr::POST(
Expand Down Expand Up @@ -339,9 +338,7 @@ upload_data_package <- function(directory = here::here(), force = FALSE){
stop()
}
if(is.null(file_size_error)){
api_url <- paste0(
"https://irmaservices.nps.gov/datastore-secure/v4/rest/Reference/",
DS_ref, "/UploadFile")
api_url <- paste0(.ds_secure_api(), "Reference/", DS_ref, "/UploadFile")
#upload the files
for(i in seq_along(files)){
req <- httr::POST(
Expand Down
7 changes: 4 additions & 3 deletions R/editEMLfunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ set_language <- function(eml_object, lang, force = FALSE, NPS = TRUE) {
#'
#' @description set_protocol adds a metadata link to the protocol under which the data being described were collected. It automatically inserts a link to the DataStore landing page for the protocol as well as ?????
#'
#' @details set_protocol requires that you have your protocols and projects organized in a specific fashion in DataStore. Errors generated by this function my stem from either a protocol that has not been published (or is not publicly available) or an obsolete protocol/project organization within DataStore.
#' @details set_protocol requires that you have your protocols and projects organized in a specific fashion in DataStore. Errors generated by this function may stem from either a protocol that has not been published (or is not publicly available) or an obsolete protocol/project organization within DataStore.
#'
#' @inheritParams set_title
#' @param protocol_id a string. The 7-digit number identifying the DataStore reference number for the Project that describes your inventory or monitoring project.
Expand All @@ -1082,7 +1082,7 @@ set_protocol <- function(eml_object, protocol_id, force = FALSE, NPS = TRUE) {
# get data to construct project:

# get protocol profile via rest services:
ds_reference <- httr::content(httr::GET(paste0("https://irmaservices.nps.gov/datastore/v4/rest/Profile/", protocol_id)))
ds_reference <- httr::content(httr::GET(paste0(.ds_api(), "Profile/", protocol_id)))

# extract project title
proj_title <- ds_reference$bibliography$title
Expand All @@ -1094,7 +1094,8 @@ set_protocol <- function(eml_object, protocol_id, force = FALSE, NPS = TRUE) {
ref <- ds_reference$series$referenceId

# rest services call to get organization name info:
org_name <- httr::content(httr::GET(paste0("https://irmaservices.nps.gov/datastore/v4/rest/Profile/", ref)))$bibliography$title
org_name <- httr::content(
httr::GET(paste0(.ds_api(), "Profile/", ref)))$bibliography$title

# Construct a project to inject into EML. Note 'role' is required but not sure what to put there.
# Also i find it confusing that onlineURL references projTitle not orgName but hopefully we will hash that out soon.
Expand Down
19 changes: 19 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## assign global package variables

#initiate new environment accessible from within package:
.pkgglobalenv <- new.env(parent=emptyenv())

#data_store API base URL:
assign("ds_api", "https://irmaservices.nps.gov/datastore/v6/rest/", envir=.pkgglobalenv)

#data_store secure API base URL:
assign("ds_secure_api", "https://irmaservices.nps.gov/datastore-secure/v6/rest/", envir=.pkgglobalenv)

.ds_api <- function(x){
get("ds_api", envir = .pkgglobalenv)
}

.ds_secure_api <- function(x){
get("ds_secure_api", envir = .pkgglobalenv)
}

#this gets rid of the "no visible binding for global variable 'x'" error in build checks:
globalVariables(c("UnitCode",
"Name",
Expand Down

0 comments on commit a571af6

Please sign in to comment.