From c1a72e0ea8d77c656997829d22d0f9dd80e02ce2 Mon Sep 17 00:00:00 2001 From: achimber-moj <161360519+achimber-moj@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:17:33 +0100 Subject: [PATCH] PI-2530 - order events by created date (#4240) --- .../hmpps/data/generator/PersonGenerator.kt | 3 +- .../digital/hmpps/SentenceIntegrationTest.kt | 28 +++++++++---------- .../delius/overview/entity/Event.kt | 6 +++- .../sentence/entity/SentenceRepository.kt | 2 +- .../hmpps/service/ComplianceServiceTest.kt | 13 ++++++--- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt index ba18a6c818..75f14536c7 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt @@ -212,7 +212,8 @@ object PersonGenerator { active = active, mainOffence = mainOffence, notes = notes, - additionalOffences = additionalOffences + additionalOffences = additionalOffences, + dateCreated = ZonedDateTime.now() ) val DISABILITIES: List = listOf( diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 4bb9178505..be40682c7e 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -50,6 +50,20 @@ class SentenceIntegrationTest { val expected = SentenceOverview( PersonGenerator.OVERVIEW.toSummary(), listOf( + Sentence( + OffenceDetails( + "1234567", + Offence("Another Murder", 1), + LocalDate.now(), + "overview", + emptyList() + ), + Conviction(null, null, null, listOf()), + null, + listOf(), + listOf(), + null + ), Sentence( OffenceDetails( "7654321", @@ -101,20 +115,6 @@ class SentenceIntegrationTest { CourtDocument(EVENT_DOCUMENT.alfrescoId, LocalDate.now().minusDays(3), "event report") ), "3 minutes completed (of 12 hours)" - ), - Sentence( - OffenceDetails( - "1234567", - Offence("Another Murder", 1), - LocalDate.now(), - "overview", - emptyList() - ), - Conviction(null, null, null, listOf()), - null, - listOf(), - listOf(), - null ) ), ProbationHistory(2, LocalDate.now().minusDays(7), 2, 2) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Event.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Event.kt index 8ab3ef43a5..61ff39be88 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Event.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Event.kt @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Court import java.time.LocalDate +import java.time.ZonedDateTime @Immutable @Entity @@ -50,7 +51,10 @@ class Event( val notes: String?, @Column(columnDefinition = "number") - val softDeleted: Boolean = false + val softDeleted: Boolean = false, + + @Column(name = "created_datetime") + val dateCreated: ZonedDateTime, ) interface EventRepository : JpaRepository { diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/SentenceRepository.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/SentenceRepository.kt index ccddc40a11..001f9cd25a 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/SentenceRepository.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/SentenceRepository.kt @@ -17,7 +17,7 @@ interface EventSentenceRepository : JpaRepository { "LEFT JOIN FETCH m.offence mo " + "LEFT JOIN FETCH ao.offence aoo " + "WHERE e.personId = :id " + - "ORDER BY e.eventNumber DESC " + "ORDER BY e.dateCreated DESC " ) fun findSentencesByPersonId(id: Long): List diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ComplianceServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ComplianceServiceTest.kt index b0770f87a3..62761e4f91 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ComplianceServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ComplianceServiceTest.kt @@ -24,6 +24,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonRe import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.RequirementRepository import uk.gov.justice.digital.hmpps.utils.Summary import java.time.LocalDate +import java.time.ZonedDateTime @ExtendWith(MockitoExtension::class) internal class ComplianceServiceTest { @@ -72,7 +73,8 @@ internal class ComplianceServiceTest { personId = OVERVIEW.id, convictionDate = LocalDate.now(), inBreach = false, - notes = "" + notes = "", + dateCreated = ZonedDateTime.now() ), Event( id = BREACH_PREVIOUS_ORDER_2.eventId ?: 0, @@ -83,7 +85,8 @@ internal class ComplianceServiceTest { personId = OVERVIEW.id, convictionDate = LocalDate.now(), inBreach = false, - notes = "" + notes = "", + dateCreated = ZonedDateTime.now() ), Event( id = 3, @@ -95,7 +98,8 @@ internal class ComplianceServiceTest { personId = OVERVIEW.id, convictionDate = LocalDate.now(), inBreach = false, - notes = "" + notes = "", + dateCreated = ZonedDateTime.now() ), Event( id = 4, @@ -107,7 +111,8 @@ internal class ComplianceServiceTest { personId = OVERVIEW.id, convictionDate = LocalDate.now(), inBreach = false, - notes = "" + notes = "", + dateCreated = ZonedDateTime.now() ), )