From c3a50503e5687da9a75ea845c38d230d1094e766 Mon Sep 17 00:00:00 2001 From: Anthony Britton <105213050+anthony-britton-moj@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:50:35 +0100 Subject: [PATCH] PI-2047 (#3565) * PI-2047 * Formatting changes * PI-2047 --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../digital/hmpps/CASIntegrationTest.kt | 7 ++++--- .../approvedpremesis/EventDetails.kt | 18 +++++++++++------- .../integrations/delius/ContactService.kt | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt b/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt index a44804aea6..20d419ed88 100644 --- a/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt +++ b/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.github.tomakehurst.wiremock.WireMockServer import com.github.tomakehurst.wiremock.client.WireMock.* import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.MethodOrderer import org.junit.jupiter.api.Order @@ -16,9 +17,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock 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 uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator -import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter import uk.gov.justice.digital.hmpps.datetime.EuropeLondon import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.* @@ -171,6 +170,7 @@ internal class CASIntegrationTest { val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn) assertThat(contact!!.type.code, equalTo("EAAR")) + assertThat(contact.date, equalTo(eventDetails.eventDetails.arrivedAt.toLocalDate())) assertThat(contact.teamId, equalTo(ProviderGenerator.DEFAULT_TEAM.id)) assertThat(contact.staffId, equalTo(ProviderGenerator.DEFAULT_STAFF.id)) @@ -207,8 +207,9 @@ internal class CASIntegrationTest { Mockito.verify(telemetryService).notificationReceived(event) val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn) - assertThat(contact!!.type.code, equalTo("EADP")) + assertThat(contact.date, equalTo(eventDetails.eventDetails.departedAt.toLocalDate())) + val person = personRepository.findByCrn(event.message.crn()) val address = addressRepository.findAll().filter { it.personId == person?.id }[0] assertThat(address!!.status.code, equalTo("P")) diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt index ec29a9dec9..047bf0223b 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt @@ -10,7 +10,9 @@ data class EventDetails( val timestamp: ZonedDateTime, val eventType: String, val eventDetails: T -) +) { + fun occurredAt() = if (eventDetails is OccurredAt) eventDetails.occurredAt else timestamp +} data class ApplicationSubmitted( val applicationId: String @@ -90,7 +92,7 @@ data class PersonArrived( val notes: String, val premises: Address, override val recordedBy: By? -) : Cas3Event, Recordable { +) : Cas3Event, Recordable, OccurredAt { override val urn = "urn:hmpps:cas3:person-arrived:$bookingId" override val noteText = listOfNotNull( @@ -99,6 +101,7 @@ data class PersonArrived( notes ).joinToString(System.lineSeparator()) override val contactTypeCode = ContactType.PERSON_ARRIVED + override val occurredAt = arrivedAt } data class PersonDeparted( @@ -111,7 +114,7 @@ data class PersonDeparted( val reason: String, val reasonDetail: String?, override val recordedBy: By? -) : Cas3Event, Recordable { +) : Cas3Event, Recordable, OccurredAt { override val urn = "urn:hmpps:cas3:person-departed:$bookingId" override val noteText = listOfNotNull( "Departure date: ${DeliusDateFormatter.format(departedAt)}", @@ -120,6 +123,7 @@ data class PersonDeparted( notes ).joinToString(System.lineSeparator()) override val contactTypeCode = ContactType.PERSON_DEPARTED + override val occurredAt = departedAt } data class Address( @@ -150,10 +154,6 @@ data class AddressLines( val district: String? ) -data class Category( - val description: String -) - data class By( val staffCode: String, val probationRegionCode: String @@ -161,4 +161,8 @@ data class By( interface Recordable { val recordedBy: By? +} + +interface OccurredAt { + val occurredAt: ZonedDateTime } \ No newline at end of file diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt index 388f2df46b..00412699cd 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt @@ -59,7 +59,7 @@ class ContactService( } else { contactRepository.save( newContact( - event.timestamp, + event.occurredAt(), personId, event.eventDetails.contactTypeCode, event.eventDetails.urn,