Skip to content

Commit

Permalink
PI-2196: Turn dry run off in preprod (#3792)
Browse files Browse the repository at this point in the history
* PI-2196: Turn dry run off in preprod
  • Loading branch information
pmcphee77 authored May 14, 2024
1 parent 9dc555d commit e7cba2c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ generic-service:

bulk-update:
enabled: true
dry-run: true
dry-run: false
schedule: 0 7 * * 1

generic-prometheus-alerts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down Expand Up @@ -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")

Expand All @@ -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",
Expand All @@ -89,6 +90,7 @@ internal class ProbationMatchingIntegrationTest {
}

@Test
@Order(2)
fun `multiple matches are refined by sentence date`() {
withMatchResponse("probation-search-multiple-results.json")

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ interface PersonRepository : JpaRepository<Person, Long> {
and e.softDeleted = false
and e.active = true
and c.softDeleted = false
and c.prisonerNumber is null
"""
)
fun findSentencedByCrn(crn: String): List<SentencedPerson>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Any> {
override fun handle(notification: Notification<Any>) {
telemetryService.notificationReceived(notification)
Expand All @@ -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}")
}
Expand All @@ -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}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}
Expand Down

0 comments on commit e7cba2c

Please sign in to comment.