Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2574 Handle missing booking from Prison API #4287

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading