Search in sources :

Example 1 with Polarity

use of org.codice.alliance.nsili.common.GIAS.Polarity in project alliance by codice.

the class NsiliSource method getSortAttributes.

/**
 * Sets a SortAttribute[] to be used in a query. The STANAG 4559 Spec has no mechanism to sort
 * queries by RELEVANCE or Shortest/Longest distance from a point, so they are ignored.
 *
 * @param sortBy - sortBy object specified in the Search UI
 * @return - an array of SortAttributes sent in the query to the source.
 */
private SortAttribute[] getSortAttributes(SortBy sortBy) {
    if (excludeSortOrder) {
        return new SortAttribute[0];
    }
    if (sortBy == null || sortableAttributes == null) {
        // Default to sorting by Date/Time modified if no sorting provided
        return new SortAttribute[] { new SortAttribute(NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED, Polarity.DESCENDING) };
    }
    String sortAttribute = sortBy.getPropertyName().getPropertyName();
    Polarity sortPolarity;
    if (sortBy.getSortOrder().toSQL().equals(ASC)) {
        sortPolarity = Polarity.ASCENDING;
    } else {
        sortPolarity = Polarity.DESCENDING;
    }
    String cardDateTimeModifiedAttribute = NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED;
    String cardSourceDateTimeModified = NsiliConstants.NSIL_CARD + "." + NsiliConstants.SOURCE_DATE_TIME_MODIFIED;
    String dateTimeDeclaredAttribute = NsiliConstants.NSIL_FILE + "." + NsiliConstants.DATE_TIME_DECLARED;
    if (sortAttribute.equals(Metacard.MODIFIED)) {
        List<SortAttribute> modifiedAttrs = new ArrayList<>();
        if (isAttributeSupported(cardDateTimeModifiedAttribute)) {
            modifiedAttrs.add(new SortAttribute(cardDateTimeModifiedAttribute, sortPolarity));
        }
        if (isAttributeSupported(cardSourceDateTimeModified)) {
            modifiedAttrs.add(new SortAttribute(cardSourceDateTimeModified, sortPolarity));
        }
        return modifiedAttrs.toArray(new SortAttribute[0]);
    } else if (sortAttribute.equals(Metacard.CREATED) && isAttributeSupported(dateTimeDeclaredAttribute)) {
        SortAttribute[] sortAttributeArray = { new SortAttribute(dateTimeDeclaredAttribute, sortPolarity) };
        return sortAttributeArray;
    } else {
        return new SortAttribute[0];
    }
}
Also used : SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) ArrayList(java.util.ArrayList) Polarity(org.codice.alliance.nsili.common.GIAS.Polarity)

Aggregations

ArrayList (java.util.ArrayList)1 Polarity (org.codice.alliance.nsili.common.GIAS.Polarity)1 SortAttribute (org.codice.alliance.nsili.common.GIAS.SortAttribute)1