DSpace 5.4 XMLUI – 更改文件名

DSpace 5.4 XMLUI – changing file names

我们在 DSpace XMLUI 工作流程中实施了一个新步骤。此步骤更改上传文件的文件名。 我们已经尝试了两种不同的方法:


我们的方法是这样的:

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();


提前感谢您的建议!

您可以使用方法 context.turnOffAuthorisationSystem() 来暂时防止发生授权异常。确保在使用方法 context.restoreAuthSystemState()!

调用 context.commit() 后恢复授权

例如:

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()
}

查看 DSpace 5x 代码,我在创建项目时在 Item.create() 中调用了以下内容。

    // 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)));

https://github.com/DSpace/DSpace/blob/dspace-5_x/dspace-api/src/main/java/org/dspace/content/Item.java#L179-L186

对于比特流,存在以下方法 Bitstream.updateLastModified()。

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)));
}

https://github.com/DSpace/DSpace/blob/dspace-5_x/dspace-api/src/main/java/org/dspace/content/Bitstream.java#L728-L734

您是否正在尝试获取索引以发现您分配给比特流的文件名?我不相信文件名在全文 (SOLR) 索引中。