Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IQSS 10975 - fix file replace #10979

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/release-notes/10975-fix-file-replace-via-api
Original file line number Diff line number Diff line change
@@ -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.)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -241,20 +242,23 @@ 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);
// and from the list associated with each category
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public List<String> 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
Expand Down
Loading