[DS-749] - Allow for bitstream display order to be changed.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6580 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robin Taylor
2011-08-24 12:09:06 +00:00
parent c21fa53bd2
commit 3e49b04e32
26 changed files with 847 additions and 74 deletions

View File

@@ -10,10 +10,7 @@ package org.dspace.content;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.*;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeConfiguration;
@@ -117,6 +114,9 @@ public class Bundle extends DSpaceObject
}
else
{
//Since bitstreams can be ordered by a column in bundle2bitstream
//We cannot use queryTable & so we need to add our table later on
r.setTable("bitstream");
bitstreams.add(new Bitstream(ourContext, r));
}
}
@@ -466,18 +466,32 @@ public class Bundle extends DSpaceObject
public void setOrder(int bitstreamIds[]) throws AuthorizeException, SQLException {
AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE);
//Map the bitstreams of the bundle by identifier
Map<Integer, Bitstream> bitstreamMap = new HashMap<Integer, Bitstream>();
for (Bitstream bitstream : bitstreams) {
bitstreamMap.put(bitstream.getID(), bitstream);
}
//We need to also reoder our cached bitstreams list
bitstreams = new ArrayList<Bitstream>();
for (int i = 0; i < bitstreamIds.length; i++) {
int bitstreamId = bitstreamIds[i];
//TODO: take into account the asc & desc ! from the dspace.cfg
TableRow row = DatabaseManager.querySingleTable(ourContext, "bundle2bitstream",
"SELECT * FROM bundle2bitstream WHERE bitstream_id= ? ", bitstreamId);
if(row == null){
//This should never occur but just in case
log.warn(LogManager.getHeader(ourContext, "Invalid bitstream id while changing bitstream order", "Bundle: " + getID() + ", bitstream id: " + bitstreamId));
}else{
row.setColumn("bitstream_order", i);
DatabaseManager.update(ourContext, row);
}
// Place the bitstream in the list of bitstreams in this bundle
bitstreams.add(bitstreamMap.get(bitstreamId));
}
}