From 754f9c820472e13ac933f6a32795e16ee221699d Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 28 Mar 2024 11:15:26 +0000 Subject: [PATCH 1/3] PI-2039 Switch label + name (#3548) --- .../simulations/__files/application-status-updated.json | 8 ++++---- .../uk/gov/justice/digital/hmpps/service/Cas2Service.kt | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/projects/cas2-and-delius/src/dev/resources/simulations/__files/application-status-updated.json b/projects/cas2-and-delius/src/dev/resources/simulations/__files/application-status-updated.json index 26cbf2524d..c226191ca5 100644 --- a/projects/cas2-and-delius/src/dev/resources/simulations/__files/application-status-updated.json +++ b/projects/cas2-and-delius/src/dev/resources/simulations/__files/application-status-updated.json @@ -12,12 +12,12 @@ "description": "More information about the application has been requested from the POM (Prison Offender Manager).", "statusDetails": [ { - "label": "personalInformation", - "name": "Personal Information" + "name": "personalInformation", + "label": "Personal Information" }, { - "label": "healthNeeds", - "name": "Health Needs" + "name": "healthNeeds", + "label": "Health Needs" } ] } diff --git a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt index b728605ded..f66fb14649 100644 --- a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt +++ b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt @@ -1,6 +1,5 @@ package uk.gov.justice.digital.hmpps.service -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import jakarta.transaction.Transactional import org.springframework.stereotype.Service import uk.gov.justice.digital.hmpps.client.approvedpremises.EventDetailsClient @@ -42,7 +41,7 @@ class Cas2Service( |Application status was updated to: ${details.eventDetails.newStatus.label} | |Details: ${details.eventDetails.newStatus.description} - |* ${details.eventDetails.newStatus.statusDetails.joinToString(separator = System.lineSeparator() + "|* ") { it.name }} + |* ${details.eventDetails.newStatus.statusDetails.joinToString(separator = System.lineSeparator() + "|* ") { it.label }} | |Details of the application can be found here: ${details.eventDetails.applicationUrl} """.trimMargin(), From 707a74bf62b5bd9203ee1c859daf0028d9c6f70b Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 28 Mar 2024 11:16:06 +0000 Subject: [PATCH 2/3] PI-1962 Add telemetry for new OSP scores (#3549) --- .../kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 7d339c32fc..4f39732a6a 100644 --- a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -138,6 +138,10 @@ fun HmppsDomainEvent.telemetryProperties() = mapOf( "ospIndecentBand" to additionalInformation["OSPIndecentBand"].toString(), "ospContactScore" to additionalInformation["OSPContactScore"].toString(), "ospContactBand" to additionalInformation["OSPContactBand"].toString(), + "ospIndirectIndecentScore" to additionalInformation["OSPIndirectIndecentScore"].toString(), + "ospIndirectIndecentBand" to additionalInformation["OSPIndirectIndecentBand"].toString(), + "ospDirectContactScore" to additionalInformation["OSPDirectContactScore"].toString(), + "ospDirectContactBand" to additionalInformation["OSPDirectContactBand"].toString(), "OGRS3Yr1" to additionalInformation["OGRS3Yr1"].toString(), "OGRS3Yr2" to additionalInformation["OGRS3Yr2"].toString() ) From 706f6becd6437a3ff5f4c4aef65c2c829f124002 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 28 Mar 2024 11:44:52 +0000 Subject: [PATCH 3/3] PI-1962 Remove feature flag (#3551) --- .../integrations/delius/RiskScoreService.kt | 41 ++++++--------- .../delius/RiskScoreServiceTest.kt | 51 +------------------ 2 files changed, 17 insertions(+), 75 deletions(-) diff --git a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt index 2a89bf65fb..22ec1a19dd 100644 --- a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt +++ b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt @@ -6,14 +6,13 @@ import org.springframework.jdbc.core.SqlParameter import org.springframework.jdbc.core.namedparam.MapSqlParameterSource import org.springframework.jdbc.core.simple.SimpleJdbcCall import org.springframework.stereotype.Service -import uk.gov.justice.digital.hmpps.flags.FeatureFlags import uk.gov.justice.digital.hmpps.messaging.RiskAssessment import java.sql.SQLException import java.sql.Types import java.time.ZonedDateTime @Service -class RiskScoreService(jdbcTemplate: JdbcTemplate, val featureFlags: FeatureFlags) { +class RiskScoreService(jdbcTemplate: JdbcTemplate) { private val updateRsrAndOspScoresProcedure = SimpleJdbcCall(jdbcTemplate) .withCatalogName("pkg_triggersupport") .withProcedureName("procUpdateCAS") @@ -28,10 +27,6 @@ class RiskScoreService(jdbcTemplate: JdbcTemplate, val featureFlags: FeatureFlag SqlParameter("p_osp_score_c", Types.NUMERIC), SqlParameter("p_osp_level_i_code", Types.VARCHAR), SqlParameter("p_osp_level_c_code", Types.VARCHAR), - ) - - private val SimpleJdbcCall.withIndirectIndecentAndDirectContact - get() = declareParameters( SqlParameter("p_osp_level_iic_code", Types.VARCHAR), SqlParameter("p_osp_level_dc_code", Types.VARCHAR), ) @@ -47,26 +42,20 @@ class RiskScoreService(jdbcTemplate: JdbcTemplate, val featureFlags: FeatureFlag ospDirectContact: RiskAssessment?, ) { try { - val params = MapSqlParameterSource() - .addValue("p_crn", crn) - .addValue("p_event_number", eventNumber) - .addValue("p_rsr_assessor_date", assessmentDate) - .addValue("p_rsr_score", rsr.score) - .addValue("p_rsr_level_code", rsr.band) - .addValue("p_osp_score_i", ospIndecent?.score) - .addValue("p_osp_score_c", ospContact?.score) - .addValue("p_osp_level_i_code", ospIndecent?.band) - .addValue("p_osp_level_c_code", ospContact?.band) - - if (featureFlags.enabled("osp-indirect-indecent-and-direct-contact")) { - updateRsrAndOspScoresProcedure.withIndirectIndecentAndDirectContact.execute( - params - .addValue("p_osp_level_iic_code", ospIndirectIndecent?.band) - .addValue("p_osp_level_dc_code", ospDirectContact?.band) - ) - } else { - updateRsrAndOspScoresProcedure.execute(params) - } + updateRsrAndOspScoresProcedure.execute( + MapSqlParameterSource() + .addValue("p_crn", crn) + .addValue("p_event_number", eventNumber) + .addValue("p_rsr_assessor_date", assessmentDate) + .addValue("p_rsr_score", rsr.score) + .addValue("p_rsr_level_code", rsr.band) + .addValue("p_osp_score_i", ospIndecent?.score) + .addValue("p_osp_score_c", ospContact?.score) + .addValue("p_osp_level_i_code", ospIndecent?.band) + .addValue("p_osp_level_c_code", ospContact?.band) + .addValue("p_osp_level_iic_code", ospIndirectIndecent?.band) + .addValue("p_osp_level_dc_code", ospDirectContact?.band) + ) } catch (e: UncategorizedSQLException) { e.sqlException.takeIf { it.isValidationError } ?.parsedValidationMessage diff --git a/projects/risk-assessment-scores-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreServiceTest.kt b/projects/risk-assessment-scores-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreServiceTest.kt index 8b05671233..d54f77db78 100644 --- a/projects/risk-assessment-scores-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreServiceTest.kt +++ b/projects/risk-assessment-scores-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreServiceTest.kt @@ -3,7 +3,6 @@ package uk.gov.justice.digital.hmpps.integrations.delius import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsString import org.hamcrest.Matchers.equalTo -import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows @@ -20,7 +19,6 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource import org.springframework.jdbc.core.namedparam.SqlParameterSource import org.springframework.jdbc.core.simple.SimpleJdbcCall import uk.gov.justice.digital.hmpps.datetime.EuropeLondon -import uk.gov.justice.digital.hmpps.flags.FeatureFlags import uk.gov.justice.digital.hmpps.messaging.RiskAssessment import java.sql.SQLException import java.time.ZonedDateTime @@ -30,17 +28,9 @@ internal class RiskScoreServiceTest { @Mock private lateinit var jdbcTemplate: JdbcTemplate - @Mock - private lateinit var featureFlags: FeatureFlags - @Mock private lateinit var simpleJdbcCall: SimpleJdbcCall - @BeforeEach - fun featureFlag() { - givenTheOspFlagIs(true) - } - @Test fun `scores are passed to the database procedure`() { givenTheDatabaseProcedureSucceeds().use { @@ -51,17 +41,6 @@ internal class RiskScoreServiceTest { } } - @Test - fun `scores are passed to the old database procedure when flag is disabled`() { - givenTheOspFlagIs(false) - givenTheDatabaseProcedureSucceeds().use { - assertDoesNotThrow { - whenUpdatingRsrAndOspScores() - thenTheOldProcedureIsCalled() - } - } - } - @Test fun `known validation errors are logged to telemetry and wrapped`() { givenTheDatabaseProcedureThrows(sqlException("CRN/Offender does not exist", 20000)).use { @@ -95,7 +74,7 @@ internal class RiskScoreServiceTest { } private fun whenUpdatingRsrAndOspScores() { - RiskScoreService(jdbcTemplate, featureFlags).updateRsrAndOspScores( + RiskScoreService(jdbcTemplate).updateRsrAndOspScores( crn = "A000001", eventNumber = 123, assessmentDate = ZonedDateTime.of(2022, 12, 15, 9, 0, 0, 0, EuropeLondon), @@ -128,32 +107,10 @@ internal class RiskScoreServiceTest { ) } - private fun thenTheOldProcedureIsCalled() { - val expectedValues = mapOf( - "p_crn" to "A000001", - "p_event_number" to 123, - "p_rsr_assessor_date" to ZonedDateTime.of(2022, 12, 15, 9, 0, 0, 0, EuropeLondon), - "p_rsr_score" to 1.00, - "p_rsr_level_code" to "A", - "p_osp_score_i" to 2.00, - "p_osp_score_c" to 4.00, - "p_osp_level_i_code" to "B", - "p_osp_level_c_code" to "D" - ) - verify(simpleJdbcCall).execute( - check { params -> - assertThat(params.values, equalTo(expectedValues)) - } - ) - } - private fun givenTheDatabaseProcedureSucceeds(): MockedConstruction { whenever(simpleJdbcCall.withProcedureName("procUpdateCAS")).thenReturn(simpleJdbcCall) whenever(simpleJdbcCall.withoutProcedureColumnMetaDataAccess()).thenReturn(simpleJdbcCall) - whenever(simpleJdbcCall.declareParameters(*Array(9) { any() })).thenReturn(simpleJdbcCall) - if (featureFlags.enabled("osp-indirect-indecent-and-direct-contact")) { - whenever(simpleJdbcCall.declareParameters(*Array(2) { any() })).thenReturn(simpleJdbcCall) - } + whenever(simpleJdbcCall.declareParameters(*Array(11) { any() })).thenReturn(simpleJdbcCall) return mockConstructionWithAnswer(SimpleJdbcCall::class.java, { simpleJdbcCall }) } @@ -163,10 +120,6 @@ internal class RiskScoreServiceTest { return mockedConstruction } - private fun givenTheOspFlagIs(value: Boolean) { - whenever(featureFlags.enabled("osp-indirect-indecent-and-direct-contact")).thenReturn(value) - } - private fun sqlException(message: String? = null, code: Int = 20000) = UncategorizedSQLException("error", "sql", SQLException(message, "", code)) }