diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/importer/TaskImporterService.java b/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/importer/TaskImporterService.java index a9692da6c5..6f9f872d12 100644 --- a/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/importer/TaskImporterService.java +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/importer/TaskImporterService.java @@ -12,13 +12,15 @@ import org.camunda.bpm.engine.impl.persistence.entity.TaskEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.PostConstruct; import javax.annotation.security.RolesAllowed; -import static io.holunda.camunda.bpm.data.CamundaBpmData.reader; -import static io.muenchendigital.digiwf.task.TaskVariables.TASK_SCHEMA_TYPE; +import java.util.HashSet; +import java.util.stream.Collectors; + import static org.springframework.http.ResponseEntity.noContent; @RequiredArgsConstructor @@ -44,16 +46,31 @@ void inform() { @RolesAllowed(CLIENT_IMPORT_TASKS) public ResponseEntity enrichExistingTasks() { - val tasks = taskService.createTaskQuery().active().withCandidateUsers().withCandidateGroups().list(); + log.info("Selecting candidates for task enrichment from " + taskService.createTaskQuery().active().count() + " tasks."); + val tasks = new HashSet(); + tasks.addAll(taskService.createTaskQuery() + .active() + .withCandidateUsers() + .list().stream().map(task -> ((TaskEntity)task)).collect(Collectors.toList())); + tasks.addAll(taskService.createTaskQuery() + .active() + .withCandidateGroups() + .list().stream().map(task -> ((TaskEntity)task)).collect(Collectors.toList())); + tasks.addAll(taskService.createTaskQuery() + .active() + .taskAssigned() + .list().stream().map(task -> ((TaskEntity)task)).collect(Collectors.toList())); + + log.info("Selected for enrichment " + tasks.size() + " tasks"); tasks.forEach((task) -> { - val taskEntity = ((TaskEntity)task); - assignmentCreateTaskListener.taskCreated(taskEntity); - cancelableTaskStatusCreateTaskListener.taskCreated(taskEntity); - taskSchemaTypeCreateTaskListener.taskCreated(taskEntity); - taskDescriptionCreateTaskListener.taskCreated(taskEntity); + assignmentCreateTaskListener.taskCreated(task); + cancelableTaskStatusCreateTaskListener.taskCreated(task); + taskSchemaTypeCreateTaskListener.taskCreated(task); + taskDescriptionCreateTaskListener.taskCreated(task); }); + log.info("Enrichment of " + tasks.size() + " tasks finished"); return noContent().build(); } diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/importer/TaskImporterServiceTest.java b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/importer/TaskImporterServiceTest.java new file mode 100644 index 0000000000..d85c13beb4 --- /dev/null +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/importer/TaskImporterServiceTest.java @@ -0,0 +1,83 @@ +package io.muenchendigital.digiwf.task.importer; + +import io.holunda.polyflow.taskpool.collector.task.TaskServiceCollectorService; +import io.muenchendigital.digiwf.task.listener.AssignmentCreateTaskListener; +import io.muenchendigital.digiwf.task.listener.CancelableTaskStatusCreateTaskListener; +import io.muenchendigital.digiwf.task.listener.TaskDescriptionCreateTaskListener; +import io.muenchendigital.digiwf.task.listener.TaskSchemaTypeCreateTaskListener; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.camunda.bpm.engine.ProcessEngineConfiguration; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.TaskService; +import org.camunda.bpm.engine.delegate.DelegateTask; +import org.camunda.bpm.engine.impl.telemetry.TelemetryRegistry; +import org.camunda.bpm.engine.test.Deployment; +import org.camunda.bpm.engine.test.junit5.ProcessEngineExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mockito.ArgumentCaptor; + +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.assertThat; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; + +@Disabled("This test is disabled from CI, since it uses the same in-mem H2 DB as CancelableTaskStatusCreateTaskListenerTest and interfers with it") +// FIXME - make sure we can run multiple tests with the engine -> maybe a dedicted ITEst-module for this is required. +class TaskImporterServiceTest { + + @RegisterExtension + public static ProcessEngineExtension extension = ProcessEngineExtension + .builder() + .useProcessEngine( + ProcessEngineConfiguration + .createStandaloneInMemProcessEngineConfiguration() + .setHistory("none") + .setJdbcUrl("jdbc:h2:mem:camunda-importer;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;") + .setSkipHistoryOptimisticLockingExceptions(true) + .setTelemetryRegistry(mock(TelemetryRegistry.class)) + .buildProcessEngine() + ) + .build(); + + private final RuntimeService runtimeService = extension.getRuntimeService(); + private final TaskService taskService = extension.getTaskService(); + + private final AssignmentCreateTaskListener listenerMock = mock(AssignmentCreateTaskListener.class); + + + private final TaskImporterService service = new TaskImporterService( + mock(TaskServiceCollectorService.class), + taskService, + listenerMock, + mock(CancelableTaskStatusCreateTaskListener.class), + mock(TaskSchemaTypeCreateTaskListener.class), + mock(TaskDescriptionCreateTaskListener.class) + ); + + private final ArgumentCaptor taskParamCaptor = ArgumentCaptor.forClass(DelegateTask.class); + + @BeforeEach + void init_bridge() { + doNothing().when(listenerMock).taskCreated(taskParamCaptor.capture()); + } + + @Test + @Deployment(resources = "process_importer_service.bpmn") + public void queries_tasks() { + + val instance = runtimeService.startProcessInstanceByKey("assignment_test_process"); + assertThat(instance).isStarted(); + + Assertions.assertThat(taskService.createTaskQuery().processDefinitionKey("assignment_test_process").count()).isEqualTo(5); + + service.enrichExistingTasks(); + + val invokedOnTasks = taskParamCaptor.getAllValues(); + Assertions.assertThat(invokedOnTasks.stream().map(DelegateTask::getTaskDefinitionKey)).containsExactlyInAnyOrder("user_assigned", "user_candidate_users", "user_candidate_groups", "user_assigned_and_candidate_group"); + Assertions.assertThat(invokedOnTasks.stream().map(DelegateTask::getTaskDefinitionKey)).doesNotContain("user_empty"); + } + +} \ No newline at end of file diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/CancelableTaskStatusCreateTaskListenerTest.java b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/CancelableTaskStatusCreateTaskListenerTest.java index 505fec7117..88b7020ace 100644 --- a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/CancelableTaskStatusCreateTaskListenerTest.java +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/CancelableTaskStatusCreateTaskListenerTest.java @@ -8,6 +8,7 @@ import org.camunda.bpm.engine.TaskService; import org.camunda.bpm.engine.delegate.DelegateTask; import org.camunda.bpm.engine.delegate.TaskListener; +import org.camunda.bpm.engine.impl.telemetry.TelemetryRegistry; import org.camunda.bpm.engine.test.Deployment; import org.camunda.bpm.engine.test.junit5.ProcessEngineExtension; import org.camunda.bpm.engine.test.mock.Mocks; @@ -19,6 +20,7 @@ import static io.muenchendigital.digiwf.task.TaskVariables.TASK_CANCELABLE; import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.assertThat; import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.task; +import static org.mockito.Mockito.mock; class CancelableTaskStatusCreateTaskListenerTest { @@ -28,15 +30,17 @@ class CancelableTaskStatusCreateTaskListenerTest { .useProcessEngine( ProcessEngineConfiguration .createStandaloneInMemProcessEngineConfiguration() - .setJdbcUrl("jdbc:h2:mem:camunda;DB_CLOSE_DELAY=1000") + .setHistory("none") + .setJdbcUrl("jdbc:h2:mem:camunda;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;") + .setSkipHistoryOptimisticLockingExceptions(true) + .setTelemetryRegistry(mock(TelemetryRegistry.class)) .buildProcessEngine() ) + .ensureCleanAfterTest(true) .build(); - private final RuntimeService runtimeService = extension.getRuntimeService(); private final TaskService taskService = extension.getTaskService(); - @BeforeEach void init_bridge() { Mocks.register("bridgeTestListener", new BridgeTestListener(new CancelableTaskStatusCreateTaskListener())); diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/test/resources/process_importer_service.bpmn b/digiwf-task/digiwf-polyflow-connector-starter/src/test/resources/process_importer_service.bpmn new file mode 100644 index 0000000000..d72e30d7e2 --- /dev/null +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/test/resources/process_importer_service.bpmn @@ -0,0 +1,146 @@ + + + + + Flow_08bu753 + + + + Flow_08bu753 + Flow_0upa54l + Flow_0drqiws + Flow_1kme650 + Flow_1onciql + Flow_1rhun6h + + + + + + + + + Flow_1yh2mao + + + + Flow_03ge0v5 + Flow_14zarld + Flow_1qcgzhy + Flow_04h13on + Flow_0bu7oeo + Flow_1yh2mao + + + + + Flow_1onciql + Flow_04h13on + + + Flow_1kme650 + Flow_1qcgzhy + + + Flow_0drqiws + Flow_14zarld + + + Flow_0upa54l + Flow_03ge0v5 + + + + + Flow_1rhun6h + Flow_0bu7oeo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +