Search in sources :

Example 11 with WorkflowTaskQuery

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));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) List(java.util.List) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery) Test(org.junit.Test)

Example 12 with WorkflowTaskQuery

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);
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 13 with WorkflowTaskQuery

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);
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 14 with WorkflowTaskQuery

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);
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 15 with WorkflowTaskQuery

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);
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Aggregations

WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)34 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)20 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)14 Serializable (java.io.Serializable)9 ArrayList (java.util.ArrayList)6 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)5 Test (org.junit.Test)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)4 Map (java.util.Map)3 Task (org.activiti.engine.task.Task)3 Date (java.util.Date)2 List (java.util.List)2 FacesContext (javax.faces.context.FacesContext)2 UserTransaction (javax.transaction.UserTransaction)2 TaskQuery (org.activiti.engine.task.TaskQuery)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTaskState (org.alfresco.service.cmr.workflow.WorkflowTaskState)2 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)2