/** * Return all the configured sort options. * * @return a set of the configured sort options * @throws SortException if sort error */ public static Set<SortOption> getSortOptions() throws SortException { if (SortOption.sortOptionsSet == null) { throw new SortException("Sort options not loaded"); } return SortOption.sortOptionsSet; }
/** * @return Returns the datatype. */ public String getDataType() { if (sortOption != null) { return sortOption.getType(); } return datatype; }
/** * Tell the class to generate the metadata bits * * @throws SortException if sort error */ private void generateMdBits() throws SortException { try { mdBits = interpretField(metadata, null); } catch (IOException e) { throw new SortException(e); } }
/** * Get the defined sort option by number (.1, .2, etc). * * @param number the number of the sort option as given in the config file * @return the configured sort option with given number * @throws SortException if sort error */ public static SortOption getSortOption(int number) throws SortException { for (SortOption so : SortOption.getSortOptions()) { if (so.getNumber() == number) { return so; } } return null; }
/** * Get the defined sort option by name * * @param name the name of the sort option as given in the config file * @return the configured sort option with given name * @throws SortException if sort error */ public static SortOption getSortOption(String name) throws SortException { for (SortOption so : SortOption.getSortOptions()) { if (StringUtils.equals(name, so.getName())) { return so; } } return null; }
/** * Get the default sort option - initially, just the first one defined. * * @return the first configured sort option * @throws SortException if sort error */ public static SortOption getDefaultSortOption() throws SortException { for (SortOption so : getSortOptions()) { return so; } return null; } }
/** * Construct a new SortOption object using the definition from the configuration * * @param number the number of the sort option as given in the config file * @param definition definition from the configuration * @throws SortException if sort error */ public SortOption(int number, String definition) throws SortException { this.number = number; String rx = "(\\w+):([\\w\\.\\*]+):(\\w+):?(\\w*)"; Pattern pattern = Pattern.compile(rx); Matcher matcher = pattern.matcher(definition); if (!matcher.matches()) { throw new SortException("Sort Order configuration is not valid: webui.itemlist.sort-option." + number + " = " + definition); } name = matcher.group(1); metadata = matcher.group(2); type = matcher.group(3); // If the option is configured to be hidden, then set the visible flag to false // otherwise, flag it as visible (true) if (matcher.groupCount() > 3 && "hide".equalsIgnoreCase(matcher.group(4))) { visible = false; } else { visible = true; } generateMdBits(); }
/** * Constructor for creating generic / internal index objects * * @param baseName The base of the table name */ private BrowseIndex(String baseName) { try { number = -1; tableBaseName = baseName; displayType = "item"; sortOption = SortOption.getDefaultSortOption(); } catch (SortException se) { // FIXME Exception handling } }
delegate = OrderFormat.getDelegate(type); if (delegate != null) { return delegate.makeSortString(value, language); return authorDelegate.makeSortString(value, language); return titleDelegate.makeSortString(value, language); return textDelegate.makeSortString(value, language); return dateDelegate.makeSortString(value, language); return authorityDelegate.makeSortString(value, language);
/** * Normalize the title of a Metadatum. * * @param value metadata value * @return normalized title */ protected String normalizeTitle(MetadataValue value) { if (!"title".equals(element)) { return value.getValue(); } return OrderFormat.makeSortString(value.getValue(), value.getLanguage(), OrderFormat.TITLE); } }
/** * Construct a new SortOption object with the given parameters * * @param number the number of the sort option as given in the config file * @param name sort option name * @param md the metadata field to sort on * @param type the type of data we are sorting by * @throws SortException if sort error */ public SortOption(int number, String name, String md, String type) throws SortException { this.name = name; this.type = type; this.metadata = md; this.number = number; this.visible = true; generateMdBits(); }
/** * Get the field for sorting associated with this index. * * @param isSecondLevel whether second level browse * @return sort field * @throws BrowseException if browse error */ public String getSortField(boolean isSecondLevel) throws BrowseException { String focusField; if (isMetadataIndex() && !isSecondLevel) { focusField = "sort_value"; } else { if (sortOption != null) { focusField = "sort_" + sortOption.getNumber(); } else { focusField = "sort_1"; // Use the first sort column } } return focusField; }
ExceptionThrowingStubSortClient implements Sorter { void sort(List<String> list) { throw new SortException("Testing the exception handling"); } }
/** * Return a normalized focus value. If there is no normalization that can be performed, * return the focus value that is passed in. * * @param value a focus value to normalize * @return the normalized focus value * @throws BrowseException if browse error */ private String normalizeJumpToValue(String value) throws BrowseException { // If the scope has a focus value (focus by value) if (scope.hasJumpToValue()) { // Normalize it based on the specified language as appropriate for this index return OrderFormat.makeSortString(scope.getJumpToValue(), scope.getJumpToValueLang(), scope.getBrowseIndex().getDataType()); } else if (scope.hasStartsWith()) { // Scope has a starts with, so normalize that instead return OrderFormat.makeSortString(scope.getStartsWith(), null, scope.getBrowseIndex().getDataType()); } // No focus value on the scope (ie. focus by id), so just return the passed focus value // This is useful in cases where we have pulled a focus value from the index // which will already be normalized, and avoids another DB lookup return value; }
/** * Convert the value into an offset into the table for this browse * * @param value value * @return the focus value to use * @throws BrowseException if browse error */ private int getOffsetForValue(String value) throws BrowseException { // we need to make sure that we select from the correct column. If the sort option // is the 0th option then we use sort_value, but if it is one of the others we have // to select from that column instead. Otherwise, we end up missing the focus value // to do comparisons in other columns. The use of the focus value needs to be consistent // across the browse SortOption so = scope.getSortOption(); if (so == null || so.getNumber() == 0) { if (browseIndex.getSortOption() != null) { so = browseIndex.getSortOption(); } } String col = "sort_1"; if (so.getNumber() > 0) { col = "sort_" + Integer.toString(so.getNumber()); } // now get the DAO to do the query for us, returning the highest // string value in the given column in the given table for the // item (I think) return dao.doOffsetQuery(col, value, scope.isAscending()); }
String getKey() { try { String key = ""; key += "-" + scope.getBrowseIndex().getName(); key += "-" + scope.getBrowseLevel(); key += "-" + scope.getStartsWith(); key += "-" + scope.getResultsPerPage(); key += "-" + scope.getSortBy(); key += "-" + scope.getSortOption().getNumber(); key += "-" + scope.getOrder(); key += "-" + scope.getOffset(); key += "-" + scope.getJumpToItem(); key += "-" + scope.getFilterValue(); key += "-" + scope.getFilterValueLang(); key += "-" + scope.getJumpToValue(); key += "-" + scope.getJumpToValueLang(); key += "-" + etAl; return key; } catch (BrowseException e) { return null; // ignore exception and return no key } } };
key += "-" + scope.getResultsPerPage(); key += "-" + scope.getSortBy(); key += "-" + scope.getSortOption().getNumber(); key += "-" + scope.getOffset(); key += "-" + scope.getJumpToItem();