@@ -7,25 +7,19 @@ import org.springframework.boot.context.event.ApplicationReadyEvent
7
7
import org.springframework.context.ApplicationListener
8
8
import org.springframework.stereotype.Component
9
9
import org.springframework.transaction.annotation.Transactional
10
- import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator
11
- import uk.gov.justice.digital.hmpps.data.generator.AppointmentGenerator
12
- import uk.gov.justice.digital.hmpps.data.generator.NSIGenerator
13
- import uk.gov.justice.digital.hmpps.data.generator.NSIManagerGenerator
14
- import uk.gov.justice.digital.hmpps.data.generator.NSIStatusGenerator
15
- import uk.gov.justice.digital.hmpps.data.generator.NSITypeGenerator
16
- import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
17
- import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator
18
- import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
19
- import uk.gov.justice.digital.hmpps.data.generator.RegistrationGenerator
20
- import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
10
+ import uk.gov.justice.digital.hmpps.api.model.CreateAppointment
11
+ import uk.gov.justice.digital.hmpps.audit.BusinessInteraction
12
+ import uk.gov.justice.digital.hmpps.data.generator.*
21
13
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
14
+ import uk.gov.justice.digital.hmpps.entity.BusinessInteractionCode
22
15
import uk.gov.justice.digital.hmpps.entity.Category
23
16
import uk.gov.justice.digital.hmpps.entity.Level
24
17
import uk.gov.justice.digital.hmpps.entity.Person
25
18
import uk.gov.justice.digital.hmpps.user.AuditUserRepository
26
19
import java.time.LocalDate
27
20
import java.time.LocalTime
28
21
import java.time.ZonedDateTime
22
+ import java.util.*
29
23
30
24
@Component
31
25
@ConditionalOnProperty(" seed.database" )
@@ -41,6 +35,9 @@ class DataLoader(
41
35
42
36
@Transactional
43
37
override fun onApplicationEvent (are : ApplicationReadyEvent ) {
38
+ BusinessInteractionCode .entries.forEach {
39
+ em.persist(BusinessInteraction (IdGenerator .getAndIncrement(), it.code, ZonedDateTime .now()))
40
+ }
44
41
em.saveAll(
45
42
NSITypeGenerator .DTR ,
46
43
NSIStatusGenerator .INITIATED ,
@@ -75,6 +72,29 @@ class DataLoader(
75
72
)
76
73
77
74
createAppointments(PersonGenerator .DEFAULT )
75
+
76
+ createAppointmentData()
77
+ }
78
+
79
+ fun createAppointmentData () {
80
+ val conflictPerson = PersonGenerator .CREATE_APPOINTMENT
81
+ val conflictManager = PersonGenerator .generateManager(PersonGenerator .CREATE_APPOINTMENT )
82
+ em.saveAll(
83
+ * AppointmentGenerator .APPOINTMENT_TYPES .toTypedArray(),
84
+ conflictPerson,
85
+ conflictManager,
86
+ AppointmentGenerator .generate(
87
+ conflictPerson,
88
+ AppointmentGenerator .ATTENDANCE_TYPE ,
89
+ LocalDate .now().plusDays(7 ),
90
+ ZonedDateTime .now().plusDays(7 ),
91
+ ZonedDateTime .now().plusDays(7 ).plusHours(1 ),
92
+ location = null ,
93
+ probationAreaId = conflictManager.probationAreaId,
94
+ team = conflictManager.team,
95
+ staff = conflictManager.staff
96
+ )
97
+ )
78
98
}
79
99
80
100
fun EntityManager.saveAll (vararg any : Any ) = any.forEach { persist(it) }
@@ -89,17 +109,19 @@ class DataLoader(
89
109
date,
90
110
start,
91
111
start.plusMinutes(30 ),
92
- if (start.minute == 30 ) AppointmentGenerator .DEFAULT_LOCATION else null ,
93
- ProviderGenerator .DEFAULT_STAFF ,
94
- if (start.isAfter(ZonedDateTime .now())) {
95
- null
96
- } else {
97
- AppointmentGenerator .ATTENDED_OUTCOME
98
- },
99
- if (start.minute == 0 ) {
112
+ probationAreaId = ProviderGenerator .DEFAULT_AREA .id,
113
+ team = ProviderGenerator .DEFAULT_TEAM ,
114
+ staff = ProviderGenerator .DEFAULT_STAFF ,
115
+ location = if (start.minute == 30 ) AppointmentGenerator .DEFAULT_LOCATION else null ,
116
+ description = if (start.minute == 0 ) {
100
117
" On the hour"
101
118
} else {
102
119
null
120
+ },
121
+ outcome = if (start.isAfter(ZonedDateTime .now())) {
122
+ null
123
+ } else {
124
+ AppointmentGenerator .ATTENDED_OUTCOME
103
125
}
104
126
)
105
127
}
0 commit comments