Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2443 Fix ordering of convictions #4188

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading