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
- Loading branch information
1 parent
0c6371f
commit 34bd07e
Showing
14 changed files
with
367 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ database: | |
tables: | ||
- audited_interaction | ||
- contact | ||
- offender_address | ||
|
||
audit: | ||
username: Cas3AndDelius | ||
|
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
16 changes: 16 additions & 0 deletions
16
...d-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AddressRDGenerator.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,16 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData | ||
|
||
object AddressRDGenerator { | ||
val CAS3_ADDRESS_TYPE = generate("A17", DatasetGenerator.ADDRESS_TYPE.id, "Approved Premises") | ||
val MAIN_ADDRESS_STATUS = generate("M", DatasetGenerator.ADDRESS_STATUS.id, "Main Address") | ||
val PREV_ADDRESS_STATUS = generate("P", DatasetGenerator.ADDRESS_STATUS.id, "Previous Address") | ||
|
||
fun generate( | ||
code: String, | ||
datasetId: Long, | ||
description: String = "Description of $code", | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = ReferenceData(id, code, description, datasetId) | ||
} |
9 changes: 9 additions & 0 deletions
9
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DatasetGenerator.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,9 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Dataset | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.DatasetCode | ||
|
||
object DatasetGenerator { | ||
val ADDRESS_TYPE = Dataset(IdGenerator.getAndIncrement(), DatasetCode.ADDRESS_TYPE) | ||
val ADDRESS_STATUS = Dataset(IdGenerator.getAndIncrement(), DatasetCode.ADDRESS_STATUS) | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/AddressService.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,49 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius | ||
|
||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.PersonArrived | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Person | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonAddress | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonAddressRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceDataRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.cas3AddressType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.mainAddressStatus | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.previousAddressStatus | ||
import java.time.LocalDate | ||
|
||
@Service | ||
class AddressService( | ||
private val personAddressRepository: PersonAddressRepository, | ||
private val referenceDataRepository: ReferenceDataRepository | ||
) { | ||
fun updateMainAddress(person: Person, details: PersonArrived) { | ||
endMainAddress(person, details.arrivedAt.toLocalDate()) | ||
toPersonAddress(person, details).apply(personAddressRepository::save) | ||
} | ||
|
||
fun endMainAddress(person: Person, endDate: LocalDate) { | ||
val currentMain = personAddressRepository.findMainAddress(person.id) | ||
currentMain?.apply { | ||
val previousStatus = referenceDataRepository.previousAddressStatus() | ||
currentMain.status = previousStatus | ||
currentMain.endDate = endDate | ||
} | ||
} | ||
|
||
private fun toPersonAddress(person: Person, details: PersonArrived): PersonAddress { | ||
val addressLines = details.premises.addressLines | ||
return PersonAddress( | ||
0, | ||
person.id, | ||
referenceDataRepository.cas3AddressType(), | ||
referenceDataRepository.mainAddressStatus(), | ||
buildingName = addressLines.buildingName, | ||
streetName = addressLines.streetName, | ||
district = addressLines.district, | ||
town = details.premises.town, | ||
county = details.premises.region, | ||
postcode = details.premises.postcode, | ||
startDate = details.arrivedAt.toLocalDate() | ||
) | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
.../src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonAddress.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,93 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Convert | ||
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 org.hibernate.type.YesNoConverter | ||
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 org.springframework.data.jpa.repository.Query | ||
import java.time.LocalDate | ||
import java.time.ZonedDateTime | ||
|
||
@Entity | ||
@Table(name = "offender_address") | ||
@EntityListeners(AuditingEntityListener::class) | ||
@SequenceGenerator(name = "offender_address_id_generator", sequenceName = "offender_address_id_seq", allocationSize = 1) | ||
class PersonAddress( | ||
@Id | ||
@Column(name = "offender_address_id") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "offender_address_id_generator") | ||
val id: Long, | ||
@Column(name = "offender_id") | ||
val personId: Long, | ||
@ManyToOne | ||
@JoinColumn(name = "address_type_id") | ||
val type: ReferenceData, | ||
@ManyToOne | ||
@JoinColumn(name = "address_status_id") | ||
var status: ReferenceData, | ||
val streetName: String?, | ||
@Column(name = "town_city") | ||
val town: String?, | ||
val county: String?, | ||
val postcode: String?, | ||
val telephoneNumber: String? = null, | ||
val buildingName: String? = null, | ||
val district: String? = null, | ||
val addressNumber: String? = null, | ||
@Convert(converter = YesNoConverter::class) | ||
val noFixedAbode: Boolean? = false, | ||
@Convert(converter = YesNoConverter::class) | ||
val typeVerified: Boolean? = false, | ||
val startDate: LocalDate = LocalDate.now(), | ||
var endDate: LocalDate? = null, | ||
@Column(updatable = false, columnDefinition = "NUMBER") | ||
val softDeleted: Boolean = false, | ||
|
||
@CreatedDate | ||
@Column(nullable = false) | ||
var createdDatetime: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@Column(nullable = false) | ||
@CreatedBy | ||
var createdByUserId: Long = 0, | ||
|
||
@Column(nullable = false) | ||
@LastModifiedDate | ||
var lastUpdatedDatetime: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@Column(nullable = false) | ||
@LastModifiedBy | ||
var lastUpdatedUserId: Long = 0, | ||
|
||
@Column(nullable = false) | ||
val partitionAreaId: Long = 0 | ||
) | ||
|
||
interface PersonAddressRepository : JpaRepository<PersonAddress, Long> { | ||
@Query( | ||
""" | ||
select pa from PersonAddress pa | ||
join fetch pa.status | ||
join fetch pa.type | ||
where pa.personId = :personId | ||
and pa.softDeleted = false | ||
and pa.endDate is null | ||
and pa.status.code = 'M' | ||
""" | ||
) | ||
fun findMainAddress(personId: Long): PersonAddress? | ||
} |
Oops, something went wrong.