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 cc6987f1e..720310325 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 @@ -152,6 +152,12 @@ class SentenceIntegrationTest { ), "3 minutes completed (of 12 hours)", listOf( + LicenceCondition( + LC_WITHOUT_NOTES.id, + LIC_COND_MAIN_CAT.description, + imposedReleasedDate = LocalDate.now().minusDays(14), + licenceConditionNotes = listOf() + ), LicenceCondition( LC_WITH_NOTES.id, LIC_COND_MAIN_CAT.description, @@ -181,12 +187,6 @@ class SentenceIntegrationTest { ) ) ), - LicenceCondition( - LC_WITHOUT_NOTES.id, - LIC_COND_MAIN_CAT.description, - imposedReleasedDate = LocalDate.now().minusDays(14), - licenceConditionNotes = listOf() - ), LicenceCondition( LC_WITH_NOTES_WITHOUT_ADDED_BY.id, LIC_COND_MAIN_CAT.description, diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt index 3d44b5b54..f4b861810 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt @@ -55,7 +55,7 @@ interface LicenceConditionRepository : JpaRepository { JOIN FETCH lc.mainCategory mc LEFT JOIN FETCH lc.subCategory WHERE lc.disposalId = :disposalId - ORDER BY mc.description ASC + ORDER BY mc.description, lc.id ASC """ ) fun findAllByDisposalId(disposalId: Long): List 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 fb762a48d..102aee1ae 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 @@ -47,7 +47,13 @@ interface OffenderManagerRepository : JpaRepository { fun countOffenderManagersByPerson(person: Person): Long - fun findOffenderManagersByPersonOrderByEndDateDesc(person: Person): List + @Query(""" + SELECT om + FROM OffenderManager om + WHERE om.person.id = :id + ORDER BY om.endDate NULLS FIRST + """) + fun findOffenderManagersByPersonOrderByEndDateDesc(id: Long): List } fun OffenderManagerRepository.getByCrn(crn: String) = diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ContactService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ContactService.kt index 07c425ae9..11a6c4891 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ContactService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ContactService.kt @@ -23,7 +23,7 @@ class ContactService( fun getContacts(crn: String): ProfessionalContact { val person = personRepository.getPerson(crn) - val contacts = offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(person) + val contacts = offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(person.id) if (contacts.isEmpty()) { throw NotFoundException("Offender Manager records", "crn", crn) diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ContactServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ContactServiceTest.kt index 2aa2c6ebc..1cdb60a93 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ContactServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ContactServiceTest.kt @@ -67,7 +67,7 @@ class ContactServiceTest { fun `no offender manager records`() { whenever(personRepository.findByCrn(PersonGenerator.OVERVIEW.crn)).thenReturn(PersonGenerator.OVERVIEW) whenever( - offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW) + offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW.id) ).thenReturn(listOf()) val exception = assertThrows { @@ -81,7 +81,7 @@ class ContactServiceTest { verify(personRepository, times(1)).findByCrn(PersonGenerator.OVERVIEW.crn) verify(offenderManagerRepository, times(1)).findOffenderManagersByPersonOrderByEndDateDesc( - PersonGenerator.OVERVIEW + PersonGenerator.OVERVIEW.id ) verifyNoMoreInteractions(personRepository) @@ -108,7 +108,7 @@ class ContactServiceTest { whenever(personRepository.findByCrn(PersonGenerator.OVERVIEW.crn)).thenReturn(PersonGenerator.OVERVIEW) whenever( - offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW) + offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW.id) ).thenReturn( listOf(OFFENDER_MANAGER_ACTIVE, OFFENDER_MANAGER_INACTIVE) ) @@ -119,7 +119,7 @@ class ContactServiceTest { verify(personRepository, times(1)).findByCrn(PersonGenerator.OVERVIEW.crn) verify(offenderManagerRepository, times(1)).findOffenderManagersByPersonOrderByEndDateDesc( - PersonGenerator.OVERVIEW + PersonGenerator.OVERVIEW.id ) verifyNoMoreInteractions(personRepository)