diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index 7da807bc5b..cebec85ff1 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.audit.BusinessInteraction import uk.gov.justice.digital.hmpps.data.generator.* import uk.gov.justice.digital.hmpps.data.generator.CourtAppearanceGenerator.COURT_APPEARANCE +import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.GENDER_MALE import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode import uk.gov.justice.digital.hmpps.user.AuditUserRepository @@ -41,6 +42,7 @@ class DataLoader( ContactGenerator.DEFAULT_BOROUGH, ContactGenerator.DEFAULT_DISTRICT, ContactGenerator.DEFAULT_STAFF, + ContactGenerator.LIMITED_ACCESS_STAFF, ContactGenerator.STAFF_1, ContactGenerator.DEFAULT_TEAM, ContactGenerator.LOCATION_BRK_1, @@ -49,7 +51,9 @@ class DataLoader( entityManager.persist(ContactGenerator.USER_1) - entityManager.persist(PersonGenerator.OVERVIEW.gender) + entityManager.persist(ContactGenerator.LIMITED_ACCESS_USER) + + entityManager.persist(GENDER_MALE) PersonGenerator.DISABILITIES.forEach { entityManager.persist(it.type) } PersonGenerator.PROVISIONS.forEach { entityManager.persist(it.type) } @@ -62,7 +66,6 @@ class DataLoader( entityManager.persistCollection(PersonGenerator.PROVISIONS) entityManager.persistCollection(PersonGenerator.PERSONAL_CIRCUMSTANCES) entityManager.persist(PersonGenerator.OVERVIEW) - entityManager.persist(CourtGenerator.BHAM) entityManager.persist(PersonGenerator.EVENT_1) entityManager.persist(PersonGenerator.EVENT_2) @@ -188,6 +191,9 @@ class DataLoader( PersonDetailsGenerator.LANGUAGE_RD, PersonDetailsGenerator.GENDER_IDENTITY_RD, PersonDetailsGenerator.PERSONAL_DETAILS, + PersonDetailsGenerator.RESTRICTION, + PersonDetailsGenerator.EXCLUSION, + PersonDetailsGenerator.RESTRICTION_EXCLUSION, PersonDetailsGenerator.DISABILITY_1_RD, PersonDetailsGenerator.DISABILITY_2_RD, PersonDetailsGenerator.PERSONAL_CIRCUMSTANCE_1_RD, @@ -222,10 +228,23 @@ class DataLoader( entityManager.flush() entityManager.merge(PersonGenerator.PERSON_1) entityManager.merge(PersonGenerator.PERSON_2) + entityManager.merge(PersonGenerator.CL_EXCLUDED) + entityManager.merge(PersonGenerator.CL_RESTRICTED) + entityManager.merge(PersonGenerator.CL_RESTRICTED_EXCLUDED) entityManager.flush() entityManager.persist(PersonGenerator.CASELOAD_PERSON_1) entityManager.persist(PersonGenerator.CASELOAD_PERSON_2) entityManager.persist(PersonGenerator.CASELOAD_PERSON_3) + + entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_EXCLUSION) + entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_RESTRICTION) + entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_BOTH) + entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_NEITHER) + + entityManager.persist(LimitedAccessGenerator.EXCLUSION) + entityManager.persist(LimitedAccessGenerator.RESTRICTION) + entityManager.persist(LimitedAccessGenerator.BOTH_EXCLUSION) + entityManager.persist(LimitedAccessGenerator.BOTH_RESTRICTION) } private fun EntityManager.persistAll(vararg entities: Any) { diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactGenerator.kt index 44bc3978a9..7e5db3feb1 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactGenerator.kt @@ -30,6 +30,7 @@ object ContactGenerator { val DEFAULT_STAFF = generateStaff("N01BDT1", "John", "Smith", emptyList()) val STAFF_1 = generateStaff("N01BDT2", "Jim", "Brown", emptyList()) + val LIMITED_ACCESS_STAFF = generateStaff("N01BDT3", "Limited", "Access", emptyList()) val DEFAULT_TEAM = generateTeam(code = "TEAM11", description = "Main Team", staff = listOf(DEFAULT_STAFF, STAFF_1)) @@ -48,6 +49,14 @@ object ContactGenerator { username = "JimBrown" ) + val LIMITED_ACCESS_USER = User( + id = IdGenerator.getAndIncrement(), + forename = "Limited", + surname = "Access", + staff = LIMITED_ACCESS_STAFF, + username = "LimitedAccess" + ) + val COMMUNICATION_CATEGORY_RD = ReferenceData(IdGenerator.getAndIncrement(), "LT", "Communication") val BREACH_CONTACT_TYPE = generateContactType("BRE02", false, "Breach Contact Type") diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.kt new file mode 100644 index 0000000000..fe427f4eed --- /dev/null +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.kt @@ -0,0 +1,38 @@ +package uk.gov.justice.digital.hmpps.data.generator + +import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator +import uk.gov.justice.digital.hmpps.entity.Exclusion +import uk.gov.justice.digital.hmpps.entity.LimitedAccessPerson +import uk.gov.justice.digital.hmpps.entity.LimitedAccessUser +import uk.gov.justice.digital.hmpps.entity.Restriction +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person +import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User +import java.time.LocalDateTime + +object LimitedAccessGenerator { + val EXCLUSION = generateExclusion(PersonDetailsGenerator.EXCLUSION) + val RESTRICTION = + generateRestriction(PersonDetailsGenerator.RESTRICTION, endDateTime = LocalDateTime.now().plusHours(1)) + val BOTH_EXCLUSION = generateExclusion(PersonDetailsGenerator.RESTRICTION_EXCLUSION) + val BOTH_RESTRICTION = generateRestriction( + PersonDetailsGenerator.RESTRICTION_EXCLUSION, + endDateTime = LocalDateTime.now().plusHours(1) + ) + + fun generateExclusion( + person: Person, + user: User = ContactGenerator.LIMITED_ACCESS_USER, + endDateTime: LocalDateTime? = null, + id: Long = IdGenerator.getAndIncrement() + ) = Exclusion(person.limitedAccess(), user.limitedAccess(), endDateTime, id) + + fun generateRestriction( + person: Person, + user: User = ContactGenerator.USER_1, + endDateTime: LocalDateTime? = null, + id: Long = IdGenerator.getAndIncrement() + ) = Restriction(person.limitedAccess(), user.limitedAccess(), endDateTime, id) + + private fun Person.limitedAccess() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id) + private fun User.limitedAccess() = LimitedAccessUser(username, id) +} diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt index bd15c59bd5..c0d760977d 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt @@ -1,6 +1,7 @@ package uk.gov.justice.digital.hmpps.data.generator import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.DEFAULT_STAFF +import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.LIMITED_ACCESS_STAFF import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.USER import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator import uk.gov.justice.digital.hmpps.integrations.delius.compliance.Nsi @@ -23,6 +24,7 @@ import java.time.ZonedDateTime object PersonGenerator { + val GENDER_MALE = ReferenceData(IdGenerator.getAndIncrement(), "M", "Male") val OVERVIEW = generateOverview("X000004") val EVENT_1 = generateEvent( OVERVIEW, @@ -185,10 +187,43 @@ object PersonGenerator { PersonDetailsGenerator.PERSONAL_DETAILS.surname ) + val CL_EXCLUDED = + generateCaseloadPerson( + PersonDetailsGenerator.EXCLUSION.id, + PersonDetailsGenerator.EXCLUSION.crn, + PersonDetailsGenerator.EXCLUSION.forename, + PersonDetailsGenerator.EXCLUSION.secondName, + PersonDetailsGenerator.EXCLUSION.surname + ) + val CL_RESTRICTED = generateCaseloadPerson( + PersonDetailsGenerator.RESTRICTION.id, + PersonDetailsGenerator.RESTRICTION.crn, + PersonDetailsGenerator.RESTRICTION.forename, + PersonDetailsGenerator.RESTRICTION.secondName, + PersonDetailsGenerator.RESTRICTION.surname + ) + + val CL_RESTRICTED_EXCLUDED = generateCaseloadPerson( + PersonDetailsGenerator.RESTRICTION_EXCLUSION.id, + PersonDetailsGenerator.RESTRICTION_EXCLUSION.crn, + PersonDetailsGenerator.RESTRICTION_EXCLUSION.forename, + PersonDetailsGenerator.RESTRICTION_EXCLUSION.secondName, + PersonDetailsGenerator.RESTRICTION_EXCLUSION.surname + ) + val CASELOAD_PERSON_1 = generateCaseload(PERSON_1, DEFAULT_STAFF, ContactGenerator.DEFAULT_TEAM) val CASELOAD_PERSON_2 = generateCaseload(PERSON_2, ContactGenerator.STAFF_1, ContactGenerator.DEFAULT_TEAM) val CASELOAD_PERSON_3 = generateCaseload(PERSON_2, DEFAULT_STAFF, ContactGenerator.DEFAULT_TEAM) + val CASELOAD_LIMITED_ACCESS_EXCLUSION = + generateCaseload(CL_EXCLUDED, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM) + val CASELOAD_LIMITED_ACCESS_RESTRICTION = + generateCaseload(CL_RESTRICTED, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM) + val CASELOAD_LIMITED_ACCESS_BOTH = + generateCaseload(CL_RESTRICTED_EXCLUDED, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM) + val CASELOAD_LIMITED_ACCESS_NEITHER = + generateCaseload(PERSON_2, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM) + fun generateEvent( person: Person, id: Long = IdGenerator.getAndIncrement(), @@ -295,8 +330,10 @@ object PersonGenerator { telephoneNumber: String? = "4321", preferredName: String? = "Dee", dateOfBirth: LocalDate = LocalDate.now().minusYears(50), - gender: ReferenceData = ReferenceData(IdGenerator.getAndIncrement(), "M", "Male"), - id: Long = IdGenerator.getAndIncrement() + gender: ReferenceData = GENDER_MALE, + id: Long = IdGenerator.getAndIncrement(), + exclusionMessage: String? = null, + restrictionMessage: String? = null ) = Person( id = id, crn = crn, @@ -314,7 +351,9 @@ object PersonGenerator { religion = null, sexualOrientation = null, genderIdentity = null, - genderIdentityDescription = null + genderIdentityDescription = null, + exclusionMessage = exclusionMessage, + restrictionMessage = restrictionMessage ) fun generateRequirement( diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt index 8194095ab6..4107ac8f1a 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt @@ -35,6 +35,21 @@ object PersonDetailsGenerator { requiresInterpreter = true ) + val EXCLUSION = generatePersonDetails( + "E123456", + exclusionMessage = "There is an exclusion on this person" + ) + val RESTRICTION = + generatePersonDetails( + "R123456", + restrictionMessage = "There is a restriction on this person" + ) + val RESTRICTION_EXCLUSION = generatePersonDetails( + "B123456", + exclusionMessage = "You are excluded from viewing this case", + restrictionMessage = "You are restricted from viewing this case" + ) + val ALIAS_1 = generateAlias("Sam", "Edward", "Smith", PERSONAL_DETAILS.id) val ALIAS_2 = generateAlias("Joe", "Richard", "Jones", PersonGenerator.OVERVIEW.id) @@ -236,6 +251,7 @@ object PersonDetailsGenerator { endDate: LocalDate? = null, verified: Boolean? = null, notes: String? = null + ) = PersonAddress( personId = personId, id = IdGenerator.getAndIncrement(), @@ -255,23 +271,25 @@ object PersonDetailsGenerator { typeVerified = verified, telephoneNumber = "0191876865", lastUpdatedUser = USER, - notes = notes + notes = notes, ) fun generatePersonDetails( crn: String, - forename: String, - secondName: String, - surname: String, - preferredName: String, - gender: ReferenceData, - religion: ReferenceData, - sexualOrientation: ReferenceData, - language: ReferenceData, - previousSurname: String, - genderIdentity: ReferenceData, - genderIdentityDescription: String, - requiresInterpreter: Boolean = false + forename: String = "TestForename", + secondName: String = "SecondName", + surname: String = "Surname", + preferredName: String = "PreferredName", + gender: ReferenceData = GENDER_FEMALE, + religion: ReferenceData = RELIGION_DEFAULT, + sexualOrientation: ReferenceData = SEXUAL_ORIENTATION, + language: ReferenceData = LANGUAGE_RD, + previousSurname: String = "PreviousSurname", + genderIdentity: ReferenceData = GENDER_IDENTITY_RD, + genderIdentityDescription: String = "genderIdentityDescription", + requiresInterpreter: Boolean = false, + exclusionMessage: String? = null, + restrictionMessage: String? = null ) = Person( id = IdGenerator.getAndIncrement(), crn = crn, @@ -292,6 +310,8 @@ object PersonDetailsGenerator { genderIdentity = genderIdentity, genderIdentityDescription = genderIdentityDescription, requiresInterpreter = requiresInterpreter, + exclusionMessage = exclusionMessage, + restrictionMessage = restrictionMessage ) fun generateDocument( diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AppointmentOutcomeIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AppointmentOutcomeIntegrationTest.kt index 91bcdb0ac1..ebb7122973 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AppointmentOutcomeIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AppointmentOutcomeIntegrationTest.kt @@ -16,6 +16,7 @@ import uk.gov.justice.digital.hmpps.api.model.appointment.AppointmentDetail import uk.gov.justice.digital.hmpps.api.model.appointment.CreateAppointment import uk.gov.justice.digital.hmpps.api.model.appointment.Outcome import uk.gov.justice.digital.hmpps.api.model.appointment.User +import uk.gov.justice.digital.hmpps.data.generator.AppointmentGenerator.APPOINTMENT_TYPES import uk.gov.justice.digital.hmpps.data.generator.AppointmentGenerator.ATTENDED_COMPLIED import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.STAFF_USER_1 import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.TEAM @@ -66,6 +67,9 @@ class AppointmentOutcomeIntegrationTest { fun `when an appointment outcome does not exist returns a 404 response`() { val response = createAppointment() + val expectedContactType = + APPOINTMENT_TYPES.firstOrNull { type -> type.code == CreateAppointment.Type.PlannedOfficeVisitNS.code } + mockMvc .perform( MockMvcRequestBuilders.patch("/appointment") @@ -76,7 +80,7 @@ class AppointmentOutcomeIntegrationTest { .andExpect( jsonPath( "$.message", - equalTo("ContactTypeOutcome with contact_type_id 8 and outcome code of ABC not found") + equalTo("ContactTypeOutcome with contact_type_id ${expectedContactType?.id} and outcome code of ABC not found") ) ) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LaoCaseloadIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LaoCaseloadIntegrationTest.kt new file mode 100644 index 0000000000..f77ce7c903 --- /dev/null +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LaoCaseloadIntegrationTest.kt @@ -0,0 +1,65 @@ +package uk.gov.justice.digital.hmpps + +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import uk.gov.justice.digital.hmpps.api.model.user.StaffCaseload +import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.LIMITED_ACCESS_USER +import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.EXCLUSION +import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION +import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION_EXCLUSION +import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson +import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken + +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = RANDOM_PORT) +internal class LaoCaseloadIntegrationTest { + @Autowired + lateinit var mockMvc: MockMvc + + @Test + fun `all caseload activity for an lao user`() { + + val person = LIMITED_ACCESS_USER + val res = mockMvc + .perform(get("/caseload/user/${person.username}").withToken()) + .andExpect(status().isOk) + .andReturn().response.contentAsJson() + + assertThat(res.caseload[0].crn, equalTo(EXCLUSION.crn)) + assertThat(res.caseload[1].crn, equalTo(RESTRICTION.crn)) + assertThat(res.caseload[2].crn, equalTo(RESTRICTION_EXCLUSION.crn)) + + assertThat(res.caseload[0].limitedAccess, equalTo(true)) + assertThat(res.caseload[0].caseName, equalTo(null)) + assertThat(res.caseload[0].latestSentence, equalTo(null)) + assertThat(res.caseload[0].nextAppointment, equalTo(null)) + assertThat(res.caseload[0].previousAppointment, equalTo(null)) + assertThat(res.caseload[0].numberOfAdditionalSentences, equalTo(null)) + + assertThat(res.caseload[1].limitedAccess, equalTo(true)) + assertThat(res.caseload[1].caseName, equalTo(null)) + assertThat(res.caseload[1].latestSentence, equalTo(null)) + assertThat(res.caseload[1].nextAppointment, equalTo(null)) + assertThat(res.caseload[1].previousAppointment, equalTo(null)) + assertThat(res.caseload[1].numberOfAdditionalSentences, equalTo(null)) + + assertThat(res.caseload[2].limitedAccess, equalTo(true)) + assertThat(res.caseload[2].caseName, equalTo(null)) + assertThat(res.caseload[2].latestSentence, equalTo(null)) + assertThat(res.caseload[2].nextAppointment, equalTo(null)) + assertThat(res.caseload[2].previousAppointment, equalTo(null)) + assertThat(res.caseload[2].numberOfAdditionalSentences, equalTo(null)) + + assertThat(res.caseload[3].limitedAccess, equalTo(false)) + assertNotEquals(res.caseload[3].caseName, null) + } +} diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/UserIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/UserIntegrationTest.kt index ce23327ab7..e873292089 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/UserIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/UserIntegrationTest.kt @@ -256,7 +256,7 @@ internal class UserIntegrationTest { assertThat(res.caseload.size, equalTo(2)) assertThat(res.caseload[0].crn, equalTo("X000005")) - assertThat(res.caseload[0].caseName.surname, equalTo("Bloggs")) + assertThat(res.caseload[0].caseName?.surname, equalTo("Bloggs")) } @Test @@ -273,7 +273,7 @@ internal class UserIntegrationTest { assertThat(res.caseload.size, equalTo(2)) assertThat(res.caseload[0].crn, equalTo("X000004")) - assertThat(res.caseload[0].caseName.surname, equalTo("Surname")) + assertThat(res.caseload[0].caseName?.surname, equalTo("Surname")) assertThat(res.metaData?.contactTypes?.size, equalTo(1)) assertThat(res.metaData?.sentenceTypes?.size, equalTo(1)) } diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/user/StaffCase.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/user/StaffCase.kt index 309bb162e8..5a3d4b47b8 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/user/StaffCase.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/user/StaffCase.kt @@ -5,11 +5,12 @@ import uk.gov.justice.digital.hmpps.api.model.overview.Appointment import java.time.LocalDate data class StaffCase( - val caseName: Name, + val caseName: Name? = null, val crn: String, - val dob: LocalDate, + val dob: LocalDate? = null, val nextAppointment: Appointment? = null, val previousAppointment: Appointment? = null, val latestSentence: String? = null, - val numberOfAdditionalSentences: Long + val numberOfAdditionalSentences: Long? = null, + val limitedAccess: Boolean? = false ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt index e458d10379..ce1bfc9e31 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt @@ -82,9 +82,12 @@ class Person( val requiresInterpreter: Boolean? = false, @Column(columnDefinition = "number") - val softDeleted: Boolean = false + val softDeleted: Boolean = false, -) + val exclusionMessage: String? = null, + val restrictionMessage: String? = null, + + ) interface PersonSummaryEntity { val id: Long @@ -106,12 +109,12 @@ interface PersonRepository : JpaRepository { select p.offender_id as id, p.first_name as forename, - p.second_name as secondName, - p.third_name as thirdName, + p.second_name as secondname, + p.third_name as thirdname, p.surname, p.crn, p.pnc_number as pnc, - p.date_of_birth_date as dateOfBirth + p.date_of_birth_date as dateofbirth from offender p where p.crn = :crn and p.soft_deleted = 0 """, nativeQuery = true diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UserService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UserService.kt index 124fd668ac..1c1c6f7dd0 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UserService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/UserService.kt @@ -15,18 +15,21 @@ class UserService( private val userRepository: UserRepository, private val caseloadRepository: CaseloadRepository, private val staffRepository: StaffRepository, - private val teamRepository: TeamRepository + private val teamRepository: TeamRepository, + private val userAccessService: UserAccessService ) { @Transactional fun getUserCaseload(username: String, pageable: Pageable): StaffCaseload { val user = userRepository.getUser(username) val caseload = caseloadRepository.findByStaffId(user.staff!!.id, pageable) + + val userAccess = userAccessService.userAccessFor(username, caseload.content.map { it.person.crn }) return StaffCaseload( totalElements = caseload.totalElements.toInt(), totalPages = caseload.totalPages, provider = user.staff.provider.description, - caseload = caseload.content.map { it.toStaffCase() }, + caseload = caseload.content.map { it.toStaffCase(userAccess.access.firstOrNull { ua -> ua.crn == it.person.crn }) }, staff = Name(forename = user.staff.forename, surname = user.staff.surname), ) } @@ -51,12 +54,13 @@ class UserService( .map { KeyPair(it.code.trim(), it.description) } val contactTypes = caseloadRepository.findContactTypesForStaff(user.staff.id).map { KeyPair(it.code.trim(), it.description) } + val userAccess = userAccessService.checkLimitedAccessFor(caseload.content.map { it.person.crn }) return StaffCaseload( totalElements = caseload.totalElements.toInt(), totalPages = caseload.totalPages, provider = user.staff.provider.description, - caseload = caseload.content.map { it.toStaffCase() }, + caseload = caseload.content.map { it.toStaffCase(userAccess.access.first { ua -> ua.crn == it.person.crn }) }, staff = Name(forename = user.staff.forename, surname = user.staff.surname), metaData = MetaData(sentenceTypes = sentenceTypes, contactTypes = contactTypes), sortedBy = sortedBy @@ -67,7 +71,7 @@ class UserService( fun getTeamCaseload(teamCode: String, pageable: Pageable): TeamCaseload { val team = teamRepository.getTeam(teamCode) val caseload = caseloadRepository.findByTeamCode(team.code, pageable) - caseload.content + return TeamCaseload( totalElements = caseload.totalElements.toInt(), totalPages = caseload.totalPages, @@ -94,12 +98,13 @@ class UserService( } } -fun Caseload.toStaffCase() = StaffCase( +fun Caseload.toStaffCase(caseAccess: CaseAccess? = null) = StaffCase( + limitedAccess = caseAccess.isLao(), caseName = Name( forename = person.forename, middleName = listOfNotNull(person.secondName, person.thirdName).joinToString(" "), surname = person.surname - ), + ).takeIf { !caseAccess.isLao() }, crn = person.crn, nextAppointment = nextAppointment?.let { Appointment( @@ -107,17 +112,18 @@ fun Caseload.toStaffCase() = StaffCase( description = it.type.description, date = it.appointmentDatetime ) - }, + }.takeIf { !caseAccess.isLao() }, previousAppointment = previousAppointment?.let { Appointment( id = it.id, description = it.type.description, date = it.appointmentDatetime ) - }, - dob = person.dateOfBirth, - latestSentence = latestSentence?.disposal?.type?.description, - numberOfAdditionalSentences = latestSentence?.let { it.totalNumberOfSentences - 1L } ?: 0L + }.takeIf { !caseAccess.isLao() }, + dob = person.dateOfBirth.takeIf { !caseAccess.isLao() }, + latestSentence = latestSentence?.disposal?.type?.description.takeIf { !caseAccess.isLao() }, + numberOfAdditionalSentences = (latestSentence?.let { it.totalNumberOfSentences - 1L } + ?: 0L).takeIf { !caseAccess.isLao() }, ) fun Caseload.toTeamCase() = TeamCase( @@ -129,3 +135,5 @@ fun Caseload.toTeamCase() = TeamCase( crn = person.crn, staff = Staff(name = Name(forename = staff.forename, surname = staff.surname), code = staff.code) ) + +fun CaseAccess?.isLao() = this != null && (this.userExcluded || this.userRestricted) diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/UserServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/UserServiceTest.kt index e8b20e4740..626d5027a2 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/UserServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/UserServiceTest.kt @@ -4,6 +4,8 @@ import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.ArgumentMatchers.anyList +import org.mockito.ArgumentMatchers.anyString import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension @@ -36,12 +38,16 @@ internal class UserServiceTest { @Mock lateinit var teamRepository: TeamRepository + @Mock + lateinit var userAccessService: UserAccessService + @InjectMocks lateinit var service: UserService @Test fun `calls get person activity function`() { val username = "username" + whenever(userAccessService.userAccessFor(anyString(), anyList())).thenReturn(UserAccess(emptyList())) whenever(userRepository.findByUsername(username)).thenReturn(USER) whenever(caseloadRepository.findByStaffId(USER.staff!!.id, Pageable.ofSize(1))).thenReturn( PageImpl(