Fix MNT-17001: Querying the audit with cmis throws 'CmisRuntimeException: maxResults must be greater than 0'

- Fix overloading of local variable when calculating audit query limit
 - Enhance test to cover negative (expected failure), zero, one and more
 - Addition of new property: opencmis.connector.default.contentChangesDefaultMaxItems=10000


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133150 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2016-11-25 21:43:15 +00:00
parent 75286950f1
commit dfc1f8ab7b
4 changed files with 68 additions and 27 deletions

View File

@@ -132,6 +132,7 @@
<property name="typesDefaultDepth" value="${opencmis.connector.default.typesDefaultDepth}" />
<property name="objectsDefaultMaxItems" value="${opencmis.connector.default.objectsDefaultMaxItems}" />
<property name="objectsDefaultDepth" value="${opencmis.connector.default.objectsDefaultDepth}" />
<property name="contentChangesDefaultMaxItems" value="${opencmis.connector.default.contentChangesDefaultMaxItems}" />
<property name="renditionKindMapping">
<map>
<entry key="cmis:thumbnail">

View File

@@ -694,6 +694,7 @@ opencmis.connector.default.typesDefaultMaxItems=500
opencmis.connector.default.typesDefaultDepth=-1
opencmis.connector.default.objectsDefaultMaxItems=10000
opencmis.connector.default.objectsDefaultDepth=100
opencmis.connector.default.contentChangesDefaultMaxItems=10000
opencmis.connector.default.openHttpSession=false
opencmis.activities.enabled=true
opencmis.bulkUpdateProperties.maxItemsSize=1000

View File

@@ -284,6 +284,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
private static final BigInteger TYPES_DEFAULT_DEPTH = BigInteger.valueOf(-1);
private static final BigInteger OBJECTS_DEFAULT_MAX_ITEMS = BigInteger.valueOf(200);
private static final BigInteger OBJECTS_DEFAULT_DEPTH = BigInteger.valueOf(10);
private static final int CONTENT_CHANGES_DEFAULT_MAX_ITEMS = 10000;
private static final String QUERY_NAME_OBJECT_ID = "cmis:objectId";
private static final String QUERY_NAME_OBJECT_TYPE_ID = "cmis:objectTypeId";
@@ -352,6 +353,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
private BigInteger typesDefaultDepth = TYPES_DEFAULT_DEPTH;
private BigInteger objectsDefaultMaxItems = OBJECTS_DEFAULT_MAX_ITEMS;
private BigInteger objectsDefaultDepth = OBJECTS_DEFAULT_DEPTH;
private int contentChangesDefaultMaxItems = CONTENT_CHANGES_DEFAULT_MAX_ITEMS;
private List<PermissionDefinition> repositoryPermissions;
private Map<String, PermissionMapping> permissionMappings;
@@ -460,6 +462,18 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
this.objectsDefaultDepth = objectsDefaultDepth;
}
/**
* Set the default number of content changes to return if nothing is specified
*/
public void setContentChangesDefaultMaxItems(int contentChangesDefaultMaxItems)
{
if (contentChangesDefaultMaxItems < 1)
{
throw new IllegalArgumentException("The default maximum number of content changes to retrieve must be greater than zero.");
}
this.contentChangesDefaultMaxItems = contentChangesDefaultMaxItems;
}
/**
* Set rendition kind mapping.
*/
@@ -3684,26 +3698,29 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
params.setForward(true);
params.setFromId(from);
int maxResults = (maxItems == null ? 0 : maxItems.intValue());
maxResults = (maxResults < 1 ? 0 : maxResults + 1);
int maxResults = (maxItems == null ? contentChangesDefaultMaxItems : maxItems.intValue());
maxResults = maxResults < 1 ? contentChangesDefaultMaxItems : maxResults; // Just a double check of the unbundled contents
int queryFor = maxResults + 1; // Query for 1 more so that we know if there are more results
auditService.auditQuery(changeLogCollectingCallback, params, maxResults);
auditService.auditQuery(changeLogCollectingCallback, params, queryFor);
String newChangeLogToken = null;
if (maxResults > 0)
{
// Check if we got more than the client requested
if (result.getObjects().size() >= maxResults)
{
// Build the change log token from the last item
StringBuilder clt = new StringBuilder();
newChangeLogToken = (from == null ? clt.append(maxItems.intValue() + 1).toString() : clt.append(from.longValue() + maxItems.intValue()).toString());
newChangeLogToken = (from == null ? clt.append(maxItems.intValue() + 1).toString() : clt.append(from.longValue() + maxItems.intValue()).toString()); // TODO: Make this readable
// Remove extra item that was not actually requested
result.getObjects().remove(result.getObjects().size() - 1).getId();
// Note to client that there are more items
result.setHasMoreItems(true);
}
else
{
// We got the same or fewer than the number requested, so there are no more items
result.setHasMoreItems(false);
}
}
if (changeLogToken != null)
{

View File

@@ -27,13 +27,6 @@
package org.alfresco.opencmis;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -137,6 +130,7 @@ import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
@@ -161,6 +155,13 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.extensions.webscripts.GUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* OpenCMIS tests.
*
@@ -2588,6 +2589,27 @@ public class CMISTest
assertFalse("CMISChangeEvent " + changeType + " should store short form of objectId " + objectId,
objectId.toString().contains(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString()));
}
int expectAtLeast = changes.getObjects().size();
// We should also be able to query without passing in any limit
changes = cmisService.getContentChanges(repositoryId, new Holder<String>(changeToken), Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE, null, null);
assertTrue("Expected to still get changes", changes.getObjects().size() >= expectAtLeast);
// and zero
changes = cmisService.getContentChanges(repositoryId, new Holder<String>(changeToken), Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE, BigInteger.valueOf(0), null);
assertTrue("Expected to still get changes", changes.getObjects().size() >= expectAtLeast);
// and one
changes = cmisService.getContentChanges(repositoryId, new Holder<String>(changeToken), Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE, BigInteger.valueOf(1), null);
assertEquals("Expected to still get changes", changes.getObjects().size(), 1);
// but not negative
try
{
changes = cmisService.getContentChanges(repositoryId, new Holder<String>(changeToken), Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE, BigInteger.valueOf(-1), null);
fail("Negative maxItems is expected to fail");
}
catch (CmisInvalidArgumentException e)
{
// Expected
}
return null;
}