From: Patrick Schmitz Date: Wed, 30 May 2012 22:41:48 +0000 (-0700) Subject: CSPACE-5289 Added default ORDER BY clause when finding docs with mix of doc types. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=638709fbc330b197dff14cda50d4edc5a031cf87;p=tmp%2Fjakarta-migration.git CSPACE-5289 Added default ORDER BY clause when finding docs with mix of doc types. --- diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 836672215..fbd6671a4 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -38,6 +38,7 @@ import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.datetime.DateTimeFormatUtils; import org.collectionspace.services.common.document.DocumentException; +import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.query.QueryContext; import org.collectionspace.services.config.service.ListResultField; import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; @@ -310,9 +311,8 @@ public class NuxeoUtils { * @throws DocumentException if the supplied value of the orderBy clause is not valid. * */ - static private final void appendNXQLOrderBy(StringBuilder query, QueryContext queryContext) + static private final void appendNXQLOrderBy(StringBuilder query, String orderByClause) throws Exception { - String orderByClause = queryContext.getOrderByClause(); if (orderByClause != null && ! orderByClause.trim().isEmpty()) { if (isValidOrderByClause(orderByClause)) { query.append(" ORDER BY "); @@ -324,6 +324,21 @@ public class NuxeoUtils { } } + /** + * Append an ORDER BY clause to the NXQL query. + * + * @param query the NXQL query to which the ORDER BY clause will be appended. + * @param queryContext the query context, which provides the ORDER BY clause to append. + * + * @throws DocumentException if the supplied value of the orderBy clause is not valid. + * + */ + static private final void appendNXQLOrderBy(StringBuilder query, QueryContext queryContext) + throws Exception { + String orderByClause = queryContext.getOrderByClause(); + appendNXQLOrderBy(query, orderByClause); + } + /** * Identifies whether the ORDER BY clause is valid. * @@ -390,6 +405,8 @@ public class NuxeoUtils { query.append(docType); } appendNXQLWhere(query, queryContext); + // For a set of DocTypes, there is no sensible ordering other than by updatedAt + appendNXQLOrderBy(query, DocumentFilter.ORDER_BY_LAST_UPDATED); // FIXME add 'order by' clause here, if appropriate return query.toString(); }