generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2f253ac
commit bc559ec
Showing
36 changed files
with
1,615 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
projects/assess-for-early-release-and-delius/deploy/values-dev.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
projects/assess-for-early-release-and-delius/deploy/values-preprod.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 70 additions & 3 deletions
73
...r-early-release-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,92 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.annotation.PostConstruct | ||
import jakarta.persistence.EntityManager | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.event.ApplicationReadyEvent | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator | ||
import org.springframework.transaction.annotation.Transactional | ||
import uk.gov.justice.digital.hmpps.data.generator.* | ||
import uk.gov.justice.digital.hmpps.user.AuditUserRepository | ||
|
||
@Component | ||
@ConditionalOnProperty("seed.database") | ||
class DataLoader( | ||
private val auditUserRepository: AuditUserRepository | ||
private val auditUserRepository: AuditUserRepository, | ||
private val entityManager: EntityManager | ||
) : ApplicationListener<ApplicationReadyEvent> { | ||
|
||
@PostConstruct | ||
fun saveAuditUser() { | ||
auditUserRepository.save(UserGenerator.AUDIT_USER) | ||
} | ||
|
||
@Transactional | ||
override fun onApplicationEvent(are: ApplicationReadyEvent) { | ||
// Perform dev/test database setup here, using JPA repositories and generator classes... | ||
entityManager.persist(ProviderGenerator.DEFAULT_PROVIDER) | ||
entityManager.persist(StaffGenerator.PDUHEAD) | ||
entityManager.persist(StaffGenerator.DEFAULT_PDUSTAFF_USER) | ||
entityManager.persist(ProviderGenerator.DEFAULT_BOROUGH) | ||
entityManager.persist(ProviderGenerator.DEFAULT_DISTRICT) | ||
|
||
createOfficeLocationsAndDistricts() | ||
|
||
entityManager.persist(ProviderGenerator.DEFAULT_TEAM) | ||
entityManager.persist(ProviderGenerator.TEAM_ENDED_OR_NULL_LOCATIONS) | ||
|
||
StaffGenerator.DEFAULT = StaffGenerator.generateStaff( | ||
StaffGenerator.DEFAULT.code, | ||
StaffGenerator.DEFAULT.forename, | ||
StaffGenerator.DEFAULT.surname, | ||
listOf(ProviderGenerator.DEFAULT_TEAM), | ||
ProviderGenerator.DEFAULT_PROVIDER, | ||
StaffGenerator.DEFAULT.middleName, | ||
StaffGenerator.DEFAULT.user, | ||
StaffGenerator.DEFAULT.id | ||
) | ||
entityManager.persist(StaffGenerator.DEFAULT) | ||
|
||
entityManager.persist(StaffGenerator.DEFAULT_STAFF_USER) | ||
entityManager.flush() | ||
|
||
entityManager.persist(PersonGenerator.DEFAULT_PERSON) | ||
entityManager.persist(PersonGenerator.PERSON_ENDED_TEAM_LOCATION) | ||
entityManager.persist(PersonGenerator.DEFAULT_CM) | ||
entityManager.persist(PersonGenerator.CM_ENDED_TEAM_LOCATION) | ||
|
||
val person = PersonGenerator.generatePerson("N123456").also(entityManager::persist) | ||
PersonGenerator.generateManager(person).also(entityManager::persist) | ||
|
||
createCaseloadData() | ||
} | ||
|
||
private fun createOfficeLocationsAndDistricts() { | ||
entityManager.persistAll( | ||
ProviderGenerator.DISTRICT_BRK, | ||
ProviderGenerator.DISTRICT_MKY, | ||
ProviderGenerator.DISTRICT_OXF, | ||
ProviderGenerator.LOCATION_BRK_1, | ||
ProviderGenerator.LOCATION_BRK_2, | ||
ProviderGenerator.LOCATION_ENDED, | ||
ProviderGenerator.LOCATION_NULL | ||
) | ||
} | ||
|
||
private fun createCaseloadData() { | ||
entityManager.persistAll( | ||
CaseloadGenerator.TEAM1, | ||
CaseloadGenerator.STAFF1, | ||
CaseloadGenerator.STAFF2, | ||
CaseloadGenerator.CASELOAD_ROLE_OM_1, | ||
CaseloadGenerator.CASELOAD_ROLE_OM_2, | ||
CaseloadGenerator.CASELOAD_ROLE_OM_3, | ||
CaseloadGenerator.CASELOAD_ROLE_OM_4, | ||
CaseloadGenerator.CASELOAD_ROLE_OS_1 | ||
) | ||
} | ||
|
||
private fun EntityManager.persistAll(vararg entities: Any) { | ||
entities.forEach { persist(it) } | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...nd-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CaseloadGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.api.model.ManagedOffender | ||
import uk.gov.justice.digital.hmpps.api.model.Name | ||
import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator.DEFAULT_TEAM | ||
import uk.gov.justice.digital.hmpps.entity.Caseload | ||
import uk.gov.justice.digital.hmpps.entity.Staff | ||
import uk.gov.justice.digital.hmpps.entity.Team | ||
import uk.gov.justice.digital.hmpps.service.asStaff | ||
import uk.gov.justice.digital.hmpps.service.asTeam | ||
import java.time.LocalDate | ||
|
||
object CaseloadGenerator { | ||
|
||
val STAFF1 = StaffGenerator.generateStaff("STCDE01", "Bob", "Smith") | ||
val STAFF2 = StaffGenerator.generateStaff("STCDE02", "Joe", "Bloggs") | ||
|
||
val TEAM1 = ProviderGenerator.generateTeam("N02BDT") | ||
|
||
val CASELOAD_ROLE_OM_1 = generateCaseload( | ||
staff = STAFF1, | ||
team = DEFAULT_TEAM, | ||
crn = "crn0001", | ||
firstName = "John", | ||
secondName = "x", | ||
surname = "Brown", | ||
allocationDate = LocalDate.of(2024, 1, 8), | ||
roleCode = Caseload.CaseloadRole.OFFENDER_MANAGER.value | ||
) | ||
|
||
val CASELOAD_ROLE_OM_2 = generateCaseload( | ||
staff = STAFF1, | ||
team = DEFAULT_TEAM, | ||
crn = "crn0022", | ||
firstName = "Jane", | ||
secondName = "y", | ||
surname = "Doe", | ||
allocationDate = LocalDate.of(2024, 1, 9), | ||
roleCode = Caseload.CaseloadRole.OFFENDER_MANAGER.value | ||
) | ||
|
||
val CASELOAD_ROLE_OM_3 = generateCaseload( | ||
staff = STAFF2, | ||
team = DEFAULT_TEAM, | ||
crn = "crn0077", | ||
firstName = "Ano", | ||
secondName = "no", | ||
surname = "mys", | ||
allocationDate = LocalDate.of(2024, 1, 10), | ||
roleCode = Caseload.CaseloadRole.OFFENDER_MANAGER.value | ||
) | ||
|
||
val CASELOAD_ROLE_OM_4 = generateCaseload( | ||
staff = STAFF2, | ||
team = TEAM1, | ||
crn = "crn0078", | ||
firstName = "Joe", | ||
secondName = "Denis", | ||
surname = "Doe", | ||
allocationDate = LocalDate.of(2024, 1, 10), | ||
roleCode = Caseload.CaseloadRole.OFFENDER_MANAGER.value | ||
) | ||
|
||
val CASELOAD_ROLE_OS_1 = generateCaseload( | ||
staff = STAFF2, | ||
team = DEFAULT_TEAM, | ||
crn = "crn0088", | ||
firstName = "Robert", | ||
secondName = "Alan", | ||
surname = "Brown", | ||
roleCode = Caseload.CaseloadRole.ORDER_SUPERVISOR.value | ||
) | ||
|
||
val MANAGED_OFFENDER = generateManagedOffender(CASELOAD_ROLE_OM_1, STAFF1, DEFAULT_TEAM) | ||
|
||
fun generateCaseload( | ||
staff: Staff, | ||
team: Team, | ||
allocationDate: LocalDate? = LocalDate.now(), | ||
roleCode: String, | ||
crn: String, | ||
firstName: String, | ||
secondName: String?, | ||
surname: String, | ||
startDate: LocalDate? = LocalDate.now(), | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Caseload( | ||
staff, | ||
team, | ||
allocationDate, | ||
roleCode, | ||
crn, | ||
firstName, | ||
secondName, | ||
surname, | ||
startDate, | ||
id | ||
) | ||
|
||
fun generateManagedOffender( | ||
caseload: Caseload, | ||
staff: Staff, | ||
team: Team | ||
) = ManagedOffender( | ||
caseload.crn, | ||
Name(caseload.firstName, caseload.secondName, caseload.surname), | ||
caseload.allocationDate, | ||
staff.asStaff(), | ||
team.asTeam() | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
...-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.entity.* | ||
|
||
object PersonGenerator { | ||
val DEFAULT_PERSON = generatePerson("T123456") | ||
val PERSON_ENDED_TEAM_LOCATION = generatePerson("T123457") | ||
val DEFAULT_CM = generateManager(DEFAULT_PERSON) | ||
val CM_ENDED_TEAM_LOCATION = | ||
generateManager(person = PERSON_ENDED_TEAM_LOCATION, team = ProviderGenerator.TEAM_ENDED_OR_NULL_LOCATIONS) | ||
|
||
fun generatePerson( | ||
crn: String, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Person( | ||
crn, | ||
softDeleted, | ||
id | ||
) | ||
|
||
fun generateManager( | ||
person: Person, | ||
provider: Provider = ProviderGenerator.DEFAULT_PROVIDER, | ||
team: Team = ProviderGenerator.DEFAULT_TEAM, | ||
staff: Staff = StaffGenerator.DEFAULT, | ||
softDeleted: Boolean = false, | ||
active: Boolean = true, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = PersonManager(person, provider, team, staff, softDeleted, active, id) | ||
} |
Oops, something went wrong.