Skip to content

Commit

Permalink
PI-2272 throw ignorable message when requirement manager not found. … (
Browse files Browse the repository at this point in the history
…#3893)

* PI-2272 throw ignorable message when requirement manager not found.  Due to record being soft deleted in delius.

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2272 throw ignorable message when requirement manager not found.  Due to record being soft deleted in delius.

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2272 throw ignorable message when requirement not found.  Can be due to record being soft deleted in delius, or incorrect requirement in request.

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-2272 throw ignorable message when requirement not found.  Can be due to record being soft deleted in delius, or incorrect requirement in request.

Signed-off-by: Amardeep Chimber <[email protected]>

* Update projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AllocateRequirementService.kt

Co-authored-by: Marcus Aspin <[email protected]>

* PI-2272 update test.

Signed-off-by: Amardeep Chimber <[email protected]>

---------

Signed-off-by: Amardeep Chimber <[email protected]>
Co-authored-by: Marcus Aspin <[email protected]>
  • Loading branch information
achimber-moj and marcus-bcl authored Jun 12, 2024
1 parent 942de20 commit f89b58e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
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

@Immutable
@Entity
@Table(name = "rqmnt")
@SQLRestriction("soft_deleted = 0")
class Requirement(
@Id
@Column(name = "rqmnt_id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -101,12 +86,14 @@ internal class AllocateRequirementServiceTest {
fun `when requirement not found exception thrown`() {
whenever(requirementRepository.findById(allocationDetail.requirementId)).thenReturn(Optional.empty())

assertThrows<NotFoundException> {
val exception = assertThrows<IgnorableMessageException> {
allocateRequirementService.createRequirementAllocation(
PersonGenerator.DEFAULT.crn,
allocationDetail
)
}

assert(exception.message.contains("Requirement no longer exists"))
}

@Test
Expand Down

0 comments on commit f89b58e

Please sign in to comment.