Skip to content

Commit

Permalink
PI-1991: Added more fields and added user info (#3477)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 authored Mar 15, 2024
1 parent a2af4cb commit 88d725e
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -151,6 +157,7 @@ object PersonDetailsGenerator {
null,
true,
LocalDate.now(),
USER,
false,
IdGenerator.getAndIncrement()
)
Expand All @@ -176,8 +183,8 @@ object PersonDetailsGenerator {
softDeleted = false,
telephoneNumber = null,
lastUpdated = LocalDate.now().minusDays(10),

)
lastUpdatedUser = USER
)

fun generatePersonAddress(
addressNumber: String,
Expand Down Expand Up @@ -206,7 +213,8 @@ object PersonDetailsGenerator {
endDate = endDate,
status = status,
type = type,
typeVerified = verified
typeVerified = verified,
lastUpdatedUser = USER
)

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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?
) {
Expand All @@ -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? =
Expand All @@ -51,6 +54,7 @@ data class Address(
to,
verified,
lastUpdated,
lastUpdatedBy,
type,
status
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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(
Expand All @@ -21,15 +23,26 @@ 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 &&
district == null && town == null && county == null && postcode == null
) {
null
} else {
ContactAddress(buildingName, buildingNumber, streetName, district, town, county, postcode, lastUpdated)
ContactAddress(
buildingName,
buildingNumber,
streetName,
district,
town,
county,
postcode,
lastUpdated,
lastUpdatedBy
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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<PersonalContactEntity, Long> {
Expand All @@ -56,4 +79,6 @@ interface PersonalContactRepository : JpaRepository<PersonalContactEntity, Long>
}

fun PersonalContactRepository.getContact(crn: String, id: Long): PersonalContactEntity =
findById(crn, id) ?: throw NotFoundException("PersonalContact", "id", id)
findById(crn, id) ?: throw NotFoundException("PersonalContact", "id", id)


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

0 comments on commit 88d725e

Please sign in to comment.