From 706f6becd6437a3ff5f4c4aef65c2c829f124002 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 28 Mar 2024 11:44:52 +0000 Subject: [PATCH] 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)) }