]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5868: Max page size is now configurable in service-config.xml. No list result...
authorremillet <remillet@yahoo.com>
Fri, 1 May 2015 22:53:31 +0000 (15:53 -0700)
committerremillet <remillet@yahoo.com>
Fri, 1 May 2015 22:53:31 +0000 (15:53 -0700)
services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountRoleDocumentHandler.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java
services/common/src/main/cspace/config/services/service-config.xml
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java

index e38f6939ae8a1a98a94c3af620267ad70994e638..a2dbcbb52511a134282224996ef2fe42396d55b3 100644 (file)
@@ -33,12 +33,11 @@ import org.collectionspace.services.authorization.AccountValue;
 import org.collectionspace.services.authorization.RoleValue;
 import org.collectionspace.services.authorization.SubjectType;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
 import org.collectionspace.services.common.storage.jpa.JpaDocumentHandler;
-
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.context.ServiceContextProperties;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -339,7 +338,7 @@ public class AccountRoleDocumentHandler
      */
     @Override
     public DocumentFilter createDocumentFilter() {
-        return new DocumentFilter(this.getServiceContext());
+        return new JpaDocumentFilter(this.getServiceContext());
     }
 
     /**
index ed28be1f3604cfab3eb9cc8c2abccb3cfeddd508..c32d17efad3c797f606c4834f0cee3786fa8b064 100644 (file)
@@ -79,6 +79,7 @@ import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.lifecycle.TransitionDef;
 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
+import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentFilter;
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.workflow.WorkflowCommon;
@@ -404,7 +405,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                 getRepositoryClient(ctx).get(ctx, spec.value, handler);
             } else {
                 String whereClause = buildWhereForAuthByName(spec.value);
-                DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+                DocumentFilter myFilter = new NuxeoDocumentFilter(whereClause, 0, 1);
                 handler.setDocumentFilter(myFilter);
                 getRepositoryClient(ctx).get(ctx, handler);
             }
@@ -650,7 +651,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             } else {
                 String itemWhereClause =
                         buildWhereForAuthItemByName(itemSpec.value, parentcsid);
-                DocumentFilter myFilter = new DocumentFilter(itemWhereClause, 0, 1);
+                DocumentFilter myFilter = new NuxeoDocumentFilter(itemWhereClause, 0, 1); // start at page 0 and get 1 item
                 handler.setDocumentFilter(myFilter);
                 getRepositoryClient(ctx).get(ctx, handler);
             }
index d0914277f6eed151e5fa9f2cda9c292ec63809a9..40ebde150afebe11b1ac953d5dfbe16a87da1fe7 100644 (file)
@@ -32,12 +32,11 @@ import org.collectionspace.services.authorization.PermissionValue;
 import org.collectionspace.services.authorization.PermissionsRolesList;
 import org.collectionspace.services.authorization.RoleValue;
 import org.collectionspace.services.authorization.SubjectType;
-
 import org.collectionspace.services.common.authorization_mgt.AuthorizationRoleRel;
 import org.collectionspace.services.common.authorization_mgt.PermissionRoleUtil;
-
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
 import org.collectionspace.services.common.storage.jpa.JpaDocumentHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -276,6 +275,6 @@ public class PermissionRoleDocumentHandler
      */
     @Override
     public DocumentFilter createDocumentFilter() {
-        return new DocumentFilter(this.getServiceContext());
+        return new JpaDocumentFilter(this.getServiceContext());
     }
 }
index 871817417d408f52a110914af4be6fd7594e0b57..1d5c28f421732c7f21ebde144639657f997a7f6d 100644 (file)
@@ -32,6 +32,7 @@
         <client-class>org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl</client-class>
         <properties>
             <types:item><types:key>pageSizeDefault</types:key><types:value>40</types:value></types:item>
+            <types:item><types:key>pageSizeMax</types:key><types:value>10</types:value></types:item>
             <types:item><types:key>refreshAuthZOnStartup</types:key><types:value>true</types:value></types:item>
         </properties>
     </repository-client>
index 1168185d1ca0c6a7a51cbb492298cb67ba42b796..e7a9e2cc48a48279a738a1d3f3b6ba7f2c556082 100644 (file)
@@ -31,14 +31,16 @@ import org.collectionspace.services.common.context.ServiceContext;
 //FIXME: it would be nice to instantiate the doc filter with the service context
 //so tenant context and other things available from the service context
 //could be utilized while building the where clause.
-public class DocumentFilter {
+public abstract class DocumentFilter {
 
     /** The Constant DEFAULT_PAGE_SIZE_INIT. */
-    public static final int DEFAULT_PAGE_SIZE_INIT = 40;
+    public static final int DEFAULT_PAGE_SIZE_INIT = 40;               // Default page size if one is specified in the service-config.xml
+    public static final int DEFAULT_PAGE_SIZE_MAX_INIT = 1000; // Default page size max if one is specified in the service-config.xml
+    
     /** The Constant PAGE_SIZE_DEFAULT_PROPERTY. */
     public static final String PAGE_SIZE_DEFAULT_PROPERTY = "pageSizeDefault";
-    /** The default page size. */
-    public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT;
+    public static final String PAGE_SIZE_MAX_PROPERTY = "pageSizeMax";
+    
     /** The where clause. */
     protected String whereClause;      // Filtering clause. Omit the "WHERE".
     /** The order by clause. */
@@ -46,10 +48,16 @@ public class DocumentFilter {
     public static final String EMPTY_ORDER_BY_CLAUSE = "";
     public static final String ORDER_BY_LAST_UPDATED = CollectionSpaceClient.CORE_UPDATED_AT + " DESC";
     public static final String ORDER_BY_CREATED_AT = CollectionSpaceClient.CORE_CREATED_AT + " DESC";
+
+    /** The max page size. */
+    protected int pageSizeMax = DEFAULT_PAGE_SIZE_MAX_INIT;            // The largest page size allowed.  Can be overridden in the service-config.xml
+    /** The default page size. */
+    public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT; // Default page size if one is specified in the service-config.xml
     /** The start page. */
     protected int startPage;           // Pagination offset for list results
     /** The page size. */
     protected int pageSize;                    // Pagination limit for list results
+    
     //queryParams is not initialized as it would require a multi-valued map implementation
     //unless it is used from opensource lib...this variable holds ref to
     //implementation available in JBoss RESTeasy
@@ -122,9 +130,13 @@ public class DocumentFilter {
     public DocumentFilter(ServiceContext ctx) {
        // Ignore errors - some contexts do not have proper service binding info
        try {
+               String pageSizeMaxString = ctx.getServiceBindingPropertyValue(
+                    DocumentFilter.PAGE_SIZE_MAX_PROPERTY); 
+               this.setPageSizeMax(pageSizeMaxString);
+
                String pageSizeString = ctx.getServiceBindingPropertyValue(
                     DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY); 
-               this.setPageSize(pageSizeString);
+               this.setPageSize(pageSizeString);               
        } catch(Exception e) {
                this.setPageSize(defaultPageSize);
        } 
@@ -343,19 +355,24 @@ public class DocumentFilter {
      *
      * @return the page size dirty
      */
-    public boolean getPageSizeDirty() {
-        return this.getPageSizeDirty();
-    }
+    abstract public boolean getPageSizeDirty();
 
     /**
      * Sets the page size.
      *
      * @param thePageSize the new page size
+     * Never allow the page size to be larger than the 'pageSizeMax' value
      */
     public void setPageSize(int thePageSize) {
-        this.pageSize = thePageSize;
+       if (thePageSize > this.pageSizeMax) {
+               this.pageSize = this.pageSizeMax; // page size can't be greater than the max page size
+       } else if (thePageSize == 0) {
+               this.pageSize = this.pageSizeMax; // a page size of 0 means use the max page size
+       } else {
+               this.pageSize = thePageSize;
+       }
     }
-
+    
     /**
      * Sets the page size.
      *
@@ -376,6 +393,28 @@ public class DocumentFilter {
 
         setPageSize(newPageSize);
     }
+    
+    /**
+     * Sets the page size.
+     *
+     * @param thePageSizeStr the new page size
+     */
+    public void setPageSizeMax(String thePageSizeMaxStr) {
+        int newPageSizeMax = DocumentFilter.DEFAULT_PAGE_SIZE_MAX_INIT;
+        if (thePageSizeMaxStr != null) {
+            try {
+                newPageSizeMax = Integer.valueOf(thePageSizeMaxStr);
+            } catch (NumberFormatException e) {
+                //FIXME This should cause a warning in the log file and should result in the
+                //FIXME page size being set to the default.  We don't need to throw an exception here.
+                throw new NumberFormatException("Bad value in service-config.xml for: "
+                        + PAGE_SIZE_MAX_PROPERTY);
+            }
+        }
+
+        this.pageSizeMax = newPageSizeMax;
+    }
+    
 
     /**
      * Sets the start page.
index 73525734973cc6235bce11361558d10622517d5f..60a7f299c3111f902d8eb8313411e3539d6fb99e 100644 (file)
@@ -50,7 +50,6 @@
 package org.collectionspace.services.common.storage.jpa;
 
 import java.util.List;
-import org.collectionspace.authentication.AuthN;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.context.ServiceContext;
 
@@ -84,4 +83,10 @@ public class JpaDocumentFilter extends DocumentFilter {
         paramList.add(new ParamBinding("tenantId", getTenantId()));
         return whereClause;
     }
+
+       @Override
+       public boolean getPageSizeDirty() {
+               // TODO Auto-generated method stub
+               return false;
+       }
 }
index bf9411f82833877f2282a513cbaf6b9dc084ad9c..0423291f1a5b0db6dc6a9fdf6b3191635488b140 100644 (file)
@@ -50,6 +50,8 @@
 
 package org.collectionspace.services.nuxeo.client.java;
 
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.context.ServiceContext;
 
@@ -57,8 +59,18 @@ import org.collectionspace.services.common.context.ServiceContext;
  * NXQL specific document filter
  */
 public class NuxeoDocumentFilter extends DocumentFilter {
-       public NuxeoDocumentFilter(ServiceContext ctx) {
+       public NuxeoDocumentFilter(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
                super(ctx);
        }
 
+       public NuxeoDocumentFilter(String whereClause, int theStartPage, int thePageSize) {
+               super(whereClause, theStartPage, thePageSize);
+       }
+
+       @Override
+       public boolean getPageSizeDirty() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
 }