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];
}
}
Aggregations