Skip to content

Commit 6a52f07

Browse files
[HIA-721]
WIP More progress
1 parent 39daf4f commit 6a52f07

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

gradle.properties

100644100755
File mode changed.

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/RiskManagementGateway.kt

+37-3
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,55 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways
22

33
import org.springframework.beans.factory.annotation.Autowired
44
import org.springframework.beans.factory.annotation.Value
5+
import org.springframework.http.HttpMethod
56
import org.springframework.stereotype.Component
67
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper
78
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.assessRisksAndNeeds.CrnRiskManagementPlans
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
10+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
811

912
@Component
1013
class RiskManagementGateway (
11-
@Value("\${risk-management-plan-search.base-url}") baseUrl: String,
14+
@Value("\${services.risk-management-plan-search.base-url}") baseUrl: String,
1215
){
1316

1417
private val webClient = WebClientWrapper(baseUrl)
1518

1619
@Autowired
1720
lateinit var hmppsAuthGateway: HmppsAuthGateway
1821

19-
fun getRiskManagementPlansForCrn(crn: String): CrnRiskManagementPlans {
20-
return CrnRiskManagementPlans(crn, "plan", emptyList())
22+
fun getRiskManagementPlansForCrn(crn: String): Response<CrnRiskManagementPlans> {
23+
24+
val requestBody =
25+
mapOf("crn" to crn)
26+
27+
val result =
28+
webClient.request<CrnRiskManagementPlans>(
29+
HttpMethod.GET,
30+
"/risks/crn/$crn/risk-management-plan",
31+
authenticationHeader(),
32+
UpstreamApi.RISK_MANAGEMENT_PLAN,
33+
requestBody,
34+
)
35+
return when (result) {
36+
is WebClientWrapper.WebClientWrapperResponse.Success -> {
37+
Response(data = result.data, errors = emptyList())
38+
}
39+
40+
is WebClientWrapper.WebClientWrapperResponse.Error -> {
41+
Response(
42+
data = CrnRiskManagementPlans("", "", emptyList()),
43+
errors = result.errors,
44+
)
45+
}
46+
}
47+
}
48+
49+
private fun authenticationHeader(): Map<String, String> {
50+
val token = hmppsAuthGateway.getClientToken("Risk Management Plan Search")
51+
52+
return mapOf(
53+
"Authorization" to "Bearer $token",
54+
)
2155
}
2256
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/hmpps/UpstreamApi.kt

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ enum class UpstreamApi {
1010
CVL,
1111
CASE_NOTES,
1212
MANAGE_POM_CASE,
13+
RISK_MANAGEMENT_PLAN,
1314
TEST,
1415
}

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/riskManagement/riskManagementGatewayTest.kt

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.riskManagement
22

33
import io.kotest.core.spec.style.DescribeSpec
4+
import io.kotest.matchers.shouldBe
45
import org.mockito.Mockito
56
import org.mockito.internal.verification.VerificationModeFactory
67
import org.mockito.kotlin.verify
@@ -39,20 +40,30 @@ class RiskManagementGatewayTest (
3940
riskManagementMockServer.stop()
4041
}
4142

42-
describe("get risks for given crn") {
43+
describe("Get risks for given CRN") {
4344
val crn = "D1974X"
4445

45-
riskManagementMockServer.stubGetRiskManagementPlan(
46-
crn,
47-
File(
48-
"src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/riskManagement/fixtures/GetRiskManagementPlanResponse.json",
49-
).readText(),
50-
)
46+
beforeEach {
47+
riskManagementMockServer.stubGetRiskManagementPlan(
48+
crn,
49+
File(
50+
"src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/riskManagement/fixtures/GetRiskManagementPlanResponse.json",
51+
).readText(),
52+
)
53+
}
5154

5255
it("authenticates using HMPPS Auth with credentials") {
5356
riskManagementGateway.getRiskManagementPlansForCrn(crn)
57+
verify(hmppsAuthGateway, VerificationModeFactory.times(1)).getClientToken("Risk Management Plan Search")
58+
}
59+
60+
it ("returns a risk management plan when searching with a valid CRN") {
61+
val response = riskManagementGateway.getRiskManagementPlansForCrn(crn)
62+
val blah = response.data
63+
blah.crn.shouldBe(crn)
64+
response.data.riskManagementPlan.size.shouldBe(1)
5465

55-
verify(hmppsAuthGateway, VerificationModeFactory.times(1)).getClientToken("Prisoner Offender Search")
66+
response.errors.size.shouldBe(0)
5667
}
5768

5869
}

0 commit comments

Comments
 (0)