Skip to content

Commit

Permalink
bugfix: fallback to process definition key if process name is missing (
Browse files Browse the repository at this point in the history
…#476)

closes #475
  • Loading branch information
lmoesle authored Sep 18, 2024
1 parent 191543f commit 36860ed
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = [email protected] &
password = test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
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;

import java.util.List;

import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable;

@Slf4j
@Component
@RequiredArgsConstructor
public class TaskInfoService implements TaskInfoUseCase {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,15 +46,42 @@ void testCreateTask() {
// Assert
final ArgumentCaptor<TaskInfo> 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<TaskInfo> taskInfoCaptor = ArgumentCaptor.forClass(TaskInfo.class);
verify(taskOutPort).createTask(taskInfoCaptor.capture());
assertThat(taskInfoCaptor.getValue())
.hasFieldOrPropertyWithValue("definitionName", mockDefinition.getKey());
}

@Test
Expand Down

0 comments on commit 36860ed

Please sign in to comment.