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 3cd704aed..3c3d912c4 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 @@ -68,7 +68,6 @@ class DataLoader( private val referralBookingDataLoader: ReferralBookingDataLoader, private val documentDataLoader: DocumentDataLoader, private val entityManagerDataLoader: EntityManagerDataLoader - ) : ApplicationListener { @PostConstruct diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/EntityManagerDataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/EntityManagerDataLoader.kt index 8b6dcb6a5..b986db423 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/EntityManagerDataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/EntityManagerDataLoader.kt @@ -5,8 +5,11 @@ import jakarta.persistence.PersistenceContext import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator +import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator.INACTIVE_PERSON_ADDRESS_ID +import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator.PERSON_ADDRESS_ID import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator -import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.Referral +import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator.BOOKING_ARRIVED_DB_RECORD +import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator.BOOKING_DEPARTED_DB_RECORD @Component class EntityManagerDataLoader { @@ -14,21 +17,13 @@ class EntityManagerDataLoader { @PersistenceContext private lateinit var entityManager: EntityManager - var personAddressId: Long? = null - - var inactivePersonAddressId: Long? = null - - var bookingArrivedDbRecord: Referral? = null - - var bookingDepartedDbRecord: Referral? = null - @Transactional fun loadData() { - personAddressId = entityManager.merge(AddressGenerator.PERSON_ADDRESS).id - inactivePersonAddressId = entityManager.merge(AddressGenerator.INACTIVE_PERSON_ADDRESS).id + PERSON_ADDRESS_ID = entityManager.merge(AddressGenerator.PERSON_ADDRESS).id + INACTIVE_PERSON_ADDRESS_ID = entityManager.merge(AddressGenerator.INACTIVE_PERSON_ADDRESS).id entityManager.merge(ReferralGenerator.EXISTING_REFERRAL) entityManager.merge(ReferralGenerator.BOOKING_WITHOUT_ARRIVAL) - bookingArrivedDbRecord = entityManager.merge(ReferralGenerator.BOOKING_ARRIVED) - bookingDepartedDbRecord = entityManager.merge(ReferralGenerator.BOOKING_DEPARTED) + BOOKING_ARRIVED_DB_RECORD = entityManager.merge(ReferralGenerator.BOOKING_ARRIVED) + BOOKING_DEPARTED_DB_RECORD = entityManager.merge(ReferralGenerator.BOOKING_DEPARTED) } } \ No newline at end of file diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ReferralBookingDataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ReferralBookingDataLoader.kt index 97f3c212d..cbf0c3ae2 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ReferralBookingDataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ReferralBookingDataLoader.kt @@ -3,28 +3,29 @@ package uk.gov.justice.digital.hmpps.data import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator +import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator.BOOKING_ARRIVED_DB_RECORD +import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator.BOOKING_DEPARTED_DB_RECORD import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.ResidenceRepository import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository @Component class ReferralBookingDataLoader( private val personRepository: PersonRepository, - private val residenceRepository: ResidenceRepository, - private val entityManagerDataLoader: EntityManagerDataLoader + private val residenceRepository: ResidenceRepository ) { fun loadData() { personRepository.save(PersonGenerator.PERSON_WITH_BOOKING) ReferralGenerator.ARRIVAL = residenceRepository.save( ReferralGenerator.generateResidence( PersonGenerator.PERSON_WITH_BOOKING, - entityManagerDataLoader.bookingArrivedDbRecord!!, + BOOKING_ARRIVED_DB_RECORD!!, arrivalDateTime = ReferralGenerator.ARRIVAL.arrivalDate, ) ) ReferralGenerator.DEPARTURE = residenceRepository.save( ReferralGenerator.generateResidence( PersonGenerator.PERSON_WITH_BOOKING, - entityManagerDataLoader.bookingDepartedDbRecord!!, + BOOKING_DEPARTED_DB_RECORD!!, arrivalDateTime = ReferralGenerator.DEPARTURE.arrivalDate, departureDateTime = ReferralGenerator.DEPARTURE.departureDate ) diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AddressGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AddressGenerator.kt index 402a5a195..dfdf0ba85 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AddressGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AddressGenerator.kt @@ -13,6 +13,8 @@ object AddressGenerator { postcode = "MB01 3TD" ) + var PERSON_ADDRESS_ID: Long? = null + var INACTIVE_PERSON_ADDRESS = generatePersonAddress( personId = PersonGenerator.PERSON_INACTIVE_EVENT.id, addressNumber = "12", @@ -21,6 +23,8 @@ object AddressGenerator { postcode = "MB01 3TD" ) + var INACTIVE_PERSON_ADDRESS_ID: Long? = null + val Q001 = generateAddress( addressNumber = "1", streetName = "Promise Street", diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferralGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferralGenerator.kt index 7b603db0e..fc3aead7a 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferralGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferralGenerator.kt @@ -32,6 +32,8 @@ object ReferralGenerator { expectedDepartureDate = LocalDate.now().plusDays(7), ) + var BOOKING_ARRIVED_DB_RECORD: Referral? = null + var ARRIVAL = generateResidence(PersonGenerator.PERSON_WITH_BOOKING, BOOKING_ARRIVED) val DEPARTED_ID = UUID.randomUUID().toString() @@ -43,6 +45,8 @@ object ReferralGenerator { expectedDepartureDate = LocalDate.now().minusDays(1) ) + var BOOKING_DEPARTED_DB_RECORD: Referral? = null + var DEPARTURE = generateResidence( PersonGenerator.PERSON_WITH_BOOKING, BOOKING_DEPARTED, departureDateTime = ZonedDateTime.of( diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationInactiveTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationInactiveTest.kt index 04ee09597..2e1e6d489 100644 --- a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationInactiveTest.kt +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationInactiveTest.kt @@ -17,8 +17,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT import org.springframework.test.context.bean.override.mockito.MockitoBean -import uk.gov.justice.digital.hmpps.data.EntityManagerDataLoader import uk.gov.justice.digital.hmpps.data.generator.* +import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator.INACTIVE_PERSON_ADDRESS_ID import uk.gov.justice.digital.hmpps.datetime.EuropeLondon import uk.gov.justice.digital.hmpps.integrations.approvedpremises.EventDetails import uk.gov.justice.digital.hmpps.integrations.approvedpremises.PersonArrived @@ -76,9 +76,6 @@ internal class MessagingIntegrationInactiveTest { @Autowired private lateinit var staffRepository: StaffRepository - @Autowired - private lateinit var entityManagerDataLoader: EntityManagerDataLoader - @Test fun `application submission with an inactive event creates an alert contact`() { // Given an application-submitted event @@ -239,7 +236,7 @@ internal class MessagingIntegrationInactiveTest { // And the main address is updated to be that of the approved premises - consequently any existing main address is made previous val addresses = personAddressRepository.findAll().filter { it.personId == PersonGenerator.PERSON_INACTIVE_EVENT.id } - .associateBy { it.id == entityManagerDataLoader.inactivePersonAddressId } + .associateBy { it.id == INACTIVE_PERSON_ADDRESS_ID } assertThat(addresses.size, equalTo(2)) val previous = addresses[true]!! assertThat(previous.endDate, equalTo(details.arrivedAt.toLocalDate())) diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationTest.kt index 511b18b6e..027845f5b 100644 --- a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationTest.kt +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/MessagingIntegrationTest.kt @@ -18,8 +18,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT import org.springframework.test.context.bean.override.mockito.MockitoBean -import uk.gov.justice.digital.hmpps.data.EntityManagerDataLoader import uk.gov.justice.digital.hmpps.data.generator.* +import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator.PERSON_ADDRESS_ID import uk.gov.justice.digital.hmpps.datetime.EuropeLondon import uk.gov.justice.digital.hmpps.integrations.approvedpremises.EventDetails import uk.gov.justice.digital.hmpps.integrations.approvedpremises.PersonArrived @@ -87,9 +87,6 @@ internal class MessagingIntegrationTest { @Autowired private lateinit var staffRepository: StaffRepository - @Autowired - private lateinit var entityManagerDataLoader: EntityManagerDataLoader - @BeforeEach fun clearTopic() { val topic = channelManager.getChannel(topicName) @@ -299,7 +296,7 @@ internal class MessagingIntegrationTest { // And the main address is updated to be that of the approved premises - consequently any existing main address is made previous val addresses = personAddressRepository.findAll().filter { it.personId == PersonGenerator.DEFAULT.id } - .associateBy { it.id == entityManagerDataLoader.personAddressId } + .associateBy { it.id == PERSON_ADDRESS_ID } assertThat(addresses.size, equalTo(2)) val previous = addresses[true]!! assertThat(previous.endDate, equalTo(details.arrivedAt.toLocalDate()))