diff --git a/ccd-definition/AuthorisationCaseEvent/CareSupervision/AuthorisationCaseEvent.json b/ccd-definition/AuthorisationCaseEvent/CareSupervision/AuthorisationCaseEvent.json index 0f8c8f8deeb..77a036268fa 100644 --- a/ccd-definition/AuthorisationCaseEvent/CareSupervision/AuthorisationCaseEvent.json +++ b/ccd-definition/AuthorisationCaseEvent/CareSupervision/AuthorisationCaseEvent.json @@ -1691,18 +1691,5 @@ "CRUD": "CR" } ] - }, - { - "LiveFrom": "01/01/2017", - "CaseTypeID": "CARE_SUPERVISION_EPO", - "CaseEventID": "sendOrderReminder", - "AccessControl": [ - { - "UserRoles": [ - "caseworker-publiclaw-courtadmin" - ], - "CRUD": "CR" - } - ] } ] diff --git a/ccd-definition/CaseEvent/CareSupervision/DEPRECATED.json b/ccd-definition/CaseEvent/CareSupervision/DEPRECATED.json index 4221110dfc4..a666d5a897d 100644 --- a/ccd-definition/CaseEvent/CareSupervision/DEPRECATED.json +++ b/ccd-definition/CaseEvent/CareSupervision/DEPRECATED.json @@ -366,5 +366,22 @@ "ShowSummary": "N", "ShowEventNotes": "Y", "EndButtonLabel": "Submit" + }, + { + "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": 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" } ] diff --git a/ccd-definition/CaseEvent/CareSupervision/MultiState.json b/ccd-definition/CaseEvent/CareSupervision/MultiState.json index 22f15c3ce92..4c8aa446e21 100644 --- a/ccd-definition/CaseEvent/CareSupervision/MultiState.json +++ b/ccd-definition/CaseEvent/CareSupervision/MultiState.json @@ -1052,23 +1052,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", diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/SendOrderReminderEventHandler.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/SendOrderReminderEventHandler.java index fab6317f025..51b12c0ae8c 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/SendOrderReminderEventHandler.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/SendOrderReminderEventHandler.java @@ -3,7 +3,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.events.cmo.SendOrderReminderEvent; import uk.gov.hmcts.reform.fpl.model.notify.NotifyData; @@ -24,7 +23,6 @@ public class SendOrderReminderEventHandler { private final ChaseMissingCMOEmailContentProvider contentProvider; private final LocalAuthorityRecipientsService localAuthorityRecipients; - @Async @EventListener public void sendNotificationToApplicant(final SendOrderReminderEvent event) { NotifyData notifyData = contentProvider.buildTemplate(event.getCaseData()); diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/jobs/CreateWAOrderChasingTasks.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/jobs/OrderChasingEmailJob.java similarity index 89% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/jobs/CreateWAOrderChasingTasks.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/jobs/OrderChasingEmailJob.java index c18eaa8e293..95f550b8a78 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/jobs/CreateWAOrderChasingTasks.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/jobs/OrderChasingEmailJob.java @@ -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; @@ -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; @@ -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 @@ -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 @@ -123,7 +123,7 @@ private boolean isInRange(Element 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; diff --git a/service/src/main/resources/application.yaml b/service/src/main/resources/application.yaml index 33095c6df7e..5c04942af93 100644 --- a/service/src/main/resources/application.yaml +++ b/service/src/main/resources/application.yaml @@ -276,12 +276,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 2 ? * * *} testing: support: diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/jobs/CreateWAOrderChasingTasksTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/jobs/OrderChasingEmailJobTest.java similarity index 85% rename from service/src/test/java/uk/gov/hmcts/reform/fpl/jobs/CreateWAOrderChasingTasksTest.java rename to service/src/test/java/uk/gov/hmcts/reform/fpl/jobs/OrderChasingEmailJobTest.java index 0b8dc21a753..383456c935e 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/jobs/CreateWAOrderChasingTasksTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/jobs/OrderChasingEmailJobTest.java @@ -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; @@ -37,13 +38,12 @@ 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; @@ -51,27 +51,27 @@ class CreateWAOrderChasingTasksTest { @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); @@ -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() @@ -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 @@ -143,12 +141,13 @@ void shouldGracefullyHandleErrorsFromCCDWhenUpdatingCaseDetails() { List 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 @@ -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