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-1669 WIP * PI-1669 WIP * PI-1669 * Formatting changes * remove unused class * PI-1669 * PI-1669 tidy up * PI-1669 mapping amendments --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
84bed8f
commit 505feb2
Showing
49 changed files
with
2,499 additions
and
107 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
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
66 changes: 63 additions & 3 deletions
66
...essment-summary-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.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 |
---|---|---|
@@ -1,25 +1,85 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.annotation.PostConstruct | ||
import jakarta.persistence.EntityManager | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.event.ApplicationReadyEvent | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator | ||
import org.springframework.transaction.annotation.Transactional | ||
import uk.gov.justice.digital.hmpps.data.generator.* | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person | ||
import uk.gov.justice.digital.hmpps.service.Risk | ||
import uk.gov.justice.digital.hmpps.set | ||
import uk.gov.justice.digital.hmpps.user.AuditUserRepository | ||
import java.time.LocalDate | ||
|
||
@Component | ||
@ConditionalOnProperty("seed.database") | ||
class DataLoader( | ||
private val auditUserRepository: AuditUserRepository | ||
private val auditUserRepository: AuditUserRepository, | ||
private val entityManager: EntityManager | ||
) : ApplicationListener<ApplicationReadyEvent> { | ||
|
||
@PostConstruct | ||
fun saveAuditUser() { | ||
auditUserRepository.save(UserGenerator.AUDIT_USER) | ||
} | ||
|
||
@Transactional | ||
override fun onApplicationEvent(are: ApplicationReadyEvent) { | ||
// Perform dev/test database setup here, using JPA repositories and generator classes... | ||
saveAll(*ReferenceDataGenerator.BUSINESS_INTERACTIONS.toTypedArray()) | ||
saveAll(*ReferenceDataGenerator.COURTS.toTypedArray()) | ||
saveAll(*ReferenceDataGenerator.OFFENCES.toTypedArray()) | ||
saveAll(ReferenceDataGenerator.FLAG_DATASET, ReferenceDataGenerator.DEFAULT_FLAG) | ||
saveAll(*ContactGenerator.TYPES.values.toTypedArray()) | ||
saveAll(*RegistrationGenerator.TYPES.values.toTypedArray()) | ||
saveAll(*ReferenceDataGenerator.REQ_MAIN_CATS.toTypedArray()) | ||
|
||
PersonGenerator.NO_RISK.withEvent().withRisk(Risk.M, Risk.L) | ||
PersonGenerator.LOW_RISK | ||
.withEvent() | ||
.withRisk(Risk.H) | ||
.withAssessment("10096930") | ||
.withAccreditedProgramRequirement() | ||
PersonGenerator.MEDIUM_RISK.withEvent().withRisk(Risk.M) | ||
PersonGenerator.HIGH_RISK.withEvent().withRisk(Risk.L, Risk.H) | ||
PersonGenerator.VERY_HIGH_RISK.withEvent().withRisk(Risk.L, Risk.M, Risk.H) | ||
} | ||
|
||
private fun Person.withEvent(): Person { | ||
val personManager = PersonGenerator.generateManager(this) | ||
val event = PersonGenerator.generateEvent(this) | ||
saveAll(this, personManager, event) | ||
this.set(Person::manager, personManager) | ||
return this | ||
} | ||
|
||
private fun Person.withAssessment(oasysId: String): Person { | ||
val contact = | ||
ContactGenerator.generateContact(this, ContactGenerator.TYPES[ContactType.Code.OASYS_ASSESSMENT.value]!!) | ||
val assessment = AssessmentGenerator.generate(this, contact, LocalDate.parse("2013-06-07"), oasysId = oasysId) | ||
entityManager.merge(assessment) | ||
return this | ||
} | ||
|
||
private fun Person.withRisk(vararg risks: Risk): Person { | ||
risks.forEach { | ||
val type = RegistrationGenerator.TYPES[it.code] | ||
val contact = ContactGenerator.generateContact(this, type!!.registrationContactType!!) | ||
val registration = RegistrationGenerator.generate(this.id, LocalDate.parse("2023-06-14"), type, contact) | ||
val reviewContact = ContactGenerator.generateContact(this, type.reviewContactType!!) | ||
highestRiskColour = type.colour | ||
saveAll(this, contact, registration.withReview(reviewContact)) | ||
} | ||
return this | ||
} | ||
|
||
private fun Person.withAccreditedProgramRequirement(): Person { | ||
saveAll(PersonGenerator.generateRequirement(this)) | ||
return this | ||
} | ||
|
||
private fun saveAll(vararg entities: Any) = entities.forEach(entityManager::merge) | ||
} |
22 changes: 22 additions & 0 deletions
22
...-summary-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/entity/IapsPerson.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,22 @@ | ||
package uk.gov.justice.digital.hmpps.data.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import org.hibernate.annotations.Immutable | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
@Immutable | ||
@Entity | ||
@Table(name = "iaps_offender") | ||
class IapsPerson( | ||
@Id | ||
@Column(name = "offender_id") | ||
val personId: Long, | ||
|
||
@Column(columnDefinition = "number") | ||
val iapsFlag: Boolean | ||
) | ||
|
||
interface IapsPersonRepository : JpaRepository<IapsPerson, Long> |
69 changes: 69 additions & 0 deletions
69
...-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AssessmentGenerator.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,69 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessment | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact | ||
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Court | ||
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Offence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person | ||
import java.time.LocalDate | ||
import java.util.* | ||
|
||
object AssessmentGenerator { | ||
fun generate( | ||
person: Person, | ||
contact: Contact, | ||
date: LocalDate = LocalDate.now().minusDays(7), | ||
eventNumber: String = "1", | ||
court: Court? = null, | ||
offence: Offence? = null, | ||
totalScore: Long = 50, | ||
description: String? = "Oasys Assessment", | ||
assessedBy: String? = "John Smith", | ||
riskFlags: String? = "M,N,M,L,N,L,L,H,N", | ||
concernFlags: String? = "YES,NO,NO,DK,YES,NO,NO,YES", | ||
dateCreated: LocalDate = date, | ||
dateReceived: LocalDate = LocalDate.now().minusDays(2), | ||
initialSentencePlanDate: LocalDate? = null, | ||
sentencePlanReviewDate: LocalDate? = null, | ||
reviewTerminated: Boolean? = null, | ||
reviewNumber: String? = null, | ||
layerType: String? = "Layer_3", | ||
ogrsScore1: Long? = 21, | ||
ogrsScore2: Long? = 42, | ||
ogpScore1: Long? = 13, | ||
ogpScore2: Long? = 26, | ||
ovpScore1: Long? = 6, | ||
ovpScore2: Long? = 12, | ||
softDeleted: Boolean = false, | ||
oasysId: String = UUID.randomUUID().toString(), | ||
id: Long = 0 | ||
) = OasysAssessment( | ||
oasysId, | ||
date, | ||
person, | ||
eventNumber, | ||
contact, | ||
court, | ||
offence, | ||
totalScore, | ||
description, | ||
assessedBy, | ||
riskFlags, | ||
concernFlags, | ||
dateCreated, | ||
dateReceived, | ||
initialSentencePlanDate, | ||
sentencePlanReviewDate, | ||
reviewTerminated, | ||
reviewNumber, | ||
layerType, | ||
ogrsScore1, | ||
ogrsScore2, | ||
ogpScore1, | ||
ogpScore2, | ||
ovpScore1, | ||
ovpScore2, | ||
softDeleted, | ||
id | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactGenerator.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,20 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person | ||
|
||
object ContactGenerator { | ||
val TYPES = ContactType.Code.entries.map { generateType(it.value) }.associateBy { it.code } | ||
|
||
fun generateContact( | ||
person: Person, | ||
type: ContactType, | ||
eventId: Long? = null, | ||
alert: Boolean? = false, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Contact(type, person, eventId, alert, softDeleted, id) | ||
|
||
fun generateType(code: String, id: Long = IdGenerator.getAndIncrement()) = ContactType(code, id) | ||
} |
8 changes: 0 additions & 8 deletions
8
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.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,46 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.* | ||
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData | ||
|
||
object PersonGenerator { | ||
val NO_RISK = generate("N123456") | ||
val LOW_RISK = generate("L123456") | ||
val MEDIUM_RISK = generate("M123456") | ||
val HIGH_RISK = generate("H123456") | ||
val VERY_HIGH_RISK = generate("V123456") | ||
|
||
fun generate( | ||
crn: String, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Person(crn, softDeleted, id) | ||
|
||
fun generateManager( | ||
person: Person, | ||
probationAreaId: Long = ProviderGenerator.DEFAULT_PROVIDER_ID, | ||
teamId: Long = ProviderGenerator.DEFAULT_TEAM_ID, | ||
staffId: Long = ProviderGenerator.DEFAULT_STAFF_ID, | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = PersonManager(person, probationAreaId, teamId, staffId, active, softDeleted, id) | ||
|
||
fun generateEvent( | ||
person: Person, | ||
number: String = "1", | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Event(number, person.id, active, softDeleted, id) | ||
|
||
fun generateRequirement( | ||
person: Person, | ||
mainCategory: RequirementMainCategory = ReferenceDataGenerator.REQ_MAIN_CATS.first(), | ||
additionalMainCategory: RequirementAdditionalMainCategory? = null, | ||
subCategory: ReferenceData? = null, | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Requirement(person, mainCategory, additionalMainCategory, subCategory, active, softDeleted, id) | ||
} |
7 changes: 7 additions & 0 deletions
7
...nd-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProviderGenerator.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,7 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
object ProviderGenerator { | ||
val DEFAULT_PROVIDER_ID = IdGenerator.getAndIncrement() | ||
val DEFAULT_TEAM_ID = IdGenerator.getAndIncrement() | ||
val DEFAULT_STAFF_ID = IdGenerator.getAndIncrement() | ||
} |
40 changes: 40 additions & 0 deletions
40
...lius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferenceDataGenerator.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,40 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.audit.BusinessInteraction | ||
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode | ||
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Court | ||
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Offence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.RequirementMainCategory | ||
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.Dataset | ||
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData | ||
import java.time.ZonedDateTime | ||
|
||
object ReferenceDataGenerator { | ||
val BUSINESS_INTERACTIONS = BusinessInteractionCode.entries.map { | ||
BusinessInteraction( | ||
IdGenerator.getAndIncrement(), | ||
it.code, | ||
ZonedDateTime.now() | ||
) | ||
} | ||
val FLAG_DATASET = generateDataset(Dataset.Code.REGISTER_TYPE_FLAG.value) | ||
val DEFAULT_FLAG = generateReferenceData("1", dataset = FLAG_DATASET) | ||
val OFFENCES = listOf("80400", "00857").map { generateOffence(it) } | ||
val COURTS = listOf("CRT150", "LVRPCC").map { generateCourt(it) } | ||
val REQ_MAIN_CATS = listOf("RM38").map { generateReqMainCat(it) } | ||
|
||
fun generateReferenceData( | ||
code: String, | ||
description: String = "Description of $code", | ||
dataset: Dataset, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = ReferenceData(code, description, dataset.id, id) | ||
|
||
fun generateDataset(code: String, id: Long = IdGenerator.getAndIncrement()) = Dataset(code, id) | ||
|
||
fun generateCourt(code: String, id: Long = IdGenerator.getAndIncrement()) = Court(code, id) | ||
|
||
fun generateOffence(code: String, id: Long = IdGenerator.getAndIncrement()) = Offence(code, id) | ||
|
||
fun generateReqMainCat(code: String, id: Long = IdGenerator.getAndIncrement()) = RequirementMainCategory(code, id) | ||
} |
Oops, something went wrong.