use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testSetOutcome.
@Test
@SuppressWarnings("unchecked")
public void testSetOutcome() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInf = startReviewPooledProcess(requestContext);
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInf.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
activitiProcessEngine.getTaskService().saveTask(task);
Map<String, String> params = new HashMap<String, String>();
params.put("select", "state,variables");
HttpResponse response = tasksClient.update("tasks", task.getId(), null, null, "{\"state\":\"completed\",\"variables\":[{\"name\":\"wf_reviewOutcome\",\"value\":\"Approve\",\"scope\":\"local\"},{\"name\":\"bpm_comment\",\"value\":\"approved by me\",\"scope\":\"local\"}]}", params, "Failed to update task", 200);
HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().includeTaskLocalVariables().singleResult();
String outcome = (String) historyTask.getTaskLocalVariables().get("bpm_outcome");
assertEquals("Approve", outcome);
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testDeleteTaskVariable.
@Test
public void testDeleteTaskVariable() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
activitiProcessEngine.getRuntimeService().setVariable(processInstance.getId(), "overlappingVariable", "Value set in process");
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
activitiProcessEngine.getTaskService().setVariableLocal(task.getId(), "myVariable", "This is a variable");
activitiProcessEngine.getTaskService().setVariableLocal(task.getId(), "overlappingVariable", "Value set in task");
// Delete a task-variable
TasksClient tasksClient = publicApiClient.tasksClient();
tasksClient.deleteTaskVariable(task.getId(), "myVariable");
assertFalse(activitiProcessEngine.getTaskService().hasVariableLocal(task.getId(), "myVariable"));
// Delete a task-variable that has the same name as a global process-variable - which should remain untouched after delete
tasksClient.deleteTaskVariable(task.getId(), "overlappingVariable");
assertFalse(activitiProcessEngine.getTaskService().hasVariableLocal(task.getId(), "overlappingVariable"));
assertTrue(activitiProcessEngine.getRuntimeService().hasVariable(processInstance.getId(), "overlappingVariable"));
assertEquals("Value set in process", activitiProcessEngine.getRuntimeService().getVariable(processInstance.getId(), "overlappingVariable"));
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTasksWithSorting.
@Test
public void testGetTasksWithSorting() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
// Start 6 processes
List<ProcessInstance> startedProcesses = new ArrayList<ProcessInstance>();
try {
int numberOfTasks = 6;
for (int i = 0; i < numberOfTasks; i++) {
startedProcesses.add(startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null));
}
List<Task> taskList = new ArrayList<Task>();
for (int i = 0; i < numberOfTasks; i++) {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(startedProcesses.get(i).getProcessInstanceId()).singleResult();
activitiProcessEngine.getTaskService().setPriority(task.getId(), (i + 1) * 10);
taskList.add(task);
}
// set last task priority to 1
activitiProcessEngine.getTaskService().setPriority(taskList.get(numberOfTasks - 1).getId(), 1);
TasksClient tasksClient = publicApiClient.tasksClient();
// Test with existing processDefinitionId
Map<String, String> params = new HashMap<String, String>();
params.put("where", "(processDefinitionId = '" + startedProcesses.get(0).getProcessDefinitionId() + "')");
params.put("orderBy", "priority ASC");
JSONObject tasksResponseJSON = tasksClient.findTasks(params);
JSONObject paginationJSON = (JSONObject) tasksResponseJSON.get("pagination");
assertEquals(6l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
JSONArray tasksListJSON = (JSONArray) tasksResponseJSON.get("entries");
assertEquals(6, tasksListJSON.size());
JSONObject taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(0)).get("entry");
assertEquals(taskList.get(numberOfTasks - 1).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(1)).get("entry");
assertEquals(taskList.get(0).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(2)).get("entry");
assertEquals(taskList.get(1).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(3)).get("entry");
assertEquals(taskList.get(2).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(4)).get("entry");
assertEquals(taskList.get(3).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(5)).get("entry");
assertEquals(taskList.get(4).getId(), taskJSON.get("id"));
params.put("orderBy", "priority DESC");
tasksResponseJSON = tasksClient.findTasks(params);
paginationJSON = (JSONObject) tasksResponseJSON.get("pagination");
assertEquals(6l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
tasksListJSON = (JSONArray) tasksResponseJSON.get("entries");
assertEquals(6, tasksListJSON.size());
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(0)).get("entry");
assertEquals(taskList.get(4).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(1)).get("entry");
assertEquals(taskList.get(3).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(2)).get("entry");
assertEquals(taskList.get(2).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(3)).get("entry");
assertEquals(taskList.get(1).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(4)).get("entry");
assertEquals(taskList.get(0).getId(), taskJSON.get("id"));
taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(5)).get("entry");
assertEquals(taskList.get(numberOfTasks - 1).getId(), taskJSON.get("id"));
params.put("orderBy", "dueAt DESC");
tasksResponseJSON = tasksClient.findTasks(params);
tasksListJSON = (JSONArray) tasksResponseJSON.get("entries");
assertEquals(6, tasksListJSON.size());
} finally {
cleanupProcessInstance(startedProcesses.toArray(new ProcessInstance[] {}));
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testChangeDueDate.
@Test
@SuppressWarnings("unchecked")
public void testChangeDueDate() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject taskObject = tasksClient.findTaskById(task.getId());
assertNull(taskObject.get("dueAt"));
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "name", "description", "dueAt", "priority", "assignee", "owner" }));
// set due date
JSONObject taskBody = new JSONObject();
String dueAt = formatDate(new Date());
taskBody.put("dueAt", dueAt);
JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertNotNull(result.get("dueAt"));
taskObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskObject.get("dueAt"));
taskBody = new JSONObject();
taskBody.put("dueAt", taskObject.get("dueAt"));
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertNotNull(result.get("dueAt"));
taskObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskObject.get("dueAt"));
JSONObject variableBody = new JSONObject();
variableBody.put("name", "bpm_workflowDueDate");
variableBody.put("value", formatDate(new Date()));
variableBody.put("type", "d:date");
variableBody.put("scope", "global");
tasksClient.updateTaskVariable(task.getId(), "bpm_workflowDueDate", variableBody);
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTasksWithPaging.
@Test
public void testGetTasksWithPaging() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
// Start 6 processes
List<ProcessInstance> startedProcesses = new ArrayList<ProcessInstance>();
try {
int numberOfTasks = 6;
for (int i = 0; i < numberOfTasks; i++) {
startedProcesses.add(startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null));
}
String processDefinitionId = startedProcesses.get(0).getProcessDefinitionId();
TasksClient tasksClient = publicApiClient.tasksClient();
// Test with existing processDefinitionId
Map<String, String> params = new HashMap<String, String>();
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
JSONObject taskListJSONObject = tasksClient.findTasks(params);
assertNotNull(taskListJSONObject);
JSONObject paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
assertEquals(6l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
JSONArray jsonEntries = (JSONArray) taskListJSONObject.get("entries");
assertEquals(6, jsonEntries.size());
validateVariables((JSONObject) jsonEntries.get(0), requestContext);
// Test with existing processDefinitionId and max items
params.clear();
params.put("maxItems", "3");
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
taskListJSONObject = tasksClient.findTasks(params);
assertNotNull(taskListJSONObject);
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) taskListJSONObject.get("entries");
assertEquals(3, jsonEntries.size());
validateVariables((JSONObject) jsonEntries.get(0), requestContext);
// Test with existing processDefinitionId and skip count
params.clear();
params.put("skipCount", "2");
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
taskListJSONObject = tasksClient.findTasks(params);
assertNotNull(taskListJSONObject);
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
assertEquals(4l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) taskListJSONObject.get("entries");
assertEquals(4, jsonEntries.size());
// Test with existing processDefinitionId and max items and skip count
params.clear();
params.put("maxItems", "3");
params.put("skipCount", "2");
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
taskListJSONObject = tasksClient.findTasks(params);
assertNotNull(taskListJSONObject);
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) taskListJSONObject.get("entries");
assertEquals(3, jsonEntries.size());
// Test with existing processDefinitionId and max items and skip count
params.clear();
params.put("maxItems", "3");
params.put("skipCount", "4");
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
taskListJSONObject = tasksClient.findTasks(params);
assertNotNull(taskListJSONObject);
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(6l, paginationJSON.get("totalItems"));
assertEquals(4l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) taskListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
} finally {
cleanupProcessInstance(startedProcesses.toArray(new ProcessInstance[] {}));
}
}
Aggregations