Skip to content

Commit

Permalink
PI-2667 Common Platform Address records - OS Places API
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-bcl committed Dec 9, 2024
1 parent 3db8d08 commit baa36e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,12 @@ internal class IntegrationTest {

verify(addressRepository).save(check<PersonAddress> {
assertThat(it.start, Matchers.equalTo(LocalDate.now()))
assertThat(it.notes, Matchers.containsString("Example Address Line 1"))
assertThat(it.streetName, Matchers.containsString("Example Address Line 1"))
assertThat(it.district, Matchers.containsString("Example Address Line 2"))
assertThat(it.town, Matchers.containsString("Example Address Line 3"))
assertThat(it.postcode, Matchers.containsString("AA1 1AA"))
assertNull(it.endDate)
assertNotNull(it.notes)
assertNull(it.notes)
assertThat(it.softDeleted, Matchers.equalTo(false))
assertThat(it.status.code, Matchers.equalTo(ReferenceData.StandardRefDataCode.ADDRESS_MAIN_STATUS.code))
assertThat(it.noFixedAbode, Matchers.equalTo(false))
Expand All @@ -302,7 +304,7 @@ internal class IntegrationTest {

verify(addressRepository).save(check<PersonAddress> {
assertThat(it.start, Matchers.equalTo(LocalDate.now()))
assertThat(it.notes, Matchers.containsString("123 Test Street, Test, AB1 2CD"))
assertThat(it.notes, Matchers.containsString("UPRN: 123456789012"))
assertThat(it.postcode, Matchers.containsString("AB1 2CD"))
assertThat(it.streetName, Matchers.containsString("Test Street"))
assertThat(it.addressNumber, Matchers.containsString("123"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PersonService(
person = savedPerson,
type = referenceDataRepository.awaitingAssessmentAddressType(),
postcode = deliveryPointAddress.postcode,
notes = "Address record automatically created by common-platform-delius-service with the following information:\n${deliveryPointAddress.address}",
notes = "UPRN: ${deliveryPointAddress.uprn}",
buildingName = listOfNotNull(
deliveryPointAddress.subBuildingName,
deliveryPointAddress.buildingName
Expand All @@ -112,9 +112,12 @@ class PersonService(
start = LocalDate.now(),
status = referenceDataRepository.mainAddressStatus(),
person = savedPerson,
notes = it.buildNotes(),
postcode = it.postcode,
type = referenceDataRepository.awaitingAssessmentAddressType()
type = referenceDataRepository.awaitingAssessmentAddressType(),
streetName = it.address1,
district = it.address2,
town = it.address3,
county = listOfNotNull(it.address4, it.address5).joinToString(", ")
)
)
}
Expand Down Expand Up @@ -168,17 +171,6 @@ class PersonService(
).any { !it.isNullOrBlank() }
}

fun Address.buildNotes(): String {
return listOf(
"Address record automatically created by common-platform-delius-service with the following information:",
"Address1: ${this.address1 ?: "N/A"}",
"Address2: ${this.address2 ?: "N/A"}",
"Address3: ${this.address3 ?: "N/A"}",
"Address4: ${this.address4 ?: "N/A"}",
"Postcode: ${this.postcode ?: "N/A"}"
).joinToString("\n")
}

fun findAddressByFreeText(address: Address): OsPlacesResponse {
val freeText = address.toFreeText()
return osClient.searchByFreeText(query = freeText, maxResults = 1, minMatch = 0.6)
Expand Down

0 comments on commit baa36e6

Please sign in to comment.