diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index efb8fde221..17dbd3e3f5 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -147,6 +147,12 @@ class DataLoader( staffRepository.save(StaffGenerator.JIM_SNOW) staffUserRepository.save(StaffGenerator.JIM_SNOW_USER) + staffRepository.save(StaffGenerator.LAO_FULL_ACCESS) + staffUserRepository.save(StaffGenerator.LAO_FULL_ACCESS_USER) + + staffRepository.save(StaffGenerator.LAO_RESTRICTED) + staffUserRepository.save(StaffGenerator.LAO_RESTRICTED_USER) + val personManagerStaff = StaffGenerator.generate(code = "N54A001") staffRepository.save(personManagerStaff) val person = PersonGenerator.DEFAULT 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 7d77000caf..18febf4d6e 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 @@ -1,8 +1,17 @@ package uk.gov.justice.digital.hmpps.data +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.data.generator.* +import uk.gov.justice.digital.hmpps.data.generator.LimitedAccessGenerator.EXCLUDED_CASE +import uk.gov.justice.digital.hmpps.data.generator.LimitedAccessGenerator.RESTRICTED_CASE +import uk.gov.justice.digital.hmpps.entity.Exclusion +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.document.entity.PersonalCircumstanceRepository import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.PersonalCircumstanceSubType @@ -34,7 +43,10 @@ class ProbationCaseDataLoader( private val additionalOffenceRepository: AdditionalOffenceRepository, private val personalCircumstanceTypeRepository: PersonalCircumstanceTypeRepository, private val personalCircumstanceSubTypeRepository: PersonalCircumstanceSubTypeRepository, - private val personalCircumstanceRepository: PersonalCircumstanceRepository + private val personalCircumstanceRepository: PersonalCircumstanceRepository, + private val mutableLimitedAccessPersonRepository: MutableLimitedAccessPersonRepository, + private val restrictionRepository: RestrictionRepository, + private val exclusionRepository: ExclusionRepository ) { fun loadData() { offenceRepository.saveAll(listOf(OffenceGenerator.OFFENCE_ONE, OffenceGenerator.OFFENCE_TWO)) @@ -46,13 +58,17 @@ class ProbationCaseDataLoader( probationCaseRepository.save(ProbationCaseGenerator.CASE_SIMPLE) probationCaseRepository.save(ProbationCaseGenerator.CASE_X320741) probationCaseRepository.save(ProbationCaseGenerator.CASE_X320811) + probationCaseRepository.save(ProbationCaseGenerator.CASE_LAO_EXCLUSION) + probationCaseRepository.save(ProbationCaseGenerator.CASE_LAO_RESTRICTED) personManagerRepository.saveAll( listOf( ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_COMPLEX).asPersonManager(), ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_SIMPLE).asPersonManager(), ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_X320741).asPersonManager(), - ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_X320811).asPersonManager() + ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_X320811).asPersonManager(), + ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_LAO_EXCLUSION).asPersonManager(), + ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_LAO_RESTRICTED).asPersonManager() ) ) @@ -102,12 +118,35 @@ class ProbationCaseDataLoader( 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())) } } +@Entity +@Table(name = "offender") +class MutableLimitedAccessPerson( + @Column(columnDefinition = "char(7)") + val crn: String, + val exclusionMessage: String?, + val restrictionMessage: String?, + @Id + @Column(name = "offender_id") + val id: Long, +) { + fun toLimitedAccessPerson() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id) +} + interface LduRepository : JpaRepository interface OffenceRepository : JpaRepository interface AdditionalOffenceRepository : JpaRepository interface PersonalCircumstanceTypeRepository : JpaRepository interface PersonalCircumstanceSubTypeRepository : JpaRepository + +interface MutableLimitedAccessPersonRepository : JpaRepository +interface RestrictionRepository : JpaRepository +interface ExclusionRepository : JpaRepository diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.kt new file mode 100644 index 0000000000..2769f5973a --- /dev/null +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.kt @@ -0,0 +1,43 @@ +package uk.gov.justice.digital.hmpps.data.generator + +import uk.gov.justice.digital.hmpps.data.MutableLimitedAccessPerson +import uk.gov.justice.digital.hmpps.entity.Exclusion +import uk.gov.justice.digital.hmpps.entity.LimitedAccessPerson +import uk.gov.justice.digital.hmpps.entity.LimitedAccessUser +import uk.gov.justice.digital.hmpps.entity.Restriction +import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCase +import uk.gov.justice.digital.hmpps.integrations.delius.staff.StaffUser +import java.time.LocalDateTime + +object LimitedAccessGenerator { + val FULL_ACCESS_USER = generateLaoUser(StaffGenerator.LAO_FULL_ACCESS_USER) + val LIMITED_ACCESS_USER = generateLaoUser(StaffGenerator.LAO_RESTRICTED_USER) + val EXCLUDED_CASE = + generateLaoPerson(ProbationCaseGenerator.CASE_LAO_EXCLUSION, exclusionMessage = "This case has an exclusion") + val RESTRICTED_CASE = generateLaoPerson( + ProbationCaseGenerator.CASE_LAO_RESTRICTED, + restrictionMessage = "This case has an restriction" + ) + + fun generateLaoUser(staffUser: StaffUser) = LimitedAccessUser(staffUser.username, staffUser.id) + + fun generateLaoPerson( + probationCase: ProbationCase, + exclusionMessage: String? = null, + restrictionMessage: String? = null, + ) = MutableLimitedAccessPerson(probationCase.crn, exclusionMessage, restrictionMessage, probationCase.id) + + fun generateExclusion( + person: LimitedAccessPerson, + user: LimitedAccessUser = LIMITED_ACCESS_USER, + endDateTime: LocalDateTime? = null, + id: Long = IdGenerator.getAndIncrement(), + ) = Exclusion(person, user, endDateTime, id) + + fun generateRestriction( + person: LimitedAccessPerson, + user: LimitedAccessUser = FULL_ACCESS_USER, + endDateTime: LocalDateTime? = null, + id: Long = IdGenerator.getAndIncrement(), + ) = Restriction(person, user, endDateTime, id) +} \ No newline at end of file diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt index a296844a96..93d0233b3e 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt @@ -57,6 +57,34 @@ object ProbationCaseGenerator { religion = ReferenceDataGenerator.RELIGION_OTHER, genderIdentity = ReferenceDataGenerator.GENDER_IDENTITY_PNS, ) + val CASE_LAO_EXCLUSION = generate( + crn = "X400000", + forename = "Elliot Exclusion", + surname = "Erickson", + dateOfBirth = LocalDate.of(1979, 4, 11), + nomsId = "A1235AI", + gender = ReferenceDataGenerator.GENDER_MALE, + ethnicity = ReferenceDataGenerator.ETHNICITY_WHITE, + nationality = ReferenceDataGenerator.NATIONALITY_BRITISH, + religion = ReferenceDataGenerator.RELIGION_OTHER, + genderIdentity = ReferenceDataGenerator.GENDER_IDENTITY_PNS, + currentExclusion = true, + currentRestriction = false, + ) + val CASE_LAO_RESTRICTED = generate( + crn = "X400001", + forename = "Reginald Restricted", + surname = "Robinson", + dateOfBirth = LocalDate.of(1981, 1, 1), + nomsId = "A1236AI", + gender = ReferenceDataGenerator.GENDER_MALE, + ethnicity = ReferenceDataGenerator.ETHNICITY_WHITE, + nationality = ReferenceDataGenerator.NATIONALITY_BRITISH, + religion = ReferenceDataGenerator.RELIGION_OTHER, + genderIdentity = ReferenceDataGenerator.GENDER_IDENTITY_PNS, + currentExclusion = false, + currentRestriction = true, + ) fun generate( crn: String, diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt index 80f25bb87e..56939347b5 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt @@ -14,9 +14,17 @@ object StaffGenerator { val JIM_SNOW = generate( name = "Jim Snow" ) + val LAO_FULL_ACCESS = generate( + name = "LAO Full Access" + ) + val LAO_RESTRICTED = generate( + name = "LAO Restricted" + ) val DEFAULT_STAFF_USER = generateStaffUser("john-smith", DEFAULT_STAFF) val JIM_SNOW_USER = generateStaffUser("JIMSNOWLDAP", JIM_SNOW) + val LAO_FULL_ACCESS_USER = generateStaffUser("LAOFULLACCESS", LAO_FULL_ACCESS) + val LAO_RESTRICTED_USER = generateStaffUser("LAORESTRICTED", LAO_RESTRICTED) fun generate( name: String = "Test",