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;
//
// 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
" 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;
//
// 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 "
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;
}