Search in sources :

Example 46 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class ReplayUserTaskCompleteEventHandler method handle.

@Override
public void handle(SimulationEvent event) {
    String taskDefinitionKey = (String) event.getProperty(EventLogUserTaskCompleteTransformer.TASK_DEFINITION_KEY);
    String processInstanceId = (String) event.getProperty(EventLogUserTaskCompleteTransformer.PROCESS_INSTANCE_ID);
    String simulationRunId = SimulationRunContext.getSimulationRunId();
    ProcessInstance processInstance = SimulationRunContext.getRuntimeService().createProcessInstanceQuery().variableValueEquals(StartReplayLogEventHandler.PROCESS_INSTANCE_ID, processInstanceId).variableValueEquals(StartReplayLogEventHandler.SIMULATION_RUN_ID, simulationRunId).singleResult();
    Task task = SimulationRunContext.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey(taskDefinitionKey).singleResult();
    @SuppressWarnings("unchecked") Map<String, Object> variables = (Map<String, Object>) event.getProperty(EventLogUserTaskCompleteTransformer.TASK_VARIABLES);
    if (variables != null) {
        if (event.getProperty(EventLogUserTaskCompleteTransformer.VARIABLES_LOCAL_SCOPE) != null && ((Boolean) event.getProperty(EventLogUserTaskCompleteTransformer.VARIABLES_LOCAL_SCOPE)).booleanValue()) {
            SimulationRunContext.getTaskService().complete(task.getId(), variables, true);
        } else {
            SimulationRunContext.getTaskService().complete(task.getId(), variables);
        }
        log.debug("completed {}, {}, {}", task, task.getName(), variables);
    } else {
        SimulationRunContext.getTaskService().complete(task.getId());
        log.debug("completed {}, {}", task, task.getName());
    }
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Map(java.util.Map)

Example 47 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class CdiTaskServiceTest method testClaimTask.

@Test
public void testClaimTask() {
    Task newTask = taskService.newTask();
    taskService.saveTask(newTask);
    taskService.claim(newTask.getId(), "kermit");
    taskService.deleteTask(newTask.getId(), true);
}
Also used : Task(org.activiti.engine.task.Task) Test(org.junit.Test)

Example 48 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class UserTaskCompleteTransformer method apply.

@Override
public SimulationEvent apply(ActivitiEvent event) {
    if (ActivitiEventType.TASK_COMPLETED.equals(event.getType())) {
        Task task = (Task) ((ActivitiEntityEvent) event).getEntity();
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("taskId", task.getId());
        properties.put(TASK_DEFINITION_KEY, task.getTaskDefinitionKey());
        properties.put(PROCESS_INSTANCE_ID, task.getProcessInstanceId());
        properties.put(TASK_VARIABLES, task.getProcessVariables());
        return new SimulationEvent.Builder(this.simulationEventType).simulationTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime().getTime()).properties(properties).build();
    }
    return null;
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 49 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class BusinessProcessBeanTest method test.

/* General test asserting that the business process bean is functional */
@Test
@Deployment
public void test() throws Exception {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // start the process
    businessProcess.startProcessByKey("businessProcessBeanTest").getId();
    // ensure that the process is started:
    assertNotNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
    // ensure that there is a single task waiting
    Task task = processEngine.getTaskService().createTaskQuery().singleResult();
    assertNotNull(task);
    String value = "value";
    businessProcess.setVariable("key", value);
    assertEquals(value, businessProcess.getVariable("key"));
    // complete the task
    assertEquals(task.getId(), businessProcess.startTask(task.getId()).getId());
    businessProcess.completeTask();
    // assert the task is completed
    assertNull(processEngine.getTaskService().createTaskQuery().singleResult());
    // assert that the process is ended:
    assertNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
}
Also used : Task(org.activiti.engine.task.Task) BusinessProcess(org.activiti.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Example 50 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class MultiInstanceTaskCompleteEventTest method testReceiveAll.

@Test
@Deployment(resources = { "org/activiti/cdi/test/impl/event/MultiInstanceTaskCompleteEventTest.process1.bpmn20.xml.bpmn" })
public void testReceiveAll() {
    TestEventListener listenerBean = getBeanInstance(TestEventListener.class);
    listenerBean.reset();
    assertEquals(0, listenerBean.getCreateTask1());
    assertEquals(0, listenerBean.getAssignTask1());
    assertEquals(0, listenerBean.getCompleteTask1());
    // start the process
    runtimeService.startProcessInstanceByKey("process1");
    Task task = taskService.createTaskQuery().singleResult();
    taskService.claim(task.getId(), "auser");
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // assert
    assertEquals(2, listenerBean.getCreateTask1());
    assertEquals(1, listenerBean.getAssignTask1());
    assertEquals(2, listenerBean.getCompleteTask1());
}
Also used : Task(org.activiti.engine.task.Task) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Task (org.activiti.engine.task.Task)955 Deployment (org.activiti.engine.test.Deployment)548 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)502 HashMap (java.util.HashMap)197 Test (org.junit.Test)123 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)109 ArrayList (java.util.ArrayList)74 Date (java.util.Date)65 Execution (org.activiti.engine.runtime.Execution)59 DelegateTask (org.activiti.engine.delegate.DelegateTask)54 TaskQuery (org.activiti.engine.task.TaskQuery)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 Job (org.activiti.engine.runtime.Job)49 Calendar (java.util.Calendar)44 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)44 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)44 JsonNode (com.fasterxml.jackson.databind.JsonNode)41 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)41 JSONObject (org.json.simple.JSONObject)40 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)38