Skip to content

Commit

Permalink
APS-1482 - link offences data to probation cases (#4430)
Browse files Browse the repository at this point in the history
APS-1482 - add offences data to probation cases
  • Loading branch information
gregkhawkins authored Nov 15, 2024
1 parent 8439efe commit 2052628
Showing 1 changed file with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import uk.gov.justice.digital.hmpps.entity.LimitedAccessPerson
import uk.gov.justice.digital.hmpps.entity.Restriction
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.Ldu
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCase
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCaseRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.manager.probation.PersonManagerRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.AdditionalOffence
Expand Down Expand Up @@ -100,9 +101,34 @@ class ProbationCaseDataLoader(
)
)

listOf(
ProbationCaseGenerator.CASE_COMPLEX,
ProbationCaseGenerator.CASE_X320741,
ProbationCaseGenerator.CASE_LAO_RESTRICTED,
ProbationCaseGenerator.CASE_LAO_EXCLUSION,
).forEach {
generateEventAndAddOffences(probationCase = it)
}

personalCircumstanceTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_TYPES)
personalCircumstanceSubTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_SUB_TYPES)
personalCircumstanceRepository.save(
PersonalCircumstanceGenerator.generate(
ProbationCaseGenerator.CASE_COMPLEX.id,
PersonalCircumstanceGenerator.PC_TYPES.first { it.code == PersonalCircumstanceType.Code.VETERAN.value },
PersonalCircumstanceGenerator.PC_SUB_TYPES.first { it.description == PersonalCircumstanceType.Code.VETERAN.value + "SUB" }
))

mutableLimitedAccessPersonRepository.save(RESTRICTED_CASE)
mutableLimitedAccessPersonRepository.save(EXCLUDED_CASE)
restrictionRepository.save(LimitedAccessGenerator.generateRestriction(RESTRICTED_CASE.toLimitedAccessPerson()))
exclusionRepository.save(LimitedAccessGenerator.generateExclusion(EXCLUDED_CASE.toLimitedAccessPerson()))
}

private fun generateEventAndAddOffences(probationCase: ProbationCase) {
val event = PersonGenerator.generateEvent(
"1",
ProbationCaseGenerator.CASE_COMPLEX.id
probationCase.id
).apply(eventRepository::save)

mainOffenceRepository.save(
Expand All @@ -120,20 +146,6 @@ class ProbationCaseDataLoader(
LocalDate.now().minusDays(5)
)
)

personalCircumstanceTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_TYPES)
personalCircumstanceSubTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_SUB_TYPES)
personalCircumstanceRepository.save(
PersonalCircumstanceGenerator.generate(
ProbationCaseGenerator.CASE_COMPLEX.id,
PersonalCircumstanceGenerator.PC_TYPES.first { it.code == PersonalCircumstanceType.Code.VETERAN.value },
PersonalCircumstanceGenerator.PC_SUB_TYPES.first { it.description == PersonalCircumstanceType.Code.VETERAN.value + "SUB" }
))

mutableLimitedAccessPersonRepository.save(RESTRICTED_CASE)
mutableLimitedAccessPersonRepository.save(EXCLUDED_CASE)
restrictionRepository.save(LimitedAccessGenerator.generateRestriction(RESTRICTED_CASE.toLimitedAccessPerson()))
exclusionRepository.save(LimitedAccessGenerator.generateExclusion(EXCLUDED_CASE.toLimitedAccessPerson()))
}
}

Expand Down

0 comments on commit 2052628

Please sign in to comment.