Skip to content

Commit

Permalink
PI-2391: Cater for LAO cases and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 committed Aug 1, 2024
1 parent 2e4a900 commit ab4f29c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": 403,
"developerMessage": "This is a restricted record. Please contact a system administrator"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@

{
"mappings": [
{
"request": {
"method": "GET",
"urlPath": "/secure/offenders/crn/Y123456/all"
},
"response": {
"status": 403,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "GET_offender_all_Y123456.json"
}
},
{
"request": {
"method": "GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,29 @@ internal class ProxyIntegrationTest {
assertThat(res.currentPageNumber, equalTo(2))
assertThat(res.unableToBeExecuted, equalTo(4))
}

@Test
fun `compare when lao case`() {
val res = mockMvc.perform(
post("/secure/compareAll")
.contentType("application/json;charset=utf-8")
.content(
"""
{
"pageNumber": 1,
"pageSize": 1,
"crns": [ "Y123456"],
"uriConfig": {
"OFFENDER_DETAIL": {}
}
}
"""
)
.withToken()
).andExpect(status().isOk).andReturn().response.contentAsJson<CompareAllReport>()

assertThat(res.totalNumberOfRequests, equalTo(1))
}
}

//{"status":403,"developerMessage":"This is a restricted record. Please contact a system administrator"}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.client.HttpStatusCodeException
import uk.gov.justice.digital.hmpps.advice.ControllerAdvice
import java.io.StringReader
import java.lang.reflect.InvocationTargetException
import java.net.URI
import kotlin.reflect.KParameter
import org.springframework.security.access.AccessDeniedException

@Service
class CommunityApiService(
@Value("\${community-api.url}") private val communityApiUrl: String,
private val mapper: ObjectMapper,
private val communityApiClient: CommunityApiClient,
private val applicationContext: ApplicationContext
private val applicationContext: ApplicationContext,
private val controllerAdvice: ControllerAdvice
) {

fun getCcdJson(compare: Compare): String {
Expand All @@ -34,8 +38,16 @@ class CommunityApiService(
val paramsFunc = function.parameters
val params = mapOf(paramsFunc[0] to instance) + functionParams

return mapper.writeValueAsString(
val response = try {
function.callBy(params)
} catch (ex: InvocationTargetException) {
when (val cause = ex.cause) {
is AccessDeniedException -> controllerAdvice.handleAccessDenied(cause)
else -> throw ex
}
}
return mapper.writeValueAsString(
response
)
}

Expand Down Expand Up @@ -73,7 +85,7 @@ class CommunityApiService(
)
}

val comApiJsonString = communityApiClient.proxy(URI.create(communityApiUrl + comApiUri), headers).body!!
val comApiJsonString = proxy(comApiUri, headers.toMutableMap()).body!!
val ccdJson = Json.createReader(StringReader(ccdJsonString)).readValue() as JsonStructure
val comApiJson = Json.createReader(StringReader(comApiJsonString)).readValue() as JsonStructure
val diff: JsonPatch = Json.createDiff(ccdJson, comApiJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ enum class Uri(
val ccdFunction: String,
val urlParams: List<String>
) {
OFFENDER_DETAIL("/secure/offenders/crn/{crn}/all", "offenderService", "getOffenderDetail", listOf("crn")),
OFFENDER_SUMMARY("/secure/offenders/crn/{crn}", "offenderService", "getOffenderDetailSummary", listOf("crn")),
OFFENDER_DETAIL("/secure/offenders/crn/{crn}/all", "probationRecordResource", "getOffenderDetail", listOf("crn")),
OFFENDER_SUMMARY("/secure/offenders/crn/{crn}", "probationRecordResource", "getOffenderDetailSummary", listOf("crn")),
OFFENDER_MANAGERS(
"/secure/offenders/crn/{crn}/allOffenderManagers?includeProbationAreaTeams={includeProbationAreaTeams}",
"offenderManagerService",
"getAllOffenderManagersForCrn",
"probationRecordResource",
"getAllOffenderManagers",
listOf("crn", "includeProbationAreaTeams")
),
CONVICTIONS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fun uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Team.toTeam
code = code.trim(),
description = description,
telephone = telephone,
emailAddress = emailAddress,
borough = KeyValue(district.borough.code, district.borough.description),
district = KeyValue(district.code, district.description),
localDeliveryUnit = KeyValue(district.code, district.description),
Expand Down

0 comments on commit ab4f29c

Please sign in to comment.