From ed00145423089ae30e477be45122b6bc52687fd9 Mon Sep 17 00:00:00 2001 From: Anthony Britton Date: Mon, 4 Mar 2024 09:47:22 +0000 Subject: [PATCH] PI-1980 --- .../digital/hmpps/data/CaseViewDataLoader.kt | 16 ++++------------ .../data/generator/RequirementGenerator.kt | 1 + .../hmpps/AllocationDemandIntegrationTest.kt | 1 + .../api/model/AllocationDemandStaffResponse.kt | 3 ++- .../digital/hmpps/api/model/SharedModels.kt | 4 +++- .../delius/caseview/CaseViewRequirement.kt | 17 ++++++++++------- .../hmpps/service/AllocationDemandService.kt | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/CaseViewDataLoader.kt b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/CaseViewDataLoader.kt index 54c04fb2eb..944ddf4a03 100644 --- a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/CaseViewDataLoader.kt +++ b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/CaseViewDataLoader.kt @@ -2,18 +2,7 @@ package uk.gov.justice.digital.hmpps.data import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.stereotype.Component -import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator -import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator -import uk.gov.justice.digital.hmpps.data.generator.CourtAppearanceGenerator -import uk.gov.justice.digital.hmpps.data.generator.CourtGenerator -import uk.gov.justice.digital.hmpps.data.generator.DisposalGenerator -import uk.gov.justice.digital.hmpps.data.generator.DocumentGenerator -import uk.gov.justice.digital.hmpps.data.generator.EventGenerator -import uk.gov.justice.digital.hmpps.data.generator.IdGenerator -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.ReferenceDataGenerator -import uk.gov.justice.digital.hmpps.data.generator.RequirementGenerator +import uk.gov.justice.digital.hmpps.data.generator.* import uk.gov.justice.digital.hmpps.data.repository.CaseViewDisposalRepository import uk.gov.justice.digital.hmpps.data.repository.CaseViewEventRepository import uk.gov.justice.digital.hmpps.data.repository.CaseViewMainOffenceRepository @@ -29,6 +18,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.courtappearance.CourtApp import uk.gov.justice.digital.hmpps.integrations.delius.courtappearance.CourtRepository import uk.gov.justice.digital.hmpps.integrations.delius.document.DocumentRepository import uk.gov.justice.digital.hmpps.integrations.delius.event.EventRepository +import uk.gov.justice.digital.hmpps.integrations.delius.event.requirement.RequirementManagerRepository import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.DisposalRepository import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.DisposalType import uk.gov.justice.digital.hmpps.set @@ -49,6 +39,7 @@ class CaseViewDataLoader( val additionalOffenceRepository: CaseViewAdditionalOffenceRepository, val requirementMainCategoryRepository: CaseViewRequirementMainCategoryRepository, val requirementRepository: CaseViewRequirementRepository, + val requirementManagerRepository: RequirementManagerRepository, val documentRepository: DocumentRepository, val courtRepository: CourtRepository, val courtAppearanceRepository: CourtAppearanceRepository, @@ -92,6 +83,7 @@ class CaseViewDataLoader( RequirementGenerator.CASE_VIEW.set("disposal", DisposalGenerator.CASE_VIEW) requirementMainCategoryRepository.save(RequirementGenerator.CASE_VIEW.mainCategory) requirementRepository.save(RequirementGenerator.CASE_VIEW) + requirementManagerRepository.save(RequirementManagerGenerator.generate(requirementId = RequirementGenerator.CASE_VIEW.id)) courtRepository.save(CourtGenerator.DEFAULT) CourtAppearanceGenerator.DEFAULT = courtAppearanceRepository.save(CourtAppearanceGenerator.generate(event)) documentRepository.saveAll( diff --git a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/RequirementGenerator.kt b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/RequirementGenerator.kt index b8c4f940bb..d2e1c4b9c9 100644 --- a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/RequirementGenerator.kt +++ b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/RequirementGenerator.kt @@ -61,6 +61,7 @@ object RequirementGenerator { RequirementMainCategoryGenerator.CASE_VIEW, ReferenceDataGenerator.REQUIREMENT_SUB_CATEGORY, 12, + listOf(), active ) } diff --git a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt index 96e4139901..a85c7bed98 100644 --- a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt +++ b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt @@ -158,6 +158,7 @@ class AllocationDemandIntegrationTest { .andExpect(jsonPath("$.activeRequirements[0].mainCategory").value("Main Category for Case View")) .andExpect(jsonPath("$.activeRequirements[0].subCategory").value("Rqmnt Sub Category")) .andExpect(jsonPath("$.activeRequirements[0].length").value("12 Months")) + .andExpect(jsonPath("$.activeRequirements[0].manager.allocated").value("false")) } companion object { diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandStaffResponse.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandStaffResponse.kt index dc025b6802..545e9dc902 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandStaffResponse.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandStaffResponse.kt @@ -20,7 +20,8 @@ data class Requirement( val mainCategory: String, val subCategory: String?, val length: String, - val id: Long + val id: Long, + val manager: Manager ) interface Court { diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/SharedModels.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/SharedModels.kt index 0b158d5f93..c4ca525de9 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/SharedModels.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/SharedModels.kt @@ -26,7 +26,9 @@ data class Manager( val name: Name, val teamCode: String, val grade: String? = null -) +) { + val allocated = !code.endsWith("U", true) +} data class InitialAppointment(val date: LocalDate, val staff: StaffMember) diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/caseview/CaseViewRequirement.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/caseview/CaseViewRequirement.kt index bd591abfac..db26f98f1d 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/caseview/CaseViewRequirement.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/caseview/CaseViewRequirement.kt @@ -1,16 +1,12 @@ package uk.gov.justice.digital.hmpps.integrations.delius.caseview -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Id -import jakarta.persistence.JoinColumn -import jakarta.persistence.ManyToOne -import jakarta.persistence.Table +import jakarta.persistence.* import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction import org.springframework.data.jpa.repository.EntityGraph import org.springframework.data.jpa.repository.JpaRepository import uk.gov.justice.digital.hmpps.integrations.delius.allocations.entity.ReferenceData +import uk.gov.justice.digital.hmpps.integrations.delius.event.requirement.RequirementManager @Immutable @Entity @@ -38,12 +34,19 @@ class CaseViewRequirement( val length: Long?, + @OneToMany + @JoinColumn(name = "rqmnt_id") + @SQLRestriction("active_flag = 1") + val managers: List, + @Column(name = "active_flag", columnDefinition = "NUMBER", nullable = false) val active: Boolean = true, @Column(updatable = false, columnDefinition = "NUMBER") val softDeleted: Boolean = false -) +) { + fun currentManager() = managers.first() +} @Immutable @Entity diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocationDemandService.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocationDemandService.kt index cdf71a6a0e..67bc72065a 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocationDemandService.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocationDemandService.kt @@ -148,7 +148,6 @@ class AllocationDemandService( val allocatingStaff = staffRepository.findStaffWithUserByUsername(allocatingStaffUsername)!! val eventId = eventRepository.findByPersonCrnAndNumberAndSoftDeletedFalse(crn, eventNumber)!!.id val requirements = caseViewRequirementRepository.findAllByDisposalEventId(eventId) - .filter { it.mainCategory.code !in listOf("W", "W2") } .map { it.toRequirement() } val initialAppointment = contactRepository.getInitialAppointmentData(person.id, eventId) val emails = ldapService.findEmailsForStaffIn(listOfNotNull(staff, allocatingStaff, initialAppointment?.staff)) @@ -175,6 +174,7 @@ class AllocationDemandService( mainCategory.description, subCategory?.description, length?.let { "$length ${mainCategory.units?.description ?: ""}" } ?: "", - id + id, + currentManager().toManager() ) }