mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 05:53:08 +00:00
Add the capability to define in which order the index should be listed by default (ascending or descending)
Also, removed two uses of 'magic' strings - replaced with static values from SortOption git-svn-id: http://scm.dspace.org/svn/repo/trunk@2259 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -83,6 +83,9 @@ public class BrowseIndex
|
||||
/** a three part array of the metadata bits (e.g. dc.contributor.author) */
|
||||
private String[] mdBits;
|
||||
|
||||
/** default order (asc / desc) for this index */
|
||||
private String defaultOrder;
|
||||
|
||||
/** additional 'internal' tables that are always defined */
|
||||
private static BrowseIndex itemIndex = new BrowseIndex("bi_item");
|
||||
private static BrowseIndex withdrawnIndex = new BrowseIndex("bi_withdrawn");
|
||||
@@ -135,9 +138,10 @@ public class BrowseIndex
|
||||
throws BrowseException
|
||||
{
|
||||
boolean valid = true;
|
||||
this.defaultOrder = SortOption.ASCENDING;
|
||||
this.number = number;
|
||||
|
||||
String rx = "(\\w+):(\\w+):([\\w\\.\\*]+):?(\\w*)";
|
||||
String rx = "(\\w+):(\\w+):([\\w\\.\\*]+):?(\\w*):?(\\w*)";
|
||||
Pattern pattern = Pattern.compile(rx);
|
||||
Matcher matcher = pattern.matcher(definition);
|
||||
|
||||
@@ -157,6 +161,15 @@ public class BrowseIndex
|
||||
if (datatype == null || datatype.equals(""))
|
||||
valid = false;
|
||||
|
||||
// If an optional ordering configuration is supplied,
|
||||
// set the defaultOrder appropriately (asc or desc)
|
||||
if (matcher.groupCount() > 4)
|
||||
{
|
||||
String order = matcher.group(5);
|
||||
if (SortOption.DESCENDING.equalsIgnoreCase(order))
|
||||
this.defaultOrder = SortOption.DESCENDING;
|
||||
}
|
||||
|
||||
tableBaseName = makeTableBaseName(number);
|
||||
}
|
||||
else if (isItemIndex())
|
||||
@@ -191,6 +204,14 @@ public class BrowseIndex
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Default order for this index, null if not specified
|
||||
*/
|
||||
public String getDefaultOrder()
|
||||
{
|
||||
return defaultOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the datatype.
|
||||
*/
|
||||
|
@@ -39,6 +39,7 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Context;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* A class which represents the initial request to the browse system.
|
||||
@@ -50,6 +51,9 @@ import org.dspace.core.Context;
|
||||
*/
|
||||
public class BrowserScope
|
||||
{
|
||||
/** the logger for this class */
|
||||
private static Logger log = Logger.getLogger(BrowserScope.class);
|
||||
|
||||
/** the DSpace context */
|
||||
private Context context;
|
||||
|
||||
@@ -57,7 +61,7 @@ public class BrowserScope
|
||||
private BrowseIndex browseIndex;
|
||||
|
||||
/** the order in which to display results */
|
||||
private String order = "ASC";
|
||||
private String order;
|
||||
|
||||
/** the field upon which to sort */
|
||||
private int sortBy;
|
||||
@@ -325,7 +329,23 @@ public class BrowserScope
|
||||
*/
|
||||
public String getOrder()
|
||||
{
|
||||
if (order != null)
|
||||
return order;
|
||||
|
||||
try
|
||||
{
|
||||
SortOption so = getSortOption();
|
||||
|
||||
if (so != null)
|
||||
return so.getDefaultOrder();
|
||||
}
|
||||
catch (BrowseException be)
|
||||
{
|
||||
// recoverable problem, just log the error and continue
|
||||
log.debug("Unable to retrieve a sort option for this browse", be);
|
||||
}
|
||||
|
||||
return SortOption.ASCENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,8 +353,18 @@ public class BrowserScope
|
||||
*/
|
||||
public void setOrder(String order)
|
||||
{
|
||||
if (order != null && !"".equals(order))
|
||||
this.order = order;
|
||||
if (order == null)
|
||||
{
|
||||
this.order = null;
|
||||
}
|
||||
else if (SortOption.ASCENDING.equalsIgnoreCase(order))
|
||||
{
|
||||
this.order = SortOption.ASCENDING;
|
||||
}
|
||||
else if (SortOption.DESCENDING.equalsIgnoreCase(order))
|
||||
{
|
||||
this.order = SortOption.DESCENDING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,7 +422,7 @@ public class BrowserScope
|
||||
// Create a dummy sortOption for the metadata sort
|
||||
String dataType = browseIndex.getDataType();
|
||||
String type = ("date".equals(dataType) ? "date" : "text");
|
||||
sortOption = new SortOption(0, browseIndex.getName(), browseIndex.getMetadata(), type);
|
||||
sortOption = new SortOption(0, browseIndex.getName(), browseIndex.getMetadata(), type, browseIndex.getDefaultOrder());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -505,17 +535,36 @@ public class BrowserScope
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if ascending, false if not
|
||||
* @return true if ascending, false if not - or not set
|
||||
*/
|
||||
public boolean isAscending()
|
||||
{
|
||||
if ("ASC".equals(order))
|
||||
if (SortOption.ASCENDING.equalsIgnoreCase(order))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SortOption.DESCENDING.equalsIgnoreCase(order))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SortOption so = getSortOption();
|
||||
|
||||
if (so != null && SortOption.DESCENDING.equalsIgnoreCase(so.getDefaultOrder()))
|
||||
return false;
|
||||
}
|
||||
catch (BrowseException be)
|
||||
{
|
||||
// recoverable problem, just log the error and continue
|
||||
log.debug("Unable to retrieve a sort option for this browse", be);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if has value, false if not
|
||||
*/
|
||||
|
@@ -55,6 +55,9 @@ import org.dspace.core.ConfigurationManager;
|
||||
*/
|
||||
public class SortOption
|
||||
{
|
||||
public static final String ASCENDING = "ASC";
|
||||
public static final String DESCENDING = "DESC";
|
||||
|
||||
/** the sort configuration number */
|
||||
private int number;
|
||||
|
||||
@@ -70,6 +73,9 @@ public class SortOption
|
||||
/** the metadata broken down into bits for convenience */
|
||||
private String[] mdBits;
|
||||
|
||||
/** default ordering for this sort, when not supplied by the user */
|
||||
private String defaultOrder;
|
||||
|
||||
/** the sort options available for this index */
|
||||
private static Set<SortOption> sortOptionsSet = null;
|
||||
private static Map<Integer, SortOption> sortOptionsMap = null;
|
||||
@@ -90,6 +96,21 @@ public class SortOption
|
||||
this.type = type;
|
||||
this.metadata = md;
|
||||
this.number = number;
|
||||
this.defaultOrder = SortOption.ASCENDING;
|
||||
generateMdBits();
|
||||
}
|
||||
|
||||
public SortOption(int number, String name, String md, String type, String defaultOrder)
|
||||
throws BrowseException
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.metadata = md;
|
||||
this.number = number;
|
||||
if (SortOption.DESCENDING.equalsIgnoreCase(defaultOrder))
|
||||
this.defaultOrder = SortOption.DESCENDING;
|
||||
else
|
||||
this.defaultOrder = SortOption.ASCENDING;
|
||||
generateMdBits();
|
||||
}
|
||||
|
||||
@@ -105,7 +126,7 @@ public class SortOption
|
||||
{
|
||||
this.number = number;
|
||||
|
||||
String rx = "(\\w+):([\\w\\.\\*]+):(\\w+)";
|
||||
String rx = "(\\w+):([\\w\\.\\*]+):(\\w+):?(\\w*)";
|
||||
Pattern pattern = Pattern.compile(rx);
|
||||
Matcher matcher = pattern.matcher(definition);
|
||||
|
||||
@@ -118,9 +139,27 @@ public class SortOption
|
||||
name = matcher.group(1);
|
||||
metadata = matcher.group(2);
|
||||
type = matcher.group(3);
|
||||
if (matcher.groupCount() > 3)
|
||||
defaultOrder = matcher.group(4);
|
||||
|
||||
// If the default order is specified as descending, keep it
|
||||
// Otherwise, set the default order to ascending
|
||||
if (SortOption.DESCENDING.equalsIgnoreCase(defaultOrder))
|
||||
defaultOrder = SortOption.DESCENDING;
|
||||
else
|
||||
defaultOrder = SortOption.ASCENDING;
|
||||
|
||||
generateMdBits();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the default ordering for this sort option
|
||||
*/
|
||||
public String getDefaultOrder()
|
||||
{
|
||||
return defaultOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the metadata.
|
||||
*/
|
||||
|
@@ -103,7 +103,7 @@ public class RecentSubmissionsManager
|
||||
|
||||
// fill in the scope with the relevant gubbins
|
||||
bs.setBrowseIndex(bi);
|
||||
bs.setOrder("DESC"); // FIXME: eek - plain text flag! Should be BrowserScope.ASC or something
|
||||
bs.setOrder(SortOption.DESCENDING);
|
||||
bs.setResultsPerPage(Integer.parseInt(count));
|
||||
bs.setBrowseContainer(dso);
|
||||
for (SortOption so : SortOption.getSortOptions())
|
||||
|
@@ -145,12 +145,6 @@ public abstract class AbstractBrowserServlet extends DSpaceServlet
|
||||
resultsperpage = 20;
|
||||
}
|
||||
|
||||
// if no order parameter, default to ascending
|
||||
if (order == null || "".equals(order))
|
||||
{
|
||||
order = "ASC";
|
||||
}
|
||||
|
||||
// if year and perhaps month have been selected, we translate these into "startsWith"
|
||||
// if startsWith has already been defined then it is overwritten
|
||||
if (year != null && !"".equals(year) && !"-1".equals(year))
|
||||
|
@@ -39,27 +39,13 @@
|
||||
*/
|
||||
package org.dspace.app.webui.servlet.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.webui.servlet.DSpaceServlet;
|
||||
import org.dspace.app.webui.util.JSPManager;
|
||||
import org.dspace.app.webui.util.UIUtil;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.AuthorizeManager;
|
||||
import org.dspace.browse.BrowseEngine;
|
||||
import org.dspace.browse.BrowseException;
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.browse.BrowseInfo;
|
||||
import org.dspace.browse.BrowserScope;
|
||||
import org.dspace.browse.IndexBrowse;
|
||||
import org.dspace.browse.*;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.ItemIterator;
|
||||
@@ -67,6 +53,14 @@ import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Servlet for editing and deleting (expunging) items
|
||||
*
|
||||
@@ -372,7 +366,7 @@ public class ItemMapServlet extends DSpaceServlet
|
||||
|
||||
// set up the browse scope
|
||||
bs.setBrowseIndex(bi);
|
||||
bs.setOrder("ASC");
|
||||
bs.setOrder(SortOption.ASCENDING);
|
||||
bs.setFilterValue(name);
|
||||
bs.setJumpToValue(null);
|
||||
bs.setResultsPerPage(10000); // an arbitrary number (large) for the time being
|
||||
|
@@ -376,7 +376,7 @@ webui.licence_bundle.show = false
|
||||
#
|
||||
# webui.browse.index.<n> = <index name> : metadata : \
|
||||
# <schema prefix>.<element>[.<qualifier>|.*] : \
|
||||
# (date | title | text) :
|
||||
# (date | title | text) : (asc | desc)
|
||||
#
|
||||
# This form represent a unique index of metadata values from the item.
|
||||
#
|
||||
@@ -389,6 +389,10 @@ webui.licence_bundle.show = false
|
||||
# <other>: any other datatype will be treated the same as 'text', although
|
||||
# it will apply any custom ordering normalisation configured below
|
||||
#
|
||||
# The final part of the configuration is optional, and specifies the default ordering
|
||||
# for the index - whether it is ASCending (the default, and best for text indexes), or
|
||||
# DESCending (useful for dates - ie. most recent submissions)
|
||||
#
|
||||
# NOTE: the text to render the index will use the <index name> parameter to select
|
||||
# the message key from Messages.properties using a key of the form:
|
||||
#
|
||||
@@ -429,13 +433,15 @@ webui.browse.index.4 = subject:metadata:dc.subject.*:text
|
||||
#
|
||||
# webui.browse.sort-option.<n> = <option name> : \
|
||||
# <schema prefix>.<element>[.<qualifier>|.*] : \
|
||||
# (date, text)
|
||||
# (date | text | ...) : (asc | desc)
|
||||
#
|
||||
# This is defined much the same as above. The only difference is that the final
|
||||
# parameter just lets the sorter know whether to expect to sort by plain text (using
|
||||
# the "text" option), or by a proper date (using the "date" option). If no options
|
||||
# are specified, you will not be able to sort any results by anthing other than the
|
||||
# key values.
|
||||
# This is defined much the same as above. The parameter after the metadata
|
||||
# just lets the sorter know which normalisation to use - standard normalisations are title,
|
||||
# text or date - however additional normalisations can be defined using the PluginManager.
|
||||
#
|
||||
# The final part of the configuration is optional, and specifies the default ordering
|
||||
# for the index - whether it is ASCending (the default, and best for text indexes), or
|
||||
# DESCending (useful for dates - ie. most recent submissions)
|
||||
#
|
||||
webui.browse.sort-option.1 = title:dc.title:title
|
||||
webui.browse.sort-option.2 = dateissued:dc.date.issued:date
|
||||
|
Reference in New Issue
Block a user