diff --git a/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index 42189bf974..cf09513d64 100644 --- a/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -115,7 +115,6 @@ internal class IntegrationTest { """ LED 11/09/2025 ACR 26/11/2022 - PED 26/10/2022 SED 10/09/2025 EXP 27/11/2022 HDE 28/10/2022 diff --git a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateService.kt b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateService.kt index 1e04fda2eb..e1c119973d 100644 --- a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateService.kt +++ b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateService.kt @@ -67,21 +67,13 @@ class CustodyDateUpdateService( sentenceDetail: SentenceDetail, custody: Custody ): List = CustodyDateType.entries.mapNotNull { cdt -> - val date = cdt.field.getter.call(sentenceDetail) - if (date == null) { - custody.keyDates.find(cdt.code)?.let { - val kd = KeyDate(it.id, it.custody, it.type, it.date) - kd.softDeleted = true - kd.version = it.version - kd - } - } else { + cdt.field.getter.call(sentenceDetail)?.let { val existing = custody.keyDates.find(cdt.code) if (existing != null) { - existing.changeDate(date) + existing.changeDate(it) } else { val kdt = referenceDataRepository.findKeyDateType(cdt.code) - KeyDate(null, custody, kdt, date) + KeyDate(null, custody, kdt, it) } } } diff --git a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/KeyDate.kt b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/KeyDate.kt index 10417e9e36..5263a08365 100644 --- a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/KeyDate.kt +++ b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/KeyDate.kt @@ -41,8 +41,11 @@ class KeyDate( fun changeDate(date: LocalDate): KeyDate? = if (this.date == date) { null } else { - val keyDate = KeyDate(id, custody, type, date) - keyDate.version = version - keyDate + // create new entity to allow dry run to not make changes + KeyDate(id, custody, type, date).also { + it.createdDateTime = createdDateTime + it.createdUserId = createdUserId + it.version = version + } } }