Skip to content

Commit

Permalink
Feature/pi 2097 crn convictions conviction (#3868)
Browse files Browse the repository at this point in the history
* PI-2097 first commit

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model object

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 add test and hook up controller with service

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update integration test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 add extension function and update service

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update return model and test.  also, temporary use localdate, instead of localdatetime to check if ci build works.

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 use localdatetime for one attribute.

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update  test

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update test to see why ci fails

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update test to see why ci fails

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update test to see why ci fails

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update test to see why ci fails, and small refactor

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update test to see why ci fails

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2097 update model and test

Signed-off-by: Amardeep Chimber <[email protected]>

* Formatting changes

* Empty-Commit

---------

Signed-off-by: Amardeep Chimber <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
achimber-moj and github-actions[bot] authored Jun 5, 2024
1 parent 0e07163 commit 0f923ee
Show file tree
Hide file tree
Showing 24 changed files with 1,661 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.api.model.DocumentType
import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.integrations.delius.event.courtappearance.entity.Outcome
import uk.gov.justice.digital.hmpps.user.AuditUserRepository
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
import java.time.ZonedDateTime

@Component
Expand All @@ -29,23 +30,23 @@ class DataLoader(
@Transactional
override fun onApplicationEvent(are: ApplicationReadyEvent) {
em.saveAll(

DocumentEntityGenerator.COURT,
DocumentEntityGenerator.INSTITUTIONAL_REPORT_TYPE,
DocumentEntityGenerator.INSTITUTIONAL_REPORT,
DocumentEntityGenerator.R_INSTITUTION,
AreaGenerator.PARTITION_AREA,
ProviderEmployeeGenerator.PROVIDER_EMPLOYEE,
ProviderGenerator.DEFAULT,
LDUGenerator.DEFAULT,
BoroughGenerator.DEFAULT,
DistrictGenerator.DEFAULT,
TeamGenerator.DEFAULT,
ReferenceDataGenerator.VIOLENCE,
SentenceGenerator.MAIN_OFFENCE,
SentenceGenerator.ADDITIONAL_OFFENCE,
BusinessInteractionGenerator.UPDATE_CONTACT,
ContactTypeGenerator.CONTACT_TYPE,

DisposalTypeGenerator.CURFEW_ORDER,
ReferenceDataGenerator.DISPOSAL_TYPE,
ReferenceDataGenerator.LENGTH_UNITS,
ReferenceDataGenerator.TERMINATION_REASON,
Expand Down Expand Up @@ -79,6 +80,21 @@ class DataLoader(
ReferenceDataGenerator.DEFAULT_ADDRESS_STATUS,
ReferenceDataGenerator.DEFAULT_ALLOCATION_REASON,
ReferenceDataGenerator.DEFAULT_TIER,
ReferenceDataGenerator.REF_DISQ,
ReferenceDataGenerator.PRISON,
ReferenceDataGenerator.ACR,
ReferenceDataGenerator.EXP,
ReferenceDataGenerator.HDE,
ReferenceDataGenerator.LED,
ReferenceDataGenerator.PED,
ReferenceDataGenerator.PSSED,
ReferenceDataGenerator.POM1,
ReferenceDataGenerator.POM2,
ReferenceDataGenerator.SED,
ReferenceDataGenerator.CRN,
ReferenceDataGenerator.TRIAL,
CourtGenerator.PROBATIONARE_AREA,
CourtGenerator.BHAM,
PersonGenerator.NEW_TO_PROBATION,
PersonGenerator.CURRENTLY_MANAGED,
PersonGenerator.PREVIOUSLY_MANAGED,
Expand All @@ -97,50 +113,72 @@ class DataLoader(
PersonGenerator.generatePersonManager(PersonGenerator.CURRENTLY_MANAGED)
)

val noSentenceEvent = SentenceGenerator.generateEvent(PersonGenerator.NO_SENTENCE)
val noSentenceManager = SentenceGenerator.generateOrderManager(noSentenceEvent, StaffGenerator.UNALLOCATED)
val outcome = Outcome(Outcome.Code.AWAITING_PSR.value, IdGenerator.getAndIncrement())
val courtAppearance = SentenceGenerator.generateCourtAppearance(noSentenceEvent, outcome)
val noSentenceEvent =
SentenceGenerator.generateEvent(PersonGenerator.NO_SENTENCE, referralDate = LocalDate.now())
val noSentenceManager =
SentenceGenerator.generateOrderManager(
noSentenceEvent,
StaffGenerator.UNALLOCATED,
CourtGenerator.PROBATIONARE_AREA,
ZonedDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneId.of("Europe/London")),
ZonedDateTime.of(LocalDate.now().minusDays(1), LocalTime.NOON, ZoneId.of("Europe/London"))
)
val outcome = SentenceGenerator.OUTCOME
val courtAppearance = SentenceGenerator.generateCourtAppearance(noSentenceEvent, outcome, ZonedDateTime.now())
em.saveAll(noSentenceEvent, noSentenceManager, outcome, courtAppearance)

val newEvent = SentenceGenerator.generateEvent(PersonGenerator.NEW_TO_PROBATION)
val newEvent = SentenceGenerator.generateEvent(PersonGenerator.NEW_TO_PROBATION, referralDate = LocalDate.now())
val newSentence =
SentenceGenerator.generateSentence(newEvent, ZonedDateTime.now(), ReferenceDataGenerator.DISPOSAL_TYPE)
val newManager = SentenceGenerator.generateOrderManager(newEvent, StaffGenerator.UNALLOCATED)
SentenceGenerator.generateSentence(newEvent, LocalDate.now(), DisposalTypeGenerator.CURFEW_ORDER)
val newManager =
SentenceGenerator.generateOrderManager(
newEvent,
StaffGenerator.UNALLOCATED,
CourtGenerator.PROBATIONARE_AREA,
ZonedDateTime.of(LocalDate.now().minusDays(1), LocalTime.NOON, ZoneId.of("Europe/London")),
ZonedDateTime.of(LocalDate.now().minusDays(3), LocalTime.NOON, ZoneId.of("Europe/London"))
)
em.saveAll(newEvent, newSentence, newManager)

val currentEvent = SentenceGenerator.generateEvent(PersonGenerator.CURRENTLY_MANAGED, inBreach = true)
val currentSentence =
SentenceGenerator.generateSentence(
currentEvent,
ZonedDateTime.now(),
ReferenceDataGenerator.DISPOSAL_TYPE,
entryLength = 12,
entryLengthUnits = ReferenceDataGenerator.LENGTH_UNITS,
lengthInDays = 99
)
val custody = SentenceGenerator.generateCustody(currentSentence, ReferenceDataGenerator.CUSTODIAL_STATUS)
val currentManager = SentenceGenerator.generateOrderManager(currentEvent, StaffGenerator.ALLOCATED)
val mainOffence =
SentenceGenerator.generateMainOffence(currentEvent, SentenceGenerator.MAIN_OFFENCE, LocalDate.now())
val additionalOffence = SentenceGenerator.generateAdditionalOffence(
currentEvent,
SentenceGenerator.ADDITIONAL_OFFENCE,
LocalDate.now()
)
val currentEvent = SentenceGenerator.CURRENTLY_MANAGED
val currentSentence = SentenceGenerator.CURRENT_SENTENCE
val custody = SentenceGenerator.CURRENT_CUSTODY
val currentManager = SentenceGenerator.CURRENT_ORDER_MANAGER
val mainOffence = SentenceGenerator.MAIN_OFFENCE_DEFAULT
val additionalOffence = SentenceGenerator.ADDITIONAL_OFFENCE_DEFAULT
val requirement = SentenceGenerator.generateRequirement(disposal = currentSentence)
val licenceCondition = SentenceGenerator.generateLicenseCondition(disposal = currentSentence)
val breachNsi = SentenceGenerator.generateBreachNsi(disposal = currentSentence)
val pssRequirement = SentenceGenerator.generatePssRequirement(custody.id)
val currentCourtAppearance = SentenceGenerator.generateCourtAppearance(currentEvent, outcome)
val currentCourtAppearance = SentenceGenerator.COURT_APPEARANCE
val currentCourtReport = SentenceGenerator.generateCourtReport(currentCourtAppearance)
val reportManager = SentenceGenerator.generateCourtReportManager(currentCourtReport)

em.saveAll(
currentEvent,
currentSentence,
AdditionalSentenceGenerator.SENTENCE_DISQ,
ReferenceDataGenerator.HOURS_WORKED,
UnpaidWorkGenerator.UNPAID_WORK_DETAILS_1,
UnpaidWorkGenerator.APPT1,
UnpaidWorkGenerator.APPT2,
UnpaidWorkGenerator.APPT3,
UnpaidWorkGenerator.APPT4,
UnpaidWorkGenerator.APPT5,
UnpaidWorkGenerator.APPT6,
UnpaidWorkGenerator.APPT7,
currentManager,
InstitutionGenerator.WSIHMP,
custody,
SentenceGenerator.CONDITIONAL_RELEASE_KEY_DATE,
SentenceGenerator.LED_KEY_DATE,
SentenceGenerator.HDC_KEY_DATE,
SentenceGenerator.PAROLE_KEY_DATE,
SentenceGenerator.SENTENCE_KEY_DATE,
SentenceGenerator.EXPECTED_RELEASE_KEY_DATE,
SentenceGenerator.SUPERVISION_KEY_DATE,
SentenceGenerator.HANDOVER_START_KEY_DATE,
SentenceGenerator.HANDOVER_KEY_DATE,
mainOffence,
additionalOffence,
requirement,
Expand All @@ -152,15 +190,27 @@ class DataLoader(
reportManager
)

val preEvent = SentenceGenerator.generateEvent(PersonGenerator.PREVIOUSLY_MANAGED, active = false)
val preEvent =
SentenceGenerator.generateEvent(
PersonGenerator.PREVIOUSLY_MANAGED,
referralDate = LocalDate.now(),
active = false
)
val preSentence = SentenceGenerator.generateSentence(
preEvent,
ZonedDateTime.now(),
ReferenceDataGenerator.DISPOSAL_TYPE,
terminationDate = ZonedDateTime.now().minusDays(7),
LocalDate.now(),
DisposalTypeGenerator.CURFEW_ORDER,
terminationDate = LocalDate.now().minusDays(7),
active = false
)
val preManager = SentenceGenerator.generateOrderManager(preEvent, StaffGenerator.ALLOCATED)
val preManager =
SentenceGenerator.generateOrderManager(
preEvent,
StaffGenerator.ALLOCATED,
CourtGenerator.PROBATIONARE_AREA,
ZonedDateTime.of(LocalDate.now().minusDays(7), LocalTime.NOON, ZoneId.of("Europe/London")),
ZonedDateTime.of(LocalDate.now().minusDays(10), LocalTime.NOON, ZoneId.of("Europe/London"))
)
em.saveAll(preEvent, preSentence, preManager)

em.merge(CourtCaseNoteGenerator.CASE_NOTE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package uk.gov.justice.digital.hmpps.data.entity

import jakarta.persistence.Column
import jakarta.persistence.Convert
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable
import jakarta.persistence.*
import org.hibernate.type.YesNoConverter
import java.time.LocalDate

Expand Down Expand Up @@ -87,18 +82,3 @@ class User(
val surname: String
)

@Entity
@Immutable
@Table(name = "r_institution")
class Institution(
@Id
@Column(name = "institution_id")
val id: Long,

@Column(name = "institution_name")
val name: String,

@Column
@Convert(converter = YesNoConverter::class)
val establishment: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.REF_DISQ
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.CURRENTLY_MANAGED
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData
import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.Event
import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.AdditionalSentence
import java.math.BigDecimal

object AdditionalSentenceGenerator {

val SENTENCE_DISQ =
generateSentence(amount = BigDecimal(7), length = 3, referenceData = REF_DISQ, event = CURRENTLY_MANAGED)

fun generateSentence(
length: Long? = null,
amount: BigDecimal? = null,
notes: String? = null,
event: Event,
referenceData: ReferenceData
) = AdditionalSentence(
IdGenerator.getAndIncrement(),
event,
referenceData,
amount,
length,
notes,
false,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Court
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.ProbationAreaEntity
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
import java.time.ZonedDateTime

object CourtGenerator {

val PROBATIONARE_AREA = ProbationAreaEntity(
true,
"West Midlands Region",
"N52",
null,
false,
IdGenerator.getAndIncrement(),
)

val BHAM = Court(
IdGenerator.getAndIncrement(),
"BRMNCC",
true,
"Birmingham Crown Court",
"0121 111 2222",
"0121 333 4444",
"Queen Elizabeth II Law Courts",
"1 Newton Street",
null,
"Birmingham",
"West Midlands",
"B4 7NA",
"England",
ReferenceDataGenerator.CRN.id,
ZonedDateTime.of(LocalDate.now().minusDays(7), LocalTime.NOON, ZoneId.of("Europe/London")),
ZonedDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneId.of("Europe/London")),
PROBATIONARE_AREA.id,
null,
PROBATIONARE_AREA,
ReferenceDataGenerator.CRN
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.DisposalType

object DisposalTypeGenerator {

val CURFEW_ORDER =
DisposalType(IdGenerator.getAndIncrement(), "Curfew Order", "SP", cja2003Order = false, legacyOrder = true, 2)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.entity.Court
import uk.gov.justice.digital.hmpps.data.entity.Institution
//import uk.gov.justice.digital.hmpps.data.entity.Institution
import uk.gov.justice.digital.hmpps.data.entity.InstitutionalReport
import uk.gov.justice.digital.hmpps.integrations.delius.entity.DocumentEntity
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData
Expand All @@ -20,7 +20,7 @@ object DocumentEntityGenerator {
dateRequested = LocalDate.of(2000, 1, 2)
)

val R_INSTITUTION = Institution(IdGenerator.getAndIncrement(), "test", false)
// val R_INSTITUTION = Institution(IdGenerator.getAndIncrement(), "test", false)

fun generateDocument(personId: Long, primaryKeyId: Long?, type: String, tableName: String?) =
DocumentEntity(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Institution
import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.InstitutionId

object InstitutionGenerator {

val WSIHMP = generate("WSIHMP", "WSI")

fun generate(code: String, prisonId: String): Institution {
return Institution(
id = InstitutionId(IdGenerator.getAndIncrement(), true),
code = code,
description = "Test institution ($code)",
institutionName = "Test institution $code",
establishmentType = ReferenceDataGenerator.PRISON,
nomisCdeCode = prisonId
)
}
}
Loading

0 comments on commit 0f923ee

Please sign in to comment.