diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt index 2194d12f44..e3fedcc622 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt @@ -101,14 +101,30 @@ class ProbationCaseDataLoader( ) ) - listOf( + generateEventAndAddOffences( ProbationCaseGenerator.CASE_COMPLEX, + eventId = 100001L, + mainOffence = Pair(200001L, LocalDate.parse("2024-10-11")), + additionalOffence = Pair(300001L, LocalDate.parse("2024-10-21")) + ) + generateEventAndAddOffences( ProbationCaseGenerator.CASE_X320741, + eventId = 100002L, + mainOffence = Pair(200002L, LocalDate.parse("2024-10-12")), + additionalOffence = Pair(300002L, LocalDate.parse("2024-10-22")) + ) + generateEventAndAddOffences( ProbationCaseGenerator.CASE_LAO_RESTRICTED, + eventId = 100003L, + mainOffence = Pair(200003L, LocalDate.parse("2024-10-13")), + additionalOffence = Pair(300003L, LocalDate.parse("2024-10-23")) + ) + generateEventAndAddOffences( ProbationCaseGenerator.CASE_LAO_EXCLUSION, - ).forEach { - generateEventAndAddOffences(probationCase = it) - } + eventId = 100004L, + mainOffence = Pair(200004L, LocalDate.parse("2024-10-14")), + additionalOffence = Pair(300004L, LocalDate.parse("2024-10-24")) + ) personalCircumstanceTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_TYPES) personalCircumstanceSubTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_SUB_TYPES) @@ -125,17 +141,24 @@ class ProbationCaseDataLoader( exclusionRepository.save(LimitedAccessGenerator.generateExclusion(EXCLUDED_CASE.toLimitedAccessPerson())) } - private fun generateEventAndAddOffences(probationCase: ProbationCase) { + private fun generateEventAndAddOffences( + probationCase: ProbationCase, + eventId: Long, + mainOffence: Pair, + additionalOffence: Pair, + ) { val event = PersonGenerator.generateEvent( "1", - probationCase.id + probationCase.id, + id = eventId ).apply(eventRepository::save) mainOffenceRepository.save( OffenceGenerator.generateMainOffence( event, OffenceGenerator.OFFENCE_ONE, - LocalDate.now().minusDays(7) + id = mainOffence.first, + date = mainOffence.second ) ) @@ -143,7 +166,8 @@ class ProbationCaseDataLoader( OffenceGenerator.generateAdditionalOffence( event, OffenceGenerator.OFFENCE_TWO, - LocalDate.now().minusDays(5) + id = additionalOffence.first, + date = additionalOffence.second ) ) } diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt index ffa54129ac..23e75f272f 100644 --- a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt @@ -70,9 +70,15 @@ class ProbationCaseIntegrationTest { assertThat(detail.mappaDetail?.level, equalTo(2)) assertThat(detail.registrations.map { it.description }, equalTo(listOf("Description of ARSO"))) val mainOffence = detail.offences.first { it.main } + assertThat(mainOffence.id, equalTo("M200001")) assertThat(mainOffence.description, equalTo("Offence One")) + assertThat(mainOffence.date, equalTo(LocalDate.parse("2024-10-11"))) + assertThat(mainOffence.eventId, equalTo(100001L)) val otherOffence = detail.offences.first { !it.main } + assertThat(otherOffence.id, equalTo("A300001")) assertThat(otherOffence.description, equalTo("Offence Two")) + assertThat(otherOffence.date, equalTo(LocalDate.parse("2024-10-21"))) + assertThat(otherOffence.eventId, equalTo(100001L)) assertThat(detail.careLeaver, equalTo(false)) assertThat(detail.veteran, equalTo(true)) } diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/offence/entity/Offence.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/offence/entity/Offence.kt index 951cdae8f7..97d91a0220 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/offence/entity/Offence.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/offence/entity/Offence.kt @@ -88,7 +88,7 @@ interface MainOffenceRepository : JpaRepository { @Query( """ select - mo.offence.id as id, + mo.id as id, mo.offence.code as code, mo.offence.description as description, mo.date as date, @@ -99,7 +99,7 @@ interface MainOffenceRepository : JpaRepository { where mo.event.personId = :personId and mo.event.active = true union all select - ao.offence.id, + ao.id, ao.offence.code, ao.offence.description, ao.date, diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt index b7359827c0..0cf9687caa 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt @@ -59,7 +59,7 @@ data class MappaDetail( ) data class Offence( - val id: Long, + val id: String, val code: String, val description: String, val date: LocalDate?, diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt index 49cc6a0f32..8585a9cd9c 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt @@ -87,7 +87,8 @@ fun CommunityManager.team() = Team( team.endDate ) -fun CaseOffence.asOffence() = Offence(id, code, description, date, main, eventId, eventNumber) +fun CaseOffence.asOffence() = + Offence(id = if (main) "M$id" else "A$id", code, description, date, main, eventId, eventNumber) fun Registration.asRegistration() = uk.gov.justice.digital.hmpps.model.Registration(type.code, type.description, date) fun Registration.asMappa() = MappaDetail(