DataONEorg / rdataone

R package for reading and writing data at DataONE data repositories
http://doi.org/10.5063/F1M61H5X
36 stars 19 forks source link

Uploading modified 'metadata-only' package causes error #256

Closed gothub closed 3 years ago

gothub commented 4 years ago

The following steps cause an error during 'uploadDataPackage':

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)
gothub commented 3 years ago

This error was due to an incorrectly spelled data.frame index. This problem was fixed in commit ac7b6c4b14e71aeefad6ea47a35f8131a8608080