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

updated existing method #518

Merged
merged 2 commits into from
Nov 15, 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
Expand Up @@ -11,10 +11,16 @@ class GetHmppsIdService(
@Autowired val getPersonService: GetPersonService,
) {
fun execute(hmppsId: String): Response<HmppsId?> {
val personResponse = getPersonService.execute(hmppsId = hmppsId)
val personResponse = getPersonService.execute(hmppsId)

val hmppsIdToReturn =
personResponse.data?.hmppsId ?: run {
// Attempt to look up the person in NOMIS if not found in the probation offender search
getPersonService.getPersonFromNomis(hmppsId).data?.prisonerNumber
}

return Response(
data = HmppsId(hmppsId = personResponse.data?.hmppsId),
data = HmppsId(hmppsIdToReturn),
errors = personResponse.errors,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ class GetPersonService(
errors = (prisonResponse?.errors ?: emptyList()) + probationResponse.errors,
)
}

fun getPersonFromNomis(nomisNumber: String) = prisonerOffenderSearchGateway.getPrisonOffender(nomisNumber)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ class HmppsIdIntegrationTest : IntegrationTestBase() {
)
}

@Test
fun `gets the nomis Id for a HMPPSID where the id is a NOMIS id AND is not in delius`() {
callApi("/v1/hmpps/id/$nomsIdNotInDelius/nomis-number")
.andExpect(status().isOk)
.andExpect(
content().json(
"""
{"data":{"nomisNumber":"A1234AA"}}
""",
),
)
}

@Test
fun `gets the nomis Id for a HMPPSID where the id is invalid`() {
callApi("/v1/hmpps/id/invalidId/nomis-number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ abstract class IntegrationTestBase {
final val pnc = URLEncoder.encode("2004/13116M", StandardCharsets.UTF_8)
final val nomsId = "G2996UX"
final val crn = "AB123123"
final val nomsIdNotInDelius = "A1234AA"

companion object {
private val hmppsAuthMockServer = HmppsAuthMockServer()
Expand Down
Loading