Skip to content

Commit

Permalink
PI-1197 check for accredited programme requirements before updating i…
Browse files Browse the repository at this point in the history
…aps (#1925)
  • Loading branch information
anthony-britton-moj authored Jul 7, 2023
1 parent 9102ac0 commit af789ec
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 32 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,9 +41,6 @@ class AllocateEventIntegrationTest {
@Autowired
private lateinit var orderManagerRepository: OrderManagerRepository

@Autowired
private lateinit var iapsEventRepository: IapsEventRepository

@MockBean
private lateinit var telemetryService: TelemetryService

Expand Down Expand Up @@ -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 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,9 +43,6 @@ class AllocatePersonIntegrationTest {
@Autowired
private lateinit var responsibleOfficerRepository: ResponsibleOfficerRepository

@Autowired
private lateinit var iapsPersonRepository: IapsPersonRepository

@MockBean
private lateinit var telemetryService: TelemetryService

Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ interface EventRepository : JpaRepository<Event, Long> {
"""
)
fun findAllOffencesByEventId(eventId: Long): List<Offence>

@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ interface PersonRepository : JpaRepository<Person, Long> {
sentenceEndDateKeyDateTypeCode: String = "SED",
custodialStatusCodes: List<String> = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -108,4 +110,7 @@ class AllocateEventService(
)
)
}

fun Event.hasAccreditedProgrammeRequirement(): Boolean =
eventRepository.countAccreditedProgrammeRequirements(id) > 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class AllocatePersonService(
)
)

personRepository.updateIaps(personId)
if (personRepository.countAccreditedProgrammeRequirements(personId) > 0) {
personRepository.updateIaps(personId)
}
}

private fun updateResponsibleOfficer(
Expand Down

0 comments on commit af789ec

Please sign in to comment.