Skip to content

Commit

Permalink
PI-1517 added nullable additional information because delius incorrec…
Browse files Browse the repository at this point in the history
…tly sends null value
  • Loading branch information
anthony-britton-moj committed Sep 28, 2023
1 parent 28731b8 commit 714a227
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.digital.hmpps.message

import com.fasterxml.jackson.annotation.JsonAlias
import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import java.time.ZonedDateTime
Expand All @@ -10,9 +11,11 @@ data class HmppsDomainEvent(
val detailUrl: String? = null,
val occurredAt: ZonedDateTime = ZonedDateTime.now(),
val description: String? = null,
val additionalInformation: AdditionalInformation = AdditionalInformation(),
@JsonAlias("additionalInformation") private val nullableAdditionalInformation: AdditionalInformation? = AdditionalInformation(),
val personReference: PersonReference = PersonReference()
)
) {
val additionalInformation = nullableAdditionalInformation ?: AdditionalInformation()
}

data class PersonReference(val identifiers: List<PersonIdentifier> = listOf()) {
fun findCrn() = get("CRN")
Expand All @@ -30,6 +33,7 @@ data class AdditionalInformation(
operator fun set(key: String, value: Any) {
info[key] = value
}

fun containsKey(key: String): Boolean {
return info.containsKey(key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class HmppsDomainEventConverterTest {
message,
equalTo(
"""
|{"Message":"{\"eventType\":\"message.event.type\",\"version\":1,\"detailUrl\":\"http://detail/url\",\"occurredAt\":\"2022-07-27T15:22:08.509+01:00\",\"description\":\"A description for the event\",\"additionalInformation\":{\"specialId\":\"6aafe304-861f-4479-8380-fec5f90f6d17\"},\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"X123456\"}]}}",
|{"Message":"{\"eventType\":\"message.event.type\",\"version\":1,\"detailUrl\":\"http://detail/url\",\"occurredAt\":\"2022-07-27T15:22:08.509+01:00\",\"description\":\"A description for the event\",\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"X123456\"}]},\"additionalInformation\":{\"specialId\":\"6aafe304-861f-4479-8380-fec5f90f6d17\"}}",
|"MessageAttributes":{"eventType":{"Type":"String","Value":"attribute.event.type"}},"MessageId":"${hmppsEvent.id}"}
""".trimMargin().replace("\\n".toRegex(), "")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A new probation case has been created",
"detailUrl": "https://example.com",
"occurredAt": "2023-09-20T16:05:59.442+01:00",
"additionalInformation": null,
"personReference": {
"identifiers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal class HandlerTest {
@Test
fun `get case note from NOMIS has null caseNoteId`() {
val message = prepMessage(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message
val prisonOffenderEvent = Notification(message = message.copy(additionalInformation = AdditionalInformation()))
val prisonOffenderEvent = Notification(message = message.copy(nullableAdditionalInformation = AdditionalInformation()))
handler.handle(prisonOffenderEvent)
verify(deliusService, times(0)).mergeCaseNote(any())
verify(prisonCaseNotesClient, times(0)).getCaseNote(any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class HandlerTest {
1,
"https//detail/url",
ZonedDateTime.now(),
additionalInformation = AdditionalInformation(
nullableAdditionalInformation = AdditionalInformation(
mutableMapOf(
"nomsNumber" to "Z0001ZZ",
"prisonId" to "ZZZ",
Expand Down Expand Up @@ -249,7 +249,7 @@ internal class HandlerTest {
whenever(featureFlags.enabled("messages_released_hospital")).thenReturn(false)
val hospitalNotification = notification.copy(
message = notification.message.copy(
additionalInformation = AdditionalInformation(
nullableAdditionalInformation = AdditionalInformation(
mutableMapOf(
"nomsNumber" to "Z0001ZZ",
"prisonId" to "OUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class FeedbackSubmittedTest {
DomainEventType.InitialAppointmentSubmitted.name,
1,
"https://interventions-service/referral/$referralId/supplier-assessment",
additionalInformation = AdditionalInformation(
nullableAdditionalInformation = AdditionalInformation(
mutableMapOf(
"serviceUserCRN" to crn,
"referralId" to referralId.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal class ReferAndMonitorHandlerTest {
1,
occurredAt = ZonedDateTime.now(),
detailUrl = "DetailUrl",
additionalInformation = AdditionalInformation(mutableMapOf("referralId" to UUID.randomUUID().toString())),
nullableAdditionalInformation = AdditionalInformation(mutableMapOf("referralId" to UUID.randomUUID().toString())),
personReference = PersonReference(listOf(PersonIdentifier("CRN", "T123456")))
),
MessageAttributes(SessionAppointmentSubmitted.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class ReferralEndSubmittedTest {
DomainEventType.ReferralEnded.name,
1,
"https://fake.org/url",
additionalInformation = AdditionalInformation(mutableMapOf("referralId" to UUID.randomUUID().toString())),
nullableAdditionalInformation = AdditionalInformation(mutableMapOf("referralId" to UUID.randomUUID().toString())),
personReference = PersonReference(listOf(PersonIdentifier("CRN", "T123456")))
)

Expand Down Expand Up @@ -73,7 +73,7 @@ internal class ReferralEndSubmittedTest {
1,
"https://fake.org/url",
personReference = PersonReference(listOf(PersonIdentifier("CRN", "T123456"))),
additionalInformation = AdditionalInformation(
nullableAdditionalInformation = AdditionalInformation(
mutableMapOf(
"referralURN" to UUID.randomUUID().toString(),
"deliveryState" to "CANCELLED",
Expand Down

0 comments on commit 714a227

Please sign in to comment.