Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
probation-integration-bot[bot] authored Oct 18, 2024
1 parent e1483b7 commit f378f0d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class PersonAddress(

@Column(name = "approved_premises_residence_id")
val approvedPremisesResidenceId: Long? = null,
)

)

interface PersonAddressRepository : JpaRepository<PersonAddress, Long>
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ interface ReferenceDataRepository : JpaRepository<ReferenceData, Long> {
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f378f0d

Please sign in to comment.