diff --git a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListener.kt b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListener.kt index d1532560cb..3fd3d2f66a 100644 --- a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListener.kt +++ b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListener.kt @@ -34,7 +34,6 @@ import java.util.concurrent.CompletionException class AwsNotificationListener( private val handler: NotificationHandler<*>, private val objectMapper: ObjectMapper, - @Value("\${messaging.consumer.sensitive-event-types:[]}") private val sensitiveEventTypes: List, @Value("\${messaging.consumer.queue}") private val queueName: String ) { @SentryTransaction(operation = "messaging") diff --git a/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListenerTest.kt b/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListenerTest.kt index c64954cfe3..773873c55c 100644 --- a/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListenerTest.kt +++ b/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/listener/AwsNotificationListenerTest.kt @@ -30,7 +30,7 @@ class AwsNotificationListenerTest { @BeforeEach fun setUp() { - listener = AwsNotificationListener(handler, objectMapper, listOf("my-sensitive-event-type"), "my-queue") + listener = AwsNotificationListener(handler, objectMapper, "my-queue") } @Test diff --git a/projects/appointment-reminders-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/appointment-reminders-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index f7429130a0..d80816deef 100644 --- a/projects/appointment-reminders-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/appointment-reminders-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -1,5 +1,6 @@ package uk.gov.justice.digital.hmpps +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.eq @@ -39,21 +40,32 @@ internal class IntegrationTest { @MockBean lateinit var telemetryService: TelemetryService - @Test - fun `returns csv report`() { + @BeforeEach + fun setup() { whenever(upwAppointmentRepository.getUnpaidWorkAppointments(any(), eq("N56"))).thenReturn( listOf( object : UnpaidWorkAppointment { override val firstName = "Test" - override val mobileNumber = "07000000000" + override val mobileNumber = "07000000001" override val appointmentDate = "01/01/2000" - override val crn = "A123456" + override val crn = "A000001" override val eventNumbers = "1" override val upwAppointmentIds = "123, 456" + }, + object : UnpaidWorkAppointment { + override val firstName = "Test" + override val mobileNumber = "07000000002" + override val appointmentDate = "01/01/2000" + override val crn = "A000002" + override val eventNumbers = "1" + override val upwAppointmentIds = "789" } ) ) + } + @Test + fun `returns csv report`() { mockMvc .perform(get("/upw-appointments.csv?providerCode=N56").withToken()) .andExpect(status().is2xxSuccessful) @@ -62,7 +74,8 @@ internal class IntegrationTest { content().string( """ firstName,mobileNumber,appointmentDate,crn,eventNumbers,upwAppointmentIds - Test,07000000000,01/01/2000,A123456,1,"123, 456" + Test,07000000001,01/01/2000,A000001,1,"123, 456" + Test,07000000002,01/01/2000,A000002,1,789 """.trimIndent() ) @@ -71,30 +84,21 @@ internal class IntegrationTest { @Test fun `sends messages to govuk notify`() { - whenever(upwAppointmentRepository.getUnpaidWorkAppointments(any(), eq("N56"))).thenReturn( - listOf( - object : UnpaidWorkAppointment { - override val firstName = "Test" - override val mobileNumber = "07000000000" - override val appointmentDate = "01/01/2000" - override val crn = "A123456" - override val eventNumbers = "1" - override val upwAppointmentIds = "123, 456" - } - ) - ) - unpaidWorkAppointmentsService.sendUnpaidWorkAppointmentReminders("N56") verify(notificationClient).sendSms( "cd713c1b-1b27-45a0-b493-37a34666635a", - "07000000000", + "07000000001", mapOf("FirstName" to "Test", "NextWorkSession" to "01/01/2000"), - "A123456:01/01/2000:123, 456" + "A000001:01/01/2000:123, 456" + ) + verify(telemetryService).trackEvent( + "UnpaidWorkAppointmentReminderSent", + mapOf("crn" to "A000001", "upwAppointmentIds" to "123, 456") ) verify(telemetryService).trackEvent( - "SentUnpaidWorkAppointmentReminder", - mapOf("crn" to "A123456", "upwAppointmentIds" to "123, 456") + "UnpaidWorkAppointmentReminderNotSent", + mapOf("crn" to "A000002", "upwAppointmentIds" to "789") ) } } diff --git a/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/App.kt b/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/App.kt index c7faac5b26..0389a06e51 100644 --- a/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/App.kt +++ b/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/App.kt @@ -1,9 +1,12 @@ package uk.gov.justice.digital.hmpps import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.runApplication +import uk.gov.justice.digital.hmpps.properties.UpwAppointmentRemindersJobProperties @SpringBootApplication +@EnableConfigurationProperties(UpwAppointmentRemindersJobProperties::class) class App fun main(args: Array) { diff --git a/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/properties/UpwAppointmentRemindersJobProperties.kt b/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/properties/UpwAppointmentRemindersJobProperties.kt new file mode 100644 index 0000000000..5c2ef4c4df --- /dev/null +++ b/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/properties/UpwAppointmentRemindersJobProperties.kt @@ -0,0 +1,10 @@ +package uk.gov.justice.digital.hmpps.properties + +import org.springframework.boot.context.properties.ConfigurationProperties + +@ConfigurationProperties(prefix = "jobs.unpaid-work-appointment-reminders") +class UpwAppointmentRemindersJobProperties( + val enabled: Boolean = false, + val provider: String? = null, + val excludedCrns: List = emptyList(), +) \ No newline at end of file diff --git a/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UnpaidWorkAppointmentsService.kt b/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UnpaidWorkAppointmentsService.kt index cb94e513af..b2b41ca6c8 100644 --- a/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UnpaidWorkAppointmentsService.kt +++ b/projects/appointment-reminders-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UnpaidWorkAppointmentsService.kt @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service +import uk.gov.justice.digital.hmpps.properties.UpwAppointmentRemindersJobProperties import uk.gov.justice.digital.hmpps.repository.UpwAppointmentRepository import uk.gov.justice.digital.hmpps.telemetry.TelemetryService import uk.gov.service.notify.NotificationClient @@ -9,6 +10,7 @@ import java.time.LocalDate @Service class UnpaidWorkAppointmentsService( + private val properties: UpwAppointmentRemindersJobProperties, private val upwAppointmentRepository: UpwAppointmentRepository, private val notificationClient: NotificationClient, private val telemetryService: TelemetryService, @@ -17,14 +19,19 @@ class UnpaidWorkAppointmentsService( fun sendUnpaidWorkAppointmentReminders(providerCode: String) { upwAppointmentRepository.getUnpaidWorkAppointments(LocalDate.now().plusDays(2), providerCode) .forEach { - notificationClient.sendSms( - templateId, - it.mobileNumber, - mapOf("FirstName" to it.firstName, "NextWorkSession" to it.appointmentDate), - "${it.crn}:${it.appointmentDate}:${it.upwAppointmentIds}" - ) - telemetryService.trackEvent( - "SentUnpaidWorkAppointmentReminder", + if (it.crn !in properties.excludedCrns) { + notificationClient.sendSms( + templateId, + it.mobileNumber, + mapOf("FirstName" to it.firstName, "NextWorkSession" to it.appointmentDate), + "${it.crn}:${it.appointmentDate}:${it.upwAppointmentIds}" + ) + telemetryService.trackEvent( + "UnpaidWorkAppointmentReminderSent", + mapOf("crn" to it.crn, "upwAppointmentIds" to it.upwAppointmentIds) + ) + } else telemetryService.trackEvent( + "UnpaidWorkAppointmentReminderNotSent", mapOf("crn" to it.crn, "upwAppointmentIds" to it.upwAppointmentIds) ) } diff --git a/projects/appointment-reminders-and-delius/src/main/resources/application.yml b/projects/appointment-reminders-and-delius/src/main/resources/application.yml index dcccd3a6b6..c1c2ba767c 100644 --- a/projects/appointment-reminders-and-delius/src/main/resources/application.yml +++ b/projects/appointment-reminders-and-delius/src/main/resources/application.yml @@ -60,6 +60,8 @@ logging.level: spring.config.activate.on-profile: integration-test spring.datasource.url: jdbc:h2:mem:./test;MODE=Oracle;DEFAULT_NULL_ORDERING=HIGH +jobs.unpaid-work-appointment-reminders.excluded-crns: [ "A000002" ] + --- spring.config.activate.on-profile: oracle spring: