Skip to content

Commit

Permalink
PI-1939 - add additional sentences to Conviction and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Mar 18, 2024
2 parents 6f3509c + 9ea3e2d commit f592087
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ class DataLoader(
entityManager.persist(AdditionalSentenceGenerator.REF_DISQ)
entityManager.persist(AdditionalSentenceGenerator.REF_FINE)
entityManager.persist(
AdditionalSentenceGenerator.generateSentence(3, null, null, PersonGenerator.EVENT_1, AdditionalSentenceGenerator.REF_DISQ)
AdditionalSentenceGenerator.generateSentence(
3,
null,
null,
PersonGenerator.EVENT_1,
AdditionalSentenceGenerator.REF_DISQ
)
)
entityManager.persist(CourtGenerator.DEFAULT)
entityManager.persist(CourtAppearanceGenerator.generate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object AdditionalSentenceGenerator {
false,
event,
referenceData
)
)

fun generateReferenceDate(code: String, description: String) =
ReferenceData(IdGenerator.getAndIncrement(), code, description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import java.time.ZonedDateTime
object PersonGenerator {

val OVERVIEW = generateOverview("X000004")
val EVENT_1 = generateEvent(OVERVIEW, eventNumber = "7654321", notes = "overview", additionalOffences = emptyList(), court = CourtGenerator.BHAM, convictionDate = LocalDate.now())
val EVENT_1 = generateEvent(
OVERVIEW,
eventNumber = "7654321",
notes = "overview",
additionalOffences = emptyList(),
court = CourtGenerator.BHAM,
convictionDate = LocalDate.now()
)
val EVENT_2 = generateEvent(
OVERVIEW,
eventNumber = "1234567",
Expand Down Expand Up @@ -291,6 +298,5 @@ object PersonGenerator {
personId: Long,
id: Long = IdGenerator.getAndIncrement(),
) = Registration(personId, type, false, false, id)

}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SentenceIntegrationTest {
),
Conviction(null, null, null, listOf())
)
)
)
)

assertEquals(expected, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.Ref
@Entity
@Table(name = "additional_sentence")
@SQLRestriction("soft_deleted = 0")
class AdditionalSentence (
class AdditionalSentence(

@Id
@Column(name = "additional_sentence_id")
Expand All @@ -37,4 +37,4 @@ class AdditionalSentence (
@JoinColumn(name = "additional_sentence_type_id")
val refData: ReferenceData? = null,

)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Event



interface EventSentenceRepository : JpaRepository<Event, Long> {
@Query(
"SELECT e FROM Event e " +
Expand All @@ -21,11 +19,10 @@ interface EventSentenceRepository : JpaRepository<Event, Long> {
fun findActiveSentencesByCrn(crn: String): List<Event>
}


interface CourtAppearanceRepository: JpaRepository<CourtAppearance, Long> {
interface CourtAppearanceRepository : JpaRepository<CourtAppearance, Long> {
fun getFirstCourtAppearanceByEventIdOrderByDate(id: Long): CourtAppearance?
}

interface AdditionalSentenceRepository: JpaRepository<AdditionalSentence, Long> {
interface AdditionalSentenceRepository : JpaRepository<AdditionalSentence, Long> {
fun getAllByEvent_Id(id: Long): List<AdditionalSentence>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CourtApp
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.EventSentenceRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AdditionalSentence as ExtraSentence


@Service
class SentenceService(
private val eventRepository: EventSentenceRepository,
Expand All @@ -25,26 +24,26 @@ class SentenceService(
})
}

fun Event.toSentence(courtAppearance: CourtAppearance?, additionalSentences: List<ExtraSentence>) = mainOffence?.let {
mainOffence ->
Sentence(
(OffenceDetails(offence = Offence(mainOffence.offence.description, mainOffence.offenceCount),
dateOfOffence = mainOffence.date,
notes = notes,
additionalOffences = additionalOffences.map {
Offence(description = it.offence.description, count = it.offenceCount ?: 0)
}
fun Event.toSentence(courtAppearance: CourtAppearance?, additionalSentences: List<ExtraSentence>) =
mainOffence?.let { mainOffence ->
Sentence(
(OffenceDetails(offence = Offence(mainOffence.offence.description, mainOffence.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() })
additionalSentences.map { it.toAdditionalSentence() }
)
)
}


fun ExtraSentence.toAdditionalSentence(): AdditionalSentence =
AdditionalSentence(length, amount, notes, refData!!.description)

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class SentenceServiceTest {
)
)

whenever(courtAppearanceRepository
.getFirstCourtAppearanceByEventIdOrderByDate(event.id))
whenever(
courtAppearanceRepository
.getFirstCourtAppearanceByEventIdOrderByDate(event.id)
)
.thenReturn(CourtAppearanceGenerator.generate(CourtGenerator.DEFAULT))

whenever(additionalSentenceRepository.getAllByEvent_Id(event.id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ class RecallReason(
val id: Long,
)

interface CustodyRepository : JpaRepository<Custody, Long> {
interface CustodyRepository : JpaRepository<Custody, Long> {
fun findAllByDisposalEventPersonCrn(crn: String): List<Custody>
}

0 comments on commit f592087

Please sign in to comment.