Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ List<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn
List<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn(
String reference, String role, Collection<Integer> currentStatus, Collection<Long> templates);

List<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameIn(
String reference, String role, Collection<Integer> currentStatus, Collection<String> templateNames);

List<TaskListEntity> findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameNot(
String reference, String role, Collection<Integer> currentStatus, String excludedTemplate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class TaskListService {
private final EntityManager entityManager;
private static final String DOCUMENT_TEMPLATE_NAME = "Hearing.Document.View";
private static final List<String> ROLES = List.of("CLAIMANT", "DEFENDANT");
private static final List<Integer> NON_PROGRESSABLE_STATUSES = List.of(
TaskStatus.AVAILABLE.getPlaceValue(),
TaskStatus.DONE.getPlaceValue(),
TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()
);

@Autowired
public TaskListService(TaskListRepository taskListRepository,
Expand Down Expand Up @@ -183,40 +188,19 @@ private void makeProgressAbleTasksInactiveForCaseIdentifierAndRole(String caseId
if (Objects.nonNull(categories)) {
List<Long> catIds = categories.stream().map(TaskItemTemplateEntity::getId).toList();
tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn(
caseIdentifier, role, List.of(
TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(),
TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()
), catIds
caseIdentifier, role, NON_PROGRESSABLE_STATUSES, catIds
);
}
} else if (Objects.nonNull(excludedTemplate)) {
tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameNot(
caseIdentifier, role, List.of(
TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(),
TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()
), excludedTemplate
caseIdentifier, role, NON_PROGRESSABLE_STATUSES, excludedTemplate
);
} else {
tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn(
caseIdentifier, role, List.of(
TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(),
TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()
)
caseIdentifier, role, NON_PROGRESSABLE_STATUSES
);
}
tasks.forEach(t -> {
TaskListEntity task = copyTaskList(t);
task.setCurrentStatus(TaskStatus.INACTIVE.getPlaceValue());
task.setNextStatus(TaskStatus.INACTIVE.getPlaceValue());
task.setHintTextCy("");
task.setHintTextEn("");
task.setUpdatedAt(OffsetDateTime.now());
task.setTaskNameEn(StringUtility.removeAnchor(t.getTaskNameEn()));
task.setTaskNameCy(StringUtility.removeAnchor(t.getTaskNameCy()));
log.info("{} task made inactive for claim = {}", task.getTaskNameEn(), caseIdentifier);
taskListRepository.save(task);
});
log.info("Total {} tasks made inactive for claim = {}", tasks.size(), caseIdentifier);
markTasksInactive(caseIdentifier, tasks);
}

@Transactional
Expand Down Expand Up @@ -247,6 +231,32 @@ public void makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingTempla
makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, null, excludedTemplate);
}

@Transactional
public void makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole(String caseIdentifier,
String role,
List<String> templateNames) {
log.info(
"makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole caseIdentifier:{} role:{} templateNames:{}",
caseIdentifier,
role,
templateNames
);

if (templateNames == null || templateNames.isEmpty()) {
log.info("No template names supplied for selective inactivation for claim = {}", caseIdentifier);
return;
}

List<TaskListEntity> tasks =
taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameIn(
caseIdentifier,
role,
NON_PROGRESSABLE_STATUSES,
templateNames
);
markTasksInactive(caseIdentifier, tasks);
}

@Transactional
public void makeViewDocumentTaskAvailable(String caseIdentifier) {
ROLES.forEach(role -> makeViewDocumentTaskAvailable(caseIdentifier, role));
Expand Down Expand Up @@ -288,4 +298,20 @@ private TaskListEntity copyTaskList(TaskListEntity task) {
task.getMessageParams()
);
}

private void markTasksInactive(String caseIdentifier, List<TaskListEntity> tasks) {
tasks.forEach(t -> {
TaskListEntity task = copyTaskList(t);
task.setCurrentStatus(TaskStatus.INACTIVE.getPlaceValue());
task.setNextStatus(TaskStatus.INACTIVE.getPlaceValue());
task.setHintTextCy("");
task.setHintTextEn("");
task.setUpdatedAt(OffsetDateTime.now());
task.setTaskNameEn(StringUtility.removeAnchor(t.getTaskNameEn()));
task.setTaskNameCy(StringUtility.removeAnchor(t.getTaskNameCy()));
log.info("{} task made inactive for claim = {}", task.getTaskNameEn(), caseIdentifier);
taskListRepository.save(task);
});
log.info("Total {} tasks made inactive for claim = {}", tasks.size(), caseIdentifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,79 @@ void shouldMakeProgressAbleTaskListInactiveExcludingTemplate_whenTaskListIsPrese
));
}

@Test
void shouldMakeOnlySelectedProgressAbleTaskListInactive_whenTaskListIsPresent() {

List<TaskListEntity> tasks = getTaskListEntitiesWithAnchorNames();
List<String> templateNames = List.of("TemplateA", "TemplateB");

when(taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameIn(
"123",
"Claimant",
List.of(
TaskStatus.AVAILABLE.getPlaceValue(),
TaskStatus.DONE.getPlaceValue(),
TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()
),
templateNames
)).thenReturn(tasks);

taskListService.makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole("123", "Claimant", templateNames);

verify(taskListRepository).findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameIn(
"123",
"Claimant",
List.of(
TaskStatus.AVAILABLE.getPlaceValue(),
TaskStatus.DONE.getPlaceValue(),
TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()
),
templateNames
);

verify(taskListRepository, atLeast(4)).save(ArgumentMatchers.argThat(
a -> {
Assertions.assertEquals(TaskStatus.INACTIVE.getPlaceValue(), a.getCurrentStatus());
Assertions.assertEquals(TaskStatus.INACTIVE.getPlaceValue(), a.getNextStatus());
Assertions.assertTrue(StringUtils.isBlank(a.getHintTextCy()));
Assertions.assertTrue(StringUtils.isBlank(a.getHintTextEn()));
Assertions.assertEquals("Link name", a.getTaskNameEn());
Assertions.assertEquals("Link name Welsh", a.getTaskNameCy());
return true;
}
));
}

@Test
void shouldNotQueryRepositoryWhenNoSelectedTemplatesProvided() {

taskListService.makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole("123", "Claimant", List.of());

verify(taskListRepository, never())
.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameIn(
any(),
any(),
any(),
any()
);
verify(taskListRepository, never()).save(any());
}

@Test
void shouldNotQueryRepositoryWhenSelectedTemplatesAreNull() {

taskListService.makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole("123", "Claimant", null);

verify(taskListRepository, never())
.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameIn(
any(),
any(),
any(),
any()
);
verify(taskListRepository, never()).save(any());
}

@Test
void shouldMakeProgressAbleTaskListInactive_Except_Ga_whenTaskListIsPresent() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import uk.gov.hmcts.reform.dashboard.services.DashboardScenariosService;
import uk.gov.hmcts.reform.dashboard.services.TaskListService;

import java.util.Collections;
import java.util.List;

import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CP_TRIAL_ARRANGEMENTS_NOTIFY_OTHER_PARTY_CLAIMANT;
import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CP_TRIAL_ARRANGEMENTS_NOTIFY_OTHER_PARTY_LR_CLAIMANT;

Expand All @@ -16,6 +19,7 @@ public class TrialArrangementsNotifyOtherPartyClaimantDashboardService extends D

private final DashboardNotificationService dashboardNotificationService;
private final TaskListService taskListService;
private static final List<String> TRIAL_TEMPLATE_NAMES = Collections.singletonList("Hearing.Arrangements.Add");

public TrialArrangementsNotifyOtherPartyClaimantDashboardService(DashboardScenariosService dashboardScenariosService,
DashboardNotificationService dashboardNotificationService,
Expand Down Expand Up @@ -46,9 +50,10 @@ protected void beforeRecordScenario(CaseData caseData, String authToken) {
CLAIMANT_ROLE
);

taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRole(
taskListService.makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole(
caseId,
CLAIMANT_ROLE
CLAIMANT_ROLE,
TRIAL_TEMPLATE_NAMES
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import uk.gov.hmcts.reform.dashboard.services.DashboardScenariosService;
import uk.gov.hmcts.reform.dashboard.services.TaskListService;

import java.util.Collections;
import java.util.List;

import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CP_TRIAL_ARRANGEMENTS_NOTIFY_OTHER_PARTY_DEFENDANT;

@Service
public class TrialArrangementsNotifyOtherPartyDefendantDashboardService extends DashboardScenarioService {

private final DashboardNotificationService dashboardNotificationService;
private final TaskListService taskListService;
private static final List<String> TRIAL_TEMPLATE_NAMES = Collections.singletonList("Hearing.Arrangements.Add");

public TrialArrangementsNotifyOtherPartyDefendantDashboardService(DashboardScenariosService dashboardScenariosService,
DashboardNotificationService dashboardNotificationService,
Expand Down Expand Up @@ -47,9 +51,10 @@ protected void beforeRecordScenario(CaseData caseData, String authToken) {
DEFENDANT_ROLE
);

taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRole(
taskListService.makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole(
caseId,
DEFENDANT_ROLE
DEFENDANT_ROLE,
TRIAL_TEMPLATE_NAMES
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import uk.gov.hmcts.reform.dashboard.services.DashboardScenariosService;
import uk.gov.hmcts.reform.dashboard.services.TaskListService;

import java.util.Collections;
import java.util.HashMap;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -55,7 +56,7 @@ void shouldNotifyClaimantWhenTrialArrangementsNotifyOtherPartyAndUnrepresented()
service.notifyTrialArrangementsNotifyOtherParty(caseData, AUTH_TOKEN);

verify(dashboardNotificationService).deleteByReferenceAndCitizenRole("1234", "CLAIMANT");
verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRole("1234", "CLAIMANT");
verify(taskListService).makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole("1234", "CLAIMANT", Collections.singletonList("Hearing.Arrangements.Add"));
verify(dashboardScenariosService).recordScenarios(
AUTH_TOKEN,
SCENARIO_AAA6_CP_TRIAL_ARRANGEMENTS_NOTIFY_OTHER_PARTY_CLAIMANT.getScenario(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import uk.gov.hmcts.reform.dashboard.services.DashboardScenariosService;
import uk.gov.hmcts.reform.dashboard.services.TaskListService;

import java.util.Collections;
import java.util.HashMap;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -54,7 +55,7 @@ void shouldNotifyDefendantWhenTrialArrangementsNotifyOtherPartyAndUnrepresented(
service.notifyTrialArrangementsNotifyOtherParty(caseData, AUTH_TOKEN);

verify(dashboardNotificationService).deleteByReferenceAndCitizenRole("1234", "DEFENDANT");
verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRole("1234", "DEFENDANT");
verify(taskListService).makeSelectedProgressAbleTasksInactiveForCaseIdentifierAndRole("1234", "DEFENDANT", Collections.singletonList("Hearing.Arrangements.Add"));
verify(dashboardScenariosService).recordScenarios(
AUTH_TOKEN,
SCENARIO_AAA6_CP_TRIAL_ARRANGEMENTS_NOTIFY_OTHER_PARTY_DEFENDANT.getScenario(),
Expand Down
Loading