From f378f0d6a818953c49ed41ce366f2c874932febb Mon Sep 17 00:00:00 2001 From: "probation-integration-bot[bot]" <177347787+probation-integration-bot[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:17:43 +0000 Subject: [PATCH] Formatting changes --- .../data/generator/ReferenceDataGenerator.kt | 12 +++- .../integrations/delius/entity/Person.kt | 6 +- .../delius/entity/PersonAddress.kt | 3 +- .../delius/entity/ReferenceData.kt | 11 +++- .../digital/hmpps/service/PersonService.kt | 63 ++++++++++--------- .../digital/hmpps/messaging/HandlerTest.kt | 21 ++++++- .../hmpps/service/PersonServiceTest.kt | 7 ++- 7 files changed, 78 insertions(+), 45 deletions(-) diff --git a/projects/common-platform-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferenceDataGenerator.kt b/projects/common-platform-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferenceDataGenerator.kt index b1946ea95b..d702df66b4 100644 --- a/projects/common-platform-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferenceDataGenerator.kt +++ b/projects/common-platform-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferenceDataGenerator.kt @@ -10,9 +10,15 @@ object ReferenceDataGenerator { val GENDER_FEMALE = generate(ReferenceData.GenderCode.FEMALE.deliusValue, GENDER.id, "Female") val GENDER_MALE = generate(ReferenceData.GenderCode.MALE.deliusValue, GENDER.id, "Male") - val INITIAL_ALLOCATION = generate(ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code, OM_ALLOCATION_REASON.id, "Initial Allocation") - val MAIN_ADDRESS_STATUS = generate(ReferenceData.StandardRefDataCode.ADDRESS_MAIN_STATUS.code, ADDRESS_STATUS.id, "Main") - val AWAITING_ASSESSMENT = generate(ReferenceData.StandardRefDataCode.AWAITING_ASSESSMENT.code, ADDRESS_TYPE.id, "Awaiting Assessment") + val INITIAL_ALLOCATION = generate( + ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code, + OM_ALLOCATION_REASON.id, + "Initial Allocation" + ) + val MAIN_ADDRESS_STATUS = + generate(ReferenceData.StandardRefDataCode.ADDRESS_MAIN_STATUS.code, ADDRESS_STATUS.id, "Main") + val AWAITING_ASSESSMENT = + generate(ReferenceData.StandardRefDataCode.AWAITING_ASSESSMENT.code, ADDRESS_TYPE.id, "Awaiting Assessment") fun generate( code: String, diff --git a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt index 194f233d2b..8d1f89732e 100644 --- a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt +++ b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt @@ -56,13 +56,13 @@ class Person( @Column(columnDefinition = "number") val softDeleted: Boolean = false, - @Column(name="current_disposal", columnDefinition = "number") + @Column(name = "current_disposal", columnDefinition = "number") val currentDisposal: Boolean = false, - @Column(name="current_restriction", columnDefinition = "number") + @Column(name = "current_restriction", columnDefinition = "number") val currentRestriction: Boolean = false, - @Column(name="pending_transfer", columnDefinition = "number") + @Column(name = "pending_transfer", columnDefinition = "number") val pendingTransfer: Boolean = false, @Column diff --git a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonAddress.kt b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonAddress.kt index 13b1c09bf4..c020a4b728 100644 --- a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonAddress.kt +++ b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonAddress.kt @@ -105,7 +105,6 @@ class PersonAddress( @Column(name = "approved_premises_residence_id") val approvedPremisesResidenceId: Long? = null, - ) - +) interface PersonAddressRepository : JpaRepository \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/ReferenceData.kt b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/ReferenceData.kt index 4a27747ae0..913ad87a41 100644 --- a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/ReferenceData.kt +++ b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/ReferenceData.kt @@ -130,8 +130,15 @@ interface ReferenceDataRepository : JpaRepository { } fun ReferenceDataRepository.initialAllocationReason() = - findByCodeAndDatasetCode(ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code, DatasetCode.OM_ALLOCATION_REASON) - ?: throw NotFoundException("Allocation Reason", "code", ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code) + findByCodeAndDatasetCode( + ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code, + DatasetCode.OM_ALLOCATION_REASON + ) + ?: throw NotFoundException( + "Allocation Reason", + "code", + ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code + ) fun ReferenceDataRepository.mainAddressStatus() = findByCodeAndDatasetCode(ReferenceData.StandardRefDataCode.ADDRESS_MAIN_STATUS.code, DatasetCode.ADDRESS_STATUS) diff --git a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt index a1e45df056..fefb382ead 100644 --- a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt +++ b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt @@ -34,43 +34,44 @@ class PersonService( ) @Transactional - fun insertPerson(person: Person, courtCode: String): Person = audit(BusinessInteractionCode.INSERT_PERSON) { audit -> - // Person record - val savedPerson = personRepository.save(person) + fun insertPerson(person: Person, courtCode: String): Person = + audit(BusinessInteractionCode.INSERT_PERSON) { audit -> + // Person record + val savedPerson = personRepository.save(person) - val courtLinkedProvider = courtRepository.findByNationalCourtCode(courtCode).probationArea - val initialAllocation = referenceDataRepository.initialAllocationReason() - val unallocatedTeam = teamRepository.findByCode(courtLinkedProvider.code + "UAT") - val unallocatedStaff = staffRepository.findByCode(unallocatedTeam.code + "U") + val courtLinkedProvider = courtRepository.findByNationalCourtCode(courtCode).probationArea + val initialAllocation = referenceDataRepository.initialAllocationReason() + val unallocatedTeam = teamRepository.findByCode(courtLinkedProvider.code + "UAT") + val unallocatedStaff = staffRepository.findByCode(unallocatedTeam.code + "U") - // Person manager record - val manager = PersonManager( - person = savedPerson, - staff = unallocatedStaff, - team = unallocatedTeam, - provider = courtLinkedProvider, - softDeleted = false, - active = true, - allocationReason = initialAllocation, - staffEmployeeID = unallocatedStaff.id, - trustProviderTeamId = unallocatedTeam.id, - allocationDate = LocalDateTime.of(1900, 1, 1, 0, 0) + // Person manager record + val manager = PersonManager( + person = savedPerson, + staff = unallocatedStaff, + team = unallocatedTeam, + provider = courtLinkedProvider, + softDeleted = false, + active = true, + allocationReason = initialAllocation, + staffEmployeeID = unallocatedStaff.id, + trustProviderTeamId = unallocatedTeam.id, + allocationDate = LocalDateTime.of(1900, 1, 1, 0, 0) - ) - personManagerRepository.save(manager) + ) + personManagerRepository.save(manager) - // Equality record - val equality = Equality( - id = null, - personId = savedPerson.id!!, - softDeleted = false, - ) + // Equality record + val equality = Equality( + id = null, + personId = savedPerson.id!!, + softDeleted = false, + ) - equalityRepository.save(equality) + equalityRepository.save(equality) - audit["offenderId"] = savedPerson.id - savedPerson - } + audit["offenderId"] = savedPerson.id + savedPerson + } fun generateCrn(): String { return generateCrn.execute()["CRN"] as String diff --git a/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt b/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt index 65b192cdc1..0aa8fb0d94 100644 --- a/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt +++ b/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt @@ -58,9 +58,24 @@ internal class HandlerTest { ) whenever(personService.generateCrn()).thenReturn("A000001") whenever(personService.insertPerson(any(), any())).thenReturn(PersonGenerator.DEFAULT) - whenever(referenceDataRepository.findByCodeAndDatasetCode(ReferenceData.GenderCode.MALE.deliusValue, DatasetCode.GENDER)).thenReturn(ReferenceDataGenerator.GENDER_MALE) - whenever(referenceDataRepository.findByCodeAndDatasetCode(ReferenceData.StandardRefDataCode.ADDRESS_MAIN_STATUS.code, DatasetCode.ADDRESS_STATUS)).thenReturn(ReferenceDataGenerator.MAIN_ADDRESS_STATUS) - whenever(referenceDataRepository.findByCodeAndDatasetCode(ReferenceData.StandardRefDataCode.AWAITING_ASSESSMENT.code, DatasetCode.ADDRESS_TYPE)).thenReturn(ReferenceDataGenerator.AWAITING_ASSESSMENT) + whenever( + referenceDataRepository.findByCodeAndDatasetCode( + ReferenceData.GenderCode.MALE.deliusValue, + DatasetCode.GENDER + ) + ).thenReturn(ReferenceDataGenerator.GENDER_MALE) + whenever( + referenceDataRepository.findByCodeAndDatasetCode( + ReferenceData.StandardRefDataCode.ADDRESS_MAIN_STATUS.code, + DatasetCode.ADDRESS_STATUS + ) + ).thenReturn(ReferenceDataGenerator.MAIN_ADDRESS_STATUS) + whenever( + referenceDataRepository.findByCodeAndDatasetCode( + ReferenceData.StandardRefDataCode.AWAITING_ASSESSMENT.code, + DatasetCode.ADDRESS_TYPE + ) + ).thenReturn(ReferenceDataGenerator.AWAITING_ASSESSMENT) val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT) handler.handle(notification) diff --git a/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonServiceTest.kt b/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonServiceTest.kt index 487387e571..c4163ab49b 100644 --- a/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonServiceTest.kt +++ b/projects/common-platform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonServiceTest.kt @@ -61,7 +61,12 @@ class PersonServiceTest { whenever(personRepository.save(person)).thenReturn(savedPerson) whenever(courtRepository.findByNationalCourtCode(anyString())).thenReturn(court) - whenever(referenceDataRepository.findByCodeAndDatasetCode(ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code, DatasetCode.OM_ALLOCATION_REASON)).thenReturn(initialAllocation) + whenever( + referenceDataRepository.findByCodeAndDatasetCode( + ReferenceData.StandardRefDataCode.INITIAL_ALLOCATION.code, + DatasetCode.OM_ALLOCATION_REASON + ) + ).thenReturn(initialAllocation) whenever(teamRepository.findByCode(anyString())).thenReturn(unallocatedTeam) whenever(staffRepository.findByCode(anyString())).thenReturn(unallocatedStaff)