return getProxy().readList(pageSize, pageNumber);\r
}\r
\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#readList(java\r
+ * .lang.String, java.lang.String)\r
+ */\r
+ @Override\r
+ public ClientResponse<AbstractCommonList> readList(String sortBy, String pageSize,\r
+ String pageNumber) {\r
+ return getProxy().readList(sortBy, pageSize, pageNumber);\r
+ }\r
+\r
/* (non-Javadoc)\r
* @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String)\r
*/\r
* @param pageNumber the page number
* @return the client response
*/
- public ClientResponse<AbstractCommonList> readList(String pageSize,
+ public ClientResponse<AbstractCommonList> readList(
+ String pageSize,
+ String pageNumber);
+
+ /**
+ * Read list.
+ *
+ * @param sortBy the sort order
+ * @param pageSize the page size
+ * @param pageNumber the page number
+ * @return the client response
+ */
+ public ClientResponse<AbstractCommonList> readList(
+ String sortBy,
+ String pageSize,
String pageNumber);
/**
* FIXME: http://issues.collectionspace.org/browse/CSPACE-1684\r
*/\r
public interface CollectionSpaceProxy {\r
+\r
+ /**\r
+ * Read list.\r
+ *\r
+ * @param pageSize the page size\r
+ * @param pageNumber the page number\r
+ * @return the client response\r
+ */\r
+ @GET\r
+ @Produces({"application/xml"})\r
+ ClientResponse<AbstractCommonList> readList(\r
+ @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) String pageSize,\r
+ @QueryParam(IClientQueryParams.START_PAGE_PARAM) String pageNumber);\r
\r
/**\r
* Read list.\r
@GET\r
@Produces({"application/xml"})\r
ClientResponse<AbstractCommonList> readList(\r
- @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) String pageSize,\r
- @QueryParam(IClientQueryParams.START_PAGE_PARAM) String pageNumber);\r
+ @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortBy,\r
+ @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) String pageSize,\r
+ @QueryParam(IClientQueryParams.START_PAGE_PARAM) String pageNumber);\r
}\r
public interface IClientQueryParams {\r
public static final String PAGE_SIZE_PARAM = "pgSz";\r
public static final String START_PAGE_PARAM = "pgNum";\r
-\r
+ public static final String SORT_BY_PARAM = "sortBy";\r
+ \r
}\r
/* Use this to keep track of resources to delete */
protected List<String> allResourceIdsCreated = new ArrayList<String>();
+ private String EMPTY_SORT_BY_ORDER = "";
/**
* Gets the logger.
private AbstractCommonList readList(String testName,
CollectionSpaceClient client,
long pageSize, long pageNumber) throws Exception {
+
+ return readList(testName, client, EMPTY_SORT_BY_ORDER, pageSize, pageNumber);
+
+ }
+ /**
+ * Read list.
+ *
+ * @param testName the test name
+ * @param client the client
+ * @param sortBy the sort order
+ * @param pageSize the page size
+ * @param pageNumber the page number
+ * @return the abstract common list
+ * @throws Exception the exception
+ */
+ private AbstractCommonList readList(String testName,
+ CollectionSpaceClient client, String sortBy,
+ long pageSize, long pageNumber) throws Exception {
ClientResponse<AbstractCommonList> response =
- client.readList(Long.toString(pageSize), Long.toString(pageNumber));
+ client.readList(sortBy, Long.toString(pageSize), Long.toString(pageNumber));
AbstractCommonList result = null;
try {
int statusCode = response.getStatus();
+ DocumentHandler.class.getCanonicalName());
}
//
- // create a default document filter with pagination if the context
- // was created with query params
+ // Create a default document filter
//
docHandler.setServiceContext(this);
DocumentFilter docFilter = docHandler.createDocumentFilter();
- docFilter.setPagination(this.getQueryParams());
+ //
+ // If the context was created with query parameters,
+ // reflect the values of those parameters in the document filter
+ // to specify sort ordering, pagination, etc.
+ //
+ if (this.getQueryParams() != null) {
+ docFilter.setSortOrder(this.getQueryParams());
+ docFilter.setPagination(this.getQueryParams());
+ }
docHandler.setDocumentFilter(docFilter);
return docHandler;
public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT;\r
/** The where clause. */\r
protected String whereClause; // Filtering clause. Omit the "WHERE".\r
+ /** The order by clause. */\r
+ protected String orderByClause; // Filtering clause. Omit the "ORDER BY".\r
+ public static final String EMPTY_ORDER_BY_CLAUSE = "";\r
/** The start page. */\r
protected int startPage; // Pagination offset for list results\r
/** The page size. */\r
/**\r
* Instantiates a new document filter.\r
*\r
- * @param theWhereClause the the where clause\r
- * @param theStartPage the the start page\r
- * @param thePageSize the the page size\r
+ * @param theWhereClause the where clause\r
+ * @param theStartPage the start page\r
+ * @param thePageSize the page size\r
*/\r
public DocumentFilter(String theWhereClause, int theStartPage, int thePageSize) {\r
+ this(theWhereClause, EMPTY_ORDER_BY_CLAUSE, theStartPage, thePageSize);\r
+ }\r
+\r
+ /**\r
+ * Instantiates a new document filter.\r
+ *\r
+ * @param theWhereClause the where clause\r
+ * @param theOrderByClause the order by clause\r
+ * @param theStartPage the start page\r
+ * @param thePageSize the page size\r
+ */\r
+ public DocumentFilter(String theWhereClause, String theOrderByClause, int theStartPage, int thePageSize) {\r
this.whereClause = theWhereClause;\r
+ this.orderByClause = theOrderByClause;\r
this.startPage = (theStartPage > 0) ? theStartPage : 0;\r
this.pageSize = (thePageSize > 0) ? thePageSize : defaultPageSize;\r
}\r
/**\r
* Append where clause.\r
*\r
- * @param theWhereClause the the where clause\r
- * @param conjunction the conjunction\r
+ * @param theWhereClause the where clause\r
+ * @param conjunction the conjunction to insert between the current\r
+ * where clause, if any, and the additional where clause to be appended\r
*/\r
public void appendWhereClause(String theWhereClause, String conjunction) {\r
- if (theWhereClause != null && theWhereClause.length() > 0) {\r
+ if (theWhereClause != null && ! theWhereClause.trim().isEmpty()) {\r
String currentClause = getWhereClause();\r
if (currentClause != null) {\r
String newClause = currentClause.concat(conjunction + theWhereClause);\r
return new ArrayList<ParamBinding>();\r
}\r
\r
+ /**\r
+ * Sets the sort ordering.\r
+ *\r
+ * @param theQueryParams the query params\r
+ */\r
+ public void setSortOrder(MultivaluedMap<String, String> theQueryParams) {\r
+ // Bail if there are no params\r
+ if (theQueryParams == null) {\r
+ return;\r
+ }\r
+ // Set the order by clause\r
+ String orderByStr = null;\r
+ List<String> list = theQueryParams.get(IClientQueryParams.SORT_BY_PARAM);\r
+ if (list != null) {\r
+ orderByStr = list.get(0);\r
+ }\r
+\r
+ // FIXME: Verify the format of the value(s) in the 'sort by'\r
+ // query param.\r
+\r
+ setOrderByClause(orderByStr);\r
+ }\r
+\r
+ /**\r
+ * Gets the order by clause.\r
+ *\r
+ * @return the order by clause\r
+ */\r
+ public String getOrderByClause() {\r
+ return orderByClause;\r
+ }\r
+\r
+ /**\r
+ * Sets the order by clause.\r
+ *\r
+ * @param theOrderByClause the new order by clause\r
+ */\r
+ public void setOrderByClause(String theOrderByClause) {\r
+ this.orderByClause = theOrderByClause;\r
+ }\r
+\r
/**\r
* Gets the start page.\r
*\r
DocumentFilter docFilter;
/** The where clause. */
String whereClause;
+ /** The order by clause. */
+ String orderByClause;
/** The domain. */
String domain;
/** The tenant id. */
* Instantiates a new query context.
*
* @param ctx the ctx
- * @param theWhereClause the the where clause
+ * @param theWhereClause the where clause
* @throws DocumentNotFoundException the document not found exception
* @throws DocumentException the document exception
*/
"Document handler has no Filter specified.");
}
whereClause = docFilter.getWhereClause();
+ orderByClause = docFilter.getOrderByClause();
}
}
/** The logger. */
@Override
public void getFiltered(ServiceContext ctx, DocumentHandler handler)
throws DocumentNotFoundException, DocumentException {
+
QueryContext queryContext = new QueryContext(ctx, handler);
RepositoryInstance repoSession = null;
}
/**
- * Append nxql where.
+ * Append a WHERE clause to the NXQL query.
*
- * @param query the query
- * @param where the where
- * @param domain the domain
+ * @param query The NXQL query to which the WHERE clause will be appended.
+ * @param querycontext The query context, which provides the WHERE clause to append.
*/
private final void appendNXQLWhere(StringBuilder query, QueryContext queryContext) {
//
// Finally, append the incoming where clause
//
String whereClause = queryContext.whereClause;
- if (whereClause != null && whereClause.length() > 0) {
+ if (whereClause != null && ! whereClause.trim().isEmpty()) {
// Due to an apparent bug/issue in how Nuxeo translates the NXQL query string
// into SQL, we need to parenthesize our 'where' clause
query.append(IQueryManager.SEARCH_QUALIFIER_AND + "(" + whereClause + ")");
}
/**
- * Builds the nxql query.
+ * 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.
+ */
+ private final void appendNXQLOrderBy(StringBuilder query, QueryContext queryContext) {
+ // Append the incoming ORDER BY clause
+ String orderByClause = queryContext.orderByClause;
+ if (orderByClause != null && ! orderByClause.trim().isEmpty()) {
+ // FIXME Verify whether enclosing parentheses may be required, and add
+ // them if so, as is being done in appendNXQLWhere.
+ query.append(" ORDER BY ");
+ query.append(orderByClause);
+ }
+
+ // FIXME Determine where and how to handle ASC[ending] and DESC[ending] qualifiers:
+ //
+ // Will these be included in the value of the relevant 'order by' query param?
+ //
+ // Will the format of the order by clause be verified, including placement of
+ // the 'order by' qualifiers?
+ }
+
+
+ /**
+ * Builds an NXQL SELECT query for a single document type.
*
- * @param docType the doc type
- * @param where the where
- * @param domain the domain
- * @param tenantId the tenant id
- * @return the string
+ * @param queryContext The query context
+ * @return an NXQL query
*/
private final String buildNXQLQuery(QueryContext queryContext) {
StringBuilder query = new StringBuilder("SELECT * FROM ");
query.append(queryContext.docType);
appendNXQLWhere(query, queryContext);
+ appendNXQLOrderBy(query, queryContext);
return query.toString();
}
/**
- * Builds the nxql query.
+ * Builds an NXQL SELECT query across multiple document types.
*
- * @param docTypes the doc types
- * @param where the where
- * @param domain the domain
- * @return the string
+ * @param docTypes a list of document types to be queried
+ * @param queryContext the query context
+ * @return an NXQL query
*/
private final String buildNXQLQuery(List<String> docTypes, QueryContext queryContext) {
StringBuilder query = new StringBuilder("SELECT * FROM ");
query.append(docType);
}
appendNXQLWhere(query, queryContext);
+ // FIXME add 'order by' clause here, if appropriate
return query.toString();
}