diff --git a/dspace-api/src/main/java/org/dspace/content/Bundle.java b/dspace-api/src/main/java/org/dspace/content/Bundle.java index 129475118d..e65ca1ff81 100644 --- a/dspace-api/src/main/java/org/dspace/content/Bundle.java +++ b/dspace-api/src/main/java/org/dspace/content/Bundle.java @@ -85,19 +85,19 @@ public class Bundle extends DSpaceObject { bitstreamOrderingDirection = "ASC"; } - + StringBuilder query = new StringBuilder(); - query.append("SELECT bitstream.* FROM bitstream, bundle2bitstream WHERE"); + query.append("SELECT bitstream.*,bundle2bitstream.bitstream_order FROM bitstream, bundle2bitstream WHERE"); query.append(" bundle2bitstream.bitstream_id=bitstream.bitstream_id AND"); query.append(" bundle2bitstream.bundle_id= ?"); - query.append(" ORDER BY bitstream."); + query.append(" ORDER BY "); query.append(bitstreamOrderingField); query.append(" "); query.append(bitstreamOrderingDirection); // Get bitstreams - TableRowIterator tri = DatabaseManager.queryTable( - ourContext, "bitstream", + TableRowIterator tri = DatabaseManager.query( + ourContext, query.toString(), bundleRow.getIntColumn("bundle_id")); @@ -105,7 +105,7 @@ public class Bundle extends DSpaceObject { while (tri.hasNext()) { - TableRow r = (TableRow) tri.next(); + TableRow r = tri.next(); // First check the cache Bitstream fromCache = (Bitstream) context.fromCache( @@ -453,9 +453,34 @@ public class Bundle extends DSpaceObject TableRow mappingRow = DatabaseManager.row("bundle2bitstream"); mappingRow.setColumn("bundle_id", getID()); mappingRow.setColumn("bitstream_id", b.getID()); + mappingRow.setColumn("bitstream_order", b.getSequenceID()); DatabaseManager.insert(ourContext, mappingRow); } + /** + * Changes bitstream order according to the array + * @param bitstreamIds the identifiers in the order they are to be set + * @throws SQLException when an SQL error has occurred (querying DSpace) + * @throws AuthorizeException If the user can't make the changes + */ + public void setOrder(int bitstreamIds[]) throws AuthorizeException, SQLException { + AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE); + + for (int i = 0; i < bitstreamIds.length; i++) { + int bitstreamId = bitstreamIds[i]; + + TableRow row = DatabaseManager.querySingleTable(ourContext, "bundle2bitstream", + "SELECT * FROM bundle2bitstream WHERE bitstream_id= ? ", bitstreamId); + + if(row == null){ + 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); + } + } + } + /** * Remove a bitstream from this bundle - the bitstream is only deleted if * this was the last reference to it diff --git a/dspace-api/src/test/resources/database_schema.sql b/dspace-api/src/test/resources/database_schema.sql index bf0ea67a5e..392927fe76 100644 --- a/dspace-api/src/test/resources/database_schema.sql +++ b/dspace-api/src/test/resources/database_schema.sql @@ -279,9 +279,10 @@ CREATE INDEX item2bundle_bundle_fk_idx ON Item2Bundle(bundle_id); ------------------------------------------------------- CREATE TABLE Bundle2Bitstream ( - id INTEGER PRIMARY KEY, - bundle_id INTEGER REFERENCES Bundle(bundle_id), - bitstream_id INTEGER REFERENCES Bitstream(bitstream_id) + id INTEGER PRIMARY KEY, + bundle_id INTEGER REFERENCES Bundle(bundle_id), + bitstream_id INTEGER REFERENCES Bitstream(bitstream_id), + bitstream_order INTEGER ); -- index by bundle_id diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index 957cb543b2..e9221eb30e 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -1291,7 +1291,7 @@ authority.minconfidence = ambiguous ## Specify the ordering that bitstreams are listed. ## ## Bitstream field to sort on. Values: sequence_id or name. Default: sequence_id -#webui.bitstream.order.field = "sequence_id" +webui.bitstream.order.field = bitstream_order ## Direction of sorting order. Values: DESC or ASC. Default: ASC #webui.bitstream.order.direction = ASC diff --git a/dspace/etc/oracle/database_schema.sql b/dspace/etc/oracle/database_schema.sql index 3ecaa1bf11..c5d4194673 100644 --- a/dspace/etc/oracle/database_schema.sql +++ b/dspace/etc/oracle/database_schema.sql @@ -233,9 +233,10 @@ CREATE INDEX item2bundle_bundle_fk_idx ON Item2Bundle(bundle_id); ------------------------------------------------------- CREATE TABLE Bundle2Bitstream ( - id INTEGER PRIMARY KEY, - bundle_id INTEGER REFERENCES Bundle(bundle_id), - bitstream_id INTEGER REFERENCES Bitstream(bitstream_id) + id INTEGER PRIMARY KEY, + bundle_id INTEGER REFERENCES Bundle(bundle_id), + bitstream_id INTEGER REFERENCES Bitstream(bitstream_id), + bitstream_order INTEGER ); -- index by bundle_id @@ -731,4 +732,4 @@ CREATE TABLE harvested_item id INTEGER PRIMARY KEY ); -CREATE INDEX harvested_item_fk_idx ON harvested_item(item_id); \ No newline at end of file +CREATE INDEX harvested_item_fk_idx ON harvested_item(item_id); diff --git a/dspace/etc/oracle/database_schema_17-18.sql b/dspace/etc/oracle/database_schema_17-18.sql new file mode 100644 index 0000000000..0d428c70e0 --- /dev/null +++ b/dspace/etc/oracle/database_schema_17-18.sql @@ -0,0 +1,29 @@ +-- +-- database_schema_17-18.sql +-- +-- Version: $Revision$ +-- +-- Date: $Date: 2009-04-23 22:26:59 -0500 (Thu, 23 Apr 2009) $ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +-- +-- SQL commands to upgrade the database schema of a live DSpace 1.7 or 1.7.x +-- to the DSpace 1.8 database schema +-- +-- DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. +-- DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. +-- DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. +-- +------------------------------------------- +-- New column for bitstream order DS-749 -- +------------------------------------------- +ALTER TABLE bundle2bitstream ADD bitstream_order INTEGER; + +--Place the sequence id's in the order +UPDATE bundle2bitstream SET bitstream_order=(SELECT sequence_id FROM bitstream WHERE bitstream.bitstream_id=bundle2bitstream.bitstream_id); diff --git a/dspace/etc/postgres/database_schema.sql b/dspace/etc/postgres/database_schema.sql index 8629b4135c..d9bd080632 100644 --- a/dspace/etc/postgres/database_schema.sql +++ b/dspace/etc/postgres/database_schema.sql @@ -270,9 +270,10 @@ CREATE INDEX item2bundle_bundle_fk_idx ON Item2Bundle(bundle_id); ------------------------------------------------------- CREATE TABLE Bundle2Bitstream ( - id INTEGER PRIMARY KEY, - bundle_id INTEGER REFERENCES Bundle(bundle_id), - bitstream_id INTEGER REFERENCES Bitstream(bitstream_id) + id INTEGER PRIMARY KEY, + bundle_id INTEGER REFERENCES Bundle(bundle_id), + bitstream_id INTEGER REFERENCES Bitstream(bitstream_id), + bitstream_order INTEGER ); -- index by bundle_id diff --git a/dspace/etc/postgres/database_schema_17-18.sql b/dspace/etc/postgres/database_schema_17-18.sql new file mode 100644 index 0000000000..0d428c70e0 --- /dev/null +++ b/dspace/etc/postgres/database_schema_17-18.sql @@ -0,0 +1,29 @@ +-- +-- database_schema_17-18.sql +-- +-- Version: $Revision$ +-- +-- Date: $Date: 2009-04-23 22:26:59 -0500 (Thu, 23 Apr 2009) $ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +-- +-- SQL commands to upgrade the database schema of a live DSpace 1.7 or 1.7.x +-- to the DSpace 1.8 database schema +-- +-- DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. +-- DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. +-- DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. DUMP YOUR DATABASE FIRST. +-- +------------------------------------------- +-- New column for bitstream order DS-749 -- +------------------------------------------- +ALTER TABLE bundle2bitstream ADD bitstream_order INTEGER; + +--Place the sequence id's in the order +UPDATE bundle2bitstream SET bitstream_order=(SELECT sequence_id FROM bitstream WHERE bitstream.bitstream_id=bundle2bitstream.bitstream_id);