Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Oct 6, 2023
1 parent d9d5004 commit 9d4c202
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationReadyEvent> {

@PostConstruct
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -90,5 +93,6 @@ class ProbationCaseDataLoader(
}
}

interface LduRepository : JpaRepository<Ldu, Long>
interface OffenceRepository : JpaRepository<Offence, Long>
interface AdditionalOffenceRepository : JpaRepository<AdditionalOffence, Long>
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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
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",
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProbationCase, Long> {
@EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team"])
@EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team.ldu"])
fun findByCrnIn(crns: List<String>): List<ProbationCase>

@EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team"])
@EntityGraph(attributePaths = ["gender", "ethnicity", "nationality", "religion", "genderIdentity", "communityManagers.team.ldu"])
fun findByCrn(crn: String): ProbationCase?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9d4c202

Please sign in to comment.