Skip to content

Commit

Permalink
HOTFIX: Null Assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
darenegade committed Jun 27, 2023
1 parent 68e2ed2 commit aae6ab5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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("");

}

}

0 comments on commit aae6ab5

Please sign in to comment.