Skip to content

Commit 0663e7a

Browse files
author
popey2700
committed
Fix merge conflicts
2 parents b4da70c + a7d9d48 commit 0663e7a

34 files changed

+1394
-179
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ ecr.repo
7171
dps-gradle-spring-boot-suppressions.xml
7272
sonar-project.properties
7373

74+
# localstack
75+
localstack/cache
76+
7477
# Helm
7578
**/Chart.lock
7679

docs/guides/setting-up-a-new-consumer.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ per environment.
1212
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
1313
- [Access to Cloud Platform’s Kubernetes cluster](https://user-guide.cloud-platform.service.justice.gov.uk/documentation/getting-started/kubectl-config.html#installing-kubectl)
1414

15+
As a pre-requisite to create a client certificate by running the script below, please ensure that:
16+
- You are logged in so that you can access AWS resources via the CLI.
17+
- Verify that you have all your AWS credentials ready by opening the config file in the ".aws" directory.
18+
1519
## Create a client certificate
1620

17-
1. Run the [generate-client-certificate.sh](/scripts/client_certificates/generate.sh) script with the name of the environment and client.
21+
Run the [generate-client-certificate.sh](/scripts/client_certificates/generate.sh) script with the name of the environment and client.
1822

1923
```bash
2024
make generate-client-certificate
2125
```
22-
2326
This will output three files in the ./scripts/client_certificates directory:
2427

2528
- a private key e.g. `dev-nhs-client.key`
@@ -114,3 +117,14 @@ kubectl -n hmpps-integration-api-[environment] get secrets [your queue secret na
114117
5. Create new [Cloud Platform Environments GitHub repository](https://github.com/ministryofjustice/cloud-platform-environments/tree/main) branch
115118
6. Update terraform to load the secret value from AWS and update filter_policy value. Follow [Example](https://github.com/ministryofjustice/cloud-platform-environments/pull/22111/files). Note: The name of aws_secretsmanager_secret module has to be same as the secret name created from step 4/5 above.
116119
7. Follow steps 3-8 in [Create an API key](#create-an-api-key) to merge branch to main.
120+
121+
## Create a new endpoint for a client
122+
123+
### Create basic infrastructure
124+
Within the [Cloud Platform Environments GitHub repository](https://github.com/ministryofjustice/cloud-platform-environments/tree/main) and the namespace of the environment:
125+
126+
1. Create a branch.
127+
2. Add a new API Gateway resource, a SQS method, a SQS method response, and an integration. Example: [api_gateway.tf](https://github.com/ministryofjustice/cloud-platform-environments/pull/22695/files)
128+
3. Ensure that all the permissions are up-to-date and add a new role and policy for your new resource. Example: [iam.tf](https://github.com/ministryofjustice/cloud-platform-environments/pull/22787/files#diff-a376622fa4a4c2fd9404d5ee4221487259264608a0cbe36b99c150c472558f29)
129+
4. Check that the integration is pointing to the right queue. Example: [api_gateway.tf](https://github.com/ministryofjustice/cloud-platform-environments/pull/22795/files)
130+
5. Deploy and test (do not use Postman, rather use a GET cURL command with "x-api-key" as your header.)

openapi.yml

+110-67
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ paths:
9696
type: object
9797
properties:
9898
data:
99+
type: object
100+
properties:
101+
prisonerOffenderSearch:
102+
$ref: "#/components/schemas/Person"
103+
probationOffenderSearch:
99104
$ref: "#/components/schemas/Person"
100105
"404":
101106
description: Failed to find a person with the provided HMPPS ID.
@@ -605,7 +610,7 @@ paths:
605610
NoQueryParametersBadRequestError:
606611
$ref: "#/components/examples/InternalServerError"
607612

608-
/v1/persons/{hmppsId}/risks:
613+
/v1/persons/{hmppsId}/risks/serious-harm:
609614
get:
610615
tags:
611616
- risks
@@ -640,7 +645,41 @@ paths:
640645
examples:
641646
NoQueryParametersBadRequestError:
642647
$ref: "#/components/examples/InternalServerError"
643-
648+
/v1/persons/{hmppsId}/risk-management-plan:
649+
get:
650+
tags:
651+
- risks
652+
summary: Returns a list of Risk Management Plans created for the person with the provided HMPPS ID.
653+
parameters:
654+
- $ref: "#/components/parameters/HmppsId"
655+
responses:
656+
"200":
657+
description: Successfully found risk management plans for a person with the provided HMPPS ID.
658+
content:
659+
application/json:
660+
schema:
661+
type: object
662+
properties:
663+
data:
664+
$ref: "#/components/schemas/RiskManagementPlan"
665+
"404":
666+
description: Failed to find risk management plans for a person with the provided HMPPS ID.
667+
content:
668+
application/json:
669+
schema:
670+
$ref: "#/components/schemas/Error"
671+
examples:
672+
PersonNotFoundError:
673+
$ref: "#/components/examples/PersonNotFoundError"
674+
"500":
675+
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
676+
content:
677+
application/json:
678+
schema:
679+
$ref: "#/components/schemas/Error"
680+
examples:
681+
NoQueryParametersBadRequestError:
682+
$ref: "#/components/examples/InternalServerError"
644683
/v1/epf/person-details/{hmppsId}/{eventNumber}:
645684
get:
646685
summary: Probation case information for the Effective Proposals Framework service
@@ -914,23 +953,6 @@ paths:
914953
NoQueryParametersBadRequestError:
915954
$ref: "#/components/examples/InternalServerError"
916955

917-
/{TBC}/v1/persons/{Id}/key-workers:
918-
get:
919-
summary: FUTURE ENDPOINT - Returns responsible officer history, transfer history and consolidated transfer review associated with a person.
920-
parameters:
921-
- $ref: "#/components/parameters/Id"
922-
responses:
923-
"200":
924-
description: Success.
925-
"500":
926-
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
927-
content:
928-
application/json:
929-
schema:
930-
$ref: "#/components/schemas/Error"
931-
examples:
932-
NoQueryParametersBadRequestError:
933-
$ref: "#/components/examples/InternalServerError"
934956

935957
/{TBC}/v1/persons/{Id}/prisoner-visits:
936958
get:
@@ -968,42 +990,6 @@ paths:
968990
NoQueryParametersBadRequestError:
969991
$ref: "#/components/examples/InternalServerError"
970992

971-
/{TBC}/v1/persons/{Id}/security:
972-
get:
973-
summary: FUTURE ENDPOINT - Returns security information such as prisoner non-associations and prisoner incidents for a person.
974-
parameters:
975-
- $ref: "#/components/parameters/Id"
976-
responses:
977-
"200":
978-
description: Success.
979-
"500":
980-
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
981-
content:
982-
application/json:
983-
schema:
984-
$ref: "#/components/schemas/Error"
985-
examples:
986-
NoQueryParametersBadRequestError:
987-
$ref: "#/components/examples/InternalServerError"
988-
989-
/{TBC}/v1/persons/{Id}/special-needs:
990-
get:
991-
summary: FUTURE ENDPOINT - Returns special needs such as drugs test summaries, drug history and drugs test lists associated with a person.
992-
parameters:
993-
- $ref: "#/components/parameters/Id"
994-
responses:
995-
"200":
996-
description: Success.
997-
"500":
998-
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
999-
content:
1000-
application/json:
1001-
schema:
1002-
$ref: "#/components/schemas/Error"
1003-
examples:
1004-
NoQueryParametersBadRequestError:
1005-
$ref: "#/components/examples/InternalServerError"
1006-
1007993
components:
1008994
parameters:
1009995
HmppsId:
@@ -1775,45 +1761,44 @@ components:
17751761
firstName:
17761762
type: string
17771763
example: Arthur
1778-
description: first name
1764+
description: First name
17791765
middleName:
17801766
type: string
17811767
example: John
17821768
nullable: true
1783-
description: middle name
1769+
description: Middle name
17841770
lastName:
17851771
type: string
17861772
example: Morgan
1787-
description: last name
1773+
description: Last name
17881774
dateOfBirth:
17891775
type: string
17901776
format: date
17911777
example: 1965-12-01
1792-
description: date of birth
1778+
description: Date of birth
17931779
gender:
17941780
type: string
17951781
example: Male
1796-
description: gender
1782+
description: Gender
17971783
ethnicity:
17981784
type: string
17991785
example: "White: Eng./Welsh/Scot./N.Irish/British"
1800-
description: ethnicity
1786+
nullable: true
1787+
description: Ethnicity
18011788
aliases:
18021789
type: array
1803-
minItems: 0
18041790
items:
18051791
$ref: "#/components/schemas/Alias"
1806-
description: list of aliases
1792+
description: List of aliases
18071793
identifiers:
18081794
$ref: "#/components/schemas/Identifiers"
18091795
pncId:
18101796
type: string
1811-
example: 2008/0545166T
18121797
description: An identifier from the Police National Computer (PNC)
18131798
hmppsId:
18141799
type: string
1815-
example: X00001
1816-
description: Currently a hmppsId is a CRN identifier however this will change in the future to be a new unique Hmpps identifier
1800+
example: 2008/0545166T
1801+
description: Hmpps identifier
18171802
contactDetails:
18181803
$ref: "#/components/schemas/ContactDetails"
18191804
PersonResponsibleOfficerName:
@@ -1955,7 +1940,6 @@ components:
19551940
nullable: true
19561941
prison:
19571942
$ref: "#/components/schemas/Prison"
1958-
19591943
Punishment:
19601944
type: object
19611945
properties:
@@ -2504,6 +2488,65 @@ components:
25042488
type: string
25052489
example: "Risk of self harm concerns due to ..."
25062490
description: Supporting comments for any current concerns
2491+
RiskManagementPlan:
2492+
type: object
2493+
properties:
2494+
assessmentId:
2495+
type: string
2496+
example: "123456"
2497+
description: The unique ID of the risk management plan
2498+
dateCompleted:
2499+
type: string
2500+
example: "2024-05-04T01:04:20"
2501+
description: The date that the risk management plan was completed
2502+
initiationDate:
2503+
type: string
2504+
example: "2024-05-04T01:04:20"
2505+
description: The date of plan initiation
2506+
assessmentStatus:
2507+
type: string
2508+
example: "COMPLETE"
2509+
description: The status of the plan
2510+
assessmentType:
2511+
type: string
2512+
example: "string"
2513+
description: The type of assessment
2514+
keyInformationCurrentSituation:
2515+
type: string
2516+
example: "string"
2517+
description: Key information about the current situation of the subject being assessed
2518+
furtherConsiderationsCurrentSituation:
2519+
type: string
2520+
example: "string"
2521+
description: Further considerations about the situation of the subject being assessed
2522+
supervision:
2523+
type: string
2524+
example: "string"
2525+
description: Who they see, when and why, any support they get from their community, family and friends, and how well they're desisting from problematic behaviour
2526+
monitoringAndControl:
2527+
type: string
2528+
example: "string"
2529+
description: Information on restrictions in place to prevent reoffending, what steps have been taken to monitor potential reoffending, including license conditions, community order requirements, PPM restrictions and such.
2530+
interventionsAndTreatment:
2531+
type: string
2532+
example: "string"
2533+
description: Interventions delivered to develop controls and protective factors to reduce risk of reoffending, including practical support, requirements to support interventions and details of who and where these interventions will be administered.
2534+
victimSafetyPlanning:
2535+
type: string
2536+
example: "string"
2537+
description: Restrictions in place to specifically protect victims of, adults known to, and children potentially at risk from the offender.
2538+
contingencyPlans:
2539+
type: string
2540+
example: "string"
2541+
description: Future plans in the form "If X happens, we will do Y...." for if parts of the risk management plan break down or requirements or restrictions are breached by the offender.
2542+
latestSignLockDate:
2543+
type: string
2544+
example: "2024-05-04T01:04:20"
2545+
description: An assessment is considered 'Signed and locked' once it is signed by the assessor, making the plan read-only. This is the date the plan has been signed by the assessor.
2546+
latestCompleteDate:
2547+
type: string
2548+
example: "2024-05-04T01:04:20"
2549+
description: Once a countersignature has been applied to the plan, the plan is considered complete. This is the date the plan has been countersigned.
25072550
OtherRisks:
25082551
type: object
25092552
properties:

scripts/client_certificates/generate.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ upload_backup() {
5151
aws s3api put-object --bucket "$bucket" --key "$client_folder/" --acl private
5252
aws s3 cp "$file_path" "s3://$path/client.pem"
5353
aws s3 cp ./"$environment"-"$client"-client.pem "s3://$path/client.pem"
54-
aws s3 cp ./truststore.key "s3://$path/truststore.key"
55-
aws s3 cp ./truststore.pem "s3://$path/truststore.pem"
54+
aws s3 cp ./"$environment"-"$client"-client.csr "s3://$path/client.csr"
55+
aws s3 cp ./"$environment"-"$client"-client.key "s3://$path/client.key"
5656

5757
aws configure set aws_access_key_id ""
5858
aws configure set aws_secret_access_key ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1
2+
3+
import org.springframework.beans.factory.annotation.Autowired
4+
import org.springframework.boot.context.properties.EnableConfigurationProperties
5+
import org.springframework.web.bind.annotation.PathVariable
6+
import org.springframework.web.bind.annotation.RequestMapping
7+
import org.springframework.web.bind.annotation.RequestParam
8+
import org.springframework.web.bind.annotation.RestController
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.config.AuthorisationConfig
10+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
11+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters
12+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.RiskManagementPlan
13+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
14+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
15+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetRiskManagementPlansForCrnService
16+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService
17+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.PaginatedResponse
18+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.paginateWith
19+
20+
@RestController
21+
@EnableConfigurationProperties(AuthorisationConfig::class)
22+
class RiskManagementController(
23+
@Autowired val getRiskManagementPlansForCrnService: GetRiskManagementPlansForCrnService,
24+
@Autowired val auditService: AuditService,
25+
) {
26+
@RequestMapping("/v1/persons/{encodedHmppsId}/risk-management-plan")
27+
fun getRiskManagementPlans(
28+
@PathVariable encodedHmppsId: String,
29+
@RequestParam(required = false, defaultValue = "1", name = "page") page: Int,
30+
@RequestParam(required = false, defaultValue = "10", name = "perPage") perPage: Int,
31+
): PaginatedResponse<RiskManagementPlan> {
32+
val hmppsId = encodedHmppsId.decodeUrlCharacters()
33+
val response = getRiskManagementPlansForCrnService.execute(hmppsId)
34+
if (response.data.isNullOrEmpty()) {
35+
if (response.hasErrorCausedBy(UpstreamApiError.Type.ENTITY_NOT_FOUND, causedBy = UpstreamApi.RISK_MANAGEMENT_PLAN)) {
36+
throw EntityNotFoundException("Could not find person with id: $hmppsId")
37+
}
38+
return emptyList<RiskManagementPlan>().paginateWith(page, perPage)
39+
}
40+
41+
auditService.createEvent("GET_RISK_MANAGEMENT_PLANS", mapOf("hmppsId" to hmppsId))
42+
return response.data.paginateWith(page, perPage)
43+
}
44+
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonController.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,17 @@ class PersonController(
6161
@GetMapping("{encodedHmppsId}")
6262
fun getPerson(
6363
@PathVariable encodedHmppsId: String,
64-
): Map<String, Person?> {
64+
): Map<String, Map<String, Person?>> {
6565
val hmppsId = encodedHmppsId.decodeUrlCharacters()
66-
val response = getPersonService.execute(hmppsId)
66+
val response = getPersonService.getCombinedDataForPerson(hmppsId)
6767

6868
if (response.hasErrorCausedBy(ENTITY_NOT_FOUND, causedBy = UpstreamApi.PROBATION_OFFENDER_SEARCH)) {
6969
throw EntityNotFoundException("Could not find person with id: $hmppsId")
7070
}
7171

7272
auditService.createEvent("GET_PERSON_DETAILS", mapOf("hmppsId" to hmppsId))
73-
return mapOf("data" to response.data)
73+
val data = response.data.mapValues { it.value }
74+
return mapOf("data" to data)
7475
}
7576

7677
@GetMapping("{encodedHmppsId}/images")

0 commit comments

Comments
 (0)