Skip to content

Commit

Permalink
PI-2350 Ignore missing court and offence codes (#4020)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Jul 11, 2024
1 parent 9beeeee commit e433d45
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import jakarta.persistence.Id
import org.hibernate.annotations.Immutable
import org.hibernate.type.YesNoConverter
import org.springframework.data.jpa.repository.JpaRepository
import uk.gov.justice.digital.hmpps.exception.NotFoundException

@Immutable
@Entity
Expand All @@ -29,4 +28,4 @@ interface CourtRepository : JpaRepository<Court, Long> {
}

fun CourtRepository.getByCode(code: String) =
findByCodeAndSelectableTrue(code) ?: findByCode(code) ?: throw NotFoundException("Court", "code", code)
findByCodeAndSelectableTrue(code) ?: findByCode(code)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import jakarta.persistence.Id
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable
import org.springframework.data.jpa.repository.JpaRepository
import uk.gov.justice.digital.hmpps.exception.NotFoundException

@Immutable
@Table(name = "r_offence")
Expand All @@ -24,6 +23,3 @@ class Offence(
interface OffenceRepository : JpaRepository<Offence, Long> {
fun findByCode(code: String): Offence?
}

fun OffenceRepository.getByCode(code: String) =
findByCode(code) ?: throw NotFoundException("Offence", "code", code)
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class AssessmentService(
person = person,
eventNumber = event.number,
contact = contact,
court = furtherInformation.courtCode?.let { courtRepository.getByCode(it) },
court = furtherInformation.courtCode
?.let { courtRepository.getByCode(it) },
offence = offences.firstOrNull { it.offenceCode != null && it.offenceSubcode != null }
?.let { offenceRepository.getByCode(it.offenceCode + it.offenceSubcode) },
?.let { offenceRepository.findByCode(it.offenceCode + it.offenceSubcode) },
totalScore = furtherInformation.totWeightedScore,
description = furtherInformation.pOAssessment?.let {
PurposeOfAssessmentMapping[it] ?: throw IllegalArgumentException("Unexpected 'pOAssessment' code '$it'")
Expand Down

0 comments on commit e433d45

Please sign in to comment.