]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2484: Added initial support to the Services document framework for returning...
authorAron Roberts <aron@socrates.berkeley.edu>
Mon, 19 Jul 2010 22:03:47 +0000 (22:03 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Mon, 19 Jul 2010 22:03:47 +0000 (22:03 +0000)
services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java
services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index c99c3cebe9bc7f3f9b8c460bde6d4d9ebabb2411..3ea1e7e21eb9a676a7a628b2002d5d258303a6a2 100644 (file)
@@ -312,6 +312,19 @@ public abstract class AbstractServiceClientImpl implements
         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
index 3932f5097f77f6133320d533ce34ad5ece4afaf7..022380679ab7d812ac65b15a6476e968b9c7e905 100644 (file)
@@ -148,7 +148,21 @@ public interface CollectionSpaceClient {
      * @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);
 
     /**
index 90807a70516aa56790ca9e52600fb16d577d27dd..f95894ab7b4eaba9ff95f59ce29c70c13b457e44 100644 (file)
@@ -38,6 +38,19 @@ import org.jboss.resteasy.client.ClientResponse;
  * 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
@@ -49,6 +62,7 @@ public interface CollectionSpaceProxy {
     @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
index 1aeec0a469ef6360594867091cd847039f009239..7d8d8007c3a26ab34f03355fa745b48082001e8e 100644 (file)
@@ -3,5 +3,6 @@ package org.collectionspace.services.client;
 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
index 8121204252de0b74ca2f4a05e401266c2d6825ce..1ffe5254263a8afd982f1aff317d2b530afd670c 100644 (file)
@@ -63,6 +63,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
 
     /* 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.
@@ -388,8 +389,26 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
     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();
index 54eeb9ecec98301178315f1c05369495c9aa1289..658c14b2e40d2c4d4b3ab630d762deb6630d3ed1 100644 (file)
@@ -449,12 +449,19 @@ public abstract class AbstractServiceContextImpl<IT, OT>
                     + 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;
index 49cdd67c892929f60a4e4208f676dd80163f6182..841204551f790e2b771bf4e3e132b946d822a2f9 100644 (file)
@@ -40,6 +40,9 @@ public class DocumentFilter {
     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
@@ -128,12 +131,25 @@ public class DocumentFilter {
     /**\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
@@ -209,11 +225,12 @@ public class DocumentFilter {
     /**\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
@@ -244,6 +261,47 @@ public class DocumentFilter {
         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
index e51105cdf5ec884c271652d76d89dba7533ec945..1ff686e611884145fcaa5edad7af8b6eba7dc737 100644 (file)
@@ -72,6 +72,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
         DocumentFilter docFilter;
         /** The where clause. */
         String whereClause;
+        /** The order by clause. */
+        String orderByClause;
         /** The domain. */
         String domain;
         /** The tenant id. */
@@ -106,7 +108,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
          * 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
          */
@@ -137,6 +139,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
                         "Document handler has no Filter specified.");
             }
             whereClause = docFilter.getWhereClause();
+            orderByClause = docFilter.getOrderByClause();
         }
     }
     /** The logger. */
@@ -621,6 +624,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
     @Override
     public void getFiltered(ServiceContext ctx, DocumentHandler handler)
             throws DocumentNotFoundException, DocumentException {
+
         QueryContext queryContext = new QueryContext(ctx, handler);
 
         RepositoryInstance repoSession = null;
@@ -899,11 +903,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
     }
 
     /**
-     * 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) {
         //
@@ -923,7 +926,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
         // 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 + ")");
@@ -935,28 +938,50 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
     }
 
     /**
-     * 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 ");
@@ -970,6 +995,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
             query.append(docType);
         }
         appendNXQLWhere(query, queryContext);
+        // FIXME add 'order by' clause here, if appropriate
         return query.toString();
     }