Skip to content

Commit

Permalink
PI-2585 Remove unused feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Oct 21, 2024
1 parent 35dce3c commit 4309ba8
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import org.hamcrest.core.IsEqual.equalTo
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyMap
import org.mockito.kotlin.*
import org.mockito.kotlin.check
import org.mockito.kotlin.eq
import org.mockito.kotlin.timeout
import org.mockito.kotlin.verify
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.context.SpringBootTest
Expand All @@ -18,7 +21,6 @@ import uk.gov.justice.digital.hmpps.data.entity.IapsPersonRepository
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
import uk.gov.justice.digital.hmpps.data.generator.RegistrationGenerator
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessmentRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
Expand Down Expand Up @@ -64,28 +66,11 @@ internal class IntegrationTest {
@MockBean
lateinit var telemetryService: TelemetryService

@MockBean
lateinit var featureFlags: FeatureFlags

lateinit var transactionTemplate: TransactionTemplate

@BeforeEach
fun setUp() {
transactionTemplate = TransactionTemplate(transactionManager)
whenever(featureFlags.enabled(any())).thenReturn(true)
}

@Test
fun `contact date is set to current date when flag is off`() {
whenever(featureFlags.enabled("assessment-summary-contact-date")).thenReturn(false)
val message = notification<HmppsDomainEvent>("assessment-summary-produced-${PersonGenerator.NO_RISK.crn}")
channelManager.getChannel(queueName).publishAndWait(prepNotification(message, wireMockServer.port()))

val person = personRepository.getByCrn(PersonGenerator.NO_RISK.crn)

val contact = contactRepository.findAll()
.single { it.person.id == person.id && it.type.code == ContactType.Code.OASYS_ASSESSMENT.value }
assertThat(contact.date, equalTo(LocalDate.now()))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.openfolder.kotlinasyncapi.annotation.channel.Publish
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.oasys.OrdsClient
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.Notification
Expand All @@ -24,13 +23,12 @@ class Handler(
override val converter: NotificationConverter<HmppsDomainEvent>,
private val ordsClient: OrdsClient,
private val assessmentSubmitted: AssessmentSubmitted,
private val featureFlags: FeatureFlags,
private val telemetryService: TelemetryService
) : NotificationHandler<HmppsDomainEvent> {
@Publish(messages = [Message(title = AssessmentSummaryProduced, payload = Schema(HmppsDomainEvent::class))])
override fun handle(notification: Notification<HmppsDomainEvent>) {
try {
if (notification.message.eventType == AssessmentSummaryProduced && featureFlags.enabled("assessment-summary-produced")) {
if (notification.message.eventType == AssessmentSummaryProduced) {
telemetryService.notificationReceived(notification)
notification.message.detailUrl
?.let { ordsClient.getAssessmentSummary(URI.create(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uk.gov.justice.digital.hmpps.service

import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessment
import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessmentRepository
import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.SentencePlan
Expand All @@ -26,7 +25,6 @@ class AssessmentService(
private val oasysAssessmentRepository: OasysAssessmentRepository,
private val eventRepository: EventRepository,
private val contactService: ContactService,
private val featureFlags: FeatureFlags,
) {
fun recordAssessment(person: Person, summary: AssessmentSummary) {
val previousAssessment = oasysAssessmentRepository.findByOasysId(summary.assessmentPk.toString())
Expand All @@ -36,14 +34,12 @@ class AssessmentService(
?: throw IgnorableMessageException("No single active custodial event")
val event = eventRepository.getByNumber(person.id, eventNumber)
val manager = checkNotNull(person.manager) { "Community Manager Not Found" }
val contactDate =
if (featureFlags.enabled("assessment-summary-contact-date")) summary.dateCompleted else LocalDate.now()
val contact = previousAssessment?.contact?.withDateTeamAndStaff(
contactDate,
summary.dateCompleted,
manager.teamId,
manager.staffId
) ?: contactService.createContact(
summary.contactDetail(contactDate),
summary.contactDetail(summary.dateCompleted),
person,
event
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package uk.gov.justice.digital.hmpps.service
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.audit.service.OptimisationTables
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.cvl.ActivatedLicence
import uk.gov.justice.digital.hmpps.integrations.cvl.AdditionalLicenceCondition
import uk.gov.justice.digital.hmpps.integrations.cvl.telemetryProperties
Expand Down Expand Up @@ -38,7 +37,6 @@ class LicenceConditionApplier(
private val licenceConditionService: LicenceConditionService,
private val contactService: ContactService,
private val optimisationTables: OptimisationTables,
private val featureFlags: FeatureFlags
) {
@Transactional
fun applyLicenceConditions(
Expand All @@ -58,41 +56,19 @@ class LicenceConditionApplier(
)
optimisationTables.rebuild(com.person.id)

return when (featureFlags.enabled("cvl-multiple-sentences")) {
true ->
when (sentences.size) {
0 -> listOf(ActionResult.Ignored("No Custodial Sentences", properties))
else -> sentences.maxBy { it.disposal.expectedEndDate() }
.let {
applyLicenceConditions(
SentencedCase(
com,
it.disposal,
licenceConditionService.findByDisposalId(it.disposal.id)
),
activatedLicence,
occurredAt
)
}
}

false -> when (sentences.size) {
0 -> listOf(ActionResult.Ignored("No Custodial Sentences", properties))
1 -> sentences.flatMap {
applyLicenceConditions(
SentencedCase(com, it.disposal, licenceConditionService.findByDisposalId(it.disposal.id)),
activatedLicence,
occurredAt
)
}

else -> listOf(
ActionResult.Ignored(
"Multiple Custodial Sentences",
properties
)
)
}
return if (sentences.isEmpty()) {
listOf(ActionResult.Ignored("No Custodial Sentences", properties))
} else {
val latestSentence = sentences.maxBy { it.disposal.expectedEndDate() }
applyLicenceConditions(
SentencedCase(
com,
latestSentence.disposal,
licenceConditionService.findByDisposalId(latestSentence.disposal.id)
),
activatedLicence,
occurredAt
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.LC_STANDARD_CATEGORY
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.LC_STANDARD_SUB_CATEGORY
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.cvl.ActivatedLicence
import uk.gov.justice.digital.hmpps.integrations.cvl.ApConditions
import uk.gov.justice.digital.hmpps.integrations.cvl.Conditions
Expand Down Expand Up @@ -54,9 +53,6 @@ internal class LicenceConditionApplierTest {
@Mock
internal lateinit var optimisationTables: OptimisationTables

@Mock
internal lateinit var featureFlags: FeatureFlags

@InjectMocks
internal lateinit var licenceConditionApplier: LicenceConditionApplier

Expand Down Expand Up @@ -136,49 +132,9 @@ internal class LicenceConditionApplierTest {
)
}

@Test
fun `when multiple active custodial sentence it is logged to telemetry feature flag set to false`() {
val crn = "M728831"
val person = PersonGenerator.generatePerson(crn)
val activatedLicence = ActivatedLicence(
crn,
LocalDate.now(),
Conditions(ApConditions(listOf(), listOf(), listOf()))
)
val occurredAt = ZonedDateTime.now()
whenever(personManagerRepository.findByPersonCrn(crn)).thenReturn(PersonGenerator.DEFAULT_CM)
whenever(custodyRepository.findCustodialSentences(crn)).thenReturn(
listOf(
SentenceGenerator.generate(SentenceGenerator.generateEvent("1", person), endDate = LocalDate.now()),
SentenceGenerator.generate(SentenceGenerator.generateEvent("2", person), endDate = LocalDate.now())
)
)

whenever(featureFlags.enabled("cvl-multiple-sentences")).thenReturn(false)

val ex = licenceConditionApplier.applyLicenceConditions(
crn,
activatedLicence,
occurredAt
)
assertThat(
ex.first(), equalTo(
ActionResult.Ignored(
"Multiple Custodial Sentences",
mapOf(
"crn" to crn,
"startDate" to activatedLicence.startDate.toString(),
"occurredAt" to occurredAt.toString(),
"sentenceCount" to "2"
)
)
)
)
}

@ParameterizedTest
@ValueSource(strings = ["endDate", "enteredEndDate"])
fun `when multiple active custodial sentence create CVL where end date is populated feature flag set to true`(field: String) {
fun `when multiple active custodial sentence create CVL where end date is populated`(field: String) {
val crn = "M728831"
val person = PersonGenerator.generatePerson(crn)
val activatedLicence = ActivatedLicence(
Expand All @@ -188,7 +144,6 @@ internal class LicenceConditionApplierTest {
)
val occurredAt = ZonedDateTime.now()
whenever(personManagerRepository.findByPersonCrn(crn)).thenReturn(PersonGenerator.DEFAULT_CM)
whenever(featureFlags.enabled("cvl-multiple-sentences")).thenReturn(true)

var sentence2: Custody? = null
var sentence4: Custody? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import com.github.tomakehurst.wiremock.WireMockServer
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.api.Order
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestMethodOrder
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.context.SpringBootTest
Expand All @@ -16,7 +18,6 @@ import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator
import uk.gov.justice.digital.hmpps.data.generator.NsiGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.EnforcementRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact
Expand Down Expand Up @@ -64,14 +65,6 @@ internal class ReferAndMonitorIntegrationTest {
@Autowired
lateinit var eventRepository: EventRepository

@MockBean
lateinit var featureFlags: FeatureFlags

@BeforeEach
fun setup() {
whenever(featureFlags.enabled("referral-withdrawal-reason")).thenReturn(true)
}

@Test
@Order(1)
fun `session appointment feedback submitted failed to comply`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import uk.gov.justice.digital.hmpps.api.model.ReferralStarted
import uk.gov.justice.digital.hmpps.audit.service.AuditableService
import uk.gov.justice.digital.hmpps.audit.service.AuditedInteractionService
import uk.gov.justice.digital.hmpps.exception.ReferralNotFoundException
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode.MANAGE_NSI
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactOutcomeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactRepository
Expand Down Expand Up @@ -40,7 +39,6 @@ class NsiService(
private val contactTypeRepository: ContactTypeRepository,
private val contactOutcomeRepository: ContactOutcomeRepository,
private val createNsi: CreateNsi,
private val featureFlags: FeatureFlags,
) : AuditableService(auditedInteractionService) {

@Transactional
Expand Down Expand Up @@ -77,9 +75,7 @@ class NsiService(
fun terminateNsi(termination: NsiTermination) = audit(MANAGE_NSI) { audit ->
val nsi = findNsi(termination)
val status = nsiStatusRepository.getByCode(END.value)
val outcomeCode = termination.withdrawalOutcome?.name
?.takeIf { featureFlags.enabled("referral-withdrawal-reason") }
?: termination.endType.outcome
val outcomeCode = termination.withdrawalOutcome?.name ?: termination.endType.outcome
val outcome = nsiOutcomeRepository.nsiOutcome(outcomeCode)

audit["offenderId"] = nsi.person.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import uk.gov.justice.digital.hmpps.api.model.ReferralStarted
import uk.gov.justice.digital.hmpps.audit.service.AuditedInteractionService
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator
import uk.gov.justice.digital.hmpps.data.generator.NsiGenerator
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactOutcomeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactTypeRepository
Expand Down Expand Up @@ -59,9 +58,6 @@ internal class NsiServiceTest {
@Mock
lateinit var telemetryService: TelemetryService

@Mock
lateinit var featureFlags: FeatureFlags

@InjectMocks
lateinit var nsiService: NsiService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import uk.gov.justice.digital.hmpps.data.generator.NsiGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import uk.gov.justice.digital.hmpps.exception.ReferralNotFoundException
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactOutcomeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactTypeRepository
Expand Down Expand Up @@ -62,9 +61,6 @@ internal class RepositoryExtensionMethodTests {
@Mock
lateinit var telemetryService: TelemetryService

@Mock
lateinit var featureFlags: FeatureFlags

@InjectMocks
lateinit var nsiService: NsiService

Expand Down
Loading

0 comments on commit 4309ba8

Please sign in to comment.