From e7cba2cda9f5b42e7fd7efb588c52c8b5a0c3c14 Mon Sep 17 00:00:00 2001 From: pmcphee77 <150798161+pmcphee77@users.noreply.github.com> Date: Tue, 14 May 2024 12:06:07 +0100 Subject: [PATCH] PI-2196: Turn dry run off in preprod (#3792) * PI-2196: Turn dry run off in preprod --- .../deploy/values-preprod.yml | 2 +- .../hmpps/ProbationMatchingIntegrationTest.kt | 21 +++++++++++-------- .../justice/digital/hmpps/entity/Person.kt | 1 - .../digital/hmpps/messaging/Handler.kt | 14 ++++++------- .../digital/hmpps/model/MatchResult.kt | 2 +- .../digital/hmpps/model/MergeResult.kt | 2 +- .../hmpps/service/PrisonMatchingService.kt | 2 +- .../hmpps/service/ProbationMatchingService.kt | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/projects/prison-identifier-and-delius/deploy/values-preprod.yml b/projects/prison-identifier-and-delius/deploy/values-preprod.yml index 90d9ac4385..6ba051595f 100644 --- a/projects/prison-identifier-and-delius/deploy/values-preprod.yml +++ b/projects/prison-identifier-and-delius/deploy/values-preprod.yml @@ -16,7 +16,7 @@ generic-service: bulk-update: enabled: true - dry-run: true + dry-run: false schedule: 0 7 * * 1 generic-prometheus-alerts: diff --git a/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationMatchingIntegrationTest.kt b/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationMatchingIntegrationTest.kt index 09f65ed51c..32b0cb0fb8 100644 --- a/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationMatchingIntegrationTest.kt +++ b/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationMatchingIntegrationTest.kt @@ -4,6 +4,7 @@ import com.github.tomakehurst.wiremock.WireMockServer import com.github.tomakehurst.wiremock.client.WireMock.* import com.github.tomakehurst.wiremock.common.ContentTypes.APPLICATION_JSON import com.github.tomakehurst.wiremock.common.ContentTypes.CONTENT_TYPE +import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test import org.mockito.Mockito.verify import org.springframework.beans.factory.annotation.Autowired @@ -23,7 +24,6 @@ import uk.gov.justice.digital.hmpps.telemetry.TelemetryService @AutoConfigureMockMvc @SpringBootTest(webEnvironment = RANDOM_PORT) -@TestPropertySource(properties = ["messaging.consumer.dry-run=true"]) internal class ProbationMatchingIntegrationTest { @Value("\${messaging.consumer.queue}") @@ -55,11 +55,12 @@ internal class ProbationMatchingIntegrationTest { verify(telemetryService).trackEvent( "MatchResultIgnored", - mapOf("reason" to "No active booking", "dryRun" to "true") + mapOf("reason" to "No active booking", "dryRun" to "false") ) } @Test + @Order(1) fun `prisoner received updates identifiers`() { withMatchResponse("probation-search-single-result.json") @@ -69,7 +70,7 @@ internal class ProbationMatchingIntegrationTest { verify(telemetryService).trackEvent( "MatchResultSuccess", mapOf( "reason" to "Matched CRN A000001 to NOMS number A0001AA and custody ${custodyId("A000001")} to 00001A", - "dryRun" to "true", + "dryRun" to "false", "nomsNumber" to "A0001AA", "bookingNo" to "00001A", "matchedBy" to "ALL_SUPPLIED", @@ -89,6 +90,7 @@ internal class ProbationMatchingIntegrationTest { } @Test + @Order(2) fun `multiple matches are refined by sentence date`() { withMatchResponse("probation-search-multiple-results.json") @@ -98,16 +100,17 @@ internal class ProbationMatchingIntegrationTest { verify(telemetryService).trackEvent( "MatchResultSuccess", mapOf( "reason" to "Matched CRN A000001 to NOMS number A0001AA and custody ${custodyId("A000001")} to 00001A", - "dryRun" to "true", + "dryRun" to "false", "nomsNumber" to "A0001AA", "bookingNo" to "00001A", "matchedBy" to "ALL_SUPPLIED", "potentialMatches" to """[{"crn":"A000002"},{"crn":"A000001"}]""", - "existingNomsNumber" to "E1234XS", + "existingNomsNumber" to "A0001AA", "matchedNomsNumber" to "A0001AA", - "nomsNumberChanged" to "true", + "nomsNumberChanged" to "false", + "existingBookingNumber" to "00001A", "matchedBookingNumber" to "00001A", - "bookingNumberChanged" to "true", + "bookingNumberChanged" to "false", "custody" to "${custodyId("A000001")}", "sentenceDateInDelius" to "2022-11-11", "sentenceDateInNomis" to "2022-11-11", @@ -127,7 +130,7 @@ internal class ProbationMatchingIntegrationTest { verify(telemetryService).trackEvent( "MatchResultNoMatch", mapOf( "reason" to "No single match found in probation system", - "dryRun" to "true", + "dryRun" to "false", "nomsNumber" to "A0001AA", "bookingNo" to "00001A", "matchedBy" to "NONE", @@ -152,7 +155,7 @@ internal class ProbationMatchingIntegrationTest { verify(telemetryService).trackEvent( "MatchResultNoMatch", mapOf( "reason" to "No single match found in probation system", - "dryRun" to "true", + "dryRun" to "false", "nomsNumber" to "A0001AA", "bookingNo" to "00001A", "matchedBy" to "ALL_SUPPLIED", diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt index 791f27d99f..0899761bb5 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt @@ -114,7 +114,6 @@ interface PersonRepository : JpaRepository { and e.softDeleted = false and e.active = true and c.softDeleted = false - and c.prisonerNumber is null """ ) fun findSentencedByCrn(crn: String): List diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index fee73848e6..f96ebfb02b 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -1,6 +1,5 @@ package uk.gov.justice.digital.hmpps.messaging -import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent @@ -17,7 +16,6 @@ class Handler( private val telemetryService: TelemetryService, private val probationMatchingService: ProbationMatchingService, private val prisonMatchingService: PrisonMatchingService, - @Value("\${messaging.consumer.dry-run:false}") private val messagingDryRun: Boolean ) : NotificationHandler { override fun handle(notification: Notification) { telemetryService.notificationReceived(notification) @@ -33,12 +31,12 @@ class Handler( "prison-offender-events.prisoner.sentence-dates-changed", "prison-offender-events.prisoner.imprisonment-status-changed" -> probationMatchingService - .matchAndUpdateIdentifiers(checkNotNull(message.personReference.findNomsNumber()), messagingDryRun) - .also { telemetryService.logResult(it, messagingDryRun) } + .matchAndUpdateIdentifiers(checkNotNull(message.personReference.findNomsNumber())) + .also { telemetryService.logResult(it) } "prison-offender-events.prisoner.merged" -> probationMatchingService - .replaceIdentifiers(message.oldNoms, message.newNoms, messagingDryRun) - .also { telemetryService.logResult(it, messagingDryRun) } + .replaceIdentifiers(message.oldNoms, message.newNoms) + .also { telemetryService.logResult(it) } else -> throw IllegalArgumentException("Unexpected domain event type: ${notification.eventType}") } @@ -47,8 +45,8 @@ class Handler( "OFFENDER_DETAILS_CHANGED", // changes to name, date of birth, identifiers in Delius "SENTENCE_CHANGED", // changes to sentence status and dates in Delius -> prisonMatchingService - .matchAndUpdateIdentifiers(message.crn, messagingDryRun) - .also { telemetryService.logResult(it, messagingDryRun) } + .matchAndUpdateIdentifiers(message.crn) + .also { telemetryService.logResult(it) } else -> throw IllegalArgumentException("Unexpected offender event type: ${notification.eventType}") } diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MatchResult.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MatchResult.kt index b194b66b40..6df2c138dc 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MatchResult.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MatchResult.kt @@ -29,7 +29,7 @@ sealed interface MatchResult { ) : MatchResult } -fun TelemetryService.logResult(result: MatchResult, dryRun: Boolean) { +fun TelemetryService.logResult(result: MatchResult, dryRun: Boolean = false) { trackEvent( result.name(), mapOf("reason" to result.reason, "dryRun" to dryRun.toString()) diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MergeResult.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MergeResult.kt index 6e6b72d01d..0acb8b8a37 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MergeResult.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/MergeResult.kt @@ -15,7 +15,7 @@ sealed interface MergeResult { MergeResult } -fun TelemetryService.logResult(result: MergeResult, dryRun: Boolean) { +fun TelemetryService.logResult(result: MergeResult, dryRun: Boolean = false) { trackEvent( result.name(), mapOf("reason" to result.reason, "dryRun" to dryRun.toString()) diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt index 6b0c8be541..4a19c85865 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt @@ -19,7 +19,7 @@ class PrisonMatchingService( private val notifier: Notifier, private val objectMapper: ObjectMapper, ) { - fun matchAndUpdateIdentifiers(crn: String, dryRun: Boolean): MatchResult { + fun matchAndUpdateIdentifiers(crn: String, dryRun: Boolean = false): MatchResult { val matchResult = findMatchingPrisonRecord(crn) if (!dryRun && matchResult is Success) { with(matchResult) { diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ProbationMatchingService.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ProbationMatchingService.kt index ba0b0e129c..50455b67f9 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ProbationMatchingService.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ProbationMatchingService.kt @@ -21,7 +21,7 @@ class ProbationMatchingService( private val notifier: Notifier, private val objectMapper: ObjectMapper, ) { - fun matchAndUpdateIdentifiers(nomsNumber: String, dryRun: Boolean): MatchResult { + fun matchAndUpdateIdentifiers(nomsNumber: String, dryRun: Boolean = false): MatchResult { val matchResult = findMatchingProbationRecord(nomsNumber) if (!dryRun && matchResult is Success) { with(matchResult) { @@ -32,7 +32,7 @@ class ProbationMatchingService( return matchResult } - fun replaceIdentifiers(oldNomsNumber: String, newNomsNumber: String, dryRun: Boolean): MergeResult { + fun replaceIdentifiers(oldNomsNumber: String, newNomsNumber: String, dryRun: Boolean = false): MergeResult { personRepository.findAllByNomsNumber(newNomsNumber).joinToString { it.crn }.takeIf { it.isNotEmpty() }?.let { return MergeResult.Ignored("NOMS number $newNomsNumber is already assigned to $it") }