Skip to content

Commit 7695e0c

Browse files
committed
Fix a bug in otherEntity routines and add a test
1 parent 356a59f commit 7695e0c

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

R/eml.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ pid_to_other_entity <- function(mn, pid, sysmeta=NULL) {
3535
stop(paste0("System Metadata for object with PID '", pid, "' did not have its fileName property set. This will result in 'NA' being set for the EML entityName and objectName (which we don't want). You need to give each data object a fileName property in its System Metadata. You can use the arcticdatautils::set_file_name() function to do this or you can use dataone::getSystemMetadata(), change the fileName property, and update it with dataone::updateSystemMetadata()"))
3636
}
3737

38-
sysmeta_to_other_entity(mn, sysmeta)
38+
sysmeta_to_other_entity(sysmeta)
3939
}
4040

4141
#' Create an EML otherEntity sub-tree for the given object.
4242
#'
43-
#' @param mn (MemberNode) The Member Node the object lives on.
4443
#' @param sysmeta (SystemMetadata) The System Metadata of the object.
4544
#'
4645
#' @return (otherEntity) The XML sub-tree.
4746
#' @export
4847
#'
4948
#' @examples
50-
sysmeta_to_other_entity <- function(mn, sysmeta) {
49+
sysmeta_to_other_entity <- function(sysmeta) {
5150
stopifnot(class(sysmeta) == "SystemMetadata")
5251

5352
# otherEntity
@@ -65,7 +64,7 @@ sysmeta_to_other_entity <- function(mn, sysmeta) {
6564
other_entity@entityType <- "Other"
6665

6766
# otherEntity/physical
68-
phys <- sysmeta_to_eml_physical(mn, sysmeta)
67+
phys <- sysmeta_to_eml_physical(sysmeta)
6968
other_entity@physical <- new("ListOfphysical", list(phys))
7069

7170
other_entity
@@ -77,7 +76,6 @@ sysmeta_to_other_entity <- function(mn, sysmeta) {
7776
#' System Metadata of an Object. Note that it sets an Online Distrubtion URL
7877
#' of the DataONE v2 resolve service for the PID.
7978
#'
80-
#' @param mn (MemberNode) The Member Node the object lives on.
8179
#' @param sysmeta (SystemMetadata) The System Metadata of the object.
8280
#'
8381
#' @return
@@ -155,7 +153,7 @@ set_other_entities <- function(mn, path, pids) {
155153

156154
# Concatenate the existing and new otherEntity elements and put back in the
157155
# EML
158-
if (length(new_entities) > 0) {
156+
if (length(other_entities) > 0) {
159157
doc@dataset@otherEntity <- new("ListOfotherEntity", other_entities)
160158
}
161159

tests/testthat/test_eml.R

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
context("EML")
22

3-
test_that("an EML otherEntity subtree can be created when the sysmeta has a filename", {
4-
skip("This test needs to be skipped until ecogrid URLs support DataONE objects.")
3+
mn <- env_load()$mn
54

5+
test_that("an EML otherEntity subtree can be created when the sysmeta has a filename", {
66
x <- file.path(system.file("tests", "testfiles", package = "arcticdatautils"), "example-sysmeta.xml")
77
doc <- XML::xmlParse(x)
88
sysmeta <- new("SystemMetadata")
@@ -17,8 +17,6 @@ test_that("an EML otherEntity subtree can be created when the sysmeta has a file
1717
})
1818

1919
test_that("an EML otherEntity subtree can be created when the sysmeta doesn't have a filename ", {
20-
skip("This test needs to be skipped until ecogrid URLs support DataONE objects.")
21-
2220
x <- file.path(system.file("tests", "testfiles", package = "arcticdatautils"), "example-sysmeta-nofilename.xml")
2321
doc <- XML::xmlParse(x)
2422
sysmeta <- new("SystemMetadata")
@@ -109,3 +107,25 @@ test_that("a project can be created with multiple organizations", {
109107
expect_equal(project@personnel[[1]]@organizationName[[1]]@.Data, "org1")
110108
expect_equal(project@personnel[[1]]@organizationName[[2]]@.Data, "org2")
111109
})
110+
111+
test_that("an other entity can be added from a pid", {
112+
if (!is_token_set(mn)) {
113+
skip("No token set. Skipping test.")
114+
}
115+
116+
data_path <- tempfile()
117+
writeLines(LETTERS, data_path)
118+
pid <- publish_object(mn, data_path, "text/plain")
119+
120+
eml_path <- file.path(system.file("inst", package = "arcticdatautils"), "example-eml.xml")
121+
122+
doc <- EML::read_eml(eml_path)
123+
doc@dataset@otherEntity <- new("ListOfotherEntity", list())
124+
125+
set_other_entities(mn, eml_path, pid)
126+
127+
doc <- EML::read_eml(eml_path)
128+
testthat::expect_length(doc@dataset@otherEntity, 1)
129+
130+
unlink(data_path)
131+
})

0 commit comments

Comments
 (0)