Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APS-1482 - changes to offence id generation and offences data setup #4444

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -125,25 +141,33 @@ class ProbationCaseDataLoader(
exclusionRepository.save(LimitedAccessGenerator.generateExclusion(EXCLUDED_CASE.toLimitedAccessPerson()))
}

private fun generateEventAndAddOffences(probationCase: ProbationCase) {
private fun generateEventAndAddOffences(
probationCase: ProbationCase,
eventId: Long,
mainOffence: Pair<Long, LocalDate>,
additionalOffence: Pair<Long, LocalDate>,
) {
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
)
)

additionalOffenceRepository.save(
OffenceGenerator.generateAdditionalOffence(
event,
OffenceGenerator.OFFENCE_TWO,
LocalDate.now().minusDays(5)
id = additionalOffence.first,
date = additionalOffence.second
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface MainOffenceRepository : JpaRepository<MainOffence, Long> {
@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,
Expand All @@ -99,7 +99,7 @@ interface MainOffenceRepository : JpaRepository<MainOffence, Long> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading