diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index f8494b14c4..98363ddb26 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -65,7 +65,7 @@ class SentenceIntegrationTest { listOf(AdditionalSentence(3, null, null, "Disqualified from Driving")) ), Order("Default Sentence Type", 12, null, LocalDate.now().minusDays(14)), - listOf(Requirement("Main", "High Intensity", 12, "my notes", Rar(1,0, 1))) + listOf(Requirement("Main", "High Intensity", 12, "my notes", Rar(1, 0, 1))) ), Sentence( OffenceDetails( diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Requirement.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Requirement.kt index 36dfea5e0f..534d5afab8 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Requirement.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Requirement.kt @@ -119,7 +119,7 @@ interface RequirementRepository : JpaRepository { AND e.active_flag = 1 """, nativeQuery = true ) - fun getRequirements(crn: String, eventNumber: String) : List + fun getRequirements(crn: String, eventNumber: String): List } @Immutable diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt index 9dbb0c4572..59c14f38d2 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt @@ -63,7 +63,9 @@ class OverviewService( return Rar(completed = completedDays, scheduled = scheduledDays) } - fun Disposal.toOrder() = Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate()) + fun Disposal.toOrder() = + Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate()) + fun Event.toSentence() = mainOffence?.offence?.let { offence -> Sentence( mainOffence = offence.toOffence(), diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 7b33d6f779..53c42b1881 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -35,25 +35,28 @@ class SentenceService( }) } - fun Event.toSentence(courtAppearance: CourtAppearance?, additionalSentences: List, crn: String) = Sentence( - OffenceDetails( - eventNumber = eventNumber, - offence = mainOffence?.let { Offence(it.offence.description, it.offenceCount) }, - dateOfOffence = mainOffence?.date, - notes = notes, - additionalOffences = additionalOffences.map { - Offence(description = it.offence.description, count = it.offenceCount ?: 0) - } - ), - Conviction( - sentencingCourt = courtAppearance?.court?.name, - responsibleCourt = court?.name, - convictionDate = convictionDate, - additionalSentences.map { it.toAdditionalSentence() } - ), - order = disposal?.toOrder(), - requirements = disposal.let { requirementRepository.getRequirements(crn, eventNumber).map { it.toRequirement() } }, - ) + fun Event.toSentence(courtAppearance: CourtAppearance?, additionalSentences: List, crn: String) = + Sentence( + OffenceDetails( + eventNumber = eventNumber, + offence = mainOffence?.let { Offence(it.offence.description, it.offenceCount) }, + dateOfOffence = mainOffence?.date, + notes = notes, + additionalOffences = additionalOffences.map { + Offence(description = it.offence.description, count = it.offenceCount ?: 0) + } + ), + Conviction( + sentencingCourt = courtAppearance?.court?.name, + responsibleCourt = court?.name, + convictionDate = convictionDate, + additionalSentences.map { it.toAdditionalSentence() } + ), + order = disposal?.toOrder(), + requirements = disposal.let { + requirementRepository.getRequirements(crn, eventNumber).map { it.toRequirement() } + }, + ) fun ExtraSentence.toAdditionalSentence(): AdditionalSentence = AdditionalSentence(length, amount, notes, type.description) @@ -61,7 +64,8 @@ class SentenceService( fun PersonSummaryEntity.toName() = Name(forename, secondName, surname) - fun Disposal.toOrder() = Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate()) + fun Disposal.toOrder() = + Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate()) fun RequirementDetails.toRequirement() = Requirement( description, diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt index 693a3280e5..67636b9190 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt @@ -111,7 +111,12 @@ class SentenceServiceTest { whenever(requirementRepository.getRequirements(PersonGenerator.OVERVIEW.crn, event.eventNumber)) .thenReturn(listOf(requirement)) - whenever(requirementRepository.getRarDaysByRequirementId(requirement._id)).thenReturn(listOf(completedRarDays, scheduledRarDays)) + whenever(requirementRepository.getRarDaysByRequirementId(requirement._id)).thenReturn( + listOf( + completedRarDays, + scheduledRarDays + ) + ) val response = service.getMostRecentActiveEvent(PersonGenerator.OVERVIEW.crn) @@ -138,7 +143,15 @@ class SentenceServiceTest { ) ), Order("Default Sentence Type", 12, null, LocalDate.now().minusDays(14)), - listOf(Requirement(requirement._description, requirement._codeDescription, requirement._length, requirement._notes, Rar(completedRarDays._days, scheduledRarDays._days, 3))) + listOf( + Requirement( + requirement._description, + requirement._codeDescription, + requirement._length, + requirement._notes, + Rar(completedRarDays._days, scheduledRarDays._days, 3) + ) + ) ) ) ) @@ -174,6 +187,5 @@ class SentenceServiceTest { override val notes: String? get() = _notes - } } \ No newline at end of file