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.
Browse files
Browse the repository at this point in the history
* PI-1586 add contacts for POM Allocation and RO change * ktlintFormat * update vars to vals
- Loading branch information
1 parent
e6f8a44
commit 20d8f69
Showing
11 changed files
with
228 additions
and
28 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
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
100 changes: 100 additions & 0 deletions
100
...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,100 @@ | ||
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.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_seq", sequenceName = "contact_id_seq", allocationSize = 1) | ||
class Contact( | ||
|
||
@Column(name = "offender_id") | ||
val personId: Long, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "contact_type_id") | ||
val type: ContactType, | ||
|
||
@Column(name = "contact_date") | ||
val date: LocalDate, | ||
|
||
@Column(name = "contact_start_time") | ||
val startTime: ZonedDateTime, | ||
|
||
@Column(name = "probation_area_id") | ||
val providerId: Long, | ||
val teamId: Long, | ||
val staffId: Long, | ||
|
||
@Column(columnDefinition = "number") | ||
val softDeleted: Boolean = false, | ||
|
||
@Id | ||
@Column(name = "contact_id") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "contact_id_seq") | ||
val id: Long = 0 | ||
) { | ||
@Version | ||
@Column(name = "row_version") | ||
val version: Long = 0 | ||
|
||
@CreatedDate | ||
var createdDatetime: ZonedDateTime = ZonedDateTime.now() | ||
|
||
@CreatedBy | ||
var createdByUserId: Long = 0 | ||
|
||
@LastModifiedDate | ||
var lastUpdatedDatetime: ZonedDateTime = ZonedDateTime.now() | ||
|
||
@LastModifiedBy | ||
var lastUpdatedUserId: Long = 0 | ||
|
||
val partitionAreaId: Long = 0 | ||
} | ||
|
||
@Immutable | ||
@Entity | ||
@Table(name = "r_contact_type") | ||
class ContactType( | ||
val code: String, | ||
@Id | ||
@Column(name = "contact_type_id") | ||
val id: Long | ||
) { | ||
enum class Code(val value: String) { | ||
POM_AUTO_ALLOCATION("EPOMAT"), | ||
POM_INTERNAL_ALLOCATION("EPOMIN"), | ||
POM_EXTERNAL_ALLOCATION("EPOMEX"), | ||
RESPONSIBLE_OFFICER_CHANGE("ROC") | ||
} | ||
} | ||
|
||
interface ContactRepository : JpaRepository<Contact, Long> | ||
|
||
interface ContactTypeRepository : JpaRepository<ContactType, Long> { | ||
fun findByCode(code: String): ContactType? | ||
} | ||
|
||
fun ContactTypeRepository.getByCode(code: String) = | ||
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
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
34 changes: 34 additions & 0 deletions
34
...-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/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,34 @@ | ||
package uk.gov.justice.digital.hmpps.services | ||
|
||
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.person.entity.PersonManagerRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.getCurrentCom | ||
import java.time.ZonedDateTime | ||
|
||
@Service | ||
class ContactService( | ||
private val personManagerRepository: PersonManagerRepository, | ||
private val contactTypeRepository: ContactTypeRepository, | ||
private val contactRepository: ContactRepository | ||
) { | ||
fun createContact(personId: Long, typeCode: ContactType.Code, dateTime: ZonedDateTime) { | ||
val com = personManagerRepository.getCurrentCom(personId) | ||
val type = contactTypeRepository.getByCode(typeCode.value) | ||
contactRepository.save( | ||
Contact( | ||
personId, | ||
type, | ||
dateTime.toLocalDate(), | ||
dateTime, | ||
com.providerId, | ||
com.team.id, | ||
com.staff.id | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.