From 791cf03696a4799451df54d6f0dc2d16b3e2b8d8 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Mon, 8 Jul 2024 16:37:10 +0000 Subject: [PATCH] PI-2346 Add full address line to core-person response --- .../hmpps/data/generator/PersonGenerator.kt | 37 ++++- .../hmpps/CorePersonIntegrationTest.kt | 128 +++++++++++++----- .../digital/hmpps/api/model/PersonDetail.kt | 2 +- .../delius/entity/PersonAddress.kt | 6 + .../digital/hmpps/service/PersonMapping.kt | 17 ++- 5 files changed, 152 insertions(+), 38 deletions(-) diff --git a/projects/core-person-record-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/core-person-record-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt index 1cb579ade2..cc3c7a460b 100644 --- a/projects/core-person-record-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt +++ b/projects/core-person-record-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt @@ -46,7 +46,18 @@ object PersonGenerator { ) val FULL_PERSON_ADDRESSES = listOf( - generateAddress(FULL_PERSON.id, MAIN_ADDRESS, "PC1 1TS", LocalDate.now().minusDays(30)) + generateAddress( + FULL_PERSON.id, + MAIN_ADDRESS, + "1", + null, + "Main Street", + "", + " ", + "London", + "PC1 1TS", + LocalDate.now().minusDays(30) + ) ) val FULL_PERSON_EXCLUSIONS = listOf( @@ -133,12 +144,32 @@ object PersonGenerator { fun generateAddress( personId: Long, status: ReferenceData, - postcode: String, + addressNumber: String?, + buildingName: String?, + streetName: String?, + townCity: String?, + county: String?, + district: String?, + postcode: String?, startDate: LocalDate, endDate: LocalDate? = null, softDeleted: Boolean = false, id: Long = IdGenerator.getAndIncrement() - ) = PersonAddress(personId, status, postcode, startDate, endDate, softDeleted, id) + ) = PersonAddress( + personId, + status, + addressNumber, + buildingName, + streetName, + townCity, + county, + district, + postcode, + startDate, + endDate, + softDeleted, + id, + ) private fun generateExclusion( personId: Long, diff --git a/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt b/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt index 7846649d0c..8535677335 100644 --- a/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt +++ b/projects/core-person-record-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CorePersonIntegrationTest.kt @@ -6,21 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get -import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath -import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status -import uk.gov.justice.digital.hmpps.api.model.LimitedAccess -import uk.gov.justice.digital.hmpps.api.model.LimitedAccessUser +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator -import uk.gov.justice.digital.hmpps.integration.delius.entity.Alias -import uk.gov.justice.digital.hmpps.integration.delius.entity.PersonAddress -import uk.gov.justice.digital.hmpps.service.asAddress -import uk.gov.justice.digital.hmpps.service.asModel -import uk.gov.justice.digital.hmpps.service.detail -import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.andExpectJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken @AutoConfigureMockMvc @@ -29,29 +18,30 @@ internal class CorePersonIntegrationTest { @Autowired lateinit var mockMvc: MockMvc - @MockBean - lateinit var telemetryService: TelemetryService - - val minPerson = PersonGenerator.MIN_PERSON.detail(listOf(), listOf()) - val fullPerson = PersonGenerator.FULL_PERSON.detail( - aliases = PersonGenerator.FULL_PERSON_ALIASES.map(Alias::asModel), - addresses = PersonGenerator.FULL_PERSON_ADDRESSES.mapNotNull(PersonAddress::asAddress), - exclusions = LimitedAccess( - message = "This case is excluded because ...", - users = listOf(LimitedAccessUser("SomeUser1")) - ), - restrictions = LimitedAccess( - message = "This case is restricted because ...", - users = listOf(LimitedAccessUser("SomeUser2"), LimitedAccessUser("FutureEndDatedUser")) - ), - ) - @Test fun `correctly returns detail by crn`() { mockMvc .perform(get("/probation-cases/${PersonGenerator.MIN_PERSON.crn}").withToken()) .andExpect(status().is2xxSuccessful) - .andExpectJson(minPerson) + .andExpect( + content().json( + """ + { + "identifiers": { + "deliusId": ${PersonGenerator.MIN_PERSON.id}, + "crn": "M123456" + }, + "name": { + "forename": "Isabelle", + "surname": "Necessary" + }, + "dateOfBirth": "1990-03-05", + "aliases": [], + "addresses": [] + } + """.trimIndent() + ) + ) } @Test @@ -59,7 +49,79 @@ internal class CorePersonIntegrationTest { mockMvc .perform(get("/probation-cases/${PersonGenerator.FULL_PERSON.id}").withToken()) .andExpect(status().is2xxSuccessful) - .andExpectJson(fullPerson) + .andExpect( + content().json( + """ + { + "identifiers": { + "deliusId": ${PersonGenerator.FULL_PERSON.id}, + "crn": "F123456", + "nomsId": "A3349EX", + "prisonerNumber": "94600E", + "pnc": "2011/0593710D", + "cro": "89861/11W", + "ni": "FJ123456W" + }, + "name": { + "forename": "Frederick", + "middleName": "Paul Bernard", + "surname": "Johnson", + "previousSurname": "No Previous", + "preferred": "Freddy" + }, + "dateOfBirth": "1975-07-15", + "title": { + "code": "TIT", + "description": "Description of TIT" + }, + "gender": { + "code": "GEN", + "description": "Description of GEN" + }, + "nationality": { + "code": "NAT", + "description": "Description of NAT" + }, + "ethnicity": { + "code": "ETH", + "description": "Description of ETH" + }, + "ethnicityDescription": "Description of ethnicity", + "contactDetails": { + "telephone": "0191 755 4789", + "mobile": "07895746789", + "email": "fred@gmail.com" + }, + "aliases": [ + { + "name": { + "forename": "Freddy", + "surname": "Banter" + }, + "dateOfBirth": "1974-02-17" + } + ], + "addresses": [ + { + "fullAddress": "1 Main Street, London, PC1 1TS", + "postcode": "PC1 1TS" + } + ], + "excludedFrom": { + "message": "This case is excluded because ...", + "users": [{ "username": "SomeUser1" }] + }, + "restrictedTo": { + "message": "This case is restricted because ...", + "users": [ + { "username": "SomeUser2" }, + { "username": "FutureEndDatedUser" } + ] + } + } + """.trimIndent() + ) + ) } @Test @@ -68,7 +130,7 @@ internal class CorePersonIntegrationTest { .perform(get("/all-probation-cases?sort=crn,desc").withToken()) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("page.totalElements", equalTo(2))) - .andExpect(jsonPath("content[0].identifiers.crn", equalTo(minPerson.identifiers.crn))) - .andExpect(jsonPath("content[1].identifiers.crn", equalTo(fullPerson.identifiers.crn))) + .andExpect(jsonPath("content[0].identifiers.crn", equalTo(PersonGenerator.MIN_PERSON.crn))) + .andExpect(jsonPath("content[1].identifiers.crn", equalTo(PersonGenerator.FULL_PERSON.crn))) } } diff --git a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt index d6e9d329a2..0b5e0c21f3 100644 --- a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt +++ b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt @@ -51,4 +51,4 @@ data class CodeDescription(val code: String, val description: String) data class Alias(val name: Name, val dateOfBirth: LocalDate) -data class Address(val postcode: String) \ No newline at end of file +data class Address(val fullAddress: String, val postcode: String) \ No newline at end of file diff --git a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integration/delius/entity/PersonAddress.kt b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integration/delius/entity/PersonAddress.kt index ba11ce3672..222dc55bc3 100644 --- a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integration/delius/entity/PersonAddress.kt +++ b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integration/delius/entity/PersonAddress.kt @@ -17,6 +17,12 @@ class PersonAddress( @ManyToOne @JoinColumn(name = "address_status_id") val status: ReferenceData, + val addressNumber: String?, + var buildingName: String?, + var streetName: String?, + var townCity: String?, + var county: String?, + var district: String?, val postcode: String?, val startDate: LocalDate?, val endDate: LocalDate?, diff --git a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonMapping.kt b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonMapping.kt index 06f9f252d6..5229bcce1d 100644 --- a/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonMapping.kt +++ b/projects/core-person-record-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonMapping.kt @@ -51,7 +51,22 @@ fun uk.gov.justice.digital.hmpps.integration.delius.entity.Alias.asModel() = Ali dateOfBirth ) -fun PersonAddress.asAddress() = postcode?.let { Address(it) } +fun PersonAddress.asAddress() = postcode?.let { + Address( + fullAddress = listOf( + buildingName, + listOf(addressNumber, streetName).trimAndJoin(" "), + district, + townCity, + county, + postcode + ).trimAndJoin(), + postcode = postcode + ) +} + +private fun List.trimAndJoin(separator: String = ", ") = + filterNotNull().filter { it.isNotBlank() }.joinToString(separator) { it.trim() } fun List.exclusionsAsLimitedAccess(message: String?) = if (isNotEmpty()) { LimitedAccess(