Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Mar 4, 2024
1 parent b0230d4 commit 1aa7c05
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ object RequirementGenerator {
RequirementMainCategoryGenerator.CASE_VIEW,
ReferenceDataGenerator.REQUIREMENT_SUB_CATEGORY,
12,
listOf(),
active
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -38,12 +34,19 @@ class CaseViewRequirement(

val length: Long?,

@OneToMany
@JoinColumn(name = "rqmnt_id")
@SQLRestriction("active_flag = 1")
val managers: List<RequirementManager>,

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -175,6 +174,7 @@ class AllocationDemandService(
mainCategory.description,
subCategory?.description,
length?.let { "$length ${mainCategory.units?.description ?: ""}" } ?: "",
id
id,
currentManager().toManager()
)
}

0 comments on commit 1aa7c05

Please sign in to comment.