From 56f97c3b0fa25f89d31adff42954784775b2fab8 Mon Sep 17 00:00:00 2001 From: Greg Hawkins Date: Tue, 19 Nov 2024 17:29:43 +0000 Subject: [PATCH 1/4] APS-1482 - changes to offence id generation and offences data setup --- .../hmpps/data/ProbationCaseDataLoader.kt | 38 ++++++++++++++----- .../hmpps/ProbationCaseIntegrationTest.kt | 6 +++ .../delius/person/offence/entity/Offence.kt | 4 +- .../justice/digital/hmpps/model/CaseDetail.kt | 2 +- .../digital/hmpps/service/CaseService.kt | 2 +- 5 files changed, 39 insertions(+), 13 deletions(-) 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..72f1b46f53 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 @@ -102,12 +102,17 @@ class ProbationCaseDataLoader( ) listOf( - ProbationCaseGenerator.CASE_COMPLEX, - ProbationCaseGenerator.CASE_X320741, - ProbationCaseGenerator.CASE_LAO_RESTRICTED, - ProbationCaseGenerator.CASE_LAO_EXCLUSION, + DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_COMPLEX, eventId = 100001L, mainOffence = Pair(200001L, LocalDate.parse("2024-10-11")), additionalOffence = Pair(300001L, LocalDate.parse("2024-10-21"))), + DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_X320741, eventId = 100002L, mainOffence = Pair(200002L, LocalDate.parse("2024-10-12")), additionalOffence = Pair(300002L, LocalDate.parse("2024-10-22"))), + DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_LAO_RESTRICTED, eventId = 100003L, mainOffence = Pair(200003L, LocalDate.parse("2024-10-13")), additionalOffence = Pair(300003L, LocalDate.parse("2024-10-23"))), + DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_LAO_EXCLUSION, eventId = 100004L, mainOffence = Pair(200004L, LocalDate.parse("2024-10-14")), additionalOffence = Pair(300004L, LocalDate.parse("2024-10-24"))), ).forEach { - generateEventAndAddOffences(probationCase = it) + generateEventAndAddOffences( + it.probationCase, + it.eventId, + it.mainOffence, + it.additionalOffence + ) } personalCircumstanceTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_TYPES) @@ -125,17 +130,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 +155,8 @@ class ProbationCaseDataLoader( OffenceGenerator.generateAdditionalOffence( event, OffenceGenerator.OFFENCE_TWO, - LocalDate.now().minusDays(5) + id = additionalOffence.first, + date = additionalOffence.second ) ) } @@ -163,6 +176,13 @@ class MutableLimitedAccessPerson( fun toLimitedAccessPerson() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id) } +data class DataLoaderCaseAndEventAndOffences( + val probationCase: ProbationCase, + val eventId: Long, + val mainOffence: Pair, + val additionalOffence: Pair +) + interface LduRepository : JpaRepository interface OffenceRepository : JpaRepository interface AdditionalOffenceRepository : JpaRepository 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..842f36a4dc 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,7 @@ 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( From 34068b3eb56b6abf7ae790bf2a6b50e67c205b9f Mon Sep 17 00:00:00 2001 From: "probation-integration-bot[bot]" <177347787+probation-integration-bot[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:32:28 +0000 Subject: [PATCH 2/4] Formatting changes --- .../hmpps/data/ProbationCaseDataLoader.kt | 28 ++++++++++++++++--- .../digital/hmpps/service/CaseService.kt | 3 +- 2 files changed, 26 insertions(+), 5 deletions(-) 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 72f1b46f53..fc3837c81e 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 @@ -102,10 +102,30 @@ class ProbationCaseDataLoader( ) listOf( - DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_COMPLEX, eventId = 100001L, mainOffence = Pair(200001L, LocalDate.parse("2024-10-11")), additionalOffence = Pair(300001L, LocalDate.parse("2024-10-21"))), - DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_X320741, eventId = 100002L, mainOffence = Pair(200002L, LocalDate.parse("2024-10-12")), additionalOffence = Pair(300002L, LocalDate.parse("2024-10-22"))), - DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_LAO_RESTRICTED, eventId = 100003L, mainOffence = Pair(200003L, LocalDate.parse("2024-10-13")), additionalOffence = Pair(300003L, LocalDate.parse("2024-10-23"))), - DataLoaderCaseAndEventAndOffences(ProbationCaseGenerator.CASE_LAO_EXCLUSION, eventId = 100004L, mainOffence = Pair(200004L, LocalDate.parse("2024-10-14")), additionalOffence = Pair(300004L, LocalDate.parse("2024-10-24"))), + DataLoaderCaseAndEventAndOffences( + ProbationCaseGenerator.CASE_COMPLEX, + eventId = 100001L, + mainOffence = Pair(200001L, LocalDate.parse("2024-10-11")), + additionalOffence = Pair(300001L, LocalDate.parse("2024-10-21")) + ), + DataLoaderCaseAndEventAndOffences( + ProbationCaseGenerator.CASE_X320741, + eventId = 100002L, + mainOffence = Pair(200002L, LocalDate.parse("2024-10-12")), + additionalOffence = Pair(300002L, LocalDate.parse("2024-10-22")) + ), + DataLoaderCaseAndEventAndOffences( + ProbationCaseGenerator.CASE_LAO_RESTRICTED, + eventId = 100003L, + mainOffence = Pair(200003L, LocalDate.parse("2024-10-13")), + additionalOffence = Pair(300003L, LocalDate.parse("2024-10-23")) + ), + DataLoaderCaseAndEventAndOffences( + ProbationCaseGenerator.CASE_LAO_EXCLUSION, + eventId = 100004L, + mainOffence = Pair(200004L, LocalDate.parse("2024-10-14")), + additionalOffence = Pair(300004L, LocalDate.parse("2024-10-24")) + ), ).forEach { generateEventAndAddOffences( it.probationCase, 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 842f36a4dc..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 = if (main) "M$id" else "A$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( From 86ce855bf9816a665620607d0cb41ad014dd3aa2 Mon Sep 17 00:00:00 2001 From: Greg Hawkins Date: Wed, 20 Nov 2024 10:52:17 +0000 Subject: [PATCH 3/4] APS-1482 - refactor to remove data class --- .../hmpps/data/ProbationCaseDataLoader.kt | 63 +++++++------------ 1 file changed, 24 insertions(+), 39 deletions(-) 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 fc3837c81e..365d1b226c 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,39 +101,30 @@ class ProbationCaseDataLoader( ) ) - listOf( - DataLoaderCaseAndEventAndOffences( - ProbationCaseGenerator.CASE_COMPLEX, - eventId = 100001L, - mainOffence = Pair(200001L, LocalDate.parse("2024-10-11")), - additionalOffence = Pair(300001L, LocalDate.parse("2024-10-21")) - ), - DataLoaderCaseAndEventAndOffences( - ProbationCaseGenerator.CASE_X320741, - eventId = 100002L, - mainOffence = Pair(200002L, LocalDate.parse("2024-10-12")), - additionalOffence = Pair(300002L, LocalDate.parse("2024-10-22")) - ), - DataLoaderCaseAndEventAndOffences( - ProbationCaseGenerator.CASE_LAO_RESTRICTED, - eventId = 100003L, - mainOffence = Pair(200003L, LocalDate.parse("2024-10-13")), - additionalOffence = Pair(300003L, LocalDate.parse("2024-10-23")) - ), - DataLoaderCaseAndEventAndOffences( - ProbationCaseGenerator.CASE_LAO_EXCLUSION, - eventId = 100004L, - mainOffence = Pair(200004L, LocalDate.parse("2024-10-14")), - additionalOffence = Pair(300004L, LocalDate.parse("2024-10-24")) - ), - ).forEach { - generateEventAndAddOffences( - it.probationCase, - it.eventId, - it.mainOffence, - it.additionalOffence - ) - } + 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, + 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) @@ -196,12 +187,6 @@ class MutableLimitedAccessPerson( fun toLimitedAccessPerson() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id) } -data class DataLoaderCaseAndEventAndOffences( - val probationCase: ProbationCase, - val eventId: Long, - val mainOffence: Pair, - val additionalOffence: Pair -) interface LduRepository : JpaRepository interface OffenceRepository : JpaRepository From 5b677ade70c1bf05f39bfb4f4b012bd534c29916 Mon Sep 17 00:00:00 2001 From: "probation-integration-bot[bot]" <177347787+probation-integration-bot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:54:03 +0000 Subject: [PATCH 4/4] Formatting changes --- .../uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt | 1 - 1 file changed, 1 deletion(-) 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 365d1b226c..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 @@ -187,7 +187,6 @@ class MutableLimitedAccessPerson( fun toLimitedAccessPerson() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id) } - interface LduRepository : JpaRepository interface OffenceRepository : JpaRepository interface AdditionalOffenceRepository : JpaRepository