Skip to content

Commit

Permalink
CVL Log no start date to telemetry (#3688)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Apr 26, 2024
1 parent 608f037 commit e44f7cc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CvlClient {
data class ActivatedLicence(
val crn: String,
@JsonAlias("licenceStartDate")
val startDate: LocalDate,
val startDate: LocalDate?,
val conditions: Conditions
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class LicenceConditionApplier(
activatedLicence: ActivatedLicence,
occurredAt: ZonedDateTime
): List<ActionResult> {
if (activatedLicence.startDate == null) {
return listOf(
ActionResult.Ignored(
"No Start Date",
activatedLicence.telemetryProperties(sentencedCase.sentence.event.number)
)
)
}
val standardResult = activatedLicence.standardConditions(sentencedCase)
val additionalResult = activatedLicence.additionalConditions(sentencedCase)
val bespokeResult = activatedLicence.bespokeConditions(sentencedCase)
Expand Down Expand Up @@ -109,7 +117,7 @@ class LicenceConditionApplier(
) {
licenceConditionService.createLicenceCondition(
sentencedCase.sentence,
startDate,
startDate!!,
category,
subCategory,
STANDARD_PREFIX,
Expand Down Expand Up @@ -144,7 +152,7 @@ class LicenceConditionApplier(
) {
licenceConditionService.createLicenceCondition(
sentencedCase.sentence,
startDate,
startDate!!,
cvlMapping.mainCategory,
cvlMapping.subCategory,
if (!cvlMapping.populateNotes) LIMITED_PREFIX else CONDITION_PREFIX,
Expand Down Expand Up @@ -174,7 +182,7 @@ class LicenceConditionApplier(
if (sentencedCase.licenceConditions.none { it.mainCategory.code == category.code && it.subCategory.code == subCategory.code }) {
licenceConditionService.createLicenceCondition(
sentencedCase.sentence,
startDate,
startDate!!,
category,
subCategory,
CONDITION_PREFIX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ 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
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.PersonManagerRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CustodyRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CvlMappingRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceConditionCategoryRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.ReferenceDataRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.*
import uk.gov.justice.digital.hmpps.set
import java.time.LocalDate
import java.time.ZonedDateTime
Expand Down Expand Up @@ -165,4 +162,43 @@ internal class LicenceConditionApplierTest {
)
)
}

@Test
fun `no start date is logged to telemetry`() {
val crn = "S728831"
val person = PersonGenerator.generatePerson(crn)
val activatedLicence = ActivatedLicence(
crn,
null,
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))
)
)

val ex = licenceConditionApplier.applyLicenceConditions(
crn,
activatedLicence,
occurredAt
)
assertThat(
ex.first(), equalTo(
ActionResult.Ignored(
"No Start Date",
mapOf(
"crn" to crn,
"eventNumber" to "1",
"startDate" to "null",
"standardConditions" to "0",
"additionalConditions" to "0",
"bespokeConditions" to "0"
)
)
)
)
}
}

0 comments on commit e44f7cc

Please sign in to comment.