From 24b0a35c066a73b7f0513862165ac1c94bf55ffc Mon Sep 17 00:00:00 2001 From: pmcphee77 <150798161+pmcphee77@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:54:51 +0100 Subject: [PATCH] PI-2074: Multiple categories for contact type (#3635) --- .../hmpps/data/generator/ContactGenerator.kt | 2 +- .../delius/overview/entity/Contact.kt | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) 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 1261aa4571..12ca89c22a 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 @@ -172,7 +172,7 @@ object ContactGenerator { ContactType(IdGenerator.getAndIncrement(), code, attendance, description, systemGenerated = systemGenerated) private fun generateContactCategory(contactType: ContactType, contactCategory: ReferenceData) = - ContactCategory(id = contactType.id, category = contactCategory) + ContactCategory(id = ContactCategoryId(contactType.id, category = contactCategory)) fun generateOfficeLocation( code: String, diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Contact.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Contact.kt index d7cb8972dd..bbba6d93fc 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Contact.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Contact.kt @@ -11,6 +11,7 @@ import uk.gov.justice.digital.hmpps.exception.NotFoundException import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.ContactDocument import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User +import java.io.Serializable import java.time.LocalDate import java.time.ZonedDateTime import java.time.format.DateTimeFormatter @@ -126,7 +127,7 @@ class Contact( fun isPhoneCallFromPop(): Boolean = type.code == ContactTypeCode.PHONE_CONTACT_FROM_POP.value fun isPhoneCallToPop(): Boolean = type.code == ContactTypeCode.PHONE_CONTACT_TO_POP.value fun isCommunication(): Boolean = - type.category?.category?.code?.equals(ContactCategoryCode.COMMUNICATION_CONTACT.value) ?: false + type.categories.map { it.id.category.code }.contains(ContactCategoryCode.COMMUNICATION_CONTACT.value) } @Immutable @@ -147,12 +148,8 @@ class ContactType( @Column val description: String, - @ManyToOne - @JoinTable( - name = "r_contact_typecontact_category", - inverseJoinColumns = [JoinColumn(name = "contact_type_id", insertable = false, updatable = false)], - ) - val category: ContactCategory? = null, + @OneToMany(mappedBy = "id.contactTypeId") + val categories: List = emptyList(), @Column(name = "sgc_flag", columnDefinition = "number") val systemGenerated: Boolean = false, @@ -166,14 +163,19 @@ class ContactType( @Entity @Table(name = "r_contact_typecontact_category") class ContactCategory( - @Id + @EmbeddedId + val id: ContactCategoryId, +) + +@Embeddable +class ContactCategoryId( @Column(name = "contact_type_id") - val id: Long, + val contactTypeId: Long, @ManyToOne @JoinColumn(name = "standard_reference_list_id") val category: ReferenceData, -) +) : Serializable @Immutable @Entity