use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testDeleteTaskVariableExceptions.
@Test
public void testDeleteTaskVariableExceptions() 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);
TasksClient tasksClient = publicApiClient.tasksClient();
// Delete a variable on an unexisting task
try {
tasksClient.deleteTaskVariable("unexisting", "myVar");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
}
// Delete an unexisting variable on an existing task
try {
tasksClient.deleteTaskVariable(task.getId(), "unexistingVarName");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexistingVarName was not found", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariablesScoped.
@Test
public void testGetTaskVariablesScoped() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
Map<String, Object> actualLocalVariables = activitiProcessEngine.getTaskService().getVariablesLocal(task.getId());
Map<String, Object> actualGlobalVariables = activitiProcessEngine.getRuntimeService().getVariables(processInstance.getId());
assertEquals(5, actualGlobalVariables.size());
assertEquals(8, actualLocalVariables.size());
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject variables = tasksClient.findTaskVariables(task.getId(), Collections.singletonMap("where", "(scope = local)"));
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
assertNotNull(list);
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
JSONObject pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(8L, pagination.get("count"));
assertEquals(8L, pagination.get("totalItems"));
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
assertEquals(actualLocalVariables.size(), entries.size());
Set<String> expectedLocalVars = new HashSet<String>();
expectedLocalVars.addAll(actualLocalVariables.keySet());
for (int i = 0; i < entries.size(); i++) {
JSONObject entry = (JSONObject) ((JSONObject) entries.get(i)).get("entry");
assertNotNull(entry);
// Check if full entry is present with correct scope
assertEquals("local", entry.get("scope"));
assertNotNull(entry.get("name"));
assertNotNull(entry.get("type"));
if (!entry.get("name").equals("bpm_hiddenTransitions")) {
assertNotNull(entry.get("value"));
}
expectedLocalVars.remove(entry.get("name"));
}
assertEquals(0, expectedLocalVars.size());
// Now check the global scope
variables = tasksClient.findTaskVariables(task.getId(), Collections.singletonMap("where", "(scope = global)"));
assertNotNull(variables);
list = (JSONObject) variables.get("list");
assertNotNull(list);
entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(4L, pagination.get("count"));
assertEquals(4L, pagination.get("totalItems"));
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
// Should contain one variable less than the actual variables in the engine, tenant-domain var is filtered out
assertEquals(actualGlobalVariables.size() - 1, entries.size());
Set<String> expectedGlobalVars = new HashSet<String>();
expectedGlobalVars.addAll(actualGlobalVariables.keySet());
expectedGlobalVars.remove(ActivitiConstants.VAR_TENANT_DOMAIN);
for (int i = 0; i < entries.size(); i++) {
JSONObject entry = (JSONObject) ((JSONObject) entries.get(i)).get("entry");
assertNotNull(entry);
// Check if full entry is present with correct scope
assertEquals("global", entry.get("scope"));
assertNotNull(entry.get("name"));
assertNotNull(entry.get("type"));
assertNotNull(entry.get("value"));
expectedGlobalVars.remove(entry.get("name"));
}
// Check if all variables are present
assertEquals(0, expectedGlobalVars.size());
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariablesReview.
@Test
public void testGetTaskVariablesReview() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInstance = startParallelReviewProcess(requestContext);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).taskAssignee(requestContext.getRunAsUser()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject variables = tasksClient.findTaskVariables(task.getId());
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
assertNotNull(list);
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
JSONObject pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(42L, pagination.get("count"));
assertEquals(42L, pagination.get("totalItems"));
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
} finally {
cleanupProcessInstance(processInstance.getId());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testDelegateTask.
@Test
@SuppressWarnings("unchecked")
public void testDelegateTask() 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();
// Delegating as non-assignee/owner/initiator/admin should result in an error
JSONObject taskBody = new JSONObject();
taskBody.put("state", "delegated");
taskBody.put("assignee", initiator);
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "state", "assignee" }));
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());
}
// Delegating (as assignee) and not passing in an asisgnee should result in an error
activitiProcessEngine.getTaskService().setAssignee(task.getId(), user);
taskBody = new JSONObject();
taskBody.put("state", "delegated");
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.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("When delegating a task, assignee should be selected and provided in the request.", expected.getHttpResponse());
}
// Delegating as assignee
taskBody.put("state", "delegated");
taskBody.put("assignee", initiator);
selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "state", "assignee" }));
assertNull(task.getDelegationState());
JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("delegated", result.get("state"));
assertEquals(initiator, result.get("assignee"));
assertEquals(requestContext.getRunAsUser(), result.get("owner"));
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(DelegationState.PENDING, task.getDelegationState());
assertEquals(initiator, task.getAssignee());
assertEquals(requestContext.getRunAsUser(), task.getOwner());
// Delegating as owner
task.setDelegationState(null);
task.setOwner(requestContext.getRunAsUser());
task.setAssignee(null);
activitiProcessEngine.getTaskService().saveTask(task);
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("delegated", result.get("state"));
assertEquals(initiator, result.get("assignee"));
assertEquals(requestContext.getRunAsUser(), result.get("owner"));
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(DelegationState.PENDING, task.getDelegationState());
assertEquals(initiator, task.getAssignee());
assertEquals(requestContext.getRunAsUser(), task.getOwner());
// Delegating as process initiator
task.setDelegationState(null);
task.setOwner(null);
task.setAssignee(null);
activitiProcessEngine.getTaskService().saveTask(task);
requestContext.setRunAsUser(initiator);
taskBody.put("assignee", user);
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("delegated", result.get("state"));
assertEquals(user, result.get("assignee"));
assertEquals(initiator, result.get("owner"));
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(DelegationState.PENDING, task.getDelegationState());
assertEquals(user, task.getAssignee());
assertEquals(initiator, task.getOwner());
// Delegating as administrator
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
task.setDelegationState(null);
task.setOwner(null);
task.setAssignee(null);
activitiProcessEngine.getTaskService().saveTask(task);
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
requestContext.setRunAsUser(tenantAdmin);
taskBody.put("assignee", user);
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("delegated", result.get("state"));
assertEquals(user, result.get("assignee"));
assertEquals(tenantAdmin, result.get("owner"));
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(DelegationState.PENDING, task.getDelegationState());
assertEquals(user, task.getAssignee());
assertEquals(tenantAdmin, task.getOwner());
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskById.
@Test
public void testGetTaskById() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
RequestContext otherContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
// Alter current engine date
Calendar createdCal = Calendar.getInstance();
createdCal.set(Calendar.MILLISECOND, 0);
Clock actiClock = activitiProcessEngine.getProcessEngineConfiguration().getClock();
actiClock.setCurrentTime(createdCal.getTime());
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Set some task-properties not set by process-definition
Calendar dueDateCal = Calendar.getInstance();
dueDateCal.set(Calendar.MILLISECOND, 0);
dueDateCal.add(Calendar.DAY_OF_YEAR, 1);
Date dueDate = dueDateCal.getTime();
task.setDescription("This is a test description");
task.setAssignee(requestContext.getRunAsUser());
task.setOwner("john");
task.setDueDate(dueDate);
activitiProcessEngine.getTaskService().saveTask(task);
TasksClient tasksClient = publicApiClient.tasksClient();
// Check resulting task
JSONObject taskJSONObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskJSONObject);
assertEquals(task.getId(), taskJSONObject.get("id"));
assertEquals(processInstance.getId(), taskJSONObject.get("processId"));
assertEquals(processInstance.getProcessDefinitionId(), taskJSONObject.get("processDefinitionId"));
assertEquals("adhocTask", taskJSONObject.get("activityDefinitionId"));
assertEquals("Adhoc Task", taskJSONObject.get("name"));
assertEquals("This is a test description", taskJSONObject.get("description"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
assertEquals("john", taskJSONObject.get("owner"));
assertEquals(dueDate, parseDate(taskJSONObject, "dueAt"));
assertEquals(createdCal.getTime(), parseDate(taskJSONObject, "startedAt"));
assertEquals(2l, taskJSONObject.get("priority"));
assertEquals("wf:adhocTask", taskJSONObject.get("formResourceKey"));
assertNull(taskJSONObject.get("endedAt"));
assertNull(taskJSONObject.get("durationInMs"));
// get unclaimed task
activitiProcessEngine.getTaskService().setAssignee(task.getId(), null);
taskJSONObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskJSONObject);
assertEquals(task.getId(), taskJSONObject.get("id"));
// get delegated task
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
activitiProcessEngine.getTaskService().setOwner(task.getId(), requestContext.getRunAsUser());
activitiProcessEngine.getTaskService().delegateTask(task.getId(), otherContext.getRunAsUser());
taskJSONObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskJSONObject);
assertEquals(task.getId(), taskJSONObject.get("id"));
assertEquals(otherContext.getRunAsUser(), taskJSONObject.get("assignee"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("owner"));
// get resolved task
activitiProcessEngine.getTaskService().resolveTask(task.getId());
taskJSONObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskJSONObject);
assertEquals(task.getId(), taskJSONObject.get("id"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("owner"));
// get completed task
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
taskJSONObject = tasksClient.findTaskById(task.getId());
assertNotNull(taskJSONObject);
assertEquals(task.getId(), taskJSONObject.get("id"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("owner"));
assertNotNull(taskJSONObject.get("endedAt"));
} finally {
cleanupProcessInstance(processInstance);
}
}
Aggregations