Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFPL-2111: Replace WA task with chasing email cron job for CMOs #5393

Merged
merged 30 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2b8710d
DFPL-2111: Replace WA task with chasing email cron job for CMOs
AlistairEdwinOsborne May 15, 2024
961f2fc
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne May 15, 2024
77bdd0b
add tests for email job
AlistairEdwinOsborne May 16, 2024
b63acc2
checkstyle
AlistairEdwinOsborne May 17, 2024
6a10c52
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne May 17, 2024
73f6e12
remove old job and tests
AlistairEdwinOsborne May 17, 2024
65ccb7e
checkstyle 2
AlistairEdwinOsborne May 17, 2024
e445293
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jun 10, 2024
0b3ad38
change to run in the middle of the day for testing
AlistairEdwinOsborne Jun 11, 2024
0c9b5cc
Merge remote-tracking branch 'origin/DFPL-2111' into DFPL-2111
AlistairEdwinOsborne Jun 11, 2024
9b1b213
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jun 14, 2024
c3f1470
remove permission from authorisationcaseevent
AlistairEdwinOsborne Jun 14, 2024
52a5e05
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jun 17, 2024
1153de1
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jun 17, 2024
8d820ad
Merge branch 'master' into DFPL-2111
Braimah101 Jun 18, 2024
54de662
set to run at 7:30 for testing
AlistairEdwinOsborne Jun 19, 2024
6c43419
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jun 20, 2024
f2c3fad
set to run at 11 for testing
AlistairEdwinOsborne Jun 20, 2024
057f3f3
Merge remote-tracking branch 'origin/DFPL-2111' into DFPL-2111
AlistairEdwinOsborne Jun 20, 2024
7885fd7
set to run at 12 for testing
AlistairEdwinOsborne Jun 20, 2024
eb99f44
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jun 24, 2024
3a257c9
Merge branch 'master' into DFPL-2111
DanCatchpole Jul 8, 2024
b37c1ea
remove async tag from event handler method
AlistairEdwinOsborne Jul 9, 2024
400c686
checkstyle
AlistairEdwinOsborne Jul 10, 2024
fde7cee
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jul 12, 2024
3c18bdf
set job to run at 2 AM GMT
AlistairEdwinOsborne Jul 12, 2024
4b2e216
Merge branch 'master' into DFPL-2111
DanCatchpole Jul 17, 2024
399992d
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jul 19, 2024
943629c
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jul 19, 2024
b001246
Merge branch 'master' into DFPL-2111
AlistairEdwinOsborne Jul 22, 2024
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
17 changes: 17 additions & 0 deletions ccd-definition/CaseEvent/CareSupervision/DEPRECATED.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,22 @@
"ShowSummary": "N",
"ShowEventNotes": "Y",
"EndButtonLabel": "Submit"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"ID": "sendOrderReminder",
AlistairEdwinOsborne marked this conversation as resolved.
Show resolved Hide resolved
"Name": "Send order reminder",
"Description": "Lets the CTSC send a reminder to the LA to upload an order.",
"DisplayOrder": 22,
"PreConditionState(s)": "PREPARE_FOR_HEARING;FINAL_HEARING;",
"PostConditionState": "*",
"SecurityClassification": "Public",
"CallBackURLAboutToStartEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/send-order-reminder/about-to-start",
"CallBackURLSubmittedEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/send-order-reminder/submitted",
"ShowSummary": "N",
"ShowEventNotes": "N",
"Publish": "Y",
"EndButtonLabel": "Send reminder"
}
]
17 changes: 0 additions & 17 deletions ccd-definition/CaseEvent/CareSupervision/MultiState.json
Original file line number Diff line number Diff line change
Expand Up @@ -1050,23 +1050,6 @@
"ShowEventNotes": "N",
"EndButtonLabel": "Done"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"ID": "sendOrderReminder",
"Name": "Send order reminder",
"Description": "Lets the CTSC send a reminder to the LA to upload an order.",
"DisplayOrder": 31,
"PreConditionState(s)": "PREPARE_FOR_HEARING;FINAL_HEARING;",
"PostConditionState": "*",
"SecurityClassification": "Public",
"CallBackURLAboutToStartEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/send-order-reminder/about-to-start",
"CallBackURLSubmittedEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/send-order-reminder/submitted",
"ShowSummary": "N",
"ShowEventNotes": "N",
"Publish": "Y",
"EndButtonLabel": "Send reminder"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.fpl.events.cmo.SendOrderReminderEvent;
import uk.gov.hmcts.reform.fpl.model.CaseData;
import uk.gov.hmcts.reform.fpl.model.HearingBooking;
import uk.gov.hmcts.reform.fpl.model.common.Element;
import uk.gov.hmcts.reform.fpl.service.CaseConverter;
import uk.gov.hmcts.reform.fpl.service.cmo.SendOrderReminderService;
import uk.gov.hmcts.reform.fpl.service.search.SearchService;
import uk.gov.hmcts.reform.fpl.service.workallocation.WorkAllocationTaskService;
import uk.gov.hmcts.reform.fpl.utils.elasticsearch.BooleanQuery;
import uk.gov.hmcts.reform.fpl.utils.elasticsearch.ESClause;
import uk.gov.hmcts.reform.fpl.utils.elasticsearch.ESQuery;
Expand All @@ -35,7 +36,6 @@
import static uk.gov.hmcts.reform.fpl.enums.State.OPEN;
import static uk.gov.hmcts.reform.fpl.enums.State.RETURNED;
import static uk.gov.hmcts.reform.fpl.enums.State.SUBMITTED;
import static uk.gov.hmcts.reform.fpl.enums.WorkAllocationTaskType.ORDER_NOT_UPLOADED;
import static uk.gov.hmcts.reform.fpl.service.search.SearchService.ES_DEFAULT_SIZE;
import static uk.gov.hmcts.reform.fpl.utils.JobHelper.buildStats;
import static uk.gov.hmcts.reform.fpl.utils.JobHelper.paginate;
Expand All @@ -44,11 +44,11 @@
@Component
@ConditionalOnProperty(value = "scheduler.enabled", havingValue = "true")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CreateWAOrderChasingTasks implements Job {
public class OrderChasingEmailJob implements Job {

private final CaseConverter converter;
private final SearchService searchService;
private final WorkAllocationTaskService workAllocationTaskService;
private final ApplicationEventPublisher applicationEventPublisher;
private final SendOrderReminderService sendOrderReminderService;

@Override
Expand Down Expand Up @@ -86,16 +86,16 @@ public void execute(JobExecutionContext jobExecutionContext) {
final Long caseId = caseDetails.getId();
try {
CaseData caseData = converter.convert(caseDetails);
if (shouldCreateChaseTask(caseData)) {
log.debug("Job '{}' creating chase task {}", jobName, caseId);
workAllocationTaskService.createWorkAllocationTask(caseData, ORDER_NOT_UPLOADED);
if (shouldSendChasingEmail(caseData)) {
log.debug("Job '{}' sending chase email for case {}", jobName, caseId);
applicationEventPublisher.publishEvent(new SendOrderReminderEvent(caseData));
chased++;
} else {
log.debug("Job '{}' skipped case {}", jobName, caseId);
skipped++;
}
} catch (Exception e) {
log.error("Job '{}' could not create WA task on {} due to {}", jobName, caseId, e.getMessage(),
log.error("Job '{}' could not send Email on {} due to {}", jobName, caseId, e.getMessage(),
e);
failed++;
Thread.sleep(2000); // If CCD is overwhelmed, stop for 2s before continuing
Expand Down Expand Up @@ -123,7 +123,7 @@ private boolean isInRange(Element<HearingBooking> booking) {
return beforeRange && afterRange;
}

private boolean shouldCreateChaseTask(CaseData caseData) {
private boolean shouldSendChasingEmail(CaseData caseData) {
// Check if the hearings within 5(-6) days have an uploaded CMO
if (isEmpty(caseData.getHearingDetails())) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ scheduler:
description: 'Find undelivered emails'
jobClass: 'uk.gov.hmcts.reform.fpl.jobs.UndeliveredEmailsFinder'
cron: ${UPDATE_SUMMARY_TAB_CRON:0 0 8 ? * * *}
- name: 'Create chasing work allocation tasks'
- name: 'Send chasing CMO email'
enabled: true
cronGroup: "NIGHTLY_CRON"
description: 'Create work allocation tasks if a CMO has not been uploaded within 5 days'
jobClass: 'uk.gov.hmcts.reform.fpl.jobs.CreateWAOrderChasingTasks'
cron: ${CHASE_CMO_TASK_CRON:0 0 2 ? * * *}
description: 'Send chasing email if a CMO has not been uploaded within 5 days'
jobClass: 'uk.gov.hmcts.reform.fpl.jobs.OrderChasingEmailJob'
cron: ${CHASE_CMO_EMAIL_CRON:0 0 12 ? * * *}

testing:
support:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
import org.quartz.JobKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.fpl.events.cmo.SendOrderReminderEvent;
import uk.gov.hmcts.reform.fpl.model.CaseData;
import uk.gov.hmcts.reform.fpl.model.HearingBooking;
import uk.gov.hmcts.reform.fpl.service.CaseConverter;
import uk.gov.hmcts.reform.fpl.service.ccd.CoreCaseDataService;
import uk.gov.hmcts.reform.fpl.service.cmo.SendOrderReminderService;
import uk.gov.hmcts.reform.fpl.service.email.NotificationService;
import uk.gov.hmcts.reform.fpl.service.search.SearchService;
import uk.gov.hmcts.reform.fpl.service.workallocation.WorkAllocationTaskService;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -37,41 +38,40 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.fpl.enums.WorkAllocationTaskType.ORDER_NOT_UPLOADED;
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element;
import static uk.gov.hmcts.reform.fpl.utils.TestDataHelper.feignException;

@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {JacksonAutoConfiguration.class})
class CreateWAOrderChasingTasksTest {
class OrderChasingEmailJobTest {

private static final Long CASE_ID = 12345L;
private static final int SEARCH_SIZE = 50;

@Mock
private SearchService searchService;
@Mock
private WorkAllocationTaskService waTaskService;
@Mock
private SendOrderReminderService sendOrderReminderService;
@Mock
private CoreCaseDataService ccdService;
private NotificationService notificationService;
@Mock
private JobExecutionContext executionContext;
@Mock
private ApplicationEventPublisher applicationEventPublisher;

// autowire required due to the model classes not having been set up properly with jackson in the past,
// springs construction of the object mapper works but a default construction of it doesn't :(
@Autowired
private ObjectMapper mapper;

private CreateWAOrderChasingTasks underTest;
private OrderChasingEmailJob underTest;

@BeforeEach
void initMocks() {
CaseConverter converter = new CaseConverter(mapper);
underTest = new CreateWAOrderChasingTasks(converter,
underTest = new OrderChasingEmailJob(converter,
searchService,
waTaskService,
applicationEventPublisher,
sendOrderReminderService);

JobDetail jobDetail = mock(JobDetail.class);
Expand All @@ -90,11 +90,11 @@ void shouldNotCallCCDWhenNothingToUpdate() {

underTest.execute(executionContext);

verifyNoInteractions(waTaskService);
verifyNoInteractions(notificationService);
}

@Test
void shouldCreateWADummyEventIfHearingWas5DaysAgo() {
void shouldSendEmailEventIfHearingWas5DaysAgo() {
CaseData caseData = CaseData.builder()
.hearingDetails(List.of(
element(HearingBooking.builder()
Expand All @@ -108,13 +108,11 @@ void shouldCreateWADummyEventIfHearingWas5DaysAgo() {
.data(mapper.convertValue(caseData, new TypeReference<>() {}))
.build());

caseData = caseData.toBuilder().id(CASE_ID).build();

when(searchService.search(any(), eq(SEARCH_SIZE), eq(0))).thenReturn(caseDetails);

underTest.execute(executionContext);

verify(waTaskService).createWorkAllocationTask(caseData, ORDER_NOT_UPLOADED);
verify(applicationEventPublisher).publishEvent(new SendOrderReminderEvent(any()));
}

@Test
Expand Down Expand Up @@ -143,12 +141,13 @@ void shouldGracefullyHandleErrorsFromCCDWhenUpdatingCaseDetails() {
List<CaseDetails> allCaseDetails = List.of(caseDetails, caseDetails2);

when(searchService.search(any(), eq(SEARCH_SIZE), eq(0))).thenReturn(allCaseDetails);

doThrow(feignException(500))
.when(waTaskService).createWorkAllocationTask(caseData, ORDER_NOT_UPLOADED);
.when(applicationEventPublisher).publishEvent(new SendOrderReminderEvent(any()));

underTest.execute(executionContext);

verify(waTaskService).createWorkAllocationTask(caseData, ORDER_NOT_UPLOADED);
verify(applicationEventPublisher, times(2)).publishEvent(new SendOrderReminderEvent(any()));
}

@Test
Expand Down Expand Up @@ -181,8 +180,7 @@ void shouldPaginateWhenNumberOfCasesAreMoreThanTheSearchSize() {

underTest.execute(executionContext);

verify(waTaskService, times(75))
.createWorkAllocationTask(any(), eq(ORDER_NOT_UPLOADED));
verify(applicationEventPublisher, times(75)).publishEvent(new SendOrderReminderEvent(any()));
}

@Test
Expand Down
Loading