use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancesGetWithFiltering.
public void testTaskInstancesGetWithFiltering() throws Exception {
// Check USER2 starts with no tasks.
personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
getJsonArray(response, 0);
// Start workflow as USER1 and assign the task to GROUP.
personManager.setUser(USER1);
WorkflowDefinition wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<>(3);
params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest1");
WorkflowPath wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
String workflowId = wfPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Start another workflow as USER1 and assign the task to GROUP.
wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest2/withSlash");
wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
workflowId = wfPath.getInstance().getId();
workflows.add(workflowId);
startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Check USER2's tasks without filtering. It should return two tasks as USER2 is a member of the GROUP
personManager.setUser(USER2);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
getJsonArray(response, 2);
// Check USER2's tasks With filtering where property bpm:description should match "descTest1"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest1"), 200);
JSONArray results = getJsonArray(response, 1);
JSONObject result = results.getJSONObject(0);
assertNotNull(result);
JSONObject properties = result.getJSONObject("properties");
assertNotNull(properties);
assertEquals("descTest1", properties.getString("bpm_description"));
// Check USER2's tasks With filtering where property bpm:description should match "descTest2"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest2/withSlash"), 200);
results = getJsonArray(response, 1);
result = results.getJSONObject(0);
assertNotNull(result);
properties = result.getJSONObject("properties");
assertNotNull(properties);
assertEquals("descTest2/withSlash", properties.getString("bpm_description"));
/*
* -ve tests
*/
// Mismatched property value - There is no task with the description "somePropValue"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/somePropValue"), 200);
getJsonArray(response, 0);
// Unregistered namespace prefix (ignores "property" parameter)
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=unknownPrefix:description/test"), 200);
getJsonArray(response, 2);
// Nonexistent property (ignores "property" parameter)
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:nonexistentProp/test"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=descTest1"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=/descTest1"), 200);
getJsonArray(response, 2);
// Check USER3's tasks without filtering. It should return 0 task as USER3 is not a member of the GROUP
personManager.setUser(USER3);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200);
getJsonArray(response, 0);
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancePut.
public void testTaskInstancePut() throws Exception {
// Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Calendar dueDate = Calendar.getInstance();
dueDate.set(Calendar.MILLISECOND, 0);
params.put(WorkflowModel.PROP_DUE_DATE, new Date());
params.put(WorkflowModel.PROP_PRIORITY, 2);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String worfklowId = adhocPath.getInstance().getId();
workflows.add(worfklowId);
WorkflowTask startTask = workflowService.getStartTask(adhocPath.getInstance().getId());
// Finish the start-task
workflowService.endTask(startTask.getId(), null);
WorkflowTask firstTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
Response response = sendRequest(new GetRequest(URL_TASKS + "/" + firstTask.getId()), 200);
JSONObject jsonProperties = new JSONObject(response.getContentAsString()).getJSONObject("data").getJSONObject("properties");
// make some changes in existing properties
jsonProperties.remove(qnameToString(WorkflowModel.ASSOC_PACKAGE));
jsonProperties.put(qnameToString(WorkflowModel.PROP_COMMENT), "Edited comment");
Calendar newDueDate = Calendar.getInstance();
newDueDate.set(Calendar.MILLISECOND, 0);
jsonProperties.put(qnameToString(WorkflowModel.PROP_DUE_DATE), ISO8601DateFormat.format(newDueDate.getTime()));
jsonProperties.put(qnameToString(WorkflowModel.PROP_DESCRIPTION), "Edited description");
jsonProperties.put(qnameToString(WorkflowModel.PROP_PRIORITY), 1);
// Add some custom properties, which are not defined in typeDef
jsonProperties.put("customIntegerProperty", 1234);
jsonProperties.put("customBooleanProperty", Boolean.TRUE);
jsonProperties.put("customStringProperty", "Property value");
// test USER3 can not update the task
personManager.setUser(USER3);
Response unauthResponse = sendRequest(new PutRequest(URL_TASKS + "/" + firstTask.getId(), jsonProperties.toString(), "application/json"), 401);
assertEquals(Status.STATUS_UNAUTHORIZED, unauthResponse.getStatus());
// test USER2 (the task owner) can update the task
personManager.setUser(USER2);
Response putResponse = sendRequest(new PutRequest(URL_TASKS + "/" + firstTask.getId(), jsonProperties.toString(), "application/json"), 200);
assertEquals(Status.STATUS_OK, putResponse.getStatus());
String jsonStr = putResponse.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONObject result = json.getJSONObject("data");
assertNotNull(result);
JSONObject editedJsonProperties = result.getJSONObject("properties");
editedJsonProperties.remove(qnameToString(ContentModel.PROP_CREATOR));
compareProperties(jsonProperties, editedJsonProperties);
// test USER1 (the task workflow initiator) can update the task
personManager.setUser(USER1);
putResponse = sendRequest(new PutRequest(URL_TASKS + "/" + firstTask.getId(), jsonProperties.toString(), "application/json"), 200);
assertEquals(Status.STATUS_OK, putResponse.getStatus());
jsonStr = putResponse.getContentAsString();
json = new JSONObject(jsonStr);
result = json.getJSONObject("data");
assertNotNull(result);
editedJsonProperties = result.getJSONObject("properties");
editedJsonProperties.remove(qnameToString(ContentModel.PROP_CREATOR));
compareProperties(jsonProperties, editedJsonProperties);
// Reassign the task to USER3 using taskInstance PUT
jsonProperties = new JSONObject();
jsonProperties.put(qnameToString(ContentModel.PROP_OWNER), USER3);
putResponse = sendRequest(new PutRequest(URL_TASKS + "/" + firstTask.getId(), jsonProperties.toString(), "application/json"), 200);
assertEquals(Status.STATUS_OK, putResponse.getStatus());
// test USER3 (now the task owner) can update the task
personManager.setUser(USER3);
jsonProperties.put(qnameToString(WorkflowModel.PROP_COMMENT), "Edited comment by USER3");
putResponse = sendRequest(new PutRequest(URL_TASKS + "/" + firstTask.getId(), jsonProperties.toString(), "application/json"), 200);
assertEquals(Status.STATUS_OK, putResponse.getStatus());
jsonStr = putResponse.getContentAsString();
json = new JSONObject(jsonStr);
result = json.getJSONObject("data");
assertNotNull(result);
editedJsonProperties = result.getJSONObject("properties");
editedJsonProperties.remove(qnameToString(ContentModel.PROP_CREATOR));
compareProperties(jsonProperties, editedJsonProperties);
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method runReviewFlow.
protected void runReviewFlow(boolean approve) throws Exception {
// Start workflow as USER1
personManager.setUser(USER1);
WorkflowDefinition reviewDef = workflowService.getDefinitionByName(getReviewWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
// Reviewer is USER2
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Date dueDate = new Date();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath reviewPath = workflowService.startWorkflow(reviewDef.getId(), params);
String workflowId = reviewPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(reviewPath.getId()).get(0);
// End start task
startTask = workflowService.endTask(startTask.getId(), null);
// Check of task is available in list of reviewer, USER2
personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(1, results.length());
String taskId = results.getJSONObject(0).getString("id");
// Delegate approval/rejection to implementing engine-test
if (approve) {
approveTask(taskId);
} else {
rejectTask(taskId);
}
// 'Approved'/'Rejected' task should be available for initiator
personManager.setUser(USER1);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER1)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(1, results.length());
// Correct task type check
String taskType = results.getJSONObject(0).getString("name");
if (approve) {
assertEquals("wf:approvedTask", taskType);
} else {
assertEquals("wf:rejectedTask", taskType);
}
workflowService.cancelWorkflow(workflowId);
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstanceGet.
public void testTaskInstanceGet() throws Exception {
// Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Calendar dueDateCal = Calendar.getInstance();
dueDateCal.clear(Calendar.MILLISECOND);
Date dueDate = dueDateCal.getTime();
NodeRef assignee = personManager.get(USER2);
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
// Get the start-task
Response response = sendRequest(new GetRequest(URL_TASKS + "/" + startTask.getId()), Status.STATUS_OK);
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONObject result = json.getJSONObject("data");
assertNotNull(result);
assertEquals(startTask.getId(), result.getString("id"));
assertEquals(URL_TASKS + "/" + startTask.getId(), result.getString("url"));
assertEquals(startTask.getName(), result.getString("name"));
assertEquals(startTask.getTitle(), result.getString("title"));
assertEquals(startTask.getDescription(), result.getString("description"));
assertEquals(startTask.getState().name(), result.getString("state"));
assertEquals("api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
checkWorkflowTaskEditable(result);
checkWorkflowTaskOwner(result, USER1);
checkWorkflowTaskPropertiesPresent(result);
JSONObject properties = result.getJSONObject("properties");
assertEquals(1, properties.getInt("bpm_priority"));
String dueDateStr = ISO8601DateFormat.format(dueDate);
assertEquals(dueDateStr, properties.getString("bpm_dueDate"));
assertEquals(assignee.toString(), properties.getString("bpm_assignee"));
assertEquals(packageRef.toString(), properties.getString("bpm_package"));
checkWorkflowInstance(startTask.getPath().getInstance(), result.getJSONObject("workflowInstance"));
checkWorkflowTaskDefinition(startTask.getDefinition(), result.getJSONObject("definition"));
// Finish the start-task, and fetch it again
personManager.setUser(USER2);
workflowService.endTask(startTask.getId(), null);
startTask = workflowService.getTaskById(startTask.getId());
response = sendRequest(new GetRequest(URL_TASKS + "/" + startTask.getId()), Status.STATUS_OK);
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
result = json.getJSONObject("data");
assertNotNull(result);
assertEquals(startTask.getId(), result.getString("id"));
assertEquals(URL_TASKS + "/" + startTask.getId(), result.getString("url"));
assertEquals(startTask.getName(), result.getString("name"));
assertEquals(startTask.getTitle(), result.getString("title"));
assertEquals(startTask.getDescription(), result.getString("description"));
assertEquals(startTask.getState().name(), result.getString("state"));
assertEquals("api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
checkWorkflowTaskReadOnly(result);
checkWorkflowTaskOwner(result, USER1);
checkWorkflowTaskPropertiesPresent(result);
checkWorkflowInstance(startTask.getPath().getInstance(), result.getJSONObject("workflowInstance"));
checkWorkflowTaskDefinition(startTask.getDefinition(), result.getJSONObject("definition"));
// Get the next active task
WorkflowTask firstTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
response = sendRequest(new GetRequest(URL_TASKS + "/" + firstTask.getId()), 200);
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
result = json.getJSONObject("data");
assertNotNull(result);
assertEquals(firstTask.getId(), result.getString("id"));
assertEquals(URL_TASKS + "/" + firstTask.getId(), result.getString("url"));
assertEquals(firstTask.getName(), result.getString("name"));
assertEquals(firstTask.getTitle(), result.getString("title"));
assertEquals(firstTask.getDescription(), result.getString("description"));
// Task should be in progress
assertEquals(firstTask.getState().name(), result.getString("state"));
assertEquals(WorkflowTaskState.IN_PROGRESS.toString(), result.getString("state"));
assertEquals("api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
checkWorkflowTaskEditable(result);
checkWorkflowTaskOwner(result, USER2);
checkWorkflowTaskPropertiesPresent(result);
checkWorkflowInstance(firstTask.getPath().getInstance(), result.getJSONObject("workflowInstance"));
checkWorkflowTaskDefinition(firstTask.getDefinition(), result.getJSONObject("definition"));
// Finish the task, and fetch it again
workflowService.endTask(firstTask.getId(), null);
firstTask = workflowService.getTaskById(firstTask.getId());
response = sendRequest(new GetRequest(URL_TASKS + "/" + firstTask.getId()), 200);
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
result = json.getJSONObject("data");
assertNotNull(result);
assertEquals(firstTask.getId(), result.getString("id"));
assertEquals(URL_TASKS + "/" + firstTask.getId(), result.getString("url"));
assertEquals(firstTask.getName(), result.getString("name"));
assertEquals(firstTask.getTitle(), result.getString("title"));
assertEquals(firstTask.getDescription(), result.getString("description"));
// The task should be completed
assertEquals(firstTask.getState().name(), result.getString("state"));
assertEquals(WorkflowTaskState.COMPLETED.toString(), result.getString("state"));
assertEquals("api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
checkWorkflowTaskReadOnly(result);
checkWorkflowTaskOwner(result, USER2);
checkWorkflowTaskPropertiesPresent(result);
checkWorkflowInstance(firstTask.getPath().getInstance(), result.getJSONObject("workflowInstance"));
checkWorkflowTaskDefinition(firstTask.getDefinition(), result.getJSONObject("definition"));
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancePutCompletedTask.
public void testTaskInstancePutCompletedTask() throws Exception {
// Start workflow as USER1 and assign to self
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER1));
params.put(WorkflowModel.PROP_DUE_DATE, new Date());
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String WorkflowId = adhocPath.getInstance().getId();
workflows.add(WorkflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
// Finish the start-task
workflowService.endTask(startTask.getId(), null);
WorkflowTask firstTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
Response getResponse = sendRequest(new GetRequest(URL_TASKS + "/" + firstTask.getId()), 200);
JSONObject jsonProperties = new JSONObject(getResponse.getContentAsString()).getJSONObject("data").getJSONObject("properties");
// Make a change
jsonProperties.put(qnameToString(WorkflowModel.PROP_DESCRIPTION), "Edited description");
// Update task. An error is expected, since the task is completed (and not editable)
sendRequest(new PutRequest(URL_TASKS + "/" + startTask.getId(), jsonProperties.toString(), "application/json"), Status.STATUS_UNAUTHORIZED);
}
Aggregations