use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class ToTaskCancelledConverter method from.
@Override
public Optional<TaskCancelledEvent> from(ActivitiEntityEvent internalEvent) {
TaskCancelledEvent event = null;
if (isTaskCancelled(internalEvent)) {
TaskEntity taskEntity = (TaskEntity) internalEvent.getEntity();
Task task = taskConverter.from(taskEntity, Task.TaskStatus.CANCELLED);
String reason = internalEvent.getReason();
event = new TaskCancelledImpl(task, reason);
}
return Optional.ofNullable(event);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method parallelMultiInstance_should_collectOutputValues.
@Test
public void parallelMultiInstance_should_collectOutputValues() {
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTasksOutputCollection");
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).hasSize(2);
taskBaseRuntime.completeTask(tasks.get(0), singletonMap("meal", "pizza"));
taskBaseRuntime.completeTask(tasks.get(1), singletonMap("meal", "pasta"));
List<VariableInstance> variables = processBaseRuntime.getVariables(processInstance);
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("meals", asList("pizza", "pasta")));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnSubProcess_should_emmit_EqualStartAndEndEvent.
@Test
public void processWithParallelMultiInstancesOnSubProcess_should_emmit_EqualStartAndEndEvent() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelSubprocess");
// then
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 0", "Task in sub-process 1");
assertThat(localEventSource.getEvents(TaskCreatedEvent.class)).extracting(event -> event.getEntity().getName()).containsExactlyInAnyOrder("Task in sub-process 0", "Task in sub-process 1");
assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
// complete first iteration: multi instance should not finish yet
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, tasks.get(0).getName(), processInstance.getId()));
assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
assertThat(localEventSource.getProcessInstanceEvents()).isEmpty();
// complete second iteration: multi instance should finish
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(1));
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, tasks.get(1).getName(), processInstance.getId()));
assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOn_CallActivity_Boundary_Event.
@Test
public void processWithParallelMultiInstancesOn_CallActivity_Boundary_Event() {
ProcessInstance parentProcessInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelCallActivityBoundaryEvent");
final Page<ProcessInstance> childrenProcessInstances = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId());
assertThat(childrenProcessInstances.getContent()).hasSize(2);
assertThat(localEventSource.getEvents(ProcessStartedEvent.class)).extracting(RuntimeEvent::getEventType, event -> event.getEntity().getId(), event -> event.getEntity().getParentId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, parentProcessInstance.getId(), null), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcessInstances.getContent().get(0).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcessInstances.getContent().get(1).getId(), parentProcessInstance.getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcessInstances.getContent().get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcessInstances.getContent().get(1).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcessInstances.getContent().get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcessInstances.getContent().get(1).getId()));
assertThat(localEventSource.getEvents(ProcessCompletedEvent.class)).isEmpty();
// when
localEventSource.clearEvents();
processBaseRuntime.signal("goMiParallelCallActivityBoundaryEvent");
// then
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, "User Task", childrenProcessInstances.getContent().get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, "User Task", childrenProcessInstances.getContent().get(1).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "Escalation Task", parentProcessInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "Escalation Task", parentProcessInstance.getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED, childrenProcessInstances.getContent().get(0).getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED, childrenProcessInstances.getContent().get(1).getId()));
List<Task> tasks = taskBaseRuntime.getTasks(parentProcessInstance);
assertThat(tasks.size()).isEqualTo(1);
assertThat(tasks).extracting(Task::getName).contains("Escalation Task");
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertThat(taskBaseRuntime.getTasks(parentProcessInstance)).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, parentProcessInstance.getId()));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithSequentialMultiInstancesOnCallActivity_should_emmit_EqualStartAndEndEvent.
@Test
public void processWithSequentialMultiInstancesOnCallActivity_should_emmit_EqualStartAndEndEvent() {
ProcessInstance parentProcessInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialCallActivity");
List<ProcessInstance> childrenProcessInstances = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId()).getContent();
assertThat(childrenProcessInstances).hasSize(1);
ProcessInstance firstChildProcInst = childrenProcessInstances.get(0);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, firstChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, firstChildProcInst.getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", firstChildProcInst.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", firstChildProcInst.getId()));
List<Task> tasks = taskBaseRuntime.getTasks(firstChildProcInst);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("User Task");
// complete first iteration, multi-instance should not complete yet
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, // second iteration was created
BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
childrenProcessInstances = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId()).getContent();
assertThat(childrenProcessInstances).hasSize(1);
ProcessInstance secondChildProcInst = childrenProcessInstances.get(0);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "User Task", firstChildProcInst.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", secondChildProcInst.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", secondChildProcInst.getId()));
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, firstChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, secondChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, secondChildProcInst.getId()));
tasks = taskBaseRuntime.getTasks(secondChildProcInst);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("User Task");
// complete second iteration, multi-instance should not complete
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "User Task", secondChildProcInst.getId()));
assertThat(processBaseRuntime.getProcessInstances()).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, secondChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, parentProcessInstance.getId()));
}
Aggregations