generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-1441 add contact when adding licence conditions
- Loading branch information
1 parent
58b68d2
commit 7480270
Showing
7 changed files
with
165 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...rc/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact.entity/Contact.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.contact.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.EntityListeners | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.Lob | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.SequenceGenerator | ||
import jakarta.persistence.Table | ||
import jakarta.persistence.Version | ||
import org.hibernate.annotations.Immutable | ||
import org.springframework.data.annotation.CreatedBy | ||
import org.springframework.data.annotation.CreatedDate | ||
import org.springframework.data.annotation.LastModifiedBy | ||
import org.springframework.data.annotation.LastModifiedDate | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import uk.gov.justice.digital.hmpps.exception.NotFoundException | ||
import java.time.LocalDate | ||
import java.time.ZonedDateTime | ||
|
||
@Entity | ||
@EntityListeners(AuditingEntityListener::class) | ||
@Table(name = "contact") | ||
@SequenceGenerator(name = "contact_id_generator", sequenceName = "contact_id_seq", allocationSize = 1) | ||
class Contact( | ||
|
||
@Column(name = "offender_id") | ||
val personId: Long, | ||
val eventId: Long?, | ||
|
||
@Column(name = "contact_date") | ||
val date: LocalDate, | ||
|
||
@Column(name = "contact_start_time") | ||
val startTime: ZonedDateTime?, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "contact_type_id") | ||
val type: ContactType, | ||
|
||
val teamId: Long, | ||
val staffId: Long, | ||
|
||
@Lob | ||
@Column | ||
val notes: String?, | ||
|
||
@Column(columnDefinition = "number") | ||
val softDeleted: Boolean = false, | ||
|
||
@Version | ||
@Column(name = "row_version") | ||
val version: Long = 0, | ||
|
||
@Id | ||
@Column(name = "contact_id") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "contact_id_generator") | ||
val id: Long = 0 | ||
) { | ||
val partitionAreaId: Long = 0 | ||
|
||
@CreatedDate | ||
var createdDatetime: ZonedDateTime = ZonedDateTime.now() | ||
|
||
@CreatedBy | ||
var createdByUserId: Long = 0 | ||
|
||
@LastModifiedDate | ||
var lastUpdatedDatetime: ZonedDateTime = ZonedDateTime.now() | ||
|
||
@LastModifiedBy | ||
var lastUpdatedUserId: Long = 0 | ||
} | ||
|
||
@Immutable | ||
@Entity | ||
@Table(name = "r_contact_type") | ||
class ContactType( | ||
|
||
val code: String, | ||
|
||
@Id | ||
@Column(name = "contact_type_id") | ||
val id: Long | ||
) { | ||
companion object { | ||
val LPOP = "LPOP" | ||
} | ||
} | ||
|
||
interface ContactRepository : JpaRepository<Contact, Long> | ||
|
||
interface ContactTypeRepository : JpaRepository<ContactType, Long> { | ||
fun findByCode(code: String): ContactType? | ||
} | ||
|
||
fun ContactTypeRepository.getByCode(code: String): ContactType = | ||
findByCode(code) ?: throw NotFoundException("ContactType", "code", code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ContactService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uk.gov.justice.digital.hmpps.service | ||
|
||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactTypeRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.getByCode | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.PersonManager | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Disposal | ||
import java.time.ZonedDateTime | ||
|
||
@Service | ||
class ContactService( | ||
private val contactTypeRepository: ContactTypeRepository, | ||
private val contactRepository: ContactRepository | ||
) { | ||
fun createContact(disposal: Disposal, com: PersonManager, startDateTime: ZonedDateTime): Contact { | ||
return contactRepository.save( | ||
Contact( | ||
disposal.event.person.id, | ||
disposal.event.id, | ||
startDateTime.toLocalDate(), | ||
startDateTime, | ||
contactTypeRepository.getByCode(ContactType.LPOP), | ||
com.team.id, | ||
com.staff.id, | ||
""" | ||
|Delius has been updated with licence conditions entered in the Create and Vary a licence service. | ||
|Select the following link to navigate to Create and Vary a licence service and view the licence. | ||
""".trimMargin() | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters