Skip to content

Commit 3a010d3

Browse files
Use SYS as user for deletes from sync (#256)
1 parent 5f93ab9 commit 3a010d3

File tree

6 files changed

+10
-4
lines changed

6 files changed

+10
-4
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/sync/internal/SyncTapAuthorisation.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.springframework.data.repository.findByIdOrNull
55
import org.springframework.stereotype.Service
66
import org.springframework.transaction.annotation.Transactional
77
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovementContext
8+
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovementContext.Companion.SYSTEM_USERNAME
89
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.set
910
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.IdGenerator.newUuid
1011
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.person.PersonSummary
@@ -68,6 +69,7 @@ class SyncTapAuthorisation(
6869
}
6970

7071
fun deleteById(id: UUID) {
72+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME).set()
7173
authorisationRepository.findByIdOrNull(id)?.also { authorisation ->
7274
val occurrenceCount = occurrenceRepository.countByAuthorisationId(authorisation.id)
7375
if (occurrenceCount > 0) {

src/main/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/sync/internal/SyncTapMovement.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.springframework.data.repository.findByIdOrNull
44
import org.springframework.stereotype.Service
55
import org.springframework.transaction.annotation.Transactional
66
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovementContext
7+
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovementContext.Companion.SYSTEM_USERNAME
78
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.set
89
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.IdGenerator.newUuid
910
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.person.PersonSummary
@@ -73,6 +74,7 @@ class SyncTapMovement(
7374
}
7475

7576
fun deleteById(id: UUID) {
77+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME).set()
7678
movementRepository.findByIdOrNull(id)?.also {
7779
it.occurrence?.removeMovement(it) { statusCode -> occurrenceStatusRepository.getByCode(statusCode) }
7880
movementRepository.delete(it)

src/main/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/sync/internal/SyncTapOccurrence.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.springframework.data.repository.findByIdOrNull
55
import org.springframework.stereotype.Service
66
import org.springframework.transaction.annotation.Transactional
77
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovementContext
8+
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovementContext.Companion.SYSTEM_USERNAME
89
import uk.gov.justice.digital.hmpps.externalmovementsapi.context.set
910
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.IdGenerator.newUuid
1011
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.referencedata.ReferenceDataDomain.Code.ABSENCE_REASON_CATEGORY
@@ -83,6 +84,7 @@ class SyncTapOccurrence(
8384
}
8485

8586
fun deleteById(id: UUID) {
87+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME).set()
8688
occurrenceRepository.findByIdOrNull(id)?.also { occurrence ->
8789
val movementCount = movementRepository.countByOccurrenceId(occurrence.id)
8890
if (movementCount > 0) {

src/test/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/integration/sync/DeleteTapAuthorisationIntTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class DeleteTapAuthorisationIntTest(
7171
auth,
7272
RevisionType.DEL,
7373
setOf(TemporaryAbsenceAuthorisation::class.simpleName!!),
74-
ExternalMovementContext.get().copy(source = DataSource.NOMIS),
74+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME, source = DataSource.NOMIS),
7575
)
7676

7777
verifyEvents(auth, setOf())

src/test/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/integration/sync/DeleteTapMovementIntTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ class DeleteTapMovementIntTest(
7171
movement,
7272
RevisionType.DEL,
7373
setOf(TemporaryAbsenceMovement::class.simpleName!!, TemporaryAbsenceOccurrence::class.simpleName!!),
74-
ExternalMovementContext.get().copy(source = DataSource.NOMIS),
74+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME, source = DataSource.NOMIS),
7575
)
7676

7777
verifyAudit(
7878
occurrence,
7979
RevisionType.MOD,
8080
setOf(TemporaryAbsenceMovement::class.simpleName!!, TemporaryAbsenceOccurrence::class.simpleName!!),
81-
ExternalMovementContext.get().copy(source = DataSource.NOMIS),
81+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME, source = DataSource.NOMIS),
8282
)
8383

8484
verifyEvents(movement, setOf())

src/test/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/integration/sync/DeleteTapOccurrenceIntTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class DeleteTapOccurrenceIntTest(
8888
occurrence,
8989
RevisionType.DEL,
9090
setOf(TemporaryAbsenceOccurrence::class.simpleName!!, TemporaryAbsenceAuthorisation::class.simpleName!!),
91-
ExternalMovementContext.get().copy(source = DataSource.NOMIS),
91+
ExternalMovementContext.get().copy(username = SYSTEM_USERNAME, source = DataSource.NOMIS),
9292
)
9393

9494
verifyEvents(occurrence, setOf())

0 commit comments

Comments
 (0)