From fbbd67640e1f31a729cca776de7c4e1f36cd78bb Mon Sep 17 00:00:00 2001 From: Anthony Britton <105213050+anthony-britton-moj@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:25:43 +0000 Subject: [PATCH] PI-1964 (#3404) * PI-1964 * Formatting changes * PI-1964 --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../generator/ConvictionEventGenerator.kt | 2 +- .../hmpps/entity/ConvictionEventEntity.kt | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt b/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt index d3f7c654e1..310d13c1fc 100644 --- a/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt +++ b/projects/soc-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ConvictionEventGenerator.kt @@ -27,7 +27,7 @@ object ConvictionEventGenerator { ) val DEFAULT_EVENT = ConvictionEventEntity( IdGenerator.getAndIncrement(), - LocalDate.now(), + LocalDate.now().minusDays(1), PERSON ) val INACTIVE_EVENT = ConvictionEventEntity( diff --git a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt index 6e8aa6e04f..c5745834c6 100644 --- a/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt +++ b/projects/soc-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/ConvictionEventEntity.kt @@ -12,6 +12,7 @@ import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction import org.springframework.data.jpa.repository.EntityGraph import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import java.time.LocalDate @Immutable @@ -165,14 +166,20 @@ class Offence( ) interface ConvictionEventRepository : JpaRepository { - @EntityGraph( - attributePaths = [ - "mainOffence.offence", - "additionalOffences.offence", - "disposal.type" - ] + @Query( + """ + select c from ConvictionEventEntity c + join fetch c.disposal d + join fetch d.type dt + join fetch c.mainOffence mo + join fetch mo.offence + left join fetch c.additionalOffences ao + left join fetch ao.offence + where c.convictionEventPerson.id = :personId and c.active = true + order by c.convictionDate desc + """ ) - fun getAllByConvictionEventPersonIdAndActiveIsTrueOrderByConvictionDateDesc(personId: Long): List + fun getActiveSentencedConvictions(personId: Long): List @EntityGraph( attributePaths = [ @@ -212,4 +219,4 @@ interface ConvictionEventRepository : JpaRepository } fun ConvictionEventRepository.getLatestConviction(personId: Long) = - getAllByConvictionEventPersonIdAndActiveIsTrueOrderByConvictionDateDesc(personId).firstOrNull() + getActiveSentencedConvictions(personId).firstOrNull()