]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5289 Added default ORDER BY clause when finding docs with mix of doc types.
authorPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 30 May 2012 22:41:48 +0000 (15:41 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 30 May 2012 22:41:48 +0000 (15:41 -0700)
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

index 836672215e20f9634cd5956f8e558be5af47e322..fbd6671a42a21e5b5c59c9edc8ad51e14832ddb7 100644 (file)
@@ -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();
     }