Commit c9452323 authored by Ard Schrijvers's avatar Ard Schrijvers

HSTTWO-4272 change the default sort on property for preview

Since preview variants do not have a publication date, we should not sort
on that field. Sorting on the modification date for preview makes much
more sense
parent 7a93d214
......@@ -49,13 +49,14 @@ import org.onehippo.cms7.services.contenttype.ContentType;
import org.onehippo.cms7.services.search.query.AndClause;
import org.onehippo.cms7.services.search.query.Query;
import org.onehippo.cms7.services.search.query.QueryUtils;
import org.onehippo.cms7.services.search.query.constraint.ExistsConstraint;
import org.onehippo.cms7.services.search.result.QueryResult;
import org.onehippo.cms7.services.search.service.SearchService;
import org.onehippo.cms7.services.search.service.SearchServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hippoecm.hst.restapi.content.DocumentsResource.SortOrder.DESCENDING;
import static org.hippoecm.repository.HippoStdPubWfNodeType.HIPPOSTDPUBWF_LAST_MODIFIED_DATE;
import static org.hippoecm.repository.HippoStdPubWfNodeType.HIPPOSTDPUBWF_PUBLICATION_DATE;
import static org.hippoecm.repository.api.HippoNodeType.HIPPO_AVAILABILITY;
import static org.hippoecm.repository.api.HippoNodeType.NT_DOCUMENT;
......@@ -150,10 +151,29 @@ public class DocumentsResource extends AbstractResource {
return Arrays.asList(attributeString.split(","));
}
private List<String> getOrderBy(final String orderBy, final boolean preview) {
if (StringUtils.isNotBlank(orderBy)) {
return parseOrderBy(orderBy);
}
if (preview) {
return Collections.singletonList(HIPPOSTDPUBWF_LAST_MODIFIED_DATE);
}
return Collections.singletonList(HIPPOSTDPUBWF_PUBLICATION_DATE);
}
private List<String> parseOrderBy(final String orderBy) {
return Arrays.asList(StringUtils.split(orderBy, ','));
}
private List<SortOrder> getSortOrder(final String sortOrder) {
if (StringUtils.isNotBlank(sortOrder)) {
return parseSortOrder(sortOrder);
}
return Collections.singletonList(DESCENDING);
}
private List<SortOrder> parseSortOrder(final String sortOrder) {
final List<SortOrder> sortOrders = new LinkedList<>();
try {
......@@ -179,22 +199,25 @@ public class DocumentsResource extends AbstractResource {
@QueryParam("_max") final String maxString,
@QueryParam("_query") final String queryString,
@QueryParam("_nodetype") final String nodeTypeString,
@QueryParam("_orderBy") @DefaultValue(HIPPOSTDPUBWF_PUBLICATION_DATE) final String orderBy,
@QueryParam("_sortOrder") @DefaultValue("descending") final String sortOrder,
@QueryParam("_orderBy") final String orderBy,
@QueryParam("_sortOrder") final String sortOrder,
@QueryParam("_attributes") final String attributeString) {
try {
final boolean preview = RequestContextProvider.get().isPreview();
final List<String> includedAttributes = parseAttributes(attributeString);
final ResourceContext context = getResourceContextFactory().createResourceContext(includedAttributes);
final int offset = parseOffset(offsetString);
final int max = parseMax(maxString);
final String parsedQuery = parseQuery(queryString);
final String parsedNodeType = parseNodeType(context, nodeTypeString);
final List<String> parsedOrderBys = parseOrderBy(orderBy);
final List<SortOrder> parsedSortOrders = parseSortOrder(sortOrder);
final List<String> parsedOrderBys = getOrderBy(orderBy, preview);
final List<SortOrder> parsedSortOrders = getSortOrder(sortOrder);
checkOrderParameters(parsedOrderBys, parsedSortOrders);
final String availability;
if (RequestContextProvider.get().isPreview() ) {
if (preview) {
availability = "preview";
} else {
availability = "live";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment