[ 
https://jira.duraspace.org/browse/DS-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21970#comment-21970
 ] 

Mark Diggory commented on DS-749:
---------------------------------

I've re-evaluated the approach provided and suggesting some alternatives

The functionality is already present in the Bundle class.

 String bitstreamOrderingField  = 
ConfigurationManager.getProperty("webui.bitstream.order.field");
        String bitstreamOrderingDirection   = 
ConfigurationManager.getProperty("webui.bitstream.order.direction");

        if (bitstreamOrderingField == null)
        {
            bitstreamOrderingField = "sequence_id";
        }

        if (bitstreamOrderingDirection == null)
        {
            bitstreamOrderingDirection = "ASC";
        }
        
        StringBuilder query = new StringBuilder();
        query.append("SELECT bitstream.* 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(bitstreamOrderingField);
        query.append(" ");
        query.append(bitstreamOrderingDirection);

a JOIN is used to bring together the following two tables and the sort is 
completed on them

CREATE TABLE Bitstream
(
   bitstream_id            INTEGER PRIMARY KEY,
   bitstream_format_id     INTEGER REFERENCES 
BitstreamFormatRegistry(bitstream_format_id),
   name                    VARCHAR(256),
   size_bytes              BIGINT,
   checksum                VARCHAR(64),
   checksum_algorithm      VARCHAR(32),
   description             TEXT,
   user_format_description TEXT,
   source                  VARCHAR(256),
   internal_id             VARCHAR(256),
   deleted                 BOOL,
   store_number            INTEGER,
   sequence_id             INTEGER
);

-------------------------------------------------------
-- Bundle2Bitstream table
-------------------------------------------------------
CREATE TABLE Bundle2Bitstream
(
  id           INTEGER PRIMARY KEY,
  bundle_id    INTEGER REFERENCES Bundle(bundle_id),
  bitstream_id INTEGER REFERENCES Bitstream(bitstream_id)
);



Concern: The Display order is a characteristic of the Bundle as a container of 
Bitstreams and not so much a feature of the Bitstream, thus there should be no 
changes to the Bitstream API.  A Bitstream is not required to be in a Bundle 
parent to exist and the "setDisplayOrder" method hasn't value on a single 
bitstream attached to a Community or Collection.  Likewise, firing Bitstream 
update events is costly and will result in updates to the browse, search and 
discovery indexes when the actual indexed content is not changing.

Display ordering should still be determined by ordering the Bitstreams that are 
in the Bundle and efficiently implemented in that Bundle's code.  By creating a 
method "Bundle.setDisplayOrder(order)" we would enableApplications to be able 
to reset the Bitstream ordering directly in the Bundle without firing Bitstream 
Change events.  The UI can use javascript to setup the ordering with/without 
server callbacks and a "update" button would complete the reordering of all the 
bitstreams adjusted by the user at once within one alteration and update of the 
Bundle class:

Adding a column to the bundle2bitstream table called "order" and configuring it 
in "webui.bitstream.order.field" will enable manual ordering of the bitstreams 
in the Bundle with minimal code changes to Bundle and surrounding application 
code and no changes to Bitstream itself. 

----

Benefits: 

Reordering Bitstream in an Bundle is an Item change Event, not a Bitstream 
change event, the Bitstream itself hasn't changed. A method 
"Bundle.setDisplayOrder(int[] bitstreams)" would enable the UI to reset the 
Bitstream ordering across all the bitstreams in the Bundle without firing 
Bitstream Change events. This assures that it is the Bundle the event is tied 
to, we can exclude these changes from issuing change events. Thus in a 
reordering action, Items would not require reindexing.

Ordering would be deterministic based on array ordering, not calculated and 
requiring adjustment of individual Bitstream records.

This approach will still efficiently impact the ordering of Bitstreams in 
Bundles system wide and be encapsulated in the DSpace api rather than 
application code.

The approach will require less "application" level logic, The UI and/or CLI 
code would be focused on assigning an order to the items. if the column is 
empty, then the order will default to database order. Once the order is 
adjusted, it will be enforced.

Tangent, Solution could be applied not just to Bitstreams, but generically to 
any DSpaceObject "container" with a container2contained table. Ordering Bundles 
in an Item, Communities/Collections in a Community.

                
> allow for bitstream display order to be changed
> -----------------------------------------------
>
>                 Key: DS-749
>                 URL: https://jira.duraspace.org/browse/DS-749
>             Project: DSpace
>          Issue Type: New Feature
>          Components: JSPUI
>            Reporter: Jose Blanco
>         Attachments: GenerateBitDisplayOrder.java
>
>
> This patch allows user with access priviledges to edit an item to change the 
> order in which a bitstream is displayed 
> in the item display.  This patch is for the JSPUI. 
> The first thing that needs to be done is that a new field needs to be added 
> to the bitstream table with the following SQL:
> alter table bitstream add display_order integer;
> Then that field needs to be populated with the values in the sequence_id 
> table.  I have provided a perl script 
> that I used to do this: fix-display-order.
> Once this is done, make the following code changes.
> File =>tools/edit-item-form.jsp
> +             <th id="t11" class="oddRowOddCol"><strong><fmt:message 
> key="jsp.tools.edit-item-form.elem10"/></strong></th>
>               <th id="t11" class="oddRowEvenCol"><strong><fmt:message 
> key="jsp.tools.edit-item-form.elem5"/></strong></th>
> AND
> +                <td headers="t11" class="<%= row %>RowOddCol">
> +                    <input type="text" name="bitstream_order_<%= key %>" 
> value="<%= (Integer.toString(bitstreams[j].getDisplayOrder()) == null ? "" : 
> Integer.toString(bitstreams[j].getDisplayOrder())) %>" size="4"/>
> +                </td>
>               <% if (bundles[i].getName().equals("ORIGINAL"))
>                  { %>
> File => Messages.properties
> jsp.tools.edit-item-form.elem9                                  = Description
> +jsp.tools.edit-item-form.elem10                                = 
> Display<BR>Order
> file Biststream.java
> +     public int getDisplayOrder()
> +     {
> +         return bRow.getIntColumn("display_order");
> +     }
> + 
> +     public void setDisplayOrder(int order)
> +     {
> +         bRow.setColumn("display_order", order);
> +         modifiedMetadata = true;
> +         addDetails("DisplayOrder");
> +     }
>  
> File => Item.java
>                 if (streams[k].getSequenceID() < 0)
>                 {
>                     streams[k].setSequenceID(sequence);
> +                    streams[k].setDisplayOrder(sequence);
>                     sequence++;
>                     streams[k].update();
>                 }
> File => Bundle.java
> -                        + "bundle2bitstream.bundle_id= ? ",
> +                         + "bundle2bitstream.bundle_id= ? "
> +                       + "ORDER BY bitstream.display_order",
> File =>  EditItemServlet.java
>                     int formatID = UIUtil.getIntParameter(request,
>                             "bitstream_format_id_" + key);
> +                    int display_order = UIUtil.getIntParameter(request,
> +                            "bitstream_order_" + key);
> AND
>                     bitstream.setName(name);
>                     bitstream.setSource(source);
>                     bitstream.setDescription(desc);
> +                    bitstream.setDisplayOrder(display_order);
> ==============================================
> This is the fix-display-order perl script used to iniailize display_order:
> #!/usr/bin/perl
> RE.
> BEGIN
> {
>         require "strict.pm";
>         strict::import();
> }
> # ----------------------------------------------------------------------
> #               start of MAIN
> # ----------------------------------------------------------------------
> use Encode;
> use utf8;
> use DBI;
> use File::Path;
> my $dbhP = DBI->connect("dbi:Pg:dbname=dspace-name", "dspace-user", 
> "password");
> &UpdateDisplayOrder ();
> $dbhP->disconnect;
> exit;
> sub UpdateDisplayOrder
> {
>     
>   my $statement = qq{select bitstream_id, sequence_id from bitstream};
>     my $sth = $dbhP->prepare($statement)
>       or die "Couldn't prepare statement: " . $dbhP->errstr;
>     
>     # Read the matching records and print them out
>     $sth->execute()             # Execute the query
>       or die "Couldn't execute statement: " . $sth->errstr;
>     my $count = 0;
>     my ( $url, $msg );
>     my ( $bitstream_id, $sequence_id, @data );
>     while (@data = $sth->fetchrow_array()) {
>       $bitstream_id       = $data[0];
>       $sequence_id        = $data[1];
>      
>       if ( $sequence_id )
>       {
>       my $sql = qq{update bitstream set display_order = $sequence_id where 
> bitstream_id= $bitstream_id};
>         &ProcessSQL ( $sql );
>       }
>     }
>     $sth->finish;
> }
> sub ProcessSQL 
>   {
>     my ( $statement ) = @_;
>     my $sth = $dbhP->prepare($statement)
>       or die "Couldn't prepare statement: " . $dbhP->errstr;
>   
>     # Read the matching records and print them out
>     $sth->execute()             # Execute the query
>       or die "Couldn't execute statement: " . $sth->errstr;
>     $sth->finish;
>   }
> __END__;
> ==============================================

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://jira.duraspace.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Dspace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-devel

Reply via email to