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

@@ -50,10 +50,10 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.events.types.ContentEvent;
import org.alfresco.events.types.ContentEventImpl;
@@ -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,25 +3698,28 @@ 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)
String newChangeLogToken = null;
// Check if we got more than the client requested
if (result.getObjects().size() >= maxResults)
{
if (result.getObjects().size() >= maxResults)
{
StringBuilder clt = new StringBuilder();
newChangeLogToken = (from == null ? clt.append(maxItems.intValue() + 1).toString() : clt.append(from.longValue() + maxItems.intValue()).toString());
result.getObjects().remove(result.getObjects().size() - 1).getId();
result.setHasMoreItems(true);
}
else
{
result.setHasMoreItems(false);
}
// 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()); // 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)