From 205665d934b1d3d3b60097f41d823564688dd79f Mon Sep 17 00:00:00 2001 From: remillet Date: Fri, 1 May 2015 15:53:31 -0700 Subject: [PATCH] CSPACE-5868: Max page size is now configurable in service-config.xml. No list results will every exceed that value. --- .../storage/AccountRoleDocumentHandler.java | 5 +- .../common/vocabulary/AuthorityResource.java | 5 +- .../PermissionRoleDocumentHandler.java | 5 +- .../cspace/config/services/service-config.xml | 1 + .../common/document/DocumentFilter.java | 59 +++++++++++++++---- .../common/storage/jpa/JpaDocumentFilter.java | 7 ++- .../client/java/NuxeoDocumentFilter.java | 14 ++++- 7 files changed, 76 insertions(+), 20 deletions(-) diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountRoleDocumentHandler.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountRoleDocumentHandler.java index e38f6939a..a2dbcbb52 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountRoleDocumentHandler.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountRoleDocumentHandler.java @@ -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()); } /** diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index ed28be1f3..c32d17efa 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -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 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 } 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); } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java index d0914277f..40ebde150 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java @@ -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()); } } diff --git a/services/common/src/main/cspace/config/services/service-config.xml b/services/common/src/main/cspace/config/services/service-config.xml index 871817417..1d5c28f42 100644 --- a/services/common/src/main/cspace/config/services/service-config.xml +++ b/services/common/src/main/cspace/config/services/service-config.xml @@ -32,6 +32,7 @@ org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl pageSizeDefault40 + pageSizeMax10 refreshAuthZOnStartuptrue diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index 1168185d1..e7a9e2cc4 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -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. diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java index 735257349..60a7f299c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java @@ -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; + } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java index bf9411f82..0423291f1 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java @@ -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 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; + } + } -- 2.47.3