generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PI-1528 add LAO endpoint * PI-1528 Add new endpoints for AP and Delius * PI-1528 Add registration info (mappa and other) * PI-1528 Add offence details * added Entity Graph for registrations
- Loading branch information
1 parent
8c35b41
commit ecbf133
Showing
20 changed files
with
905 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...es-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.data.generator.OffenceGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.asPerson | ||
import uk.gov.justice.digital.hmpps.data.generator.asPersonManager | ||
import uk.gov.justice.digital.hmpps.data.generator.asTeam | ||
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCaseRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.manager.probation.PersonManagerRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.AdditionalOffence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.MainOffenceRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Offence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegisterType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegistrationRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.staff.StaffRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.team.TeamRepository | ||
import java.time.LocalDate | ||
|
||
@Component | ||
class ProbationCaseDataLoader( | ||
private val probationAreaRepository: ProbationAreaRepository, | ||
private val teamRepository: TeamRepository, | ||
private val staffRepository: StaffRepository, | ||
private val personManagerRepository: PersonManagerRepository, | ||
private val probationCaseRepository: ProbationCaseRepository, | ||
private val registrationRepository: RegistrationRepository, | ||
private val eventRepository: EventRepository, | ||
private val offenceRepository: OffenceRepository, | ||
private val mainOffenceRepository: MainOffenceRepository, | ||
private val additionalOffenceRepository: AdditionalOffenceRepository | ||
) { | ||
fun loadData() { | ||
offenceRepository.saveAll(listOf(OffenceGenerator.OFFENCE_ONE, OffenceGenerator.OFFENCE_TWO)) | ||
probationAreaRepository.save(ProbationCaseGenerator.COM_PROVIDER) | ||
teamRepository.save(ProbationCaseGenerator.COM_TEAM.asTeam()) | ||
staffRepository.save(ProbationCaseGenerator.COM_UNALLOCATED) | ||
probationCaseRepository.save(ProbationCaseGenerator.CASE_COMPLEX) | ||
probationCaseRepository.save(ProbationCaseGenerator.CASE_SIMPLE) | ||
|
||
personManagerRepository.saveAll( | ||
listOf( | ||
ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_COMPLEX).asPersonManager(), | ||
ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_SIMPLE).asPersonManager() | ||
) | ||
) | ||
|
||
registrationRepository.save( | ||
PersonGenerator.generateRegistration( | ||
ProbationCaseGenerator.CASE_COMPLEX.asPerson(), | ||
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.MAPPA.value]!!, | ||
LocalDate.now().minusDays(7), | ||
ReferenceDataGenerator.REGISTER_CATEGORIES["M3"], | ||
ReferenceDataGenerator.REGISTER_LEVELS["M2"] | ||
) | ||
) | ||
|
||
registrationRepository.save( | ||
PersonGenerator.generateRegistration( | ||
ProbationCaseGenerator.CASE_COMPLEX.asPerson(), | ||
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.SEX_OFFENCE.value]!!, | ||
LocalDate.now().minusDays(7) | ||
) | ||
) | ||
|
||
val event = PersonGenerator.generateEvent( | ||
"1", | ||
ProbationCaseGenerator.CASE_COMPLEX.id | ||
).apply(eventRepository::save) | ||
|
||
mainOffenceRepository.save( | ||
OffenceGenerator.generateMainOffence( | ||
event, | ||
OffenceGenerator.OFFENCE_ONE, | ||
LocalDate.now().minusDays(7) | ||
) | ||
) | ||
|
||
additionalOffenceRepository.save( | ||
OffenceGenerator.generateAdditionalOffence( | ||
event, | ||
OffenceGenerator.OFFENCE_TWO, | ||
LocalDate.now().minusDays(5) | ||
) | ||
) | ||
} | ||
} | ||
|
||
interface OffenceRepository : JpaRepository<Offence, Long> | ||
interface AdditionalOffenceRepository : JpaRepository<AdditionalOffence, Long> |
31 changes: 31 additions & 0 deletions
31
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/OffenceGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.Event | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.AdditionalOffence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.MainOffence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Offence | ||
import java.time.LocalDate | ||
|
||
object OffenceGenerator { | ||
val OFFENCE_ONE = generate("OFF1", "Offence One") | ||
val OFFENCE_TWO = generate("OFF2", "Offence Two") | ||
|
||
fun generate(code: String, description: String, id: Long = IdGenerator.getAndIncrement()) = | ||
Offence(code, description, id) | ||
|
||
fun generateMainOffence( | ||
event: Event, | ||
offence: Offence, | ||
date: LocalDate, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = MainOffence(event, offence, date, softDeleted, id) | ||
|
||
fun generateAdditionalOffence( | ||
event: Event, | ||
offence: Offence, | ||
date: LocalDate, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = AdditionalOffence(event, offence, date, softDeleted, id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...lius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_PROVIDER | ||
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_TEAM | ||
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_UNALLOCATED | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.CommunityManager | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.CommunityManagerTeam | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCase | ||
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.ReferenceData | ||
import uk.gov.justice.digital.hmpps.integrations.delius.team.Team | ||
import java.time.LocalDate | ||
|
||
object ProbationCaseGenerator { | ||
val COM_PROVIDER = ProbationAreaGenerator.generate("N01") | ||
val COM_TEAM = generateComTeam("N01COM", "Community Manager Team") | ||
val COM_UNALLOCATED = StaffGenerator.generate("Unallocated", "N01COMU") | ||
val CASE_COMPLEX = generate( | ||
"C246139", | ||
"James", | ||
"Brown", | ||
LocalDate.of(1979, 3, 12), | ||
"John", | ||
"Jack", | ||
"A5671YZ", | ||
ReferenceDataGenerator.GENDER_MALE, | ||
ReferenceDataGenerator.ETHNICITY_WHITE, | ||
ReferenceDataGenerator.NATIONALITY_BRITISH, | ||
ReferenceDataGenerator.RELIGION_OTHER, | ||
ReferenceDataGenerator.GENDER_IDENTITY_PNS, | ||
currentExclusion = true, | ||
currentRestriction = true | ||
) | ||
val CASE_SIMPLE = generate("S517283", "Teresa", "Green", LocalDate.of(1987, 8, 2)) | ||
|
||
fun generate( | ||
crn: String, | ||
forename: String, | ||
surname: String, | ||
dateOfBirth: LocalDate, | ||
secondName: String? = null, | ||
thirdName: String? = null, | ||
nomsId: String? = null, | ||
gender: ReferenceData? = null, | ||
ethnicity: ReferenceData? = null, | ||
nationality: ReferenceData? = null, | ||
religion: ReferenceData? = null, | ||
genderIdentity: ReferenceData? = null, | ||
currentExclusion: Boolean = false, | ||
currentRestriction: Boolean = false, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = ProbationCase( | ||
crn, | ||
nomsId, | ||
forename, | ||
secondName, | ||
thirdName, | ||
surname, | ||
dateOfBirth, | ||
gender, | ||
ethnicity, | ||
nationality, | ||
religion, | ||
genderIdentity, | ||
currentExclusion, | ||
currentRestriction, | ||
listOf(), | ||
softDeleted, | ||
id | ||
) | ||
|
||
fun generateComTeam(code: String, description: String, id: Long = IdGenerator.getAndIncrement()) = | ||
CommunityManagerTeam(code, description, id) | ||
|
||
fun generateManager( | ||
pc: ProbationCase, | ||
team: CommunityManagerTeam = COM_TEAM, | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = CommunityManager(pc, team, active, softDeleted, id) | ||
} | ||
|
||
fun ProbationCase.asPerson() = PersonGenerator.generate(crn, id) | ||
fun CommunityManagerTeam.asTeam() = Team(id, code, description, COM_PROVIDER, null) | ||
fun CommunityManager.asPersonManager() = | ||
PersonManagerGenerator.generate(person.asPerson(), COM_TEAM.asTeam(), COM_UNALLOCATED, id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.