Skip to content

Commit 43067fc

Browse files
authored
PI-2696 Add timestamp to court appearance date (#4491)
1 parent 8948a7e commit 43067fc

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

projects/pathfinder-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtAppearanceGenerator.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.data.generator
22

33
import uk.gov.justice.digital.hmpps.entity.*
44
import java.time.LocalDate
5+
import java.time.ZoneId
56

67
object CourtAppearanceGenerator {
78
val DEFAULT_PERSON = CourtAppearancePerson(
@@ -28,7 +29,7 @@ object CourtAppearanceGenerator {
2829
"Breach - Continued/Fine"
2930
)
3031
val DEFAULT_CA = CourtAppearanceEntity(
31-
LocalDate.now(),
32+
LocalDate.now().plusDays(1).atTime(12, 30).atZone(ZoneId.systemDefault()),
3233
IdGenerator.getAndIncrement(),
3334
DEFAULT_EVENT,
3435
DEFAULT_CA_TYPE,
@@ -44,14 +45,14 @@ object CourtAppearanceGenerator {
4445
PERSON_2
4546
)
4647
val CA_2 = CourtAppearanceEntity(
47-
LocalDate.now(),
48+
LocalDate.now().plusDays(1).atTime(12, 30).atZone(ZoneId.systemDefault()),
4849
IdGenerator.getAndIncrement(),
4950
EVENT_2,
5051
DEFAULT_CA_TYPE,
5152
DEFAULT_COURT
5253
)
5354
val CA_3 = CourtAppearanceEntity(
54-
LocalDate.of(2090, 1, 1),
55+
LocalDate.of(2090, 1, 1).atStartOfDay(ZoneId.systemDefault()),
5556
IdGenerator.getAndIncrement(),
5657
EVENT_2,
5758
DEFAULT_CA_TYPE,

projects/pathfinder-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtAppearancesIntegrationTest.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import uk.gov.justice.digital.hmpps.model.CourtAppearance
1515
import uk.gov.justice.digital.hmpps.model.CourtAppearancesContainer
1616
import uk.gov.justice.digital.hmpps.model.Type
1717
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.andExpectJson
18+
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.objectMapper
1819
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withJson
1920
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
20-
import java.time.LocalDate
2121

2222
@AutoConfigureMockMvc
2323
@SpringBootTest(webEnvironment = RANDOM_PORT)
@@ -56,7 +56,7 @@ internal class CourtAppearancesIntegrationTest {
5656
"courtAppearances": {
5757
"X012771": [
5858
{
59-
"appearanceDate": "${LocalDate.now()}",
59+
"appearanceDate": ${objectMapper.writeValueAsString(CourtAppearanceGenerator.DEFAULT_CA.appearanceDate)},
6060
"type": {
6161
"code": "T",
6262
"description": "Trial/Adjournment"
@@ -70,7 +70,7 @@ internal class CourtAppearancesIntegrationTest {
7070
],
7171
"X012774": [
7272
{
73-
"appearanceDate": "2090-01-01",
73+
"appearanceDate": ${objectMapper.writeValueAsString(CourtAppearanceGenerator.CA_3.appearanceDate)},
7474
"type": {
7575
"code": "T",
7676
"description": "Trial/Adjournment"
@@ -82,7 +82,7 @@ internal class CourtAppearancesIntegrationTest {
8282
"offenderId": ${CourtAppearanceGenerator.PERSON_2.id}
8383
},
8484
{
85-
"appearanceDate": "${LocalDate.now()}",
85+
"appearanceDate": ${objectMapper.writeValueAsString(CourtAppearanceGenerator.CA_2.appearanceDate)},
8686
"type": {
8787
"code": "T",
8888
"description": "Trial/Adjournment"

projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/CourtAppearanceEntity.kt

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import org.hibernate.annotations.Immutable
55
import org.hibernate.annotations.SQLRestriction
66
import org.springframework.data.jpa.repository.JpaRepository
77
import org.springframework.data.jpa.repository.Query
8+
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
89
import java.time.LocalDate
10+
import java.time.ZonedDateTime
911

1012
@Entity
1113
@Immutable
@@ -30,7 +32,7 @@ class Court(
3032
class CourtAppearanceEntity(
3133

3234
@Column(name = "appearance_date")
33-
val appearanceDate: LocalDate,
35+
val appearanceDate: ZonedDateTime,
3436

3537
@Id
3638
@Column(name = "court_appearance_id")
@@ -102,7 +104,7 @@ interface CourtAppearanceRepository : JpaRepository<CourtAppearanceEntity, Long>
102104
order by ca.appearanceDate desc
103105
"""
104106
)
105-
fun findMostRecentCourtAppearancesByCrn(dateFrom: LocalDate, crn: String): List<CourtAppearanceEntity>
107+
fun findMostRecentCourtAppearancesByCrn(dateFrom: ZonedDateTime, crn: String): List<CourtAppearanceEntity>
106108

107109
@Query(
108110
"""
@@ -112,7 +114,10 @@ interface CourtAppearanceRepository : JpaRepository<CourtAppearanceEntity, Long>
112114
order by ca.appearanceDate desc
113115
"""
114116
)
115-
fun findMostRecentCourtAppearancesByNomsNumber(dateFrom: LocalDate, nomsNumber: String): List<CourtAppearanceEntity>
117+
fun findMostRecentCourtAppearancesByNomsNumber(
118+
dateFrom: ZonedDateTime,
119+
nomsNumber: String
120+
): List<CourtAppearanceEntity>
116121

117122
@Query(
118123
"""
@@ -124,6 +129,6 @@ interface CourtAppearanceRepository : JpaRepository<CourtAppearanceEntity, Long>
124129
)
125130
fun findCourtAppearancesForCrns(
126131
crns: List<String>,
127-
dateFrom: LocalDate = LocalDate.now()
132+
dateFrom: ZonedDateTime = LocalDate.now().atStartOfDay(EuropeLondon)
128133
): List<CourtAppearanceEntity>
129134
}

projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CourtAppearance.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package uk.gov.justice.digital.hmpps.model
22

3-
import java.time.LocalDate
3+
import java.time.ZonedDateTime
44

55
data class CourtAppearance(
6-
val appearanceDate: LocalDate,
6+
val appearanceDate: ZonedDateTime,
77
val type: Type,
88
val courtCode: String,
99
val courtName: String,

projects/pathfinder-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CourtAppearanceService.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package uk.gov.justice.digital.hmpps.service
33
import org.springframework.stereotype.Service
44
import org.springframework.transaction.annotation.Transactional
55
import uk.gov.justice.digital.hmpps.controller.IdentifierType
6+
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
67
import uk.gov.justice.digital.hmpps.entity.CourtAppearanceEntity
78
import uk.gov.justice.digital.hmpps.entity.CourtAppearanceRepository
89
import uk.gov.justice.digital.hmpps.model.AllCourtAppearancesContainer
@@ -18,8 +19,11 @@ class CourtAppearanceService(private val courtAppearanceRepository: CourtAppeara
1819
var fromDate = LocalDate.now()
1920
requestDate?.also { fromDate = it }
2021
val courtAppearances = when (type) {
21-
IdentifierType.CRN -> courtAppearanceRepository.findMostRecentCourtAppearancesByCrn(fromDate, value)
22-
IdentifierType.NOMS -> courtAppearanceRepository.findMostRecentCourtAppearancesByNomsNumber(fromDate, value)
22+
IdentifierType.CRN -> courtAppearanceRepository
23+
.findMostRecentCourtAppearancesByCrn(fromDate.atStartOfDay(EuropeLondon), value)
24+
25+
IdentifierType.NOMS -> courtAppearanceRepository
26+
.findMostRecentCourtAppearancesByNomsNumber(fromDate.atStartOfDay(EuropeLondon), value)
2327
}
2428
courtAppearances.forEach { courtAppearanceModels.add(it.toModel()) }
2529
return CourtAppearancesContainer(courtAppearanceModels)

0 commit comments

Comments
 (0)