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

HIA-574 -- New local image for case-notes #370

Merged
merged 20 commits into from
Feb 13, 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
9 changes: 9 additions & 0 deletions Dockerfile.setup-case-notes-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:current-alpine3.17

RUN apk update && apk add bash

COPY src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/prismMocks/case-notes-api-docs.json /case-notes-api-docs.json

RUN npm install -g @stoplight/prism-cli

CMD prism mock -p 4010 -h 0.0.0.0 /case-notes-api-docs.json
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ services:
ports:
- '4070:4010'

case-notes-api:
build:
context: .
dockerfile: Dockerfile.setup-case-notes-api
container_name: case-notes-api
healthcheck:
test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/case-notes/1234 -O /dev/null'
ports:
- '4080:4010'

local-stack-aws:
image: localstack/localstack:0.14.0
container_name: local-stack-aws
Expand Down
36 changes: 36 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,36 @@ paths:
PersonNotFoundError:
$ref: "#/components/examples/PersonNotFoundError"

/v1/persons/{HmppsId}/case-notes:
get:
summary: Returns case notes associated with a person.
parameters:
- $ref: "#/components/parameters/HmppsId"
responses:
"200":
description: Successfully found case notes for a person with the provided HMPPS ID.
content:
application/json:
schema:
type: object
properties:
data:
type: array
minItems: 0
items:
$ref: "#/components/schemas/CaseNote"
pagination:
$ref: "#/components/schemas/Pagination"
"404":
description: Failed to find case notes for a person with the provided HMPPS ID.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
examples:
PersonNotFoundError:
$ref: "#/components/examples/PersonNotFoundError"

/{TBC}/v1/persons/{Id}/accommodations:
get:
summary: FUTURE ENDPOINT - Returns accommodation and referral information associated with a person.
Expand Down Expand Up @@ -806,6 +836,12 @@ components:
ageAtRelease:
type: integer
format: int64
CaseNote:
type: object
properties:
caseNoteId:
type: string
example: 1234
CaseSentence:
required:
- date
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
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.CaseNote
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetCaseNotesForPersonService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.PaginatedResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.paginateWith

@RestController
@RequestMapping("/v1/persons")
class CaseNotesController(
@Autowired val getCaseNoteForPersonService: GetCaseNotesForPersonService,
@Autowired val auditService: AuditService,
) {
@GetMapping("{encodedHmppsId}/case-notes")
fun getCaseNotesForPerson(
@PathVariable encodedHmppsId: String,
@RequestParam(required = false, defaultValue = "1", name = "page") page: Int,
@RequestParam(required = false, defaultValue = "10", name = "perPage") perPage: Int,
): PaginatedResponse<CaseNote> {
val hmppsId = encodedHmppsId.decodeUrlCharacters()
val response = getCaseNoteForPersonService.execute(hmppsId)

if (response.hasErrorCausedBy(UpstreamApiError.Type.ENTITY_NOT_FOUND, causedBy = UpstreamApi.CASE_NOTES)) {
throw EntityNotFoundException("Could not find person with id: $hmppsId")
}
auditService.createEvent("GET_CASE_NOTES", "Person case notes with hmpps id: $hmppsId has been retrieved")
return response.data.paginateWith(page, perPage)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpMethod
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.CaseNote
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisPageCaseNote

@Component
class CaseNotesGateway(
@Value("\${services.case-notes.base-url}") baseUrl: String,
) {
private val webClient = WebClientWrapper(baseUrl)

@Autowired
lateinit var hmppsAuthGateway: HmppsAuthGateway

fun getCaseNotesForPerson(id: String): Response<List<CaseNote>> {
val result =
webClient.request<NomisPageCaseNote>(
HttpMethod.GET,
"/case-notes/$id",
authenticationHeader(),
UpstreamApi.CASE_NOTES,
)

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

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

private fun authenticationHeader(): Map<String, String> {
val token = hmppsAuthGateway.getClientToken("CaseNotes")

return mapOf(
"Authorization" to "Bearer $token",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps
data class CaseNote(
val caseNoteId: String? = null,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

enum class UpstreamApi {
NOMIS, PRISONER_OFFENDER_SEARCH, PROBATION_OFFENDER_SEARCH, NDELIUS, ASSESS_RISKS_AND_NEEDS, ADJUDICATIONS, CVL, TEST
NOMIS, PRISONER_OFFENDER_SEARCH, PROBATION_OFFENDER_SEARCH, NDELIUS, ASSESS_RISKS_AND_NEEDS, ADJUDICATIONS, CVL, CASE_NOTES, TEST
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis

data class NomisCaseNote(
val caseNoteId: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis

import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.CaseNote

data class NomisPageCaseNote(
val content: List<NomisCaseNote> = listOf(),
) {
fun toCaseNotes(): List<CaseNote> = this.content.map {
CaseNote(caseNoteId = it.caseNoteId)
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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.CaseNotesGateway
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.CaseNote
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response

@Service
class GetCaseNotesForPersonService(
@Autowired val caseNotesGateway: CaseNotesGateway,
@Autowired val getPersonService: GetPersonService,
) {
fun execute(hmppsId: String): Response<List<CaseNote>> {
val personResponse = getPersonService.execute(hmppsId = hmppsId)
val nomisNumber = personResponse.data?.identifiers?.nomisNumber

var caseNotes: Response<List<CaseNote>> = Response(data = emptyList())

if (nomisNumber != null) {
caseNotes = caseNotesGateway.getCaseNotesForPerson(id = nomisNumber)
}

return Response(
data = caseNotes.data,
errors = personResponse.errors + caseNotes.errors,
)
}
}
3 changes: 3 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
base-url: https://manage-adjudications-api-dev.hmpps.service.justice.gov.uk
create-and-vary-licence:
base-url: https://create-and-vary-a-licence-api-dev.hmpps.service.justice.gov.uk
case-notes:
base-url: https://dev.offender-case-notes.service.justice.gov.uk
hmpps-auth:
base-url: https://sign-in-dev.hmpps.service.justice.gov.uk
username: ${CLIENT_ID}
Expand All @@ -37,6 +39,7 @@ authorisation:
- "/v1/persons/.*/risks"
- "/v1/persons/.*/adjudications"
- "/v1/persons/.*/licences/conditions"
- "/v1/persons/.*/case-notes"
ctrlo:
- "/v1/epf/person-details/.*/.*"
kubernetes-health-check-client:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-local-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
base-url: http://adjudications-api:4010
create-and-vary-licence:
base-url: http://create-and-vary-licence-api:4010
case-notes:
base-url: http://case-notes-api:4010
hmpps-auth:
base-url: http://hmpps-auth:8080

Expand All @@ -34,6 +36,7 @@ authorisation:
- "/v1/persons/.*/needs"
- "/v1/persons/.*/risks"
- "/v1/persons/.*/reported-adjudications"
- "/v1/persons/.*/case-notes"
- "/v1/epf/person-details/.*/.*"
- "/health"
- "/health/ping"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
base-url: http://localhost:4045
create-and-vary-licence:
base-url: http://localhost:4070
case-notes:
base-url: http://localhost:4080

hmpps.sqs:
provider: localstack
Expand All @@ -40,6 +42,7 @@ authorisation:
- "/v1/persons/.*/needs"
- "/v1/persons/.*/risks"
- "/v1/persons/.*/reported-adjudications"
- "/v1/persons/.*/case-notes"
- "/v1/epf/person-details/.*/.*"
- "/health"
- "/health/ping"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
base-url: https://manage-adjudications-api-preprod.hmpps.service.justice.gov.uk
create-and-vary-licence:
base-url: https://create-and-vary-a-licence-api-preprod.hmpps.service.justice.gov.uk
case-notes:
base-url: https://preprod.offender-case-notes.service.justice.gov.uk
hmpps-auth:
base-url: https://sign-in-preprod.hmpps.service.justice.gov.uk
username: ${CLIENT_ID}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
base-url: https://manage-adjudications-api-prod.hmpps.service.justice.gov.uk
create-and-vary-licence:
base-url: https://create-and-vary-a-licence-api-prod.hmpps.service.justice.gov.uk
case-notes:
base-url: https://prod.offender-case-notes.service.justice.gov.uk
hmpps-auth:
base-url: https://sign-in.hmpps.service.justice.gov.uk
username: ${CLIENT_ID}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
base-url: http://localhost:4006
create-and-vary-licence:
base-url: http://localhost:4007
case-notes:
base-url: http://localhost:4008

hmpps.sqs:
provider: localstack
Expand All @@ -52,9 +54,9 @@ authorisation:
- "/v1/epf/person-details/.*/.*"
- "/v1/persons/.*/adjudications"
- "/v1/persons/.*/licences/conditions"
- "/v1/persons/.*/case-notes"
- "/health"
- "/health/ping"
- "/health/readiness"
- "/health/liveness"
- "/info"
-
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ services:
base-url: http://localhost:4045
create-and-vary-licence:
base-url: http://localhost:4070
case-notes:
base-url: http://localhost:4080

sentry:
traces-sample-rate: "0.05"
Expand Down
Loading
Loading