Reputation: 38
We implemented a new step into our DSpace XMLUI workflow. This step changes the filename of the uploaded file. We've already tried two different approaches:
Our method looks like this:
private void updateFileName(DBConnection dspaceDbConnection, Context c, Item item, String fName)
throws Exception {
Bundle[] bundles = item.getBundles("ORIGINAL");
for (int i = 0; i < bundles.length; i++) {
Bitstream[] bitstreams = bundles[i].getBitstreams();
for (int j = 0; j < bitstreams.length; j++) {
bitstreams[j].setName(fileName);
bitstreams[j].update();
log.info("file name change:" + fileName);
}
}
c.commit();
Thank you for your suggestions in advance!
Upvotes: 1
Views: 404
Reputation: 3956
Looking at the DSpace 5x code, I the following is called in Item.create() when creating an item.
// Call update to give the item a last modified date. OK this isn't
// amazingly efficient but creates don't happen that often.
context.turnOffAuthorisationSystem();
i.update();
context.restoreAuthSystemState();
context.addEvent(new Event(Event.CREATE, Constants.ITEM, i.getID(),
null, i.getIdentifiers(context)));
For a Bitstream, the following method Bitstream.updateLastModified() exists.
public void updateLastModified()
{
//Also fire a modified event since the bitstream HAS been modified
ourContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, getID(), null, getIdentifiers(ourContext)));
}
Are you attempting to get the index to discover the file name that you have assigned to the bitstream? I do not believe that the file names are in the full text (SOLR) index.
Upvotes: 1
Reputation:
You could make use of method context.turnOffAuthorisationSystem() to temporarily prevent authorization exceptions from occurring. Make sure to restore the authorization after calling context.commit() with method context.restoreAuthSystemState()!
For example:
private void updateFileName(DBConnection dspaceDbConnection, Context c, Item item, String fName)
throws Exception {
try{
c.turnOffAuthorisationSystem()
Bundle[] bundles = item.getBundles("ORIGINAL");
for (int i = 0; i < bundles.length; i++) {
Bitstream[] bitstreams = bundles[i].getBitstreams();
for (int j = 0; j < bitstreams.length; j++) {
bitstreams[j].setName(fileName);
bitstreams[j].update();
log.info("file name change:" + fileName);
}
}
c.commit();
}
finally {
c.restoreAuthSystemState()
}
Upvotes: 1