Search code examples
javadspace

DSpace 5.4 XMLUI – changing file names


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:

  • The first:
    We followed the hints here. Problem is that our editors (they got their own user group) are obviously not authorized to do the filename change. Even when we gave them bitstream write permission in all choosable collections the authorization error still occured.


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();
  • With not succeeding in that way, we decided to do the file name change via java method directly on the database (SQL, something like UPDATE metadatavalue SET text_value = ...). It works out fine, apart from the fact that the index doesn't update our database changes.

    Therefor we got the following questions:
  • Which is the preferred or best way to change file names in DSpace?
  • Is there a feasible way to tell the index to take specific changes on the database?
    or
  • Is there a way to give DSpace groups the authorization to change bitstream metadata?


Thank you for your suggestions in advance!


Solution

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

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

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

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

    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.