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

prison search fix #525

Merged
merged 2 commits into from
Nov 21, 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,6 +1,5 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways

import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpMethod
Expand All @@ -19,8 +18,6 @@ class PrisonerOffenderSearchGateway(
) {
private val webClient = WebClientWrapper(baseUrl)

private val log: org.slf4j.Logger = LoggerFactory.getLogger(this::class.java)

@Autowired
lateinit var hmppsAuthGateway: HmppsAuthGateway

Expand Down Expand Up @@ -59,7 +56,6 @@ class PrisonerOffenderSearchGateway(
}

fun getPrisonOffender(nomsNumber: String): Response<POSPrisoner?> {
log.info("looking up the person via prison search $nomsNumber")
val result =
webClient.request<POSPrisoner>(
HttpMethod.GET,
Expand All @@ -70,12 +66,10 @@ class PrisonerOffenderSearchGateway(

return when (result) {
is WebClientWrapperResponse.Success -> {
log.info("found a match via prison search $nomsNumber")
Response(data = result.data)
}

is WebClientWrapperResponse.Error -> {
log.error("An error occurred getting person from prion search: ${result.errors}")
Response(
data = null,
errors = result.errors,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services

import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.HmppsId
Expand All @@ -11,23 +10,23 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
class GetHmppsIdService(
@Autowired val getPersonService: GetPersonService,
) {
private val log: org.slf4j.Logger = LoggerFactory.getLogger(this::class.java)

fun execute(hmppsId: String): Response<HmppsId?> {
val personResponse = getPersonService.execute(hmppsId.uppercase())

var hmppsIdToReturn =
personResponse.data?.hmppsId
log.info("hmppsId from probation: $hmppsIdToReturn")
if (hmppsIdToReturn == null) {
hmppsIdToReturn = getPersonService.getPersonFromNomis(hmppsId.uppercase()).data?.prisonerNumber
log.info("hmppsId from prison: $hmppsIdToReturn")
return if (hmppsIdToReturn != null) {
Response(
data = HmppsId(hmppsIdToReturn),
errors = personResponse.errors,
)
} else {
val prisonerResponse = getPersonService.getPersonFromNomis(hmppsId.uppercase())
hmppsIdToReturn = prisonerResponse.data?.prisonerNumber
Response(
data = HmppsId(hmppsIdToReturn),
errors = prisonerResponse.errors,
)
}

return Response(
data = HmppsId(hmppsIdToReturn),
errors = personResponse.errors,
)
}

fun getNomisNumber(hmppsId: String): Response<NomisNumber?> {
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,3 @@ authorisation:
- "/v1/persons/.*/plp/inductionScheduleUpdated"
- "/v1/hmpps/id/by-nomis-number/[^/]*$"
- "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$"

logging:
level:
root: INFO
uk.gov.justice.digital.hmpps.hmppsintegrationapi: DEBUG