From 36860eda4c8063401cfe1b71764d3d980c960e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6sle?= <37705369+lmoesle@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:58:55 +0200 Subject: [PATCH] bugfix: fallback to process definition key if process name is missing (#476) closes #475 --- .../src/main/resources/application.yml | 2 +- .../src/test/resources/tasklist.http | 4 +- .../application/service/TaskInfoService.java | 8 +++- .../service/TaskInfoServiceTest.java | 46 +++++++++++++++---- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/examples/single-deployment-unit-example/src/main/resources/application.yml b/examples/single-deployment-unit-example/src/main/resources/application.yml index 7a60a0d5..e04c5f5f 100644 --- a/examples/single-deployment-unit-example/src/main/resources/application.yml +++ b/examples/single-deployment-unit-example/src/main/resources/application.yml @@ -32,7 +32,7 @@ camunda: # https://docs.camunda.org/manual/7.21/user-guide/spring-boot-integrati metrics: enabled: false db-reporter-activate: false - auto-deployment-enabled: false + auto-deployment-enabled: true deployment-resource-pattern: "processes/*.bpmn" management: diff --git a/examples/single-deployment-unit-example/src/test/resources/tasklist.http b/examples/single-deployment-unit-example/src/test/resources/tasklist.http index 6bd8b944..db935d1c 100644 --- a/examples/single-deployment-unit-example/src/test/resources/tasklist.http +++ b/examples/single-deployment-unit-example/src/test/resources/tasklist.http @@ -1,10 +1,10 @@ ### Get Access Token -POST http://keycloak:9090/auth/realms/miranum/protocol/openid-connect/token +POST http://keycloak:9090/auth/realms/miragon/protocol/openid-connect/token Content-Type: application/x-www-form-urlencoded grant_type = password & client_secret = s3creT & -client_id = miranum & +client_id = inquiry & username = alex.admin@example.com & password = test diff --git a/platform/engine/task/src/main/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoService.java b/platform/engine/task/src/main/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoService.java index 1dac6f87..4875bd53 100644 --- a/platform/engine/task/src/main/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoService.java +++ b/platform/engine/task/src/main/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoService.java @@ -10,6 +10,7 @@ import io.miragon.miranum.platform.tasklist.domain.TaskCustomFields; import io.miragon.miranum.platform.tasklist.domain.TaskInfo; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.camunda.bpm.engine.delegate.DelegateTask; import org.springframework.stereotype.Component; @@ -17,6 +18,7 @@ import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; +@Slf4j @Component @RequiredArgsConstructor public class TaskInfoService implements TaskInfoUseCase { @@ -76,10 +78,14 @@ public void createTask(DelegateTask task) { .build()) .toList(); + if (miranumProcessDefinition.getName() == null) { + log.warn("The process {} has no name! Miranum Tasklist is falling back to the process definition key as the definition name", miranumProcessDefinition.getKey()); + } + final TaskInfo taskInfo = TaskInfo.builder() .id(task.getId()) .description(TASK_DESCRIPTION_VARIABLE.from(task).getOrDefault("")) - .definitionName(miranumProcessDefinition.getName()) + .definitionName(miranumProcessDefinition.getName() != null ? miranumProcessDefinition.getName() : miranumProcessDefinition.getKey()) .instanceId(task.getProcessInstanceId()) .assignee(task.getAssignee()) .authorities(authorities) diff --git a/platform/engine/task/src/test/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoServiceTest.java b/platform/engine/task/src/test/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoServiceTest.java index 7c29e655..d2280c26 100644 --- a/platform/engine/task/src/test/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoServiceTest.java +++ b/platform/engine/task/src/test/java/io/miragon/miranum/platform/tasklist/application/service/TaskInfoServiceTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import java.util.List; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -45,15 +46,42 @@ void testCreateTask() { // Assert final ArgumentCaptor taskInfoCaptor = ArgumentCaptor.forClass(TaskInfo.class); verify(taskOutPort).createTask(taskInfoCaptor.capture()); - assertThat(taskInfoCaptor.getValue().getId()).isEqualTo("task123"); - assertThat(taskInfoCaptor.getValue().getDescription()).isBlank(); - assertThat(taskInfoCaptor.getValue().getDefinitionName()).isEqualTo("Process Name"); - assertThat(taskInfoCaptor.getValue().getInstanceId()).isEqualTo("instance123"); - assertThat(taskInfoCaptor.getValue().getAssignee()).isEqualTo("user123"); - assertThat(taskInfoCaptor.getValue().getCandidateUsers()).isEmpty(); - assertThat(taskInfoCaptor.getValue().getCandidateGroups()).isEmpty(); - assertThat(taskInfoCaptor.getValue().getFormKey()).isBlank(); - assertThat(taskInfoCaptor.getValue().getCustomFields()).isEmpty(); + assertThat(taskInfoCaptor.getValue()) + .hasFieldOrPropertyWithValue("id", "task123") + .hasFieldOrProperty("description") + .hasFieldOrPropertyWithValue("definitionName", "Process Name") + .hasFieldOrPropertyWithValue("instanceId", "instance123") + .hasFieldOrPropertyWithValue("assignee", "user123") + .hasFieldOrPropertyWithValue("candidateUsers", List.of()) + .hasFieldOrPropertyWithValue("candidateGroups", List.of()) + .hasFieldOrProperty("formKey") + .hasFieldOrPropertyWithValue("customFields", List.of()); + } + + @Test + void testCreateTaskForProcessesWithoutAProcessName() { + // Arrange + final DelegateTask mockTask = mock(DelegateTask.class); + when(mockTask.getId()).thenReturn("task123"); + when(mockTask.getProcessDefinitionId()).thenReturn("processDef123"); + when(mockTask.getProcessInstanceId()).thenReturn("instance123"); + when(mockTask.getAssignee()).thenReturn("user123"); + when(mockTask.getCandidates()).thenReturn(Set.of()); + + MiranumProcessDefinition mockDefinition = MiranumProcessDefinition.builder() + .key("processDef123") + .name(null) + .build(); + when(miranumProcessDefinitionPort.getProcessDefinitionById("processDef123")).thenReturn(mockDefinition); + + // Act + taskInfoService.createTask(mockTask); + + // Assert + final ArgumentCaptor taskInfoCaptor = ArgumentCaptor.forClass(TaskInfo.class); + verify(taskOutPort).createTask(taskInfoCaptor.capture()); + assertThat(taskInfoCaptor.getValue()) + .hasFieldOrPropertyWithValue("definitionName", mockDefinition.getKey()); } @Test