Skip to content

Commit 4150099

Browse files
Added plp induction schedule endpoint.
1 parent 4660ea3 commit 4150099

File tree

17 files changed

+209
-1
lines changed

17 files changed

+209
-1
lines changed

Dockerfile.prism

+4
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ RUN sed -i 's/\*\/\*/application\/json/g' /prismMocks/assess-risks-and-needs.jso
2121
RUN sed -i 's/\*\/\*/application\/json/g' /prismMocks/case-notes.json
2222
RUN sed -i 's/\*\/\*/application\/json/g' /prismMocks/prisoner-offender-search.json
2323

24+
# new files from this point on need to start with an x- followed by the port number:
25+
ADD https://learningandworkprogress-api-dev.hmpps.service.justice.gov.uk/v3/api-docs /prismMocks/x4020-plp-api.json
26+
27+
2428
ENTRYPOINT sh -c 'port=4010; for file in $(ls /prismMocks/*.json | sort); do node dist/index.js mock -p $port -h 0.0.0.0 $file & port=$((port + 1)); done; wait'

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ services:
1414
curl -H "Authorization: Bearer abc" -f http://0.0.0.0:4016/api/offenders/A1234AA &&
1515
curl -H "Authorization: Bearer abc" -f http://0.0.0.0:4017/prisoner/A1234AL &&
1616
curl -H "Authorization: Bearer abc" -f http://0.0.0.0:4018/case-details/crn/1234 &&
17-
curl -H "Authorization: Bearer abc" -f http://0.0.0.0:4019/search?crn=sit'
17+
curl -H "Authorization: Bearer abc" -f http://0.0.0.0:4019/search?crn=sit &&
18+
curl -H "Authorization: Bearer abc" -f http://0.0.0.0:4020/inductions/K5995YZ/induction-schedule'
1819
ports:
1920
- '4010:4010'
2021
- '4011:4011'
@@ -26,6 +27,7 @@ services:
2627
- '4017:4017'
2728
- '4018:4018'
2829
- '4019:4019'
30+
- '4020:4020'
2931

3032
local-stack-aws:
3133
image: localstack/localstack:3.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person
2+
3+
import io.swagger.v3.oas.annotations.Operation
4+
import io.swagger.v3.oas.annotations.Parameter
5+
import io.swagger.v3.oas.annotations.media.Content
6+
import io.swagger.v3.oas.annotations.media.Schema
7+
import io.swagger.v3.oas.annotations.responses.ApiResponse
8+
import io.swagger.v3.oas.annotations.tags.Tag
9+
import io.swagger.v3.oas.annotations.tags.Tags
10+
import org.springframework.beans.factory.annotation.Autowired
11+
import org.springframework.web.bind.annotation.GetMapping
12+
import org.springframework.web.bind.annotation.PathVariable
13+
import org.springframework.web.bind.annotation.RequestMapping
14+
import org.springframework.web.bind.annotation.RestController
15+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
16+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters
17+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse
18+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule
19+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
20+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetInductionScheduleForPersonService
21+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService
22+
23+
@RestController
24+
@RequestMapping("/v1/persons")
25+
@Tags(Tag(name = "persons"), Tag(name = "alerts"))
26+
class PLPController(
27+
@Autowired val getInductionScheduleForPersonService: GetInductionScheduleForPersonService,
28+
@Autowired val auditService: AuditService,
29+
) {
30+
@GetMapping("{encodedHmppsId}/plp/inductionScheduleUpdated")
31+
@Operation(
32+
summary = "Returns plp the induction schedule associated with a person.",
33+
responses = [
34+
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found induction schedule for a person with the provided HMPPS ID."),
35+
ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]),
36+
ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]),
37+
],
38+
)
39+
fun getInductionSchedule(
40+
@Parameter(description = "A URL-encoded HMPPS identifier", example = "2008%2F0545166T") @PathVariable encodedHmppsId: String,
41+
): DataResponse<InductionSchedule> {
42+
val hmppsId = encodedHmppsId.decodeUrlCharacters()
43+
val response = getInductionScheduleForPersonService.execute(hmppsId)
44+
45+
if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
46+
throw EntityNotFoundException("Could not find person with id: $hmppsId")
47+
}
48+
auditService.createEvent("GET_INDUCTION_SCHEDULE", mapOf("hmppsId" to hmppsId))
49+
return DataResponse(response.data)
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways
2+
3+
import org.springframework.beans.factory.annotation.Autowired
4+
import org.springframework.beans.factory.annotation.Value
5+
import org.springframework.http.HttpMethod
6+
import org.springframework.stereotype.Component
7+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper
8+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper.WebClientWrapperResponse
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule
10+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
11+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
12+
13+
@Component
14+
class PLPGateway(
15+
@Value("\${services.plp.base-url}") baseUrl: String,
16+
) {
17+
private val webClient = WebClientWrapper(baseUrl)
18+
19+
@Autowired
20+
lateinit var hmppsAuthGateway: HmppsAuthGateway
21+
22+
fun getInductionSchedule(prisonerNumber: String): Response<InductionSchedule> {
23+
val result =
24+
webClient.request<InductionSchedule>(
25+
HttpMethod.GET,
26+
"/inductions/$prisonerNumber/induction-schedule",
27+
authenticationHeader(),
28+
UpstreamApi.PLP,
29+
)
30+
31+
return when (result) {
32+
is WebClientWrapperResponse.Success -> {
33+
val inductionSchedule = result.data
34+
Response(data = inductionSchedule)
35+
}
36+
37+
is WebClientWrapperResponse.Error -> {
38+
Response(
39+
data = InductionSchedule(),
40+
errors = result.errors,
41+
)
42+
}
43+
}
44+
}
45+
46+
private fun authenticationHeader(): Map<String, String> {
47+
val token = hmppsAuthGateway.getClientToken("PLP")
48+
return mapOf(
49+
"Authorization" to "Bearer $token",
50+
)
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
4+
import io.swagger.v3.oas.annotations.media.Schema
5+
import java.time.LocalDate
6+
7+
@JsonIgnoreProperties(ignoreUnknown = true)
8+
data class InductionSchedule(
9+
@Schema(
10+
description = "An ISO-8601 date representing when the Induction should be completed by.",
11+
example = "2023-09-01",
12+
)
13+
val deadlineDate: LocalDate? = null,
14+
@Schema(
15+
description = "The current status of the Induction Schedule",
16+
example = "SCHEDULED",
17+
)
18+
val scheduleStatus: String? = null,
19+
@Schema(
20+
description = "The Induction Schedule rule used to determine deadline date.",
21+
example = "NEW_PRISON_ADMISSION",
22+
)
23+
val scheduleCalculationRule: String? = null,
24+
)

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

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ enum class UpstreamApi {
1212
MANAGE_POM_CASE,
1313
RISK_MANAGEMENT_PLAN,
1414
TEST,
15+
PLP,
1516
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services
2+
3+
import org.springframework.beans.factory.annotation.Autowired
4+
import org.springframework.stereotype.Service
5+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PLPGateway
6+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule
7+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
8+
9+
@Service
10+
class GetInductionScheduleForPersonService(
11+
@Autowired val plpGateway: PLPGateway,
12+
@Autowired val getPersonService: GetPersonService,
13+
) {
14+
fun execute(hmppsId: String): Response<InductionSchedule> {
15+
val response = getPersonService.getNomisNumber(hmppsId = hmppsId)
16+
17+
response.data?.nomisNumber?.let {
18+
return plpGateway.getInductionSchedule(it)
19+
}
20+
return Response(InductionSchedule(), response.errors)
21+
}
22+
}

src/main/resources/application-dev.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ services:
1919
base-url: https://dev.offender-case-notes.service.justice.gov.uk
2020
manage-pom-case-api:
2121
base-url: https://dev.moic.service.justice.gov.uk
22+
plp:
23+
base-url: https://learningandworkprogress-api-dev.hmpps.service.justice.gov.uk
2224
hmpps-auth:
2325
base-url: https://sign-in-dev.hmpps.service.justice.gov.uk
2426
username: ${CLIENT_ID}
@@ -48,6 +50,7 @@ authorisation:
4850
- "/v1/persons/.*/risks/categories"
4951
- "/v1/persons/.*/person-responsible-officer"
5052
- "/v1/persons/.*/risk-management-plan"
53+
- "/v1/persons/.*/plp/inductionScheduleUpdated"
5154
- "/v1/hmpps/reference-data"
5255
ctrlo:
5356
- "/v1/epf/person-details/.*/[^/]*$"

src/main/resources/application-integration-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ services:
3030
base-url: http://localhost:4018
3131
probation-offender-search:
3232
base-url: http://localhost:4019
33+
plp:
34+
base-url: http://localhost:4020
3335

3436
hmpps.sqs:
3537
provider: localstack
@@ -66,6 +68,7 @@ authorisation:
6668
- "/v1/persons/.*/person-responsible-officer"
6769
- "/v1/persons/.*/risk-management-plan"
6870
- "/v1/persons/.*/cell-location"
71+
- "/v1/persons/.*/plp/inductionScheduleUpdated"
6972
- "/v1/epf/person-details/.*/[^/]*$"
7073
- "/v1/hmpps/id/nomis-number/[^/]*$"
7174
- "/v1/hmpps/id/.*/nomis-number"

src/main/resources/application-local-docker.yml

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
prisoner-offender-search.base-url: http://prism:4017
1212
probation-integration-epf.base-url: http://prism:4018
1313
probation-offender-search.base-url: http://prism:4019
14+
plp.base-url: http://prism:4020
1415

1516
authorisation:
1617
consumers:
@@ -41,8 +42,10 @@ authorisation:
4142
- "/v1/persons/.*/person-responsible-officer"
4243
- "/v1/persons/.*/risk-management-plan"
4344
- "/v1/persons/.*/cell-location"
45+
- "/v1/persons/.*/plp/inductionScheduleUpdated"
4446
- "/v1/epf/person-details/.*/[^/]*$"
4547
- "/v1/hmpps/id/nomis-number/[^/]*$"
48+
- "/v1/hmpps/id/.*/nomis-number"
4649
- "/health"
4750
- "/health/ping"
4851
- "/health/readiness"

src/main/resources/application-local.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
prisoner-offender-search.base-url: http://localhost:4017
1212
probation-integration-epf.base-url: http://localhost:4018
1313
probation-offender-search.base-url: http://localhost:4019
14+
plp.base-url: http://localhost:4020
1415

1516
hmpps.sqs:
1617
provider: localstack
@@ -48,6 +49,7 @@ authorisation:
4849
- "/v1/persons/.*/status-information"
4950
- "/v1/persons/.*/risk-management-plan"
5051
- "/v1/persons/.*/cell-location"
52+
- "/v1/persons/.*/plp/inductionScheduleUpdated"
5153
- "/v1/epf/person-details/.*/[^/]*$"
5254
- "/v1/hmpps/id/nomis-number/[^/]*$"
5355
- "/health"

src/main/resources/application-preprod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ services:
1919
base-url: https://preprod.offender-case-notes.service.justice.gov.uk
2020
manage-pom-case-api:
2121
base-url: https://preprod.moic.service.justice.gov.uk
22+
plp:
23+
base-url: https://learningandworkprogress-api-preprod.hmpps.service.justice.gov.uk
2224
hmpps-auth:
2325
base-url: https://sign-in-preprod.hmpps.service.justice.gov.uk
2426
username: ${CLIENT_ID}

src/main/resources/application-prod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ services:
1919
base-url: https://prod.offender-case-notes.service.justice.gov.uk
2020
manage-pom-case-api:
2121
base-url: https://moic.service.justice.gov.uk
22+
plp:
23+
base-url: https://learningandworkprogress-api.hmpps.service.justice.gov.uk
2224
hmpps-auth:
2325
base-url: https://sign-in.hmpps.service.justice.gov.uk
2426
username: ${CLIENT_ID}

src/main/resources/application-test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ services:
3030
base-url: http://localhost:4008
3131
manage-pom-case-api:
3232
base-url: http://localhost:4009
33+
plp:
34+
base-url: http://localhost:4010
3335

3436
hmpps.sqs:
3537
provider: localstack
@@ -67,7 +69,9 @@ authorisation:
6769
- "/v1/persons/.*/risk-management-plan"
6870
- "/v1/persons/.*/cell-location"
6971
- "/v1/persons/.*/status-information"
72+
- "/v1/persons/.*/plp/inductionScheduleUpdated"
7073
- "/v1/hmpps/id/nomis-number/[^/]*$"
74+
- "/v1/hmpps/id/.*/nomis-number"
7175
- "/health"
7276
- "/health/ping"
7377
- "/health/readiness"

src/main/resources/application.yml

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ services:
7878
base-url: http://localhost:4080
7979
manage-pom-case-api:
8080
base-url: http://localhost:4090
81+
plp:
82+
base-url: http://localhost:4100
8183

8284
sentry:
8385
traces-sample-rate: "0.05"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration.person
2+
3+
import org.junit.jupiter.api.Test
4+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
5+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
6+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration.IntegrationTestBase
7+
8+
class PLPIntegrationTest : IntegrationTestBase() {
9+
@Test
10+
fun `returns person cell location if in prison`() {
11+
callApi("$basePath/K5995YZ/plp/inductionScheduleUpdated")
12+
.andExpect(status().isOk)
13+
.andExpect(
14+
content().json(
15+
"""
16+
{"data": {
17+
"deadlineDate":"2019-08-24",
18+
"scheduleStatus":"SCHEDULED",
19+
"scheduleCalculationRule": "NEW_PRISON_ADMISSION"}}
20+
""",
21+
),
22+
)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data":
3+
{
4+
"deadlineDate":"2024-11-12",
5+
"status":"SCHEDULED"
6+
}
7+
}

0 commit comments

Comments
 (0)