Skip to content

Commit 9157a8d

Browse files
authored
Merge branch 'main' into dependabot/pip/scripts/data_analysis/requests-2.32.0
2 parents 3a4f4d5 + e914607 commit 9157a8d

32 files changed

+199
-155
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ __pycache__/
8686
*.key
8787
*.csr
8888
*.pem
89+
90+
# Localstack
91+
localstack/cache

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ services:
112112
dockerfile: Dockerfile.setup-create-and-vary-a-licence-api
113113
container_name: create-and-vary-licence-api
114114
healthcheck:
115-
test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/public/licences/id/abc -O /dev/null'
115+
test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/public/licences/id/123 -O /dev/null'
116116
ports:
117117
- '4070:4010'
118118

docs/adr/0003-manually-manage-openapi-file.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Accepted
1111
The [OpenAPI specification](https://spec.openapis.org/oas/latest.html) is a standard for describing REST APIs and
1212
[Swagger UI](https://swagger.io/tools/swagger-ui/) is used to visualise and interact with a specification file in more
1313
user-friendly manner. These are used widely used within HMPPS to document APIs,
14-
e.g. [Prison API's OpenAPI specification](https://api.prison.service.justice.gov.uk/v3/api-docs)
15-
and [Prison API's Swagger UI](https://api.prison.service.justice.gov.uk/swagger-ui/index.html). This is achieved by
14+
e.g. [Prison API's OpenAPI specification](https://prison-api.prison.service.justice.gov.uk/v3/api-docs)
15+
and [Prison API's Swagger UI](https://prison-api.prison.service.justice.gov.uk/swagger-ui/index.html). This is achieved by
1616
using the [SpringDoc OpenAPI library](https://springdoc.org) and annotating the codebase which the library then uses to
1717
expose two endpoints: one for the OpenAPI specification in JSON format and another for Swagger UI.
1818

openapi.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,10 @@ components:
16711671
example:
16721672
- "2018-02-10"
16731673
- "2019-02-10"
1674+
courtName:
1675+
type: string
1676+
description: The court name
1677+
example: "London Magistrates Court"
16741678
description:
16751679
type: string
16761680
example: Commit an act / series of acts with intent to pervert the course of public justice

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CreateAndVaryLicenceGateway(
4545
}
4646
}
4747

48-
fun getLicenceConditions(id: String): Response<List<LicenceCondition>> {
48+
fun getLicenceConditions(id: Int): Response<List<LicenceCondition>> {
4949
val result =
5050
webClient.request<CvlLicence>(
5151
HttpMethod.GET,

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
1111
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
1212
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
1313
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
14+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.ContactDetailsWithAddress
1415
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.Offender
1516

1617
@Component
@@ -116,8 +117,26 @@ class ProbationOffenderSearchGateway(
116117
}
117118

118119
fun getAddressesForPerson(hmppsId: String): Response<List<Address>> {
119-
val offender = getOffender(hmppsId)
120-
return Response(data = offender.data?.contactDetails?.addresses.orEmpty().map { it.toAddress() }, errors = offender.errors)
120+
val result =
121+
webClient.requestList<ContactDetailsWithAddress>(
122+
HttpMethod.POST,
123+
"/search",
124+
authenticationHeader(),
125+
UpstreamApi.PROBATION_OFFENDER_SEARCH,
126+
mapOf("crn" to hmppsId),
127+
)
128+
129+
return when (result) {
130+
is WebClientWrapperResponse.Success -> {
131+
return Response(result.data.firstOrNull()?.contactDetails?.addresses.orEmpty().map { it.toAddress() })
132+
}
133+
is WebClientWrapperResponse.Error -> {
134+
Response(
135+
data = emptyList(),
136+
errors = result.errors,
137+
)
138+
}
139+
}
121140
}
122141

123142
private fun authenticationHeader(): Map<String, String> {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps
22

3-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.Address
4-
53
data class ContactDetailsWithEmailAndPhone(
6-
val addresses: List<Address>?,
74
val phoneNumbers: List<PhoneNumber>?,
85
val emails: List<String>?,
96
)

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class Offence(
88
val cjsCode: String? = null,
99
val hoCode: String? = null,
1010
val courtDates: List<LocalDate?> = listOf(),
11+
val courtName: String? = null,
1112
val description: String? = null,
1213
val endDate: LocalDate? = null,
1314
val startDate: LocalDate? = null,

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ data class NDeliusAdditionalOffence(
1010
val code: String? = null,
1111
val date: String? = null,
1212
) {
13-
fun toOffence(courtDates: List<LocalDate>): Offence =
13+
fun toOffence(
14+
courtDates: List<LocalDate>,
15+
courtName: String?,
16+
): Offence =
1417
Offence(
1518
serviceSource = UpstreamApi.NDELIUS,
1619
systemSource = SystemSource.PROBATION_SYSTEMS,
1720
cjsCode = null,
1821
hoCode = this.code,
1922
courtDates = courtDates,
23+
courtName = courtName,
2024
endDate = null,
2125
startDate = if (!this.date.isNullOrEmpty()) LocalDate.parse(this.date) else null,
2226
statuteCode = null,

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

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.ndelius
22

33
data class NDeliusCourtAppearance(
44
val date: CharSequence? = null,
5+
val court: String? = null,
56
)

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ data class NDeliusMainOffence(
1010
val code: String? = null,
1111
val date: String? = null,
1212
) {
13-
fun toOffence(courtDates: List<LocalDate>): Offence =
13+
fun toOffence(
14+
courtDates: List<LocalDate>,
15+
courtName: String?,
16+
): Offence =
1417
Offence(
1518
serviceSource = UpstreamApi.NDELIUS,
1619
systemSource = SystemSource.PROBATION_SYSTEMS,
1720
cjsCode = null,
1821
hoCode = this.code,
1922
courtDates = courtDates,
23+
courtName = courtName,
2024
endDate = null,
2125
startDate = LocalDate.parse(this.date),
2226
statuteCode = null,

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ data class NDeliusSupervision(
1717
) {
1818
fun toOffences(): List<Offence> {
1919
val courtDates = this.courtAppearances.mapNotNull { LocalDate.parse(it.date, DateTimeFormatter.ISO_OFFSET_DATE_TIME) }
20-
return listOf(this.mainOffence.toOffence(courtDates)) + this.additionalOffences.map { it.toOffence(courtDates) }
20+
val courtName = this.courtAppearances.firstOrNull()?.court
21+
val mainOffence = this.mainOffence.toOffence(courtDates, courtName)
22+
val additionalOffences = this.additionalOffences.map { it.toOffence(courtDates, courtName) }
23+
return listOf(mainOffence) + additionalOffences
2124
}
2225

2326
fun toSentence(): Sentence {

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch
22

3-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
43
import java.time.LocalDate
4+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address as HmppsAddress
5+
6+
data class ContactDetailsWithAddress(
7+
val contactDetails: Addresses? = null,
8+
)
9+
10+
data class Addresses(
11+
val addresses: List<Address>? = listOf(),
12+
)
513

614
data class Address(
715
val addressNumber: String?,
@@ -18,7 +26,7 @@ data class Address(
1826
val notes: String?,
1927
) {
2028
fun toAddress() =
21-
Address(
29+
HmppsAddress(
2230
country = null,
2331
county = this.county,
2432
endDate = this.to,
@@ -39,7 +47,7 @@ data class Address(
3947
val description: String?,
4048
) {
4149
fun toAddressType() =
42-
Address.Type(
50+
HmppsAddress.Type(
4351
code = this.code,
4452
description = this.description ?: this.code,
4553
)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch
22

3-
open class ContactDetails(
4-
open val addresses: List<Address>? = listOf(),
5-
)
3+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PhoneNumber
4+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactDetailsWithEmailAndPhone as PersonContactDetails
5+
6+
class ContactDetails(
7+
val phoneNumbers: List<PhoneNumber>?,
8+
val emailAddresses: List<String>?,
9+
) {
10+
fun toContactDetails(): PersonContactDetails =
11+
PersonContactDetails(
12+
phoneNumbers = this.phoneNumbers,
13+
emails = this.emailAddresses,
14+
)
15+
}

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

-17
This file was deleted.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class Offender(
1313
val gender: String? = null,
1414
val offenderProfile: OffenderProfile = OffenderProfile(),
1515
val offenderAliases: List<OffenderAlias> = listOf(),
16-
val contactDetails: ContactDetailsWithEmailAndPhone? = null,
16+
val contactDetails: ContactDetails? = null,
1717
val otherIds: OtherIds = OtherIds(),
1818
val age: Number = 0,
1919
) {
@@ -34,7 +34,7 @@ data class Offender(
3434
),
3535
pncId = otherIds.pncNumber,
3636
hmppsId = otherIds.crn,
37-
contactDetails = this.contactDetails?.toContactdetails(),
37+
contactDetails = this.contactDetails?.toContactDetails(),
3838
)
3939

4040
fun toPersonProtectedCharacteristics(): PersonProtectedCharacteristics =

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionService.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ class GetLicenceConditionService(
2121
if (crn != null) {
2222
licences = createAndVaryLicenceGateway.getLicenceSummaries(id = crn)
2323
licences.data.forEach {
24-
val conditions = createAndVaryLicenceGateway.getLicenceConditions(it.id)
25-
it.conditions = conditions.data
24+
val licenceId = it.id.toIntOrNull()
25+
if (licenceId != null) {
26+
val conditions = createAndVaryLicenceGateway.getLicenceConditions(licenceId)
27+
it.conditions = conditions.data
28+
} else {
29+
it.conditions = emptyList()
30+
}
2631
}
2732
personLicences = PersonLicences(hmppsId, licences.data.firstOrNull()?.offenderNumber, licences.data)
2833
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetPersonService.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ class GetPersonService(
3232
"probationOffenderSearch" to probationResponse.data,
3333
)
3434

35-
val errors = (prisonResponse?.errors ?: emptyList()) + probationResponse.errors
36-
3735
return Response(
3836
data = data,
39-
errors = errors,
37+
errors = (prisonResponse?.errors ?: emptyList()) + probationResponse.errors,
4038
)
4139
}
4240
}

src/main/resources/application-preprod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
prison-api:
3-
base-url: https://api-preprod.prison.service.justice.gov.uk
3+
base-url: https://prison-api-preprod.prison.service.justice.gov.uk
44
prisoner-offender-search:
55
base-url: https://prisoner-search-preprod.prison.service.justice.gov.uk
66
probation-offender-search:

src/main/resources/application-prod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
prison-api:
3-
base-url: https://api.prison.service.justice.gov.uk
3+
base-url: https://prison-api.prison.service.justice.gov.uk
44
prisoner-offender-search:
55
base-url: https://prisoner-search.prison.service.justice.gov.uk
66
probation-offender-search:

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/OffencesControllerTest.kt

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ internal class OffencesControllerTest(
5656
cjsCode = "RR99999",
5757
hoCode = "05800",
5858
courtDates = listOf(LocalDate.parse("2023-03-03")),
59+
courtName = "Llandudno Magistrates Court",
5960
description = "This is a description of an offence.",
6061
endDate = LocalDate.parse("2023-02-01"),
6162
startDate = LocalDate.parse("2023-01-01"),
@@ -90,6 +91,7 @@ internal class OffencesControllerTest(
9091
"cjsCode": "RR99999",
9192
"hoCode": "05800",
9293
"courtDates": ["2023-03-03"],
94+
"courtName": "Llandudno Magistrates Court",
9395
"description": "This is a description of an offence.",
9496
"endDate":"2023-02-01",
9597
"startDate": "2023-01-01",
@@ -154,6 +156,7 @@ internal class OffencesControllerTest(
154156
systemSource = SystemSource.PROBATION_SYSTEMS,
155157
cjsCode = "RR99999",
156158
courtDates = listOf(LocalDate.parse("2023-03-03")),
159+
courtName = "Llandudno Magistrates Court",
157160
description = "This is a description of an offence.",
158161
endDate = LocalDate.parse("2023-02-01"),
159162
startDate = LocalDate.parse("2023-01-01"),

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonControllerTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ internal class PersonControllerTest(
7676
lastName = "Allen",
7777
middleName = "Jonas",
7878
dateOfBirth = LocalDate.parse("2023-03-01"),
79-
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
79+
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
8080
),
8181
Person(
8282
firstName = "Barry",
8383
lastName = "Allen",
8484
middleName = "Rock",
8585
dateOfBirth = LocalDate.parse("2022-07-22"),
86-
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
86+
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
8787
),
8888
),
8989
),

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/createAndVaryLicence/GetLicenceConditionsTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GetLicenceConditionsTests(
2929
) : DescribeSpec(
3030
{
3131
val createAndVaryLicenceApiMockServer = CreateAndVaryLicenceApiMockServer()
32-
val conditionId = "X777776"
32+
val conditionId = 12345
3333

3434
beforeEach {
3535
createAndVaryLicenceApiMockServer.start()

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/ndelius/GetOffencesForPersonTest.kt

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class GetOffencesForPersonTest(
7373
LocalDate.parse("2009-07-07"),
7474
LocalDate.parse("2009-07-07"),
7575
),
76+
courtName = "Llandudno Magistrates Court",
7677
description = "Common assault and battery - 10501",
7778
endDate = null,
7879
startDate = LocalDate.parse("2009-03-31"),
@@ -86,6 +87,7 @@ class GetOffencesForPersonTest(
8687
LocalDate.parse("2009-07-07"),
8788
LocalDate.parse("2009-07-07"),
8889
),
90+
courtName = "Llandudno Magistrates Court",
8991
description = "Other Criminal Damage (including causing explosion) - 05800",
9092
endDate = null,
9193
startDate = LocalDate.parse("2009-03-31"),
@@ -99,6 +101,7 @@ class GetOffencesForPersonTest(
99101
LocalDate.parse("2009-09-01"),
100102
LocalDate.parse("2009-08-11"),
101103
),
104+
courtName = "Llandudno Magistrates Court",
102105
description = "Threatening behaviour, fear or provocation of violence (Public Order Act 1986) - 12511",
103106
endDate = null,
104107
startDate = LocalDate.parse("2009-07-31"),
@@ -112,6 +115,7 @@ class GetOffencesForPersonTest(
112115
LocalDate.parse("2009-09-01"),
113116
LocalDate.parse("2009-08-11"),
114117
),
118+
courtName = "Llandudno Magistrates Court",
115119
description = "Stealing from the person of another - 03900",
116120
endDate = null,
117121
startDate = LocalDate.parse("2009-08-14"),
@@ -125,6 +129,7 @@ class GetOffencesForPersonTest(
125129
LocalDate.parse("2009-09-01"),
126130
LocalDate.parse("2009-08-11"),
127131
),
132+
courtName = "Llandudno Magistrates Court",
128133
description = "Migrated Breach Offences",
129134
endDate = null,
130135
startDate = LocalDate.parse("1900-01-01"),

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/ndelius/fixtures/GetSupervisionsResponse.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@
139139
{
140140
"type": "Sentence",
141141
"date": "2009-09-01T00:00:00+01:00",
142-
"court": "Rhuddlan Magistrates Court",
142+
"court": "Llandudno Magistrates Court",
143143
"plea": "Guilty"
144144
},
145145
{
146146
"type": "Trial/Adjournment",
147147
"date": "2009-08-11T00:00:00+01:00",
148-
"court": "Rhuddlan Magistrates Court",
148+
"court": "Llandudno Magistrates Court",
149149
"plea": "Guilty"
150150
}
151151
]

0 commit comments

Comments
 (0)