Skip to content

Commit f3dc70c

Browse files
committed
Move update_rights_holder to access.R
1 parent afc51f6 commit f3dc70c

File tree

2 files changed

+57
-57
lines changed

2 files changed

+57
-57
lines changed

R/access.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,63 @@ get_related_pids <- function(mn, pid) {
9696
}
9797

9898

99+
#' Change the rightsHolder field for a given PID.
100+
#'
101+
#' Update the rights holder to the provided subject for the object identified in
102+
#' the provided system metadata document on the given Member Node.
103+
#'
104+
#' @param mn the MNode instance to be changed (MNode)
105+
#' @param pids the identifiers for the object to be changed (character)
106+
#' @param subject the identifier of the new rightsHolder, often an ORCID or DN (character)
107+
#' @import dataone
108+
#' @import datapack
109+
#' @export
110+
update_rights_holder <- function(mn, pids, subject) {
111+
stopifnot(class(mn) == "MNode")
112+
stopifnot(is.character(pids),
113+
all(nchar(pid) > 0))
114+
stopifnot(is.character(subject),
115+
nchar(subject) > 0)
116+
117+
result <- vector(mode = "logical", length = length(pids))
118+
119+
for (i in seq_along(pids)) {
120+
pid <- pids[i]
121+
122+
# Get System Metadata
123+
sysmeta <- dataone::getSystemMetadata(mn, pid)
124+
125+
# Change rightsHolder (if needed)
126+
if (sysmeta@rightsHolder == subject) {
127+
log_message(paste0("rightsHolder field is already set to ", subject, ". System Metadata not updated."))
128+
result[i] <- TRUE
129+
} else {
130+
sysmeta@rightsHolder <- subject
131+
132+
# Update System Metadata
133+
log_message(paste0("Updating rightsHolder for PID ", pid, " to ", subject, "."))
134+
response <- tryCatch({
135+
dataone::updateSystemMetadata(mn,
136+
pid = pid,
137+
sysmeta = sysmeta)
138+
},
139+
error = function(e) {
140+
log_message(e)
141+
e
142+
})
143+
144+
if (inherits(response, "error")) {
145+
result[i] <- FALSE
146+
} else {
147+
result[i] <- TRUE
148+
}
149+
}
150+
}
151+
152+
return(result)
153+
}
154+
155+
99156
#' Set the given subject as the rightsHolder and subject with write and
100157
#' changePermission access for the given PID.
101158
#'

R/editing.R

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -269,63 +269,6 @@ publish_update <- function(mn,
269269
}
270270

271271

272-
#' Change the rightsHolder field for a given PID.
273-
#'
274-
#' Update the rights holder to the provided subject for the object identified in
275-
#' the provided system metadata document on the given Member Node.
276-
#'
277-
#' @param mn the MNode instance to be changed (MNode)
278-
#' @param pids the identifiers for the object to be changed (character)
279-
#' @param subject the identifier of the new rightsHolder, often an ORCID or DN (character)
280-
#' @import dataone
281-
#' @import datapack
282-
#' @export
283-
update_rights_holder <- function(mn, pids, subject) {
284-
stopifnot(class(mn) == "MNode")
285-
stopifnot(is.character(pids),
286-
all(nchar(pid) > 0))
287-
stopifnot(is.character(subject),
288-
nchar(subject) > 0)
289-
290-
result <- vector(mode = "logical", length = length(pids))
291-
292-
for (i in seq_along(pids)) {
293-
pid <- pids[i]
294-
295-
# Get System Metadata
296-
sysmeta <- dataone::getSystemMetadata(mn, pid)
297-
298-
# Change rightsHolder (if needed)
299-
if (sysmeta@rightsHolder == subject) {
300-
log_message(paste0("rightsHolder field is already set to ", subject, ". System Metadata not updated."))
301-
result[i] <- TRUE
302-
} else {
303-
sysmeta@rightsHolder <- subject
304-
305-
# Update System Metadata
306-
log_message(paste0("Updating rightsHolder for PID ", pid, " to ", subject, "."))
307-
response <- tryCatch({
308-
dataone::updateSystemMetadata(mn,
309-
pid = pid,
310-
sysmeta = sysmeta)
311-
},
312-
error = function(e) {
313-
log_message(e)
314-
e
315-
})
316-
317-
if (inherits(response, "error")) {
318-
result[i] <- FALSE
319-
} else {
320-
result[i] <- TRUE
321-
}
322-
}
323-
}
324-
325-
return(result)
326-
}
327-
328-
329272
#' Create a resource map.
330273
#'
331274
#' Similar to but different than update_resource_map in that it uses a create

0 commit comments

Comments
 (0)