diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index f2fd6e6fd7..ea042e4ffa 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -80,7 +80,8 @@ class DataLoader( private val caseloadRepository: CaseloadRepository, private val registrationRepository: RegistrationRepository, private val referralRepository: ReferralRepository, - private val probationCaseDataLoader: ProbationCaseDataLoader + private val probationCaseDataLoader: ProbationCaseDataLoader, + private val lduRepository: LduRepository ) : ApplicationListener { @PostConstruct @@ -110,6 +111,7 @@ class DataLoader( approvedPremisesRepository.save(ApprovedPremisesGenerator.NO_STAFF) officeLocationRepository.save(OfficeLocationGenerator.DEFAULT) + lduRepository.save(TeamGenerator.AP_TEAM_LDU) teamRepository.save(TeamGenerator.APPROVED_PREMISES_TEAM) teamRepository.save(TeamGenerator.APPROVED_PREMISES_TEAM_WITH_NO_STAFF) teamRepository.save(TeamGenerator.NON_APPROVED_PREMISES_TEAM) diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt index 863157272c..355c53345e 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ProbationCaseDataLoader.kt @@ -10,6 +10,7 @@ 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.Ldu 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 @@ -24,6 +25,7 @@ import java.time.LocalDate @Component class ProbationCaseDataLoader( private val probationAreaRepository: ProbationAreaRepository, + private val lduRepository: LduRepository, private val teamRepository: TeamRepository, private val staffRepository: StaffRepository, private val personManagerRepository: PersonManagerRepository, @@ -37,6 +39,7 @@ class ProbationCaseDataLoader( fun loadData() { offenceRepository.saveAll(listOf(OffenceGenerator.OFFENCE_ONE, OffenceGenerator.OFFENCE_TWO)) probationAreaRepository.save(ProbationCaseGenerator.COM_PROVIDER) + lduRepository.save(ProbationCaseGenerator.COM_LDU) teamRepository.save(ProbationCaseGenerator.COM_TEAM.asTeam()) staffRepository.save(ProbationCaseGenerator.COM_UNALLOCATED) probationCaseRepository.save(ProbationCaseGenerator.CASE_COMPLEX) @@ -90,5 +93,6 @@ class ProbationCaseDataLoader( } } +interface LduRepository : JpaRepository interface OffenceRepository : JpaRepository interface AdditionalOffenceRepository : JpaRepository diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt index 7c03b4a56c..517ed02e89 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ProbationCaseGenerator.kt @@ -5,6 +5,7 @@ import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_TE 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.Ldu 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 @@ -12,7 +13,8 @@ import java.time.LocalDate object ProbationCaseGenerator { val COM_PROVIDER = ProbationAreaGenerator.generate("N01") - val COM_TEAM = generateComTeam("N01COM", "Community Manager Team") + val COM_LDU = generateLdu("N01LDU", "COM LDU") + val COM_TEAM = generateComTeam("N01COM", "Community Manager Team", COM_LDU) val COM_UNALLOCATED = StaffGenerator.generate("Unallocated", "N01COMU") val CASE_COMPLEX = generate( "C246139", @@ -69,8 +71,11 @@ object ProbationCaseGenerator { id ) - fun generateComTeam(code: String, description: String, id: Long = IdGenerator.getAndIncrement()) = - CommunityManagerTeam(code, description, id) + fun generateLdu(code: String, description: String = "LDU of $code", id: Long = IdGenerator.getAndIncrement()) = + Ldu(code, description, id) + + fun generateComTeam(code: String, description: String, ldu: Ldu, id: Long = IdGenerator.getAndIncrement()) = + CommunityManagerTeam(code, description, ldu, id) fun generateManager( pc: ProbationCase, @@ -82,6 +87,6 @@ object ProbationCaseGenerator { } fun ProbationCase.asPerson() = PersonGenerator.generate(crn, id) -fun CommunityManagerTeam.asTeam() = Team(id, code, description, COM_PROVIDER, null) +fun CommunityManagerTeam.asTeam() = Team(id, code, description, COM_PROVIDER, null, ldu.id) fun CommunityManager.asPersonManager() = PersonManagerGenerator.generate(person.asPerson(), COM_TEAM.asTeam(), COM_UNALLOCATED, id) diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/TeamGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/TeamGenerator.kt index 2d9c9436fb..3635e8f461 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/TeamGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/TeamGenerator.kt @@ -8,6 +8,7 @@ import java.util.concurrent.atomic.AtomicLong object TeamGenerator { private val teamCodeGenerator = AtomicLong(1) + val AP_TEAM_LDU = ProbationCaseGenerator.generateLdu("N54LDU") val APPROVED_PREMISES_TEAM = generate(ApprovedPremisesGenerator.DEFAULT) val APPROVED_PREMISES_TEAM_WITH_NO_STAFF = generate(ApprovedPremisesGenerator.NO_STAFF) val NON_APPROVED_PREMISES_TEAM = generate() @@ -16,13 +17,15 @@ object TeamGenerator { fun generate( approvedPremises: ApprovedPremises? = null, code: String = "N54${teamCodeGenerator.getAndIncrement().toString().padStart(3, '0')}", - description: String = "Description of Team $code" + description: String = "Description of Team $code", + districtId: Long = AP_TEAM_LDU.id ) = Team( id = IdGenerator.getAndIncrement(), code = code, description = description, probationArea = ProbationAreaGenerator.DEFAULT, - approvedPremises = approvedPremises + approvedPremises = approvedPremises, + districtId ) } diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt index 339e3a50bc..ee7782a773 100644 --- a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProbationCaseIntegrationTest.kt @@ -16,9 +16,12 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator +import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_TEAM import uk.gov.justice.digital.hmpps.model.CaseDetail import uk.gov.justice.digital.hmpps.model.CaseSummaries +import uk.gov.justice.digital.hmpps.model.Ldu import uk.gov.justice.digital.hmpps.model.Name +import uk.gov.justice.digital.hmpps.model.Team import uk.gov.justice.digital.hmpps.security.withOAuth2Token import java.time.LocalDate @@ -75,6 +78,10 @@ class ProbationCaseIntegrationTest { assertThat(detail.case.dateOfBirth, equalTo(LocalDate.of(1979, 3, 12))) assertTrue(detail.case.currentExclusion) assertTrue(detail.case.currentRestriction) + assertThat( + detail.case.manager.team, + equalTo(Team(COM_TEAM.code, COM_TEAM.description, Ldu(COM_TEAM.ldu.code, COM_TEAM.ldu.description))) + ) assertThat(detail.mappaDetail?.category, equalTo(3)) assertThat(detail.mappaDetail?.level, equalTo(2)) assertThat(detail.registrations.map { it.description }, equalTo(listOf("Description of ARSO"))) diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/ProbationCase.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/ProbationCase.kt index 4bca188933..e4936e3697 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/ProbationCase.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/ProbationCase.kt @@ -115,15 +115,34 @@ class CommunityManagerTeam( val description: String, + @ManyToOne + @JoinColumn(name = "district_id") + val ldu: Ldu, + @Id @Column(name = "team_id") val id: Long ) +@Immutable +@Entity +@Table(name = "district") +class Ldu( + + @Column(name = "code") + val code: String, + + val description: String, + + @Id + @Column(name = "district_id") + val id: Long +) + interface ProbationCaseRepository : JpaRepository { - @EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team"]) + @EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team.ldu"]) fun findByCrnIn(crns: List): List - @EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team"]) + @EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team.ldu"]) fun findByCrn(crn: String): ProbationCase? } diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/team/Team.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/team/Team.kt index a7891de080..ae7f047311 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/team/Team.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/team/Team.kt @@ -33,5 +33,8 @@ class Team( joinColumns = [JoinColumn(name = "team_id")], inverseJoinColumns = [JoinColumn(name = "approved_premises_id")] ) - val approvedPremises: ApprovedPremises? + val approvedPremises: ApprovedPremises?, + + @Column(name = "district_id") + val districtId: Long ) diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt index e1d6f9255a..883b85b5bb 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/model/CaseDetail.kt @@ -33,14 +33,11 @@ data class Profile( val religion: String? ) -data class Manager( - val team: Team -) +data class Manager(val team: Team) -data class Team( - val code: String, - val name: String -) +data class Team(val code: String, val name: String, val ldu: Ldu) + +data class Ldu(val code: String, val name: String) data class MappaDetail( val level: Int?, diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt index bd3c9be7e8..798295b3fb 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseService.kt @@ -14,6 +14,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.enti import uk.gov.justice.digital.hmpps.model.CaseDetail import uk.gov.justice.digital.hmpps.model.CaseSummaries import uk.gov.justice.digital.hmpps.model.CaseSummary +import uk.gov.justice.digital.hmpps.model.Ldu import uk.gov.justice.digital.hmpps.model.Manager import uk.gov.justice.digital.hmpps.model.MappaDetail import uk.gov.justice.digital.hmpps.model.Name @@ -65,7 +66,7 @@ fun ProbationCase.manager(): Manager = Manager(team()) } -fun CommunityManager.team() = Team(team.code, team.description) +fun CommunityManager.team() = Team(team.code, team.description, Ldu(team.ldu.code, team.ldu.description)) fun CaseOffence.asOffence() = Offence(description, date, main, eventNumber)