Skip to content

Commit

Permalink
PI-2443 Fix ordering of convictions (#4188)
Browse files Browse the repository at this point in the history
* PI-2443: Sort by referral date then id

* PI-2443: Sort by referral date then id

* PI-2443: Added more fields to avoid ordering differences

* PI-2443: Added more fields to avoid ordering differences
  • Loading branch information
pmcphee77 authored Aug 21, 2024
1 parent f10e3ef commit 0bff9fa
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ internal class ConvictionByCrnIntegrationTest {
.perform(get("/probation-case/$crn/convictions").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.length()").value(2))
.andExpect(jsonPath("$[0].active").value(true))
.andExpect(jsonPath("$[1].active").value(false))
.andExpect(jsonPath("$[1].active").value(true))
.andExpect(jsonPath("$[0].active").value(false))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import org.hibernate.annotations.SQLRestriction
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData
import uk.gov.justice.digital.hmpps.integrations.delius.event.courtappearance.entity.CourtAppearance
import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Court
import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Disposal
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Officer
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.ProbationAreaEntity
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Team
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.ProviderEmployee
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.*
import java.time.LocalDate
import java.time.ZonedDateTime

Expand Down Expand Up @@ -136,5 +137,93 @@ class OrderManager(

@Id
@Column(name = "order_manager_id")
val id: Long
val id: Long,

@OneToOne
@JoinColumn(name = "allocation_reason_id")
val allocationReason: ReferenceData? = null,

@OneToOne
@JoinColumn(name = "provider_employee_id")
val providerEmployee: ProviderEmployee? = null,

@OneToOne
@JoinColumn(name = "provider_team_id")
val providerTeam: ProviderTeam? = null,

@ManyToOne
@JoinColumn(name = "transfer_reason_id")
val transferReason: TransferReason? = null,

@OneToOne
@JoinColumns(
JoinColumn(
name = "staff_employee_id",
referencedColumnName = "staff_employee_id",
insertable = false,
updatable = false
),
JoinColumn(
name = "trust_provider_flag",
referencedColumnName = "trust_provider_flag",
insertable = false,
updatable = false
)
)
val officer: Officer? = null,

@JoinColumns(
JoinColumn(
name = "trust_provider_team_id",
referencedColumnName = "trust_provider_team_id",
insertable = false,
updatable = false
),
JoinColumn(
name = "trust_provider_flag",
referencedColumnName = "trust_provider_flag",
insertable = false,
updatable = false
)
) @OneToOne
val trustProviderTeam: AllTeam? = null,

)

@Entity
@Immutable
@Table(name = "r_transfer_reason")
class TransferReason(
@Id
@Column(name = "transfer_reason_id")
val id: Long,

@Column(name = "code")
val code: String
)

@Entity
@Immutable
class AllTeam(
@Column(name = "trust_provider_flag")
val trustProvideFlag: Long,

@Id
@Column(name = "trust_provider_team_id")
val trustProviderTeamId: Long,

@JoinColumn(name = "probation_area_id")
@OneToOne
val probationArea: ProbationAreaEntity? = null,

@Column(name = "description")
val description: String? = null,

@Column(name = "telephone")
val telephone: String? = null,

@JoinColumn(name = "district_id")
@OneToOne
val district: District? = null
)

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ProbationAreaEntity(
@Column(name = "private", columnDefinition = "number")
val privateSector: Boolean,

@ManyToOne @JoinColumn(name = "organisation_id")
@ManyToOne
@JoinColumn(name = "organisation_id")
val organisation: Organisation,

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ConvictionService(
return when (activeOnly) {
true -> eventRepository.findAllByPersonAndActiveIsTrue(person)
else -> eventRepository.findAllByPerson(person)
}.sortedByDescending(Event::referralDate).map { it.toConviction() }
}.sortedWith(compareByDescending(Event::referralDate).thenByDescending(Event::id))
.map { it.toConviction() }
}

fun getConvictionFor(crn: String, eventId: Long): Conviction? {
Expand Down

0 comments on commit 0bff9fa

Please sign in to comment.