The following steps cause an error during 'uploadDataPackage':
download an existing package that contains package members (i.e. data objects)
use 'removeMember' to remove all data objects
replace the existing metadata object with a new file using 'replaceMember'
upload the new 'metadata-only' package with uploadDataPackage
This is the error:
> packageId <- uploadDataPackage(d1c, pkg, public = FALSE, accessRules=myAccessRules, packageId=resourceMap, quiet=FALSE)
Updating a modified package to member node https://data.piscoweb.org/catalog/d1/mn/v2
Updated data object with id: doi:10.6085/AA/MLPA_intertidal.57.31, obsoleting id: doi:10.6085/AA/MLPA_intertidal.57.30
Error in if (dp@relations[["updated"]]) { : argument is of length zero
Here is the script used to reveal this error:
#clear environment
rm(list = ls())
#set token; need to login to MetacatUI and get token from profile
#set up environment
#load libraries
library(dataone)
library(datapack)
library(EML)
library(datamgmt)
#set up node endpoints for PISCO
cn <- CNode("PROD")
d1c<-D1Client("PROD","urn:node:PISCO")
mn <- d1c@mn
#set working directory
setwd("C:/Users/Dragonoak/Documents/work/R/cbs")
#make sure files are in working directory
getwd()
list.files()
#set package id for package to be updated
packageId <- "resourceMap_MLPA_intertidal.57.30"
#download data package
pkg <- getDataPackage(d1c, identifier=packageId, lazyLoad=TRUE, limit="0MB", quiet=FALSE)
#view contents of package
pkg
#set eml schema
#options(emld_db = "eml-2.1.1")
options(emld_db = "eml-2.2.0")
#validate EML
updatedMetadata <- "MLPA_intertidal.57.31"
eml_validate(updatedMetadata)
#correct resource map if created via java tools on PISCO server
# Remove these lines once datapack version > 1.3.2 has been installed
# Properly remove the 'dc:creator' relationship from the resource map
# First get the package relationships
relations <- getRelationships(pkg)
# Find 'dc:creator' if it exists
otherCreatorBlankNodeId <- relations[relations$predicate == datapack:::otherCreator,'object']
if (length(otherCreatorBlankNodeId)) {
message("Removing unneeded dc:creator relationships from the resource map...")
# Remove all triples from the 'dc:creator' blank node
pkg <- removeRelationships(pkg, subject=otherCreatorBlankNodeId)
# Remove the 'dc:creator' linked to the resource map
pkg <- removeRelationships(pkg, predicate=datapack:::otherCreator)
}
# End "remove dc:creator"
# At this point, the 'dc:creator' relationship should not be in the package
pkg
# Now make any changes needed to the package
#select old metadata file
oldMetadata <- selectMember(pkg, name = "sysmeta@identifier", value = "doi:10.6085/AA/MLPA_intertidal.57.30")
#replace metadata in package; update version of EML if necessary
pkg <- replaceMember(pkg, oldMetadata, replacement=updatedMetadata, formatId="https://eml.ecoinformatics.org/eml-2.2.0", newId="doi:10.6085/AA/MLPA_intertidal.57.31")
#remove object from data package
#pkg <- removeMember(pkg, oldfile, removeRelationships=TRUE)
pkg <- removeMember(pkg, "doi:10.6085/AA/MLPA_intertidal.33.2", removeRelationships=TRUE)
pkg <- removeMember(pkg, "doi:10.6085/AA/MLPA_intertidal.58.4", removeRelationships=TRUE)
pkg <- removeMember(pkg, "doi:10.6085/AA/MLPA_intertidal.59.4", removeRelationships=TRUE)
pkg <- removeMember(pkg, "doi:10.6085/AA/pisco_intertidal.31.7", removeRelationships=TRUE)
#create resource map id
resourceMap <- "resourceMap_MLPA_intertidal.57.31"
#add/modify access rules if necessary
myAccessRules <- data.frame(subject="CN=PISCO-data-managers,DC=dataone,DC=org", permission="changePermission")
#upload package
packageId <- uploadDataPackage(d1c, pkg, public = TRUE, accessRules=myAccessRules, packageId=resourceMap, quiet=FALSE)
The following steps cause an error during 'uploadDataPackage':
Here is the script used to reveal this error: