diff --git a/libs/dev-tools/src/main/kotlin/uk/gov/justice/digital/hmpps/TestHelper.kt b/libs/dev-tools/src/main/kotlin/uk/gov/justice/digital/hmpps/TestHelper.kt index 15f9156d32..3b36353a9e 100644 --- a/libs/dev-tools/src/main/kotlin/uk/gov/justice/digital/hmpps/TestHelper.kt +++ b/libs/dev-tools/src/main/kotlin/uk/gov/justice/digital/hmpps/TestHelper.kt @@ -30,7 +30,8 @@ fun prepNotification( "{wiremock.port}", port.toString() ) - ) + ), + attributes = notification.attributes ) fun ZonedDateTime.closeTo(dateTime: ZonedDateTime?, unit: ChronoUnit = ChronoUnit.SECONDS, number: Int = 1): Boolean { diff --git a/projects/prison-case-notes-to-probation/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CaseNoteMessageGenerator.kt b/projects/prison-case-notes-to-probation/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CaseNoteMessageGenerator.kt index 9b5983bcec..07f794fd28 100644 --- a/projects/prison-case-notes-to-probation/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CaseNoteMessageGenerator.kt +++ b/projects/prison-case-notes-to-probation/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CaseNoteMessageGenerator.kt @@ -1,12 +1,17 @@ package uk.gov.justice.digital.hmpps.data.generator import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent +import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader object CaseNoteMessageGenerator { - val EXISTS_IN_DELIUS: HmppsDomainEvent = ResourceLoader.message("case-note-exists-in-delius") - val NEW_TO_DELIUS: HmppsDomainEvent = ResourceLoader.message("case-note-new-to-delius") - val NOT_FOUND: HmppsDomainEvent = ResourceLoader.message("case-note-not-found") - val RESETTLEMENT_PASSPORT: HmppsDomainEvent = ResourceLoader.message("resettlement-passport-casenote") - val NOMS_NUMBER_ADDED: HmppsDomainEvent = ResourceLoader.message("noms-number-added") + val EXISTS_IN_DELIUS: Notification = + ResourceLoader.notification("case-note-exists-in-delius") + val NEW_TO_DELIUS: Notification = + ResourceLoader.notification("case-note-new-to-delius") + val NOT_FOUND: Notification = ResourceLoader.notification("case-note-not-found") + val RESETTLEMENT_PASSPORT: Notification = + ResourceLoader.notification("resettlement-passport-casenote") + val NOMS_NUMBER_ADDED: Notification = + ResourceLoader.notification("noms-number-added") } diff --git a/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-exists-in-delius.json b/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-exists-in-delius.json index acd8f1bb79..64499cc362 100644 --- a/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-exists-in-delius.json +++ b/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-exists-in-delius.json @@ -2,7 +2,7 @@ "MessageId": "ae06c49e-1f41-4b9f-b2f2-dcca610d02cd", "Type": "Notification", "Timestamp": "2019-10-21T14:01:18.500Z", - "Message": "{\"eventType\":\"person.case-note.updated\",\"version\":1,\"description\":\"A prison case note has been amended\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/case-notes/AA0001A/0ec15f8b-6b57-471f-b02a-c89169a6a3e5\",\"additionalInformation\":{\"id\":\"0ec15f8b-6b57-471f-b02a-c89169a6a3e5\",\"legacyId\":\"1111\",\"type\":\"NEG\",\"subType\":\"IEP_WARN\"},\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"AA0001A\"}]}}", + "Message": "{\"eventType\":\"person.case-note.updated\",\"version\":1,\"description\":\"A prison case note has been amended\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/case-notes/AA0001A/0ec15f8b-6b57-471f-b02a-c89169a6a3e5\",\"additionalInformation\":{\"id\":\"0ec15f8b-6b57-471f-b02a-c89169a6a3e5\",\"legacyId\":\"1111\",\"type\":\"GEN\",\"subType\":\"OSE\"},\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"AA0001A\"}]}}", "TopicArn": "arn:aws:sns:eu-west-1:000000000000:offender_events", "MessageAttributes": { "eventType": { @@ -11,11 +11,11 @@ }, "type": { "Type": "String", - "Value": "NEG" + "Value": "GEN" }, "subType": { "Type": "String", - "Value": "IEP_WARN" + "Value": "OSE" } } } \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-new-to-delius.json b/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-new-to-delius.json index 0fd185dd13..af1f94f862 100644 --- a/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-new-to-delius.json +++ b/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-new-to-delius.json @@ -2,7 +2,7 @@ "MessageId": "ae06c49e-1f41-4b9f-b2f2-dcca610d02cd", "Type": "Notification", "Timestamp": "2019-10-21T14:01:18.500Z", - "Message": "{\"eventType\":\"person.case-note.created\",\"version\":1,\"description\":\"A prison case note has been created\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/case-notes/AA0001A/2cf4f9e1-df22-49a1-a2a7-5968a96529e3\",\"additionalInformation\":{\"id\":\"2cf4f9e1-df22-49a1-a2a7-5968a96529e3\",\"legacyId\":\"2222\",\"type\":\"NEG\",\"subType\":\"IEP_WARN\"},\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"AA0001A\"}]}}", + "Message": "{\"eventType\":\"person.case-note.created\",\"version\":1,\"description\":\"A prison case note has been created\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/case-notes/AA0001A/2cf4f9e1-df22-49a1-a2a7-5968a96529e3\",\"additionalInformation\":{\"id\":\"2cf4f9e1-df22-49a1-a2a7-5968a96529e3\",\"legacyId\":\"2222\",\"type\":\"KA\",\"subType\":\"KS\"},\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"AA0001A\"}]}}", "TopicArn": "arn:aws:sns:eu-west-1:000000000000:offender_events", "MessageAttributes": { "eventType": { @@ -11,11 +11,11 @@ }, "type": { "Type": "String", - "Value": "NEG" + "Value": "KA" }, "subType": { "Type": "String", - "Value": "IEP_WARN" + "Value": "KS" } } } \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-not-found.json b/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-not-found.json index b29376fb06..d52dc283dc 100644 --- a/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-not-found.json +++ b/projects/prison-case-notes-to-probation/src/dev/resources/messages/case-note-not-found.json @@ -2,7 +2,7 @@ "MessageId": "ae06c49e-1f41-4b9f-b2f2-dcca610d02cd", "Type": "Notification", "Timestamp": "2019-10-21T14:01:18.500Z", - "Message": "{\"eventType\":\"person.case-note.created\",\"version\":1,\"description\":\"A prison case note has been created\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/case-notes/AA0001A/da82e1df-1a74-486e-842c-6ce961575211\",\"additionalInformation\":{\"id\":\"da82e1df-1a74-486e-842c-6ce961575211\",\"legacyId\":\"432109\",\"type\":\"NEG\",\"subType\":\"IEP_WARN\"},\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"AA0001A\"}]}}", + "Message": "{\"eventType\":\"person.case-note.created\",\"version\":1,\"description\":\"A prison case note has been created\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/case-notes/AA0001A/da82e1df-1a74-486e-842c-6ce961575211\",\"additionalInformation\":{\"id\":\"da82e1df-1a74-486e-842c-6ce961575211\",\"legacyId\":\"432109\",\"type\":\"OMIC\",\"subType\":\"GEN\"},\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"AA0001A\"}]}}", "TopicArn": "arn:aws:sns:eu-west-1:000000000000:offender_events", "MessageAttributes": { "eventType": { @@ -11,11 +11,11 @@ }, "type": { "Type": "String", - "Value": "NEG" + "Value": "OMIC" }, "subType": { "Type": "String", - "Value": "IEP_WARN" + "Value": "GEN" } } } \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseNotesIntegrationTest.kt b/projects/prison-case-notes-to-probation/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseNotesIntegrationTest.kt index d82b8fcc5e..69c5138652 100644 --- a/projects/prison-case-notes-to-probation/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseNotesIntegrationTest.kt +++ b/projects/prison-case-notes-to-probation/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseNotesIntegrationTest.kt @@ -20,12 +20,16 @@ import org.springframework.test.context.bean.override.mockito.MockitoSpyBean import uk.gov.justice.digital.hmpps.audit.repository.AuditedInteractionRepository import uk.gov.justice.digital.hmpps.data.generator.* import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter +import uk.gov.justice.digital.hmpps.integrations.delius.model.DeliusCaseNote import uk.gov.justice.digital.hmpps.integrations.delius.repository.CaseNoteRepository import uk.gov.justice.digital.hmpps.integrations.delius.repository.OffenderRepository import uk.gov.justice.digital.hmpps.integrations.delius.repository.StaffRepository +import uk.gov.justice.digital.hmpps.message.MessageAttribute +import uk.gov.justice.digital.hmpps.message.MessageAttributes import uk.gov.justice.digital.hmpps.messaging.HmppsChannelManager import uk.gov.justice.digital.hmpps.telemetry.TelemetryService import uk.gov.justice.digital.hmpps.test.CustomMatchers.isCloseTo +import java.time.Duration import java.time.ZonedDateTime const val CASE_NOTE_MERGED = "CaseNoteMerged" @@ -62,10 +66,10 @@ class CaseNotesIntegrationTest { val nomisCaseNote = PrisonCaseNoteGenerator.EXISTING_IN_BOTH channelManager.getChannel(queueName).publishAndWait( - prepMessage(CaseNoteMessageGenerator.EXISTS_IN_DELIUS, wireMockserver.port()) + prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS, wireMockserver.port()) ) - val saved = caseNoteRepository.findByNomisId(nomisCaseNote.eventId) + val saved = caseNoteRepository.findByExternalReference("${DeliusCaseNote.URN_PREFIX}${nomisCaseNote.id}") assertThat( saved?.notes, @@ -93,11 +97,11 @@ class CaseNotesIntegrationTest { assertNull(original) channelManager.getChannel(queueName).publishAndWait( - prepMessage(CaseNoteMessageGenerator.NEW_TO_DELIUS, wireMockserver.port()) + prepNotification(CaseNoteMessageGenerator.NEW_TO_DELIUS, wireMockserver.port()) ) verify(telemetryService).trackEvent(eq(CASE_NOTE_MERGED), anyMap(), anyMap()) - val saved = caseNoteRepository.findByNomisId(nomisCaseNote.eventId) + val saved = caseNoteRepository.findByExternalReference("${DeliusCaseNote.URN_PREFIX}${nomisCaseNote.id}") assertNotNull(saved) assertThat( @@ -135,7 +139,7 @@ class CaseNotesIntegrationTest { @Test fun `case note not found - noop`() { channelManager.getChannel(queueName).publishAndWait( - prepMessage(CaseNoteMessageGenerator.NOT_FOUND, wireMockserver.port()) + prepNotification(CaseNoteMessageGenerator.NOT_FOUND, wireMockserver.port()) ) verify(telemetryService, never()).trackEvent(eq(CASE_NOTE_MERGED), anyMap(), anyMap()) @@ -146,11 +150,11 @@ class CaseNotesIntegrationTest { val nomisCaseNote = PrisonCaseNoteGenerator.RESETTLEMENT_PASSPORT channelManager.getChannel(queueName).publishAndWait( - prepMessage(CaseNoteMessageGenerator.RESETTLEMENT_PASSPORT, wireMockserver.port()) + prepNotification(CaseNoteMessageGenerator.RESETTLEMENT_PASSPORT, wireMockserver.port()) ) verify(telemetryService).trackEvent(eq(CASE_NOTE_MERGED), anyMap(), anyMap()) - val saved = caseNoteRepository.findByNomisId(nomisCaseNote.eventId) + val saved = caseNoteRepository.findByExternalReference("${DeliusCaseNote.URN_PREFIX}${nomisCaseNote.id}") assertNotNull(saved) assertThat( @@ -179,7 +183,7 @@ class CaseNotesIntegrationTest { assert(originals.isEmpty()) channelManager.getChannel(queueName).publishAndWait( - prepMessage(CaseNoteMessageGenerator.NOMS_NUMBER_ADDED, wireMockserver.port()) + prepNotification(CaseNoteMessageGenerator.NOMS_NUMBER_ADDED, wireMockserver.port()) ) verify(telemetryService).trackEvent( @@ -190,4 +194,20 @@ class CaseNotesIntegrationTest { val saved = caseNoteRepository.findAll().filter { it.offenderId == offender.id } assertThat(saved.size, equalTo(4)) } + + @Test + fun `case note not of interest - noop`() { + val existing = CaseNoteMessageGenerator.EXISTS_IN_DELIUS + channelManager.getChannel(queueName).publishAndWait( + prepNotification( + existing.copy( + attributes = MessageAttributes(existing.eventType!!).apply { + this["type"] = MessageAttribute("String", "NOTOF") + this["subType"] = MessageAttribute("String", "INTEREST") + } + ), wireMockserver.port()) + ) + + verify(telemetryService, never()).trackEvent(eq(CASE_NOTE_MERGED), anyMap(), anyMap()) + } } diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/model/DeliusCaseNote.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/model/DeliusCaseNote.kt index 00623be997..09a40ed0bb 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/model/DeliusCaseNote.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/model/DeliusCaseNote.kt @@ -9,7 +9,11 @@ import java.time.ZonedDateTime import java.util.* data class DeliusCaseNote(val header: CaseNoteHeader, val body: CaseNoteBody) { - val urn = header.uuid?.let { "urn:uk:gov:hmpps:prison-case-note:${it}" } + val urn = header.uuid?.let { "$URN_PREFIX${it}" } + + companion object { + const val URN_PREFIX = "urn:uk:gov:hmpps:prison-case-note:" + } } data class CaseNoteHeader(val nomisId: String, val legacyId: Long, val uuid: UUID?) diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/CaseNoteTypesOfInterest.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/CaseNoteTypesOfInterest.kt new file mode 100644 index 0000000000..969b7a7d1d --- /dev/null +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/CaseNoteTypesOfInterest.kt @@ -0,0 +1,22 @@ +package uk.gov.justice.digital.hmpps.integrations.prison + +object CaseNoteTypesOfInterest { + private val typeSubTypeMap = mapOf( + "PRISON" to setOf("RELEASE"), + "TRANSFER" to setOf("FROMTOL"), + "GEN" to setOf("OSE"), + "RESET" to setOf("BCST"), + "ALERT" to setOf(), + "OMIC" to setOf(), + "OMIC_OPD" to setOf(), + "KA" to setOf() + ) + + fun forSearchRequest(): Set = + typeSubTypeMap.map { TypeSubTypeRequest(it.key, it.value) }.toSet() + + fun verifyOfInterest(type: String, subType: String): Boolean { + val subTypes = typeSubTypeMap[type] ?: return false + return subTypes.isEmpty() || subTypes.contains(subType) + } +} \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt index 447b4dcabc..2cff90855f 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt @@ -25,19 +25,7 @@ data class SearchCaseNotes( val page: Int = 1, val size: Int = Int.MAX_VALUE, val sort: String = "occurredAt,desc", -) { - companion object { - val TYPES_OF_INTEREST = setOf( - TypeSubTypeRequest("PRISON", setOf("RELEASE")), - TypeSubTypeRequest("TRANSFER", setOf("FROMTOL")), - TypeSubTypeRequest("GEN", setOf("OSE")), - TypeSubTypeRequest("ALERT"), - TypeSubTypeRequest("OMIC"), - TypeSubTypeRequest("OMIC_OPD"), - TypeSubTypeRequest("KA"), - ) - } -} +) data class TypeSubTypeRequest(val type: String, val subTypes: Set = setOf()) diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 9d00f4e3fc..89e51de3c7 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -6,8 +6,12 @@ import org.openfolder.kotlinasyncapi.annotation.channel.Message import org.openfolder.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.integrations.prison.CaseNoteTypesOfInterest import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification +import uk.gov.justice.digital.hmpps.messaging.Handler.Companion.CASE_NOTE_PUBLISHED +import uk.gov.justice.digital.hmpps.messaging.Handler.Companion.PERSON_CASE_NOTE_CREATED +import uk.gov.justice.digital.hmpps.messaging.Handler.Companion.PERSON_CASE_NOTE_UPDATED @Component @Channel("prison-case-notes-to-probation-queue") @@ -34,10 +38,21 @@ class Handler( ] ) override fun handle(notification: Notification) { - when (notification.eventType) { - CASE_NOTE_PUBLISHED -> caseNotePublished.handle(notification.message) - PRISON_IDENTIFIER_ADDED -> prisonIdentifierAdded.handle(notification.message) - PERSON_CASE_NOTE_CREATED, PERSON_CASE_NOTE_UPDATED -> personCaseNote.handle(notification.message) + when { + notification.eventType == PRISON_IDENTIFIER_ADDED -> prisonIdentifierAdded.handle(notification.message) + notification.isCaseNoteOfInterest() -> personCaseNote.handle(notification.message) + notification.publishedOfInterest() -> caseNotePublished.handle(notification.message) } } } + +private fun Notification<*>.publishedOfInterest(): Boolean = + eventType == CASE_NOTE_PUBLISHED && typeIsOfInterest() + +private fun Notification<*>.isCaseNoteOfInterest(): Boolean = + (eventType == PERSON_CASE_NOTE_CREATED || eventType == PERSON_CASE_NOTE_UPDATED) && typeIsOfInterest() + +val Notification<*>.type get() = attributes["type"]?.value +val Notification<*>.subType get() = attributes["subType"]?.value + +private fun Notification<*>.typeIsOfInterest() = CaseNoteTypesOfInterest.verifyOfInterest(type!!, subType!!) \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonIdentifierAdded.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonIdentifierAdded.kt index 1bdc5f7ff6..4036fbf59b 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonIdentifierAdded.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonIdentifierAdded.kt @@ -4,11 +4,8 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService -import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNoteFilters -import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNotesClient -import uk.gov.justice.digital.hmpps.integrations.prison.SearchCaseNotes -import uk.gov.justice.digital.hmpps.integrations.prison.SearchCaseNotes.Companion.TYPES_OF_INTEREST -import uk.gov.justice.digital.hmpps.integrations.prison.toDeliusCaseNote +import uk.gov.justice.digital.hmpps.integrations.prison.* +import uk.gov.justice.digital.hmpps.integrations.prison.CaseNoteTypesOfInterest.forSearchRequest import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.telemetry.TelemetryService import java.net.URI @@ -27,7 +24,7 @@ class PrisonIdentifierAdded( "NomsNumber not found for ${event.eventType}" } val uri = URI.create("$caseNotesBaseUrl/search/case-notes/$nomsId") - val caseNotes = caseNotesApi.searchCaseNotes(uri, SearchCaseNotes(TYPES_OF_INTEREST)).content + val caseNotes = caseNotesApi.searchCaseNotes(uri, SearchCaseNotes(forSearchRequest())).content .filter { cn -> PrisonCaseNoteFilters.filters.none { it.predicate.invoke(cn) } } caseNotes.forEach { deliusService.mergeCaseNote(it.toDeliusCaseNote()) } diff --git a/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt b/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt index 278983515d..cd7a6e1f55 100644 --- a/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt +++ b/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt @@ -20,8 +20,10 @@ import uk.gov.justice.digital.hmpps.exceptions.StaffCodeExhaustedException import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNote import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNotesClient +import uk.gov.justice.digital.hmpps.message.MessageAttributes import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.prepMessage +import uk.gov.justice.digital.hmpps.prepNotification import uk.gov.justice.digital.hmpps.telemetry.TelemetryService import java.net.URI import java.time.ZonedDateTime @@ -43,7 +45,7 @@ internal class PersonCaseNoteTest { @Test fun `when case note not found - noop`() { - val message = prepMessage(CaseNoteMessageGenerator.NOT_FOUND).message + val message = prepNotification(CaseNoteMessageGenerator.NOT_FOUND).message whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))) .thenThrow(HttpClientErrorException(HttpStatus.NOT_FOUND)) @@ -66,7 +68,7 @@ internal class PersonCaseNoteTest { text = "", amendments = listOf() ) - val message = prepMessage(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message + val message = prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))).thenReturn(prisonCaseNote) handler.handle(message) verify(deliusService, times(0)).mergeCaseNote(any()) @@ -87,7 +89,7 @@ internal class PersonCaseNoteTest { text = "Prisoner being transferred", amendments = listOf() ) - val message = prepMessage(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message + val message = prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))).thenReturn(prisonCaseNote) handler.handle(message) @@ -113,7 +115,7 @@ internal class PersonCaseNoteTest { text = text, amendments = listOf() ) - val message = prepMessage(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message + val message = prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))).thenReturn(prisonCaseNote) handler.handle(message) @@ -137,7 +139,7 @@ internal class PersonCaseNoteTest { text = "Notes for an offender without noms number in delius", amendments = listOf() ) - val poe = Notification(prepMessage(CaseNoteMessageGenerator.NEW_TO_DELIUS).message) + val poe = Notification(prepNotification(CaseNoteMessageGenerator.NEW_TO_DELIUS).message) whenever(prisonCaseNotesClient.getCaseNote(URI.create(poe.message.detailUrl!!))).thenReturn(prisonCaseNote) whenever(deliusService.mergeCaseNote(any())).thenThrow(OffenderNotFoundException("A001")) @@ -160,7 +162,7 @@ internal class PersonCaseNoteTest { text = "Notes for an exceptional case note", amendments = listOf() ) - val poe = Notification(prepMessage(CaseNoteMessageGenerator.NEW_TO_DELIUS).message) + val poe = Notification(prepNotification(CaseNoteMessageGenerator.NEW_TO_DELIUS).message) whenever(prisonCaseNotesClient.getCaseNote(URI.create(poe.message.detailUrl!!))).thenReturn(prisonCaseNote) whenever(deliusService.mergeCaseNote(any())).thenThrow(StaffCodeExhaustedException("A999"))