diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListener.java b/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListener.java index 3bcc055999..7d582c5a82 100644 --- a/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListener.java +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListener.java @@ -13,6 +13,8 @@ import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import java.util.Optional; + import static io.holunda.camunda.bpm.data.CamundaBpmData.writer; import static io.muenchendigital.digiwf.task.TaskVariables.TASK_ASSIGNEE; @@ -31,7 +33,7 @@ public class AssignmentAssignTaskListener { public AssignTaskCommand taskAssigned(final DelegateTask task) { if (properties.isShadow()) { - val assignee = task.getAssignee(); + val assignee = Optional.ofNullable(task.getAssignee()).filter(s -> !s.isEmpty()).orElse(null); val writer = writer(task); if (properties.isLocal()) { log.debug("Shadowing assignment information for task {} in local variable: {}", task.getId(), assignee); diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListener.java b/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListener.java index b5f1510a5b..6a4288ee15 100644 --- a/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListener.java +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/main/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListener.java @@ -15,11 +15,14 @@ import javax.annotation.PostConstruct; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import static io.holunda.camunda.bpm.data.CamundaBpmData.reader; import static io.holunda.camunda.bpm.data.CamundaBpmData.writer; -import static io.muenchendigital.digiwf.task.TaskVariables.*; +import static io.muenchendigital.digiwf.task.TaskVariables.TASK_ASSIGNEE; +import static io.muenchendigital.digiwf.task.TaskVariables.TASK_CANDIDATE_GROUPS; +import static io.muenchendigital.digiwf.task.TaskVariables.TASK_CANDIDATE_USERS; /** * Task listener responsible for shadowing assignment information from task into process variables and deleting it from task attributes. @@ -40,7 +43,7 @@ public void report() { public void taskCreated(final DelegateTask task) { val reader = reader(task); if (properties.isShadow()) { - val assignee = task.getAssignee(); + val assignee = Optional.ofNullable(task.getAssignee()).filter(s -> !s.isEmpty()).orElse(null); val candidateUsers = task.getCandidates().stream().filter(link -> link.getUserId() != null && link.getType().equals(IdentityLinkType.CANDIDATE)).map(IdentityLink::getUserId).collect(Collectors.toList()); val candidateGroups = task.getCandidates().stream().map(IdentityLink::getGroupId).filter(Objects::nonNull).collect(Collectors.toList()); val lowerCaseCandidateGroups = toLowerCase(candidateGroups); diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListenerTest.java b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListenerTest.java index 82a25c82a0..1ec90e9f91 100644 --- a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListenerTest.java +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentAssignTaskListenerTest.java @@ -85,4 +85,18 @@ public void shadows_assignee_local_and_deletes_from_task() { assertThat(event.getAssignee()).isEqualTo("assignee"); } + @Test + public void sets_empty_assigne_to_null_with_empty_assignee() { + when(properties.isShadow()).thenReturn(true); + when(properties.isLocal()).thenReturn(true); + delegateTask.setAssignee(""); + + assignmentAssignTaskListener.taskAssigned(delegateTask); + + assertThat(delegateTask.getVariablesLocal()).containsEntry(TASK_ASSIGNEE.getName(), null); + + assertThat(delegateTask.getAssignee()).isEqualTo(""); + + } + } \ No newline at end of file diff --git a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListenerTest.java b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListenerTest.java index 0e7c0c8ef6..0048a7b2fc 100644 --- a/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListenerTest.java +++ b/digiwf-task/digiwf-polyflow-connector-starter/src/test/java/io/muenchendigital/digiwf/task/listener/AssignmentCreateTaskListenerTest.java @@ -2,16 +2,15 @@ import io.muenchendigital.digiwf.task.TaskManagementProperties; import org.assertj.core.util.Lists; -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity; -import org.camunda.bpm.engine.impl.persistence.entity.TaskEntity; import org.camunda.community.mockito.delegate.DelegateTaskFake; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static io.muenchendigital.digiwf.task.TaskVariables.*; +import static io.muenchendigital.digiwf.task.TaskVariables.TASK_ASSIGNEE; +import static io.muenchendigital.digiwf.task.TaskVariables.TASK_CANDIDATE_GROUPS; +import static io.muenchendigital.digiwf.task.TaskVariables.TASK_CANDIDATE_USERS; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; class AssignmentCreateTaskListenerTest { @@ -89,4 +88,18 @@ public void shadows_assignee_local_and_deletes_from_task() { assertThat(DelegateTaskFake.candidateGroupIds(delegateTask)).isEmpty(); } + @Test + public void sets_empty_assigne_to_null_with_empty_assignee() { + when(properties.isShadow()).thenReturn(true); + when(properties.isLocal()).thenReturn(true); + delegateTask.setAssignee(""); + + assignmentCreateTaskListener.taskCreated(delegateTask); + + assertThat(delegateTask.getVariablesLocal()).containsEntry(TASK_ASSIGNEE.getName(), null); + + assertThat(delegateTask.getAssignee()).isEqualTo(""); + + } + }