From 88d725e9f834baf5c6c4d2e3cb98ecf9aab77f7b Mon Sep 17 00:00:00 2001 From: pmcphee77 <150798161+pmcphee77@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:48:15 +0000 Subject: [PATCH] PI-1991: Added more fields and added user info (#3477) --- .../justice/digital/hmpps/data/DataLoader.kt | 1 + .../hmpps/data/generator/UserGenerator.kt | 3 +++ .../personalDetails/PersonDetailsGenerator.kt | 16 ++++++++--- .../justice/digital/hmpps/api/model/Name.kt | 2 +- .../api/model/personalDetails/Address.kt | 4 +++ .../model/personalDetails/ContactAddress.kt | 19 ++++++++++--- .../model/personalDetails/PersonalContact.kt | 8 +++++- .../delius/personalDetails/entity/Address.kt | 9 +++++++ .../entity/PersonalContactEntity.kt | 27 ++++++++++++++++++- .../integrations/delius/user/entity/User.kt | 22 +++++++++++++++ .../hmpps/service/PersonalDetailsService.kt | 14 +++++++--- 11 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/user/entity/User.kt 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 58b635a65b..14c7af7b82 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 @@ -29,6 +29,7 @@ class DataLoader( override fun onApplicationEvent(are: ApplicationReadyEvent) { entityManager.persist(PersonGenerator.OVERVIEW.gender) + entityManager.persist(UserGenerator.USER) PersonGenerator.DISABILITIES.forEach { entityManager.persist(it.type) } PersonGenerator.PROVISIONS.forEach { entityManager.persist(it.type) } PersonGenerator.PERSONAL_CIRCUMSTANCES.forEach { diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/UserGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/UserGenerator.kt index 519be56fb4..bdef5846a9 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/UserGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/UserGenerator.kt @@ -1,7 +1,10 @@ package uk.gov.justice.digital.hmpps.data.generator +import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User import uk.gov.justice.digital.hmpps.user.AuditUser object UserGenerator { val AUDIT_USER = AuditUser(IdGenerator.getAndIncrement(), "ManageSupervisionAndDelius") + + val USER = User(id = IdGenerator.getAndIncrement(), forename = "Manage", surname = "Supervision") } 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 981b4ad482..b865ad8cb5 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 @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.data.generator.personalDetails import uk.gov.justice.digital.hmpps.data.generator.IdGenerator import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator +import uk.gov.justice.digital.hmpps.data.generator.UserGenerator.USER import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.ContactAddress import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonAddress @@ -93,8 +94,13 @@ object PersonDetailsGenerator { "Steven", "Smith", "Brother", + "email.test", + "0897676554", + LocalDate.now(), + LocalDate.now(), RELATIONSHIP_TYPE, - CONTACT_ADDRESS + CONTACT_ADDRESS, + USER ) val PERSON_ADDRESS_STATUS_1 = ReferenceData(IdGenerator.getAndIncrement(), "M", "Main Address") @@ -151,6 +157,7 @@ object PersonDetailsGenerator { null, true, LocalDate.now(), + USER, false, IdGenerator.getAndIncrement() ) @@ -176,8 +183,8 @@ object PersonDetailsGenerator { softDeleted = false, telephoneNumber = null, lastUpdated = LocalDate.now().minusDays(10), - - ) + lastUpdatedUser = USER + ) fun generatePersonAddress( addressNumber: String, @@ -206,7 +213,8 @@ object PersonDetailsGenerator { endDate = endDate, status = status, type = type, - typeVerified = verified + typeVerified = verified, + lastUpdatedUser = USER ) fun generatePersonDetails( diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Name.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Name.kt index e8497e115f..156325da1f 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Name.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Name.kt @@ -4,7 +4,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person data class Name( val forename: String, - val middleName: String?, + val middleName: String? = null, val surname: String ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt index 22ada74956..dc27163afe 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt @@ -1,5 +1,6 @@ package uk.gov.justice.digital.hmpps.api.model.personalDetails +import uk.gov.justice.digital.hmpps.api.model.Name import java.time.LocalDate data class Address( @@ -14,6 +15,7 @@ data class Address( val to: LocalDate?, val verified: Boolean?, val lastUpdated: LocalDate?, + val lastUpdatedBy: Name, val type: String?, val status: String? ) { @@ -30,6 +32,7 @@ data class Address( to: LocalDate? = null, verified: Boolean? = null, lastUpdated: LocalDate? = null, + lastUpdatedBy: Name, type: String? = null, status: String? = null ): Address? = @@ -51,6 +54,7 @@ data class Address( to, verified, lastUpdated, + lastUpdatedBy, type, status ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/ContactAddress.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/ContactAddress.kt index 67be65b0db..eeee097665 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/ContactAddress.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/ContactAddress.kt @@ -1,5 +1,6 @@ package uk.gov.justice.digital.hmpps.api.model.personalDetails +import uk.gov.justice.digital.hmpps.api.model.Name import java.time.LocalDate data class ContactAddress( @@ -10,7 +11,8 @@ data class ContactAddress( val town: String?, val county: String?, val postcode: String?, - val lastUpdated: LocalDate? + val lastUpdated: LocalDate, + val lastUpdatedBy: Name, ) { companion object { fun from( @@ -21,7 +23,8 @@ data class ContactAddress( town: String? = null, county: String? = null, postcode: String? = null, - lastUpdated: LocalDate? = null + lastUpdated: LocalDate, + lastUpdatedBy: Name ): ContactAddress? = if ( buildingName == null && buildingNumber == null && streetName == null && @@ -29,7 +32,17 @@ data class ContactAddress( ) { null } else { - ContactAddress(buildingName, buildingNumber, streetName, district, town, county, postcode, lastUpdated) + ContactAddress( + buildingName, + buildingNumber, + streetName, + district, + town, + county, + postcode, + lastUpdated, + lastUpdatedBy + ) } } } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalContact.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalContact.kt index ad4e4bd322..1fb53b0948 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalContact.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalContact.kt @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.api.model.personalDetails import uk.gov.justice.digital.hmpps.api.model.Name import uk.gov.justice.digital.hmpps.api.model.PersonSummary +import java.time.LocalDate data class PersonalContact( val personSummary: PersonSummary, @@ -10,5 +11,10 @@ data class PersonalContact( val relationship: String?, val relationshipType: String, val address: ContactAddress?, - val notes: String? + val notes: String?, + val phone: String?, + val email: String?, + val startDate: LocalDate?, + val lastUpdated: LocalDate, + val lastUpdatedBy: Name ) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt index e9c232d178..cf0ecbdf55 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt @@ -7,6 +7,7 @@ import org.hibernate.type.YesNoConverter import org.springframework.data.jpa.repository.EntityGraph import org.springframework.data.jpa.repository.JpaRepository import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData +import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User import java.time.LocalDate @Immutable @@ -47,6 +48,10 @@ class PersonAddress( @Column(name = "last_updated_datetime") val lastUpdated: LocalDate?, + @ManyToOne + @JoinColumn(name = "last_updated_user_id") + val lastUpdatedUser: User, + @Column(columnDefinition = "number") val softDeleted: Boolean, @@ -81,6 +86,10 @@ class ContactAddress( @Column(name = "last_updated_datetime") val lastUpdated: LocalDate, + @ManyToOne + @JoinColumn(name = "last_updated_user_id") + val lastUpdatedUser: User, + @Column(columnDefinition = "NUMBER") val softDeleted: Boolean = false ) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt index 3329eda21f..bc627a9819 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt @@ -2,15 +2,19 @@ package uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity import jakarta.persistence.* import org.hibernate.annotations.Immutable +import org.hibernate.annotations.SQLRestriction import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query import uk.gov.justice.digital.hmpps.exception.NotFoundException import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData +import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User +import java.time.LocalDate @Entity @Immutable @Table(name = "personal_contact") +@SQLRestriction("soft_deleted = 0") class PersonalContactEntity( @Id @Column(name = "personal_contact_id") @@ -32,6 +36,18 @@ class PersonalContactEntity( @Column(name = "relationship") val relationship: String, + @Column(name = "email") + val email: String, + + @Column(name = "mobile_number") + val mobileNumber: String, + + @Column(name = "start_date") + val startDate: LocalDate?, + + @Column(name = "last_updated_datetime") + val lastUpdated: LocalDate, + @ManyToOne @JoinColumn(name = "relationship_type_id") val relationshipType: ReferenceData, @@ -40,8 +56,15 @@ class PersonalContactEntity( @JoinColumn(name = "address_id") val address: ContactAddress, + @ManyToOne + @JoinColumn(name = "last_updated_user_id") + val lastUpdatedUser: User, + @Column(name = "notes", columnDefinition = "clob") val notes: String? = null, + + @Column(columnDefinition = "number") + val softDeleted: Boolean = false ) interface PersonalContactRepository : JpaRepository { @@ -56,4 +79,6 @@ interface PersonalContactRepository : JpaRepository } fun PersonalContactRepository.getContact(crn: String, id: Long): PersonalContactEntity = - findById(crn, id) ?: throw NotFoundException("PersonalContact", "id", id) \ No newline at end of file + findById(crn, id) ?: throw NotFoundException("PersonalContact", "id", id) + + diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/user/entity/User.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/user/entity/User.kt new file mode 100644 index 0000000000..268787b661 --- /dev/null +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/user/entity/User.kt @@ -0,0 +1,22 @@ +package uk.gov.justice.digital.hmpps.integrations.delius.user.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import org.hibernate.annotations.Immutable + +@Entity +@Immutable +@Table(name = "user_") +class User( + @Id + @Column(name = "user_id") + val id: Long, + + @Column(name = "forename") + val forename: String, + + @Column(name = "surname") + val surname: String +) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt index a090304752..f750bddd68 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt @@ -117,7 +117,12 @@ fun PersonalContactEntity.toContact() = PersonalContact( address = address.toAddress(), notes = notes, relationshipType = relationshipType.description, - contactId = id + contactId = id, + lastUpdated = lastUpdated, + email = email, + phone = mobileNumber, + lastUpdatedBy = Name(forename = lastUpdatedUser.forename, surname = lastUpdatedUser.surname), + startDate = startDate ) fun Person.toSummary() = @@ -137,7 +142,9 @@ fun PersonAddress.toAddress() = Address.from( verified = typeVerified, lastUpdated = lastUpdated, status = status.description, - type = type.description + type = type.description, + lastUpdatedBy = Name(forename = lastUpdatedUser.forename, surname = lastUpdatedUser.surname) + ) fun ContactAddress.toAddress() = uk.gov.justice.digital.hmpps.api.model.personalDetails.ContactAddress.from( @@ -148,7 +155,8 @@ fun ContactAddress.toAddress() = uk.gov.justice.digital.hmpps.api.model.personal town = town, county = county, postcode = postcode, - lastUpdated = lastUpdated + lastUpdated = lastUpdated, + lastUpdatedBy = Name(forename = lastUpdatedUser.forename, surname = lastUpdatedUser.surname) ) fun PersonDocument.toDocument() = Document(id = alfrescoId, name = name, lastUpdated = lastUpdated)