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

Jose Blanco commented on DS-749:
--------------------------------

Bitstream ordering patch for xmlui:

This patch is for the xmlui interface.  It makes it possible for an 
administrator to change the 
order in which bitstreams are displayed on the item view page.  I have included 
in this patch a
new file, GenerateBitDisplayOrder.java, which is used to populate the new field 
in the bitstream 
table - display_order.  In my previous submission of this patch, I used a perl 
script to do this, 
but it was pointed out that it would be better to have a java file to serve 
this purpose.  This 
file can be executed via the launcher - "bin/dspace add-bitstream-order". 

Below are more details.

dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/i18n/messages.xml

+       <message 
key="xmlui.administrative.item.EditItemBitstreamsForm.column0">Order</message>
        <message 
key="xmlui.administrative.item.EditItemBitstreamsForm.column1"></message>


dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Administrative/administrative.js

            var userFormat = cocoon.request.get("user_format");
+           var displayOrder = cocoon.request.get("display_order");

-           result = 
FlowItemUtils.processEditBitstream(getDSContext(),itemID,bitstreamID,primary,description,formatID,userFormat);
+           result = 
FlowItemUtils.processEditBitstream(getDSContext(),itemID,bitstreamID,primary,description,formatID,userFormat,displayOrder);

dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowItemUtils.java

-   public static FlowResult processEditBitstream(Context context, int itemID, 
int bitstreamID, String primary, String description, int formatID, String 
userFormat) throws SQLException, AuthorizeException,  AuthorizeBioException
+    public static FlowResult processEditBitstream(Context context, int itemID, 
int bitstreamID, String primary, String description, int formatID, String 
userFormat, String displayOrder) throws SQLException, AuthorizeException,  
AuthorizeBioException
        {
                FlowResult result = new FlowResult();
                result.setContinue(false);
                
                Bitstream bitstream = Bitstream.find(context, bitstreamID);
                BitstreamFormat currentFormat = bitstream.getFormat();

                //Step 1:
-               // Update the bitstream's description
+               // Update the bitstream's description, and display order
                if (description != null)
                {
                        bitstream.setDescription(description);
                }

+               if (displayOrder != null)
+               {
+                   bitstream.setDisplayOrder(Integer.parseInt(displayOrder));
+               }


=> I wanted to use the messages.xml file to store the display string, but could 
not get it to work.
dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/item/EditItemBitstreamsForm.java

                // User supplied format
                Text userFormat = edit.addItem().addText("user_format");
                userFormat.setLabel(T_user_label);
                userFormat.setHelp(T_user_help);
                userFormat.setValue(bitstream.getUserFormatDescription());

+               // Display Order
+               if (bundles != null && bundles.length > 0)
+               {
+                   if ( bundles[0].getName().equals("ORIGINAL") )
+                   {
+                       Text displayOrder = 
edit.addItem().addText("display_order");
+                       displayOrder.setLabel("Display Order");
+                       displayOrder.setHelp("Order in whcih files will be 
displayed in item view page.");
+                       
displayOrder.setValue(Integer.toString(bitstream.getDisplayOrder()));
+                   }
+               }

dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/administrative/item/EditItemBitstreamsForm.java


+       private static final Message T_column0 = 
message("xmlui.administrative.item.EditItemBitstreamsForm.column0");
        private static final Message T_column1 = 
message("xmlui.administrative.item.EditItemBitstreamsForm.column1");

Further down:

+               header.addCellContent(T_column0);
                header.addCellContent(T_column1);
                header.addCellContent(T_column2);
                header.addCellContent(T_column3);
                header.addCellContent(T_column4);
                header.addCellContent(T_column5);

                Bundle[] bundles = item.getBundles();

                for (Bundle bundle : bundles)
                {

-                       Cell bundleCell = files.addRow().addCell(1, 5);
+                       Cell bundleCell = files.addRow().addCell(1, 6);

Further down:

                                String viewURL = contextPath + 
"/bitstream/id/"+bitstream.getID()+"/"+bitstream.getName();


+                               Integer order = bitstream.getDisplayOrder();
                                Row row = files.addRow();
+                               if ( !  bundle.getName().equals("ORIGINAL") )
+                               {
+                                   row.addCell().addContent("N/A");
+                               }
+                               else
+                               {
+                                   
row.addCell().addContent(Integer.toString(order));
+                               }

AND further down:

                if (AuthorizeManager.authorizeActionBoolean(context, item, 
Constants.ADD))
                {
-                       Cell cell = files.addRow().addCell(1, 5);
+                       Cell cell = files.addRow().addCell(1, 6);
                        
cell.addXref(contextPath+"/admin/item?administrative-continue="+knot.getId()+"&submit_add",T_submit_add);
                }
                else
                {
-                       Cell cell = files.addRow().addCell(1, 5);
+                       Cell cell = files.addRow().addCell(1, 6);
                        cell.addHighlight("fade").addContent(T_no_upload);
                }


launcher.xml
    <command>
        <name>update-handle-prefix</name>
        <description>Update handle records and metadata when moving from one 
handle to another</description>
        <step>
            <class>org.dspace.handle.UpdateHandlePrefix</class>
        </step>
    </command>

+    <command>
+        <name>add-bitstream-order</name>
+        <description>Populates the bitstream table field 
display_order</description>
+        <step>
+            <class>org.dspace.storage.rdbms.GenerateBitDisplayOrder</class>
+        </step>
+    </command>

=> New file to store populate the new display_order field in the bitstream 
table. This file
is attached with this patch.
dspace-api/src/main/java/org/dspace/storage/rdbms/GenerateBitDisplayOrder.java 

                
> 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
>
> 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