use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUnClaimTask.
@Test
@SuppressWarnings("unchecked")
public void testUnClaimTask() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String user = requestContext.getRunAsUser();
String initiator = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
ProcessInstance processInstance = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
// Unclaiming the task when NOT assignee, owner, initiator or admin results in error
JSONObject taskBody = new JSONObject();
taskBody.put("state", "unclaimed");
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "state" }));
try {
tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
// Unclaiming as process initiator
requestContext.setRunAsUser(initiator);
activitiProcessEngine.getTaskService().setAssignee(task.getId(), null);
JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertNull(result.get("assignee"));
assertNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
// Unclaiming as assignee
activitiProcessEngine.getTaskService().setAssignee(task.getId(), user);
requestContext.setRunAsUser(user);
assertNotNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertNull(result.get("assignee"));
assertNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
// Unclaim as owner
activitiProcessEngine.getTaskService().setOwner(task.getId(), user);
activitiProcessEngine.getTaskService().setAssignee(task.getId(), initiator);
assertNotNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertNull(result.get("assignee"));
assertNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
// Unclaim as admin
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
activitiProcessEngine.getTaskService().setAssignee(task.getId(), initiator);
activitiProcessEngine.getTaskService().deleteUserIdentityLink(task.getId(), requestContext.getRunAsUser(), IdentityLinkType.CANDIDATE);
assertNotNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertNull(result.get("assignee"));
assertNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(task.getId()).singleResult().getAssignee());
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext 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.api.tests.client.RequestContext 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.api.tests.client.RequestContext 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.api.tests.client.RequestContext 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);
}
}
Aggregations