Skip to content

Commit

Permalink
API method to return the Review schedule (#528)
Browse files Browse the repository at this point in the history
* API method to return the Review schedule

* API method to return the Review schedule

* API method to return the Review schedule

* added permissions
  • Loading branch information
stevomcallister authored Nov 25, 2024
1 parent 4eb82bc commit 1caa0b6
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ReviewSchedule
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetInductionScheduleForPersonService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetReviewScheduleForPersonService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService

@RestController
@RequestMapping("/v1/persons")
@Tags(Tag(name = "persons"), Tag(name = "alerts"))
class PLPController(
@Autowired val getInductionScheduleForPersonService: GetInductionScheduleForPersonService,
@Autowired val getReviewScheduleForPersonService: GetReviewScheduleForPersonService,
@Autowired val auditService: AuditService,
) {
@GetMapping("{encodedHmppsId}/plp-induction-schedule")
@GetMapping("{hmppsId}/plp-induction-schedule")
@Operation(
summary = "Returns plp the induction schedule associated with a person.",
responses = [
Expand All @@ -37,9 +39,8 @@ class PLPController(
],
)
fun getInductionSchedule(
@Parameter(description = "A URL-encoded HMPPS identifier", example = "2008%2F0545166T") @PathVariable encodedHmppsId: String,
@Parameter(description = "A HMPPS id", example = "A123123") @PathVariable hmppsId: String,
): DataResponse<InductionSchedule> {
val hmppsId = encodedHmppsId.decodeUrlCharacters()
val response = getInductionScheduleForPersonService.execute(hmppsId)

if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
Expand All @@ -48,4 +49,25 @@ class PLPController(
auditService.createEvent("GET_INDUCTION_SCHEDULE", mapOf("hmppsId" to hmppsId))
return DataResponse(response.data)
}

@GetMapping("{hmppsId}/plp-review-schedule")
@Operation(
summary = "Returns plp the review schedule associated with a person.",
responses = [
ApiResponse(responseCode = "200", useReturnTypeSchema = true, description = "Successfully found induction schedule for a person with the provided HMPPS ID."),
ApiResponse(responseCode = "404", content = [Content(schema = Schema(ref = "#/components/schemas/PersonNotFound"))]),
ApiResponse(responseCode = "500", content = [Content(schema = Schema(ref = "#/components/schemas/InternalServerError"))]),
],
)
fun getReviewSchedule(
@Parameter(description = "A HmppsId ", example = "A123123") @PathVariable hmppsId: String,
): DataResponse<ReviewSchedule> {
val response = getReviewScheduleForPersonService.execute(hmppsId)

if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
throw EntityNotFoundException("Could not find person with id: $hmppsId")
}
auditService.createEvent("GET_REVIEW_SCHEDULE", mapOf("hmppsId" to hmppsId))
return DataResponse(response.data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrap
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper.WebClientWrapperResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ReviewSchedule
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi

@Component
Expand Down Expand Up @@ -43,6 +44,30 @@ class PLPGateway(
}
}

fun getReviewSchedule(prisonerNumber: String): Response<ReviewSchedule> {
val result =
webClient.request<ReviewSchedule>(
HttpMethod.GET,
"/inductions/$prisonerNumber/review-schedule",
authenticationHeader(),
UpstreamApi.PLP,
)

return when (result) {
is WebClientWrapperResponse.Success -> {
val inductionSchedule = result.data
Response(data = inductionSchedule)
}

is WebClientWrapperResponse.Error -> {
Response(
data = ReviewSchedule(),
errors = result.errors,
)
}
}
}

private fun authenticationHeader(): Map<String, String> {
val token = hmppsAuthGateway.getClientToken("PLP")
return mapOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDate

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.USE_DEFAULTS)
data class ReviewSchedule(
@Schema(
description = "An ISO-8601 date representing when the Review should be completed by.",
example = "2023-09-01",
)
val deadlineDate: LocalDate? = null,
val nomisNumber: String? = null,
val description: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PLPGateway
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ReviewSchedule
import java.time.LocalDate

@Service
class GetReviewScheduleForPersonService(
@Autowired val plpGateway: PLPGateway,
@Autowired val getPersonService: GetPersonService,
) {
fun execute(hmppsId: String): Response<ReviewSchedule> {
val response = getPersonService.getNomisNumber(hmppsId = hmppsId)

response.data?.nomisNumber?.let {
return Response(
ReviewSchedule(
deadlineDate = LocalDate.now().plusMonths(1),
nomisNumber = it,
description = "This is a hardcoded response.",
),
)
// return plpGateway.getReviewSchedule(it) // <-- this will be call the PLP service once the downstream code is written
}
return Response(ReviewSchedule(), response.errors)
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ authorisation:
- "/v1/persons/.*/person-responsible-officer"
- "/v1/persons/.*/risk-management-plan"
- "/v1/persons/.*/plp-induction-schedule"
- "/v1/persons/.*/plp-review-schedule"
- "/v1/hmpps/reference-data"
ctrlo:
- "/v1/epf/person-details/.*/[^/]*$"
Expand Down Expand Up @@ -112,5 +113,6 @@ authorisation:
- "/v1/persons/[^/]*$"
meganexus:
- "/v1/persons/.*/plp-induction-schedule"
- "/v1/persons/.*/plp-review-schedule"
- "/v1/hmpps/id/by-nomis-number/[^/]*$"
- "/v1/hmpps/id/nomis-number/by-hmpps-id/[^/]*$"
1 change: 1 addition & 0 deletions src/main/resources/application-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ authorisation:
- "/v1/persons/.*/risk-management-plan"
- "/v1/persons/.*/cell-location"
- "/v1/persons/.*/plp-induction-schedule"
- "/v1/persons/.*/plp-review-schedule"
- "/v1/epf/person-details/.*/[^/]*$"
- "/v1/hmpps/id/nomis-number/[^/]*$"
- "/v1/hmpps/id/by-nomis-number/[^/]*$"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-local-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ authorisation:
- "/v1/persons/.*/risk-management-plan"
- "/v1/persons/.*/cell-location"
- "/v1/persons/.*/plp-induction-schedule"
- "/v1/persons/.*/plp-review-schedule"
- "/v1/epf/person-details/.*/[^/]*$"
- "/v1/hmpps/id/nomis-number/[^/]*$"
- "/v1/hmpps/id/by-nomis-number/[^/]*$"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ authorisation:
- "/v1/persons/.*/risk-management-plan"
- "/v1/persons/.*/cell-location"
- "/v1/persons/.*/plp-induction-schedule"
- "/v1/persons/.*/plp-review-schedule"
- "/v1/epf/person-details/.*/[^/]*$"
- "/v1/hmpps/id/nomis-number/[^/]*$"
- "/v1/hmpps/id/by-nomis-number/[^/]*$"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ authorisation:
- "/v1/persons/.*/cell-location"
- "/v1/persons/.*/status-information"
- "/v1/persons/.*/plp-induction-schedule"
- "/v1/persons/.*/plp-review-schedule"
- "/v1/hmpps/id/nomis-number/[^/]*$"
- "/v1/hmpps/id/.*/nomis-number"
- "/v1/hmpps/id/by-nomis-number/[^/]*$"
Expand Down

0 comments on commit 1caa0b6

Please sign in to comment.