From f2830af4acb4195000c2f8a5d8a6041291ca81fe Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 8 Mar 2011 05:54:27 +0000 Subject: [PATCH] CSPACE-705: Default sorting was still not functioning for ALL services. If the default document filter was null then items would not be sorted. --- .../services/common/document/DocumentFilter.java | 1 + .../client/java/RepositoryJavaClientImpl.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index 841204551..1ff4415ea 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -43,6 +43,7 @@ public class DocumentFilter { /** The order by clause. */ protected String orderByClause; // Filtering clause. Omit the "ORDER BY". public static final String EMPTY_ORDER_BY_CLAUSE = ""; + public static final String ORDER_BY_LAST_UPDATED = "collectionspace_core:updatedAt DESC"; /** The start page. */ protected int startPage; // Pagination offset for list results /** The page size. */ diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 427a8a9a2..a83eac3b6 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -568,6 +568,14 @@ public class RepositoryJavaClientImpl implements RepositoryClient { } } } + + private boolean isClauseEmpty(String theString) { + boolean result = true; + if (theString != null && !theString.isEmpty()) { + result = false; + } + return result; + } /** * getFiltered get all documents for an entity service from the Document repository, @@ -581,10 +589,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient { public void getFiltered(ServiceContext ctx, DocumentHandler handler) throws DocumentNotFoundException, DocumentException { - DocumentFilter filter = handler.getDocumentFilter(); + DocumentFilter filter = handler.getDocumentFilter(); String oldOrderBy = filter.getOrderByClause(); - if (oldOrderBy!=null && oldOrderBy.isEmpty()){ - filter.setOrderByClause("collectionspace_core:updatedAt DESC"); //per http://issues.collectionspace.org/browse/CSPACE-705 + if (isClauseEmpty(oldOrderBy) == true){ + filter.setOrderByClause(DocumentFilter.ORDER_BY_LAST_UPDATED); //per http://issues.collectionspace.org/browse/CSPACE-705 } QueryContext queryContext = new QueryContext(ctx, handler); RepositoryInstance repoSession = null; -- 2.47.3