Skip to content

Commit

Permalink
PI-2574 Handle missing booking from Prison API (#4287)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Oct 8, 2024
1 parent 0608be7 commit cf09ead
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.digital.hmpps

import com.github.tomakehurst.wiremock.client.WireMock.*
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Assertions.*
Expand Down Expand Up @@ -670,4 +671,24 @@ class PcstdIntegrationTest : PcstdIntegrationTestBase() {
)
}
}

@Test
fun `missing booking is ignored`() {
val notification = NotificationGenerator.PRISONER_RELEASED
wireMockServer.stubFor(
get(urlPathEqualTo("/api/bookings/offenderNo/${BookingGenerator.RELEASED.personReference}"))
.willReturn(aResponse().withStatus(404))
)

channelManager.getChannel(queueName).publishAndWait(notification)

verifyTelemetry("BookingNotFound") {
mapOf(
"occurredAt" to notification.message.occurredAt.toString(),
"nomsNumber" to "A0001AA",
"institution" to "WSI",
"details" to "Movement reason code NCS"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.openfolder.kotlinasyncapi.annotation.channel.Message
import org.openfolder.kotlinasyncapi.annotation.channel.Publish
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.client.HttpClientErrorException
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
Expand Down Expand Up @@ -115,9 +116,12 @@ class Handler(
}
}

private fun PrisonApiClient.bookingFromNomsId(nomsId: String) =
getBookingByNomsId(nomsId).takeIf { it.active || it.movementType == "REL" }
?: throw IgnorableMessageException("BookingInactive", mapOf("nomsNumber" to nomsId))
private fun PrisonApiClient.bookingFromNomsId(nomsId: String) = try {
getBookingByNomsId(nomsId)
} catch (e: HttpClientErrorException.NotFound) {
throw IgnorableMessageException("BookingNotFound", mapOf("nomsNumber" to nomsId))
}.takeIf { it.active || it.movementType == "REL" }
?: throw IgnorableMessageException("BookingInactive", mapOf("nomsNumber" to nomsId))
}

fun HmppsDomainEvent.prisonId() = additionalInformation["prisonId"] as String?
Expand Down

0 comments on commit cf09ead

Please sign in to comment.