Skip to content

Commit

Permalink
Remove usages of log_message in interactive functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amoeba committed Sep 12, 2017
1 parent 8c242e8 commit 574c6c2
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 104 deletions.
42 changes: 21 additions & 21 deletions R/access.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ set_rights_holder <- function(mn, pids, subject) {

# Change rightsHolder (if needed)
if (sysmeta@rightsHolder == subject) {
log_message(paste0("rightsHolder field is already set to ", subject, ". System Metadata not updated."))
message(paste0("rightsHolder field is already set to ", subject, ". System Metadata not updated."))
result[i] <- TRUE
} else {
# Update System Metadata
log_message(paste0("Updating rightsHolder for PID ", pid, " from ", sysmeta@rightsHolder, " to ", subject, "."))
message(paste0("Updating rightsHolder for PID ", pid, " from ", sysmeta@rightsHolder, " to ", subject, "."))

sysmeta@rightsHolder <- subject

Expand All @@ -47,7 +47,7 @@ set_rights_holder <- function(mn, pids, subject) {
sysmeta = sysmeta)
},
error = function(e) {
log_message(e)
message(e)
e
})

Expand Down Expand Up @@ -103,10 +103,10 @@ set_access <- function(mn, pids, subjects, permissions=c("read", "write", "chang

if (changed) {
result[pid] <- TRUE
log_message(paste0("Updating System Metadata for ", pid, "."))
message(paste0("Updating System Metadata for ", pid, "."))
dataone::updateSystemMetadata(mn, pid, sysmeta)
} else {
log_message(paste0("No changes needed for ", pid, ". Not updating."))
message(paste0("No changes needed for ", pid, ". Not updating."))
result[pid] <- FALSE
}
}
Expand Down Expand Up @@ -154,8 +154,8 @@ remove_public_read <- function(mn, pids) {
dataone::getSystemMetadata(mn, pid)
},
error = function(e) {
log_message(paste0("Failed to get system metadata for PID '", pid, "' on MN '", mn@endpoint, "'.\n"))
log_message(e)
message(paste0("Failed to get system metadata for PID '", pid, "' on MN '", mn@endpoint, "'.\n"))
message(e)
e
})

Expand All @@ -167,22 +167,22 @@ remove_public_read <- function(mn, pids) {
changed <- FALSE

if (!datapack::hasAccessRule(sysmeta, "public", "read")) {
log_message(paste0("Skipping setting public read because ", pid, " is not public."))
message(paste0("Skipping setting public read because ", pid, " is not public."))
next
}

changed <- TRUE

log_message(paste0("Removing public read access on ", pid, "."))
message(paste0("Removing public read access on ", pid, "."))
sysmeta@accessPolicy <- sysmeta@accessPolicy[!(grepl("public", sysmeta@accessPolicy$subject) & grepl("read", sysmeta@accessPolicy$permission)),]

# Update the sysmeta
update_response <- tryCatch({
dataone::updateSystemMetadata(mn, pid, sysmeta)
},
error = function(e) {
log_message(paste0("Failed to update System Metadata for PID '", pid, "'.\n"))
log_message(e)
message(paste0("Failed to update System Metadata for PID '", pid, "'.\n"))
message(e)
e
})

Expand Down Expand Up @@ -230,8 +230,8 @@ set_rights_and_access <- function(mn, pids, subject, permissions=c("read", "writ
dataone::getSystemMetadata(mn, pid)
},
error = function(e) {
log_message(paste0("Failed to get system metadata for PID '", pid, "' on MN '", mn@endpoint, "'.\n"))
log_message(e)
message(paste0("Failed to get system metadata for PID '", pid, "' on MN '", mn@endpoint, "'.\n"))
message(e)
e
})

Expand All @@ -246,41 +246,41 @@ set_rights_and_access <- function(mn, pids, subject, permissions=c("read", "writ
if (subject != sysmeta@rightsHolder) {
changed <- TRUE

log_message(paste0("Setting rights holder to ", subject, "."))
message(paste0("Setting rights holder to ", subject, "."))
sysmeta@rightsHolder <- subject
} else {
log_message(paste0("Skipping setting rightsHolder as rightsHolder is already ", sysmeta@rightsHolder, ".\n"))
message(paste0("Skipping setting rightsHolder as rightsHolder is already ", sysmeta@rightsHolder, ".\n"))
}

for (permission in permissions) {
if (datapack::hasAccessRule(sysmeta, subject, permission)) {
log_message(paste0("Skipping the addition of permission '", permission, "' for subject '", subject, "'\n"))
message(paste0("Skipping the addition of permission '", permission, "' for subject '", subject, "'\n"))
next
}

changed <- TRUE

log_message(paste0("Adding permission '", permission, "' for subject '", subject, "'\n"))
message(paste0("Adding permission '", permission, "' for subject '", subject, "'\n"))
sysmeta <- datapack::addAccessRule(sysmeta, subject, permission)
}

if (changed == TRUE) {
log_message(paste0("Updating System Metadata for ", pid, "."))
message(paste0("Updating System Metadata for ", pid, "."))

update_response <- tryCatch({
dataone::updateSystemMetadata(mn, pid, sysmeta)
},
error = function(e) {
log_message(paste0("Failed to update System Metadata for PID '", pid, "'.\n"))
log_message(e)
message(paste0("Failed to update System Metadata for PID '", pid, "'.\n"))
message(e)
e
})

if (inherits(update_response, "error")) {
stop("Failed update.")
}
} else {
log_message(paste0("No changes needed for ", pid, "."))
message(paste0("No changes needed for ", pid, "."))
}

# Save the result for this PID
Expand Down
38 changes: 19 additions & 19 deletions R/editing.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ publish_object <- function(mn,

# Get the clone_pid sysmeta to use for the rightsHolder and accessPolicy, and replicationPolicy
if (!is.null(clone_pid)) {
log_message(paste0("Cloning System Metadata for new object from ", clone_pid, "."))
message(paste0("Cloning System Metadata for new object from ", clone_pid, "."))
clone_sysmeta <- dataone::getSystemMetadata(mn, clone_pid)
}

Expand All @@ -80,7 +80,7 @@ publish_object <- function(mn,
sysmeta <- clear_replication_policy(sysmeta)

if (!is.null(sid)) {
log_message(paste0("Setting SID to '", sid, "'."))
message(paste0("Setting SID to '", sid, "'."))
sysmeta@seriesId <- sid
}

Expand Down Expand Up @@ -143,7 +143,7 @@ update_object <- function(mn, pid, path, format_id=NULL, new_pid=NULL, sid=NULL)
paste0("The format_id of '", format_id, "' is not a valid format ID. See https://cn.dataone.org/cn/v2/formats for the current list. This package stores a copy and may be out of date with that list so please email the author if needed."))
}

log_message(paste0("Updating object ", pid, " with the file at ", path, "."))
message(paste0("Updating object ", pid, " with the file at ", path, "."))

# Generate a PID if needed
if (is.null(new_pid)) {
Expand Down Expand Up @@ -321,35 +321,35 @@ publish_update <- function(mn,
# Get some things from the node
if (is.null(metadata_path)) {
# Get the metadata doc
log_message("Getting metadata from the MN.")
message("Getting metadata from the MN.")
eml <- EML::read_eml(rawToChar(dataone::getObject(mn, metadata_pid)), asText = TRUE)
} else {
# Alternatively, read an edited metadata file from disk if provided
if (!file.exists(metadata_path)) {
stop(paste0("Metadata doesn't exist: ", metadata_path))
}

log_message(paste0("Getting metadata from the path: ", metadata_path, "."))
message(paste0("Getting metadata from the path: ", metadata_path, "."))
eml <- EML::read_eml(metadata_path)
}

# get the metadata sysmeta from the node
metadata_sysmeta <- dataone::getSystemMetadata(mn, metadata_pid)

log_message("Downloaded EML and sysmeta...")
message("Downloaded EML and sysmeta...")

# Generate PIDs for our updated objects
if (is.null(identifier)) {
if (use_doi) {
log_message("Minting a new DOI")
message("Minting a new DOI")
metadata_updated_pid <- dataone::generateIdentifier(mn, scheme = "DOI")
log_message(paste0("Minted a new DOI of ", metadata_updated_pid, "."))
message(paste0("Minted a new DOI of ", metadata_updated_pid, "."))
} else {
metadata_updated_pid <- new_uuid()
log_message(paste0("Using generated UUID PID of ", metadata_updated_pid, "."))
message(paste0("Using generated UUID PID of ", metadata_updated_pid, "."))
}
} else {
log_message(paste0("Using manually-specified identifier of ", identifier, "."))
message(paste0("Using manually-specified identifier of ", identifier, "."))
metadata_updated_pid <- identifier
}

Expand Down Expand Up @@ -428,7 +428,7 @@ publish_update <- function(mn,
metadata_pid,
metadata_sysmeta@rightsHolder)

log_message(paste0("Updated metadata document ", metadata_pid, " with ", metadata_updated_pid, "."))
message(paste0("Updated metadata document ", metadata_pid, " with ", metadata_updated_pid, "."))

# Update the resource map
#########################
Expand All @@ -443,7 +443,7 @@ publish_update <- function(mn,

set_rights_holder(mn, response[["resource_map"]], metadata_sysmeta@rightsHolder)

log_message("Updated resource map")
message("Updated resource map")

# Update the parent resource map to add the new package
#######################################################
Expand All @@ -452,12 +452,12 @@ publish_update <- function(mn,
stop("Missing required parameters to update parent package.")
}

log_message("Updating parent resource map...")
message("Updating parent resource map...")

# Check to see if the just-updated package is in the list of
# parent_child_pids, notify the user, and add it to the list
if (!(resmap_updated_pid %in% parent_child_pids)) {
log_message("Adding the new resource map to the list of child PIDs in the parent package.")
message("Adding the new resource map to the list of child PIDs in the parent package.")
parent_child_pids <- c(parent_child_pids, resmap_updated_pid)
}

Expand Down Expand Up @@ -514,7 +514,7 @@ create_resource_map <- function(mn,
nchar(metadata_pid) > 0)

if (check_first) {
log_message("Checking all the object passed in as arguments exist before going on...")
message("Checking all the object passed in as arguments exist before going on...")

stopifnot(object_exists(mn, metadata_pid))
if (!is.null(data_pids))
Expand Down Expand Up @@ -598,7 +598,7 @@ update_resource_map <- function(mn,
nchar(metadata_pid) > 0)

if (check_first) {
log_message("Checking all the object passed in as arguments exist before going on...")
message("Checking all the object passed in as arguments exist before going on...")

stopifnot(object_exists(mn, resource_map_pid))
stopifnot(object_exists(mn, metadata_pid))
Expand Down Expand Up @@ -646,7 +646,7 @@ update_resource_map <- function(mn,

rm(sysmeta)

log_message(paste0("Getting updated copy of System Metadata for ", resource_map_pid))
message(paste0("Getting updated copy of System Metadata for ", resource_map_pid))
sysmeta <- dataone::getSystemMetadata(mn, resource_map_pid)
stopifnot(class(sysmeta) == "SystemMetadata")

Expand All @@ -671,7 +671,7 @@ update_resource_map <- function(mn,
}

# Update it
log_message(paste0("Updating resource map..."))
message(paste0("Updating resource map..."))
resmap_update_response <- dataone::updateObject(mn,
pid = resource_map_pid,
newpid = identifier,
Expand All @@ -686,7 +686,7 @@ update_resource_map <- function(mn,
file.remove(new_rm_path)
}

log_message(paste0("Successfully updated ", resource_map_pid, " with ", identifier, "."))
message(paste0("Successfully updated ", resource_map_pid, " with ", identifier, "."))

return(resmap_update_response)
}
Expand Down
8 changes: 4 additions & 4 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ create_dummy_metadata <- function(mn, data_pids=NULL) {
sysmeta <- add_admin_group_access(sysmeta)
sysmeta <- datapack::addAccessRule(sysmeta, "public", "read")

log_message(paste0("Creating metadata ", pid))
message(paste0("Creating metadata ", pid))
pid <- dataone::createObject(mn, pid, metadata_file, sysmeta)

# Remove the temporary EML File
Expand Down Expand Up @@ -77,7 +77,7 @@ create_dummy_object <- function(mn) {
sysmeta <- add_admin_group_access(sysmeta)
sysmeta <- datapack::addAccessRule(sysmeta, "public", "read")

log_message(paste0("Creating object ", pid))
message(paste0("Creating object ", pid))
create_response <- dataone::createObject(mn, pid, tmp, sysmeta)

file.remove(tmp)
Expand Down Expand Up @@ -134,7 +134,7 @@ create_dummy_package <- function(mn, size = 2) {
sysmeta <- add_admin_group_access(sysmeta)
sysmeta <- datapack::addAccessRule(sysmeta, "public", "read")

log_message(paste0("Creating resource map ", pid))
message(paste0("Creating resource map ", pid))
resource_map_pid <- dataone::createObject(mn, pid, resmap_path, sysmeta)

list(metadata = meta_pid,
Expand Down Expand Up @@ -178,7 +178,7 @@ create_dummy_parent_package <- function(mn, children) {
sysmeta <- add_admin_group_access(sysmeta)
sysmeta <- datapack::addAccessRule(sysmeta, "public", "read")

log_message(paste0("Creating parent package map ", pid))
message(paste0("Creating parent package map ", pid))
create_response <- createObject(mn, pid, resmap_path, sysmeta)

list(parent = create_response,
Expand Down
2 changes: 1 addition & 1 deletion R/inserting.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ create_from_folder <- function(mn, path, data_pids=NULL) {
publish_object(mn, data_path, data_format_ids[data_path])
},
error = function(e) {
log_message(e)
message(e)
e
})

Expand Down
Loading

0 comments on commit 574c6c2

Please sign in to comment.