]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5943: Sort results returned by primary termDisplayName.
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 4 Apr 2013 21:23:27 +0000 (14:23 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 4 Apr 2013 21:23:27 +0000 (14:23 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index ddd4a7708bde17ee5cfbb78190fd4c3f9e8b0a11..1b97743f611c23143d2043ce0b076003982795ba 100644 (file)
@@ -711,10 +711,12 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         // FIXME: Get all of the following values from appropriate external constants.
         // At present, these are duplicated in both RepositoryJavaClientImpl
         // and in AuthorityItemDocumentModelHandler.
+        final String TERM_GROUP_LIST_NAME = "TERM_GROUP_LIST_NAME";
         final String TERM_GROUP_TABLE_NAME_PARAM = "TERM_GROUP_TABLE_NAME";
         final String IN_AUTHORITY_PARAM = "IN_AUTHORITY";
         
         Map<String,String> params = super.getJDBCQueryParams();
+        params.put(TERM_GROUP_LIST_NAME, getItemTermInfoGroupXPathBase());
         params.put(TERM_GROUP_TABLE_NAME_PARAM, getTermGroupTableName());
         params.put(IN_AUTHORITY_PARAM, getInAuthorityValue());
         return params;
index ef460e73df35f83adf29b79a73c930d508fefffd..b9de12ebb0cd74240f48b1acb12a01357310e053 100644 (file)
@@ -23,6 +23,8 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -923,6 +925,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
         //
         // At present, the two constants below are duplicated in both RepositoryJavaClientImpl
         // and in AuthorityItemDocumentModelHandler.
+        final String TERM_GROUP_LIST_NAME = "TERM_GROUP_LIST_NAME";
         final String TERM_GROUP_TABLE_NAME_PARAM = "TERM_GROUP_TABLE_NAME";
         final String IN_AUTHORITY_PARAM = "IN_AUTHORITY";
         // Get this from a constant in AuthorityResource or equivalent
@@ -952,12 +955,12 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                 " WHERE (termgroup.termdisplayname ILIKE ?) ";
         }
         
-        // FIXME: At present, we are planning to order results in code,
-        // by sorting the returned list of DocumentModels.
+        // At present, results are ordered in code, below, rather than in SQL,
+        // and the orderByClause below is thus intentionally blank.
         //
-        // To implement the orderByClause below in SQL, rather than in code;
-        // e.g. via 'ORDER BY termgroup.termdisplayname', that column must be
-        // returned by the SELECT statement.
+        // To implement the orderByClause below in SQL; e.g. via
+        // 'ORDER BY termgroup.termdisplayname', the relevant column
+        // must be returned by the SELECT statement.
         String orderByClause = "";
         
         String limitClause;
@@ -1029,9 +1032,9 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
         //
         // Currently, restrictByTenantID(), below, is a stub method awaiting
         // implementation. It always returns 'false', so that results are NOT
-        // restricted to a specific tenant. However, the code below does
-        // successfully restrict results, as well, when a 'true' value is
-        // returned from that method.
+        // restricted to a specific tenant. However, whenever a 'true' value
+        // is returned from that method, the code below will successfully
+        // restrict results.
         if (restrictByTenantID()) {
                 joinClauses = joinClauses
                     + " INNER JOIN collectionspace_core core "
@@ -1088,6 +1091,19 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                 result.add(NuxeoUtils.getDocumentModel(repoSession, docId));
             }
         }
+        
+        // Order the results
+        final String COMMON_PART_SCHEMA = handler.getServiceContext().getCommonPartLabel();
+        final String DISPLAY_NAME_XPATH =
+                "//" + handler.getJDBCQueryParams().get(TERM_GROUP_LIST_NAME) + "/[0]/termDisplayName";
+        Collections.sort(result, new Comparator<DocumentModel>() {
+            @Override
+            public int compare(DocumentModel doc1, DocumentModel doc2) {
+                String termDisplayName1 = (String) NuxeoUtils.getXPathValue(doc1, COMMON_PART_SCHEMA, DISPLAY_NAME_XPATH);
+                String termDisplayName2 = (String) NuxeoUtils.getXPathValue(doc2, COMMON_PART_SCHEMA, DISPLAY_NAME_XPATH);
+                return termDisplayName1.compareTo(termDisplayName2);
+            }
+        });
 
         return result;
     }