Skip to content

Commit 745b463

Browse files
Merge branch 'main' into pgp-SDIT-1759-move-preprod-prison-api
2 parents 89daca4 + 2f84092 commit 745b463

File tree

22 files changed

+176
-135
lines changed

22 files changed

+176
-135
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

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/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/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/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
]

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/probationoffendersearch/GetAddressesForPersonTest.kt

+8-10
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ class GetAddressesForPersonTest(
2929
) : DescribeSpec(
3030
{
3131
val probationOffenderSearchApiMockServer = ProbationOffenderSearchApiMockServer()
32-
val hmppsId = "2002/1121M"
32+
val hmppsId = "X777776"
3333

3434
beforeEach {
3535
probationOffenderSearchApiMockServer.start()
3636
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
37-
"{\"pncNumber\": \"$hmppsId\"}",
37+
"{\"crn\": \"$hmppsId\"}",
3838
"""
3939
[
4040
{
41-
"firstName": "English",
42-
"surname": "Breakfast",
4341
"contactDetails": {
4442
"addresses": [
4543
{
@@ -102,7 +100,7 @@ class GetAddressesForPersonTest(
102100

103101
it("returns an empty list when no addresses are found") {
104102
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
105-
"{\"pncNumber\": \"$hmppsId\"}",
103+
"{\"crn\": \"$hmppsId\"}",
106104
"""
107105
[
108106
{
@@ -123,7 +121,7 @@ class GetAddressesForPersonTest(
123121

124122
it("returns an error when no results are returned") {
125123
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
126-
"{\"pncNumber\": \"$hmppsId\"}",
124+
"{\"crn\": \"$hmppsId\"}",
127125
"[]",
128126
)
129127

@@ -134,7 +132,7 @@ class GetAddressesForPersonTest(
134132

135133
it("returns an empty list when there is no contactDetails field") {
136134
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
137-
"{\"pncNumber\": \"$hmppsId\"}",
135+
"{\"crn\": \"$hmppsId\"}",
138136
"""
139137
[
140138
{
@@ -152,7 +150,7 @@ class GetAddressesForPersonTest(
152150

153151
it("returns an empty list when contactDetails field is null") {
154152
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
155-
"{\"pncNumber\": \"$hmppsId\"}",
153+
"{\"crn\": \"$hmppsId\"}",
156154
"""
157155
[
158156
{
@@ -171,7 +169,7 @@ class GetAddressesForPersonTest(
171169

172170
it("returns an empty list when contactDetails.addresses field is null") {
173171
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
174-
"{\"pncNumber\": \"$hmppsId\"}",
172+
"{\"crn\": \"$hmppsId\"}",
175173
"""
176174
[
177175
{
@@ -192,7 +190,7 @@ class GetAddressesForPersonTest(
192190

193191
it("returns an empty list when the type is an empty object") {
194192
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
195-
"{\"pncNumber\": \"$hmppsId\"}",
193+
"{\"crn\": \"$hmppsId\"}",
196194
"""
197195
[
198196
{

0 commit comments

Comments
 (0)