Skip to content

Commit b4da70c

Browse files
author
popey2700
committed
Fix Bug with Perons
1 parent e070e13 commit b4da70c

File tree

10 files changed

+60
-61
lines changed

10 files changed

+60
-61
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ __pycache__/
8383
*.key
8484
*.csr
8585
*.pem
86+
87+
# Localstack
88+
localstack/cache

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/probationoffendersearch/Address.kt

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

3-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
3+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address as HmppsAddress
44
import java.time.LocalDate
55

6+
data class ContactDetailsWithAddress(
7+
val contactDetails: Addresses? = null,
8+
)
9+
10+
data class Addresses (
11+
val addresses: List<Address>? = listOf(),
12+
)
13+
614
data class Address(
715
val addressNumber: String?,
816
val district: 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/PersonControllerTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ internal class PersonControllerTest(
7474
lastName = "Allen",
7575
middleName = "Jonas",
7676
dateOfBirth = LocalDate.parse("2023-03-01"),
77-
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
77+
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
7878
),
7979
Person(
8080
firstName = "Barry",
8181
lastName = "Allen",
8282
middleName = "Rock",
8383
dateOfBirth = LocalDate.parse("2022-07-22"),
84-
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
84+
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
8585
),
8686
),
8787
),

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
{

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/smoke/person/PersonSmokeTest.kt

-19
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ class PersonSmokeTest : DescribeSpec(
7070
"pncId": "2012/0052494Q",
7171
"hmppsId": "A123456",
7272
"contactDetails": {
73-
"addresses": [
74-
{
75-
"addressNumber": "string",
76-
"district": "string",
77-
"buildingName": "string",
78-
"county": "string",
79-
"from": "2019-08-24",
80-
"postcode": "string",
81-
"streetName": "string",
82-
"type": {
83-
"code": "string",
84-
"description": "string"
85-
},
86-
"to": "2019-08-24",
87-
"town": "string",
88-
"noFixedAbode": true,
89-
"notes": "string"
90-
}
91-
],
9273
"phoneNumbers": [
9374
{
9475
"number": "string",

0 commit comments

Comments
 (0)