use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.
the class ActivitiTaskComponentTest method testUpdateTask.
@SuppressWarnings("unchecked")
@Test
public void testUpdateTask() {
NodeRef nodeRef = new NodeRef("workspace:///someRef");
NodeRef anotherRef = new NodeRef("workspace:///anotherRef");
QName propQname = QName.createQName("testProp");
QName nodeRefPropQname = QName.createQName("testAssoc");
QName singleNodeRefPropQname = QName.createQName("testAssocSingleValue");
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
// Start the workflow-path
WorkflowPath path = workflowEngine.startWorkflow(workflowDef.getId(), props);
WorkflowTask startTask = workflowEngine.getStartTask(path.getInstance().getId());
// End the start-task
workflowEngine.endTask(startTask.getId(), null);
// Get the task to update
WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(WorkflowTaskState.IN_PROGRESS);
taskQuery.setProcessId(path.getInstance().getId());
List<WorkflowTask> tasks = workflowEngine.queryTasks(taskQuery);
WorkflowTask task = tasks.get(0);
// Test altering plain properties
props = new HashMap<QName, Serializable>();
props.put(propQname, "54321");
props.put(singleNodeRefPropQname, nodeRef);
workflowEngine.updateTask(task.getId(), props, null, null);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals("54321", task.getProperties().get(propQname));
// Test adding association
HashMap<QName, List<NodeRef>> toAdd = new HashMap<QName, List<NodeRef>>();
toAdd.put(nodeRefPropQname, Arrays.asList(anotherRef, nodeRef));
workflowEngine.updateTask(task.getId(), null, toAdd, null);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals(2, ((List<NodeRef>) task.getProperties().get(nodeRefPropQname)).size());
// Test removing association
HashMap<QName, List<NodeRef>> toRemove = new HashMap<QName, List<NodeRef>>();
toRemove.put(nodeRefPropQname, Arrays.asList(nodeRef));
workflowEngine.updateTask(task.getId(), null, null, toRemove);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals(1, ((List<NodeRef>) task.getProperties().get(nodeRefPropQname)).size());
assertEquals(anotherRef, ((List<NodeRef>) task.getProperties().get(nodeRefPropQname)).get(0));
// Test changing single-valued association
toAdd = new HashMap<QName, List<NodeRef>>();
toRemove = new HashMap<QName, List<NodeRef>>();
toRemove.put(singleNodeRefPropQname, Arrays.asList(nodeRef));
toAdd.put(singleNodeRefPropQname, Arrays.asList(anotherRef));
workflowEngine.updateTask(task.getId(), null, toAdd, toRemove);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals(anotherRef, task.getProperties().get(singleNodeRefPropQname));
// Test clearing single-valued association
toRemove = new HashMap<QName, List<NodeRef>>();
toRemove.put(singleNodeRefPropQname, Arrays.asList(anotherRef));
workflowEngine.updateTask(task.getId(), null, null, toRemove);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
// Association value should be empty now
assertNull(task.getProperties().get(singleNodeRefPropQname));
}
use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.
the class ActivitiTaskComponentTest method checkTaskVariableTaskPresent.
private void checkTaskVariableTaskPresent(WorkflowTaskState state, QName varName, Object varValue, String expectedTask) {
WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(state);
Map<QName, Object> customProperties = new HashMap<QName, Object>();
customProperties.put(varName, varValue);
taskQuery.setTaskCustomProps(customProperties);
assertTaskPresent(taskQuery, expectedTask);
}
use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method checkTaskPropsQuery.
protected void checkTaskPropsQuery(List<String> expectedTaskIds, WorkflowTaskState state, String optionalProcessId) {
WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(state);
Map<QName, Object> taskProps = new HashMap<QName, Object>();
taskProps.put(customStringProp, "stringValue");
taskQuery.setTaskCustomProps(taskProps);
if (optionalProcessId != null) {
taskQuery.setProcessId(optionalProcessId);
}
checkTasksFoundUsingQuery(expectedTaskIds, taskQuery);
taskProps = new HashMap<QName, Object>();
taskProps.put(customStringProp, "otherValue");
taskQuery = createWorkflowTaskQuery(state);
taskQuery.setTaskCustomProps(taskProps);
if (optionalProcessId != null) {
taskQuery.setProcessId(optionalProcessId);
}
checkNoTasksFoundUsingQuery(taskQuery);
}
use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method getNextTaskForWorkflow.
protected WorkflowTask getNextTaskForWorkflow(String workflowInstanceId) {
WorkflowTaskQuery taskQuery = new WorkflowTaskQuery();
taskQuery.setProcessId(workflowInstanceId);
taskQuery.setTaskState(WorkflowTaskState.IN_PROGRESS);
List<WorkflowTask> workflowTasks = workflowService.queryTasks(taskQuery);
assertEquals(1, workflowTasks.size());
return workflowTasks.get(0);
}
use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method checkQueryTasksInactiveWorkflow.
protected void checkQueryTasksInactiveWorkflow(String workflowInstanceId) {
WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED);
taskQuery.setActive(false);
taskQuery.setProcessId(workflowInstanceId);
List<WorkflowTask> tasks = workflowService.queryTasks(taskQuery);
assertNotNull(tasks);
assertEquals(3, tasks.size());
taskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED);
taskQuery.setActive(true);
taskQuery.setProcessId(workflowInstanceId);
checkNoTasksFoundUsingQuery(taskQuery);
}
Aggregations