Skip to content

Commit

Permalink
Seed LAO Test Data for Approved Premises (#3960)
Browse files Browse the repository at this point in the history
This commit enhances the approved-premises-and-delius seed data to include two new offenders and two new users to supports testing of LAO access in Approved Premises.

Two new users and cases are added:

* LAOFULLACCESS - has access to the excluded case X400000
* LAORESTRICTED - does not have access to the restricted case X400001
  • Loading branch information
davidatkinsuk authored Jul 8, 2024
1 parent 2f7ff5d commit 1382861
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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()
)
)

Expand Down Expand Up @@ -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<Ldu, Long>
interface OffenceRepository : JpaRepository<Offence, Long>
interface AdditionalOffenceRepository : JpaRepository<AdditionalOffence, Long>

interface PersonalCircumstanceTypeRepository : JpaRepository<PersonalCircumstanceType, Long>
interface PersonalCircumstanceSubTypeRepository : JpaRepository<PersonalCircumstanceSubType, Long>

interface MutableLimitedAccessPersonRepository : JpaRepository<MutableLimitedAccessPerson, Long>
interface RestrictionRepository : JpaRepository<Restriction, Long>
interface ExclusionRepository : JpaRepository<Exclusion, Long>
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1382861

Please sign in to comment.