diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/requirement/Requirement.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/requirement/Requirement.kt index 6157539e3c..8b597bc9cb 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/requirement/Requirement.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/requirement/Requirement.kt @@ -1,13 +1,8 @@ package uk.gov.justice.digital.hmpps.integrations.delius.event.requirement -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.FetchType -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 uk.gov.justice.digital.hmpps.integrations.delius.allocations.entity.ReferenceData import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.Disposal import uk.gov.justice.digital.hmpps.integrations.delius.person.Person @@ -15,6 +10,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.Person @Immutable @Entity @Table(name = "rqmnt") +@SQLRestriction("soft_deleted = 0") class Requirement( @Id @Column(name = "rqmnt_id", nullable = false) diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementService.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementService.kt index bad576dfea..df7a2af6f6 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementService.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementService.kt @@ -37,7 +37,10 @@ class AllocateRequirementService( fun createRequirementAllocation(crn: String, allocationDetail: RequirementAllocation) = audit(BusinessInteractionCode.CREATE_COMPONENT_TRANSFER) { audit -> val requirement = requirementRepository.findByIdOrNull(allocationDetail.requirementId) - ?: throw NotFoundException("Requirement", "id", allocationDetail.requirementId) + ?: throw IgnorableMessageException( + "Requirement no longer exists", + mapOf("id" to allocationDetail.requirementId.toString()) + ) audit["offenderId"] = requirement.person.id audit["eventId"] = requirement.disposal.event.id diff --git a/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementServiceTest.kt b/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementServiceTest.kt index 8813316cdb..893e580a84 100644 --- a/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementServiceTest.kt +++ b/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementServiceTest.kt @@ -11,25 +11,10 @@ import org.mockito.ArgumentMatchers import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any -import org.mockito.kotlin.never -import org.mockito.kotlin.times -import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever +import org.mockito.kotlin.* import uk.gov.justice.digital.hmpps.audit.service.AuditedInteractionService import uk.gov.justice.digital.hmpps.audit.service.OptimisationTables -import uk.gov.justice.digital.hmpps.data.generator.ContactTypeGenerator -import uk.gov.justice.digital.hmpps.data.generator.DisposalGenerator -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.generator.PersonGenerator -import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator -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.RequirementManagerGenerator -import uk.gov.justice.digital.hmpps.data.generator.StaffGenerator -import uk.gov.justice.digital.hmpps.data.generator.TeamGenerator -import uk.gov.justice.digital.hmpps.data.generator.TransferReasonGenerator +import uk.gov.justice.digital.hmpps.data.generator.* import uk.gov.justice.digital.hmpps.exception.ConflictException import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException import uk.gov.justice.digital.hmpps.exception.NotActiveException @@ -45,7 +30,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.event.requirement.Requir import uk.gov.justice.digital.hmpps.integrations.delius.provider.TeamStaffContainer import uk.gov.justice.digital.hmpps.integrations.workforceallocations.AllocationDetail.RequirementAllocation import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader -import java.util.Optional +import java.util.* @ExtendWith(MockitoExtension::class) internal class AllocateRequirementServiceTest { @@ -101,12 +86,14 @@ internal class AllocateRequirementServiceTest { fun `when requirement not found exception thrown`() { whenever(requirementRepository.findById(allocationDetail.requirementId)).thenReturn(Optional.empty()) - assertThrows { + val exception = assertThrows { allocateRequirementService.createRequirementAllocation( PersonGenerator.DEFAULT.crn, allocationDetail ) } + + assert(exception.message.contains("Requirement no longer exists")) } @Test