use of org.alfresco.service.cmr.workflow.WorkflowDefinition in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testWorkflowDefinitionGet.
public void testWorkflowDefinitionGet() throws Exception {
personManager.setUser(USER1);
// Get the latest definition for the adhoc-workflow
WorkflowDefinition wDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
String responseUrl = MessageFormat.format(URL_WORKFLOW_DEFINITION, wDef.getId());
Response response = sendRequest(new GetRequest(responseUrl), Status.STATUS_OK);
JSONObject json = new JSONObject(response.getContentAsString());
JSONObject workflowDefinitionJSON = json.getJSONObject("data");
assertNotNull(workflowDefinitionJSON);
// Check fields
assertTrue(workflowDefinitionJSON.has("id"));
assertTrue(workflowDefinitionJSON.getString("id").length() > 0);
assertTrue(workflowDefinitionJSON.has("url"));
String url = workflowDefinitionJSON.getString("url");
assertTrue(url.length() > 0);
assertTrue(url.startsWith("api/workflow-definitions/"));
assertTrue(workflowDefinitionJSON.has("name"));
assertTrue(workflowDefinitionJSON.getString("name").length() > 0);
assertEquals(getAdhocWorkflowDefinitionName(), workflowDefinitionJSON.getString("name"));
assertTrue(workflowDefinitionJSON.has("title"));
assertTrue(workflowDefinitionJSON.getString("title").length() > 0);
assertTrue(workflowDefinitionJSON.has("description"));
assertTrue(workflowDefinitionJSON.getString("description").length() > 0);
assertTrue(workflowDefinitionJSON.has("startTaskDefinitionUrl"));
String startTaskDefUrl = workflowDefinitionJSON.getString("startTaskDefinitionUrl");
assertEquals(startTaskDefUrl, "api/classes/" + getSafeDefinitionName(ADHOC_START_TASK_TYPE));
assertTrue(workflowDefinitionJSON.has("startTaskDefinitionType"));
assertEquals(ADHOC_START_TASK_TYPE, workflowDefinitionJSON.getString("startTaskDefinitionType"));
// Check task-definitions
JSONArray taskDefinitions = workflowDefinitionJSON.getJSONArray("taskDefinitions");
assertNotNull(taskDefinitions);
// Two task definitions should be returned. Start-task is not included
assertEquals(2, taskDefinitions.length());
// Should be adhoc-task
JSONObject firstTaskDefinition = (JSONObject) taskDefinitions.get(0);
checkTaskDefinitionTypeAndUrl(ADHOC_TASK_TYPE, firstTaskDefinition);
// Should be adhoc completed task
JSONObject secondTaskDefinition = (JSONObject) taskDefinitions.get(1);
checkTaskDefinitionTypeAndUrl(ADHOC_TASK_COMPLETED_TYPE, secondTaskDefinition);
}
use of org.alfresco.service.cmr.workflow.WorkflowDefinition 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.WorkflowDefinition 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.WorkflowDefinition 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.WorkflowDefinition 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