diff --git a/config/alfresco/public-rest-context.xml b/config/alfresco/public-rest-context.xml
index a927bde1cb..9519b9f065 100644
--- a/config/alfresco/public-rest-context.xml
+++ b/config/alfresco/public-rest-context.xml
@@ -1011,6 +1011,7 @@
+
diff --git a/source/java/org/alfresco/rest/workflow/api/impl/TasksImpl.java b/source/java/org/alfresco/rest/workflow/api/impl/TasksImpl.java
index a2feb2e4bc..49c6664796 100644
--- a/source/java/org/alfresco/rest/workflow/api/impl/TasksImpl.java
+++ b/source/java/org/alfresco/rest/workflow/api/impl/TasksImpl.java
@@ -138,6 +138,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
private MessageService messageService;
private PersonService personService;
private ActivitiPropertyConverter propertyConverter;
+ private int taskVariablesLimit = 20000;
public void setPropertyConverter(ActivitiPropertyConverter propertyConverter)
{
@@ -159,6 +160,16 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
this.personService = personService;
}
+ public int getTaskVariablesLimit()
+ {
+ return taskVariablesLimit;
+ }
+
+ public void setTaskVariablesLimit(int taskVariablesLimit)
+ {
+ this.taskVariablesLimit = taskVariablesLimit;
+ }
+
@Override
public CollectionWithPagingInfo getTasks(Parameters parameters)
{
@@ -293,6 +304,9 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
query.includeTaskLocalVariables();
}
+ // use the limit set in alfresco-global.properties
+ query.limitTaskVariables(taskVariablesLimit);
+
List variableProperties = propertyWalker.getVariableProperties();
setQueryUsingVariables(query, variableProperties);
diff --git a/source/test-java/org/alfresco/rest/workflow/api/tests/TaskWorkflowApiTest.java b/source/test-java/org/alfresco/rest/workflow/api/tests/TaskWorkflowApiTest.java
index 47761b0e83..0f78aed998 100644
--- a/source/test-java/org/alfresco/rest/workflow/api/tests/TaskWorkflowApiTest.java
+++ b/source/test-java/org/alfresco/rest/workflow/api/tests/TaskWorkflowApiTest.java
@@ -1995,6 +1995,81 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
}
}
+ @Test
+ public void testGetTasksWithPagingAndVariablesLimit() throws Exception
+ {
+ RequestContext requestContext = initApiClientWithTestUser();
+ List startedProcesses = new ArrayList();
+
+ // system.workflow.engine.activiti.taskvariableslimit is set to 200 in test-resources/alfresco-global.properties
+ try
+ {
+ // MNT-16040: Create tasks with a number of variables just below the taskvariableslimit and test that skipCount is working as expected.
+ int numberOfTasks = 15;
+ for (int i = 0; i < numberOfTasks; i++)
+ {
+ startedProcesses.add(startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null));
+ }
+ TaskService taskService = activitiProcessEngine.getTaskService();
+ List taskList = new ArrayList();
+ for (int i = 0; i < numberOfTasks; i++)
+ {
+ Task task = taskService.createTaskQuery().processInstanceId(startedProcesses.get(i).getProcessInstanceId()).singleResult();
+ taskService.setPriority(task.getId(), (i + 1) * 10);
+
+ // Add an extra variable to the task, there are other 12 added, so a total of 13 variables for each task.
+ taskService.setVariableLocal(task.getId(), "test1", "test1");
+ taskList.add(task);
+ }
+
+ TasksClient tasksClient = publicApiClient.tasksClient();
+
+ // Test without skipCount
+ Map params = new HashMap();
+ params.put("where", "(includeProcessVariables = true AND includeTaskVariables = true)");
+ JSONObject taskListJSONObject = tasksClient.findTasks(params);
+ assertNotNull(taskListJSONObject);
+ JSONObject paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
+ assertEquals(15l, paginationJSON.get("count"));
+ assertEquals(15l, paginationJSON.get("totalItems"));
+ assertEquals(0l, paginationJSON.get("skipCount"));
+ assertEquals(false, paginationJSON.get("hasMoreItems"));
+ JSONArray jsonEntries = (JSONArray) taskListJSONObject.get("entries");
+ assertEquals(15, jsonEntries.size());
+
+ // Test with skipCount
+ params.clear();
+ params.put("skipCount", "5");
+ params.put("where", "(includeProcessVariables = true AND includeTaskVariables = true)");
+ taskListJSONObject = tasksClient.findTasks(params);
+ assertNotNull(taskListJSONObject);
+ paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
+ assertEquals(10l, paginationJSON.get("count"));
+ assertEquals(15l, paginationJSON.get("totalItems"));
+ assertEquals(5l, paginationJSON.get("skipCount"));
+ assertEquals(false, paginationJSON.get("hasMoreItems"));
+ jsonEntries = (JSONArray) taskListJSONObject.get("entries");
+ assertEquals(10, jsonEntries.size());
+
+ params.clear();
+ params.put("maxItems", "10");
+ params.put("where", "(includeProcessVariables = true AND includeTaskVariables = true)");
+ taskListJSONObject = tasksClient.findTasks(params);
+ assertNotNull(taskListJSONObject);
+ paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
+ assertEquals(10l, paginationJSON.get("count"));
+ assertEquals(15l, paginationJSON.get("totalItems"));
+ assertEquals(0l, paginationJSON.get("skipCount"));
+ assertEquals(true, paginationJSON.get("hasMoreItems"));
+ jsonEntries = (JSONArray) taskListJSONObject.get("entries");
+ assertEquals(10, jsonEntries.size());
+ }
+ finally
+ {
+ cleanupProcessInstance(startedProcesses.toArray(new ProcessInstance[] {}));
+ }
+ }
+
protected void validateVariables(JSONObject entry, RequestContext requestContext) {
JSONObject taskObject = (JSONObject) entry.get("entry");
JSONArray variables = (JSONArray) taskObject.get("variables");
diff --git a/source/test-resources/alfresco-global.properties b/source/test-resources/alfresco-global.properties
index a9754d1e0d..654011a248 100644
--- a/source/test-resources/alfresco-global.properties
+++ b/source/test-resources/alfresco-global.properties
@@ -1,2 +1,4 @@
opencmis.tck.readtimeout=10000
-opencmis.tck.connecttimeout=10000
\ No newline at end of file
+opencmis.tck.connecttimeout=10000
+
+system.workflow.engine.activiti.taskvariableslimit=200
\ No newline at end of file