diff --git a/doc/release-notes/10975-fix-file-replace-via-api b/doc/release-notes/10975-fix-file-replace-via-api new file mode 100644 index 00000000000..71646015a32 --- /dev/null +++ b/doc/release-notes/10975-fix-file-replace-via-api @@ -0,0 +1,3 @@ +A bug that caused replacing files via API when file PIDs were enabled has been fixed. + + For testing purposes, the FAKE PID provider can now be used with file PIDs enabled. (The FAKE provider is not recommended for any production use.) \ No newline at end of file diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java index dc8884405ef..209791faafb 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java @@ -230,7 +230,8 @@ public Dataset execute(CommandContext ctxt) throws CommandException { if (!theDataset.getOrCreateEditVersion().equals(fmd.getDatasetVersion())) { fmd = FileMetadataUtil.getFmdForFileInEditVersion(fmd, theDataset.getOrCreateEditVersion()); } - } + } + fmd.setDataFile(ctxt.em().merge(fmd.getDataFile())); fmd = ctxt.em().merge(fmd); // There are two datafile cases as well - the file has been released, so we're @@ -241,13 +242,15 @@ public Dataset execute(CommandContext ctxt) throws CommandException { ctxt.engine().submit(new DeleteDataFileCommand(fmd.getDataFile(), getRequest())); // and remove the file from the dataset's list theDataset.getFiles().remove(fmd.getDataFile()); + ctxt.em().remove(fmd.getDataFile()); + ctxt.em().remove(fmd); } else { - // if we aren't removing the file, we need to explicitly remove the fmd from the - // context and then remove it from the datafile's list ctxt.em().remove(fmd); + // if we aren't removing the file, we need to remove it from the datafile's list FileMetadataUtil.removeFileMetadataFromList(fmd.getDataFile().getFileMetadatas(), fmd); } - // In either case, to fully remove the fmd, we have to remove any other possible + // In either case, we've removed from the context + // And, to fully remove the fmd, we have to remove any other possible // references // From the datasetversion FileMetadataUtil.removeFileMetadataFromList(theDataset.getOrCreateEditVersion().getFileMetadatas(), fmd); @@ -255,6 +258,7 @@ public Dataset execute(CommandContext ctxt) throws CommandException { for (DataFileCategory cat : theDataset.getCategories()) { FileMetadataUtil.removeFileMetadataFromList(cat.getFileMetadatas(), fmd); } + } for(FileMetadata fmd: theDataset.getOrCreateEditVersion().getFileMetadatas()) { logger.fine("FMD: " + fmd.getId() + " for file: " + fmd.getDataFile().getId() + "is in final draft version"); diff --git a/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/fake/FakeDOIProvider.java b/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/fake/FakeDOIProvider.java index a967fb40620..023b766f2ac 100644 --- a/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/fake/FakeDOIProvider.java +++ b/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/fake/FakeDOIProvider.java @@ -44,8 +44,11 @@ public List getProviderInformation() { } @Override - public String createIdentifier(DvObject dvo) throws Throwable { - return "fakeIdentifier"; + public String createIdentifier(DvObject dvObject) throws Throwable { + if(dvObject.getIdentifier() == null || dvObject.getIdentifier().isEmpty() ){ + dvObject = generatePid(dvObject); + } + return dvObject.getIdentifier(); } @Override