|
1 | 1 | package uk.gov.justice.digital.hmpps.data
|
2 | 2 |
|
3 | 3 | import jakarta.annotation.PostConstruct
|
| 4 | +import jakarta.persistence.EntityManager |
| 5 | +import jakarta.transaction.Transactional |
4 | 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
5 | 7 | import org.springframework.boot.context.event.ApplicationReadyEvent
|
6 | 8 | import org.springframework.context.ApplicationListener
|
7 | 9 | import org.springframework.stereotype.Component
|
| 10 | +import uk.gov.justice.digital.hmpps.data.generator.Data.BUSINESS_INTERACTIONS |
| 11 | +import uk.gov.justice.digital.hmpps.data.generator.Data.CONTACT_TYPES |
| 12 | +import uk.gov.justice.digital.hmpps.data.generator.Data.DUPLICATE_STAFF_1 |
| 13 | +import uk.gov.justice.digital.hmpps.data.generator.Data.DUPLICATE_STAFF_2 |
| 14 | +import uk.gov.justice.digital.hmpps.data.generator.Data.MANAGER |
| 15 | +import uk.gov.justice.digital.hmpps.data.generator.Data.MANAGER_STAFF |
| 16 | +import uk.gov.justice.digital.hmpps.data.generator.Data.PERSON |
| 17 | +import uk.gov.justice.digital.hmpps.data.generator.Data.STAFF |
8 | 18 | import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
|
9 | 19 | import uk.gov.justice.digital.hmpps.user.AuditUserRepository
|
10 | 20 |
|
11 | 21 | @Component
|
12 | 22 | @ConditionalOnProperty("seed.database")
|
13 | 23 | class DataLoader(
|
14 |
| - private val auditUserRepository: AuditUserRepository |
| 24 | + private val auditUserRepository: AuditUserRepository, |
| 25 | + private val entityManager: EntityManager, |
15 | 26 | ) : ApplicationListener<ApplicationReadyEvent> {
|
16 |
| - |
17 | 27 | @PostConstruct
|
18 | 28 | fun saveAuditUser() {
|
19 | 29 | auditUserRepository.save(UserGenerator.AUDIT_USER)
|
20 | 30 | }
|
21 | 31 |
|
| 32 | + @Transactional |
22 | 33 | override fun onApplicationEvent(are: ApplicationReadyEvent) {
|
23 |
| - // Perform dev/test database setup here, using JPA repositories and generator classes... |
| 34 | + listOf( |
| 35 | + PERSON, |
| 36 | + STAFF, |
| 37 | + STAFF.user, |
| 38 | + DUPLICATE_STAFF_1, |
| 39 | + DUPLICATE_STAFF_1.user, |
| 40 | + DUPLICATE_STAFF_2, |
| 41 | + DUPLICATE_STAFF_2.user, |
| 42 | + MANAGER_STAFF, |
| 43 | + MANAGER, |
| 44 | + *CONTACT_TYPES, |
| 45 | + *BUSINESS_INTERACTIONS, |
| 46 | + ).forEach { |
| 47 | + entityManager.persist(it) |
| 48 | + } |
24 | 49 | }
|
25 | 50 | }
|
0 commit comments