From af789ec7a72e4b94d821d31e8f5aec0c7e2fd009 Mon Sep 17 00:00:00 2001 From: Anthony Britton <105213050+anthony-britton-moj@users.noreply.github.com> Date: Fri, 7 Jul 2023 09:33:04 +0100 Subject: [PATCH] PI-1197 check for accredited programme requirements before updating iaps (#1925) --- .../hmpps/data/repository/IapsEventRepository.kt | 6 ------ .../hmpps/data/repository/IapsPersonRepository.kt | 6 ------ .../data/repository/IapsRequirementRepository.kt | 6 ------ .../digital/hmpps/AllocateEventIntegrationTest.kt | 6 ------ .../digital/hmpps/AllocatePersonIntegrationTest.kt | 6 ------ .../integrations/delius/event/EventRepository.kt | 13 +++++++++++++ .../integrations/delius/person/PersonRepository.kt | 13 +++++++++++++ .../digital/hmpps/service/AllocateEventService.kt | 7 ++++++- .../digital/hmpps/service/AllocatePersonService.kt | 4 +++- 9 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsEventRepository.kt delete mode 100644 projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsPersonRepository.kt delete mode 100644 projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsRequirementRepository.kt diff --git a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsEventRepository.kt b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsEventRepository.kt deleted file mode 100644 index 69989b7ae2..0000000000 --- a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsEventRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package uk.gov.justice.digital.hmpps.data.repository - -import org.springframework.data.jpa.repository.JpaRepository -import uk.gov.justice.digital.hmpps.data.entity.IapsEvent - -interface IapsEventRepository : JpaRepository diff --git a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsPersonRepository.kt b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsPersonRepository.kt deleted file mode 100644 index 9a7323ed3d..0000000000 --- a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsPersonRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package uk.gov.justice.digital.hmpps.data.repository - -import org.springframework.data.jpa.repository.JpaRepository -import uk.gov.justice.digital.hmpps.data.entity.IapsPerson - -interface IapsPersonRepository : JpaRepository diff --git a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsRequirementRepository.kt b/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsRequirementRepository.kt deleted file mode 100644 index 82516d8fd8..0000000000 --- a/projects/workforce-allocations-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/repository/IapsRequirementRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package uk.gov.justice.digital.hmpps.data.repository - -import org.springframework.data.jpa.repository.JpaRepository -import uk.gov.justice.digital.hmpps.data.entity.IapsRequirement - -interface IapsRequirementRepository : JpaRepository diff --git a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocateEventIntegrationTest.kt b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocateEventIntegrationTest.kt index c967b00212..d60be32fda 100644 --- a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocateEventIntegrationTest.kt +++ b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocateEventIntegrationTest.kt @@ -14,7 +14,6 @@ import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.data.repository.findByIdOrNull import uk.gov.justice.digital.hmpps.data.generator.EventGenerator import uk.gov.justice.digital.hmpps.data.generator.OrderManagerGenerator -import uk.gov.justice.digital.hmpps.data.repository.IapsEventRepository import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactRepository import uk.gov.justice.digital.hmpps.integrations.delius.contact.ContactTypeCode import uk.gov.justice.digital.hmpps.integrations.delius.event.Event @@ -42,9 +41,6 @@ class AllocateEventIntegrationTest { @Autowired private lateinit var orderManagerRepository: OrderManagerRepository - @Autowired - private lateinit var iapsEventRepository: IapsEventRepository - @MockBean private lateinit var telemetryService: TelemetryService @@ -113,8 +109,6 @@ class AllocateEventIntegrationTest { val updatedOmCount = orderManagerRepository.findAll().count { it.eventId == event.id } assertThat(updatedOmCount, equalTo(originalOmCount + 1)) - assert(iapsEventRepository.findById(event.id).isPresent) - val cadeContact = contactRepository.findAll() .firstOrNull { it.eventId == oldOm.eventId && it.type.code == ContactTypeCode.CASE_ALLOCATION_DECISION_EVIDENCE.value } diff --git a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocatePersonIntegrationTest.kt b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocatePersonIntegrationTest.kt index b0d02c64f0..cf1662cf72 100644 --- a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocatePersonIntegrationTest.kt +++ b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocatePersonIntegrationTest.kt @@ -13,7 +13,6 @@ import org.springframework.data.repository.findByIdOrNull import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator import uk.gov.justice.digital.hmpps.data.generator.PersonManagerGenerator import uk.gov.justice.digital.hmpps.data.generator.ResponsibleOfficerGenerator -import uk.gov.justice.digital.hmpps.data.repository.IapsPersonRepository import uk.gov.justice.digital.hmpps.integrations.delius.person.Person import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonManager import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonManagerRepository @@ -44,9 +43,6 @@ class AllocatePersonIntegrationTest { @Autowired private lateinit var responsibleOfficerRepository: ResponsibleOfficerRepository - @Autowired - private lateinit var iapsPersonRepository: IapsPersonRepository - @MockBean private lateinit var telemetryService: TelemetryService @@ -143,7 +139,5 @@ class AllocatePersonIntegrationTest { val updatedRoCount = responsibleOfficerRepository.findAll().count { it.personId == person.id } assertThat(updatedRoCount, equalTo(originalRoCount + 1)) - - assert(iapsPersonRepository.findById(person.id).isPresent) } } diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/EventRepository.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/EventRepository.kt index 6bad8153a7..cb1856e5a2 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/EventRepository.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/EventRepository.kt @@ -42,6 +42,19 @@ interface EventRepository : JpaRepository { """ ) fun findAllOffencesByEventId(eventId: Long): List + + @Query( + """ + select count(r) + from Requirement r + where r.disposal.event.id = :eventId + and (r.mainCategory.code = 'RM38' + or (r.mainCategory.code = '7' and (r.subCategory.code is null or r.subCategory.code <> 'RS66')) + or (r.additionalMainCategory.code in ('RM38', '7')) + ) + """ + ) + fun countAccreditedProgrammeRequirements(eventId: Long): Int } fun EventRepository.getByPersonCrnAndNumber(crn: String, number: String) = findByPersonCrnAndNumber(crn, number) diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt index b68471e436..78af87099b 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt @@ -102,6 +102,19 @@ interface PersonRepository : JpaRepository { sentenceEndDateKeyDateTypeCode: String = "SED", custodialStatusCodes: List = listOf("A", "C", "D", "R", "I", "AT") ): CaseType? + + @Query( + """ + select count(r) + from Requirement r + where r.person.id = :personId + and (r.mainCategory.code = 'RM38' + or (r.mainCategory.code = '7' and (r.subCategory.code is null or r.subCategory.code <> 'RS66')) + or (r.additionalMainCategory.code in ('RM38', '7')) + ) + """ + ) + fun countAccreditedProgrammeRequirements(personId: Long): Int } fun PersonRepository.getCaseType(crn: String) = findCaseType(crn) ?: CaseType.UNKNOWN diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateEventService.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateEventService.kt index 5da74db249..6fbdc16bac 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateEventService.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateEventService.kt @@ -89,7 +89,9 @@ class AllocateEventService( createCadeContact(allocationDetail, event, newOrderManager) - eventRepository.updateIaps(event.id) + if (event.hasAccreditedProgrammeRequirement()) { + eventRepository.updateIaps(event.id) + } } fun createCadeContact(allocationDetail: EventAllocationDetail, event: Event, orderManager: OrderManager) { @@ -108,4 +110,7 @@ class AllocateEventService( ) ) } + + fun Event.hasAccreditedProgrammeRequirement(): Boolean = + eventRepository.countAccreditedProgrammeRequirements(id) > 0 } diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocatePersonService.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocatePersonService.kt index ce6ade1798..d30b7978ea 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocatePersonService.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocatePersonService.kt @@ -80,7 +80,9 @@ class AllocatePersonService( ) ) - personRepository.updateIaps(personId) + if (personRepository.countAccreditedProgrammeRequirements(personId) > 0) { + personRepository.updateIaps(personId) + } } private fun updateResponsibleOfficer(