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-2161: Created post endpoint for /nomis-case-note/{crn} * PI-2161: Moved staff code generator to common library
- Loading branch information
Showing
54 changed files
with
1,138 additions
and
371 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...commons/src/main/kotlin/uk/gov/justice/digital/hmpps/exception/InvalidRequestException.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,8 @@ | ||
package uk.gov.justice.digital.hmpps.exception | ||
|
||
open class InvalidRequestException(message: String) : RuntimeException(message) { | ||
constructor( | ||
fieldName: String, | ||
value: Any | ||
) : this("Invalid $fieldName of $value sent in payload") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import uk.gov.justice.digital.hmpps.extensions.ClassPathExtension | ||
|
||
dependencies { | ||
compileOnly("org.springframework.boot:spring-boot-starter-data-jpa") | ||
implementation(project(":libs:commons")) | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
implementation("org.springframework.boot:spring-boot-starter-validation") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
testImplementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
testImplementation(libs.bundles.mockito) | ||
} | ||
|
||
configure<ClassPathExtension> { | ||
jacocoExclusions = listOf( | ||
"**/exception/**", | ||
"**/config/**", | ||
"**/entity**", | ||
"**/logging/**" | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
libs/prison-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/PrisonStaff.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,61 @@ | ||
package uk.gov.justice.digital.hmpps.entity | ||
|
||
import jakarta.persistence.* | ||
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 java.time.ZonedDateTime | ||
|
||
@EntityListeners(AuditingEntityListener::class) | ||
@Entity(name = "PrisonStaff") | ||
@Table(name = "staff") | ||
class PrisonStaff( | ||
|
||
@Id | ||
@Column(name = "staff_id") | ||
@SequenceGenerator(name = "staff_id_seq", sequenceName = "staff_id_seq", allocationSize = 1) | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "staff_id_seq") | ||
val id: Long = 0, | ||
|
||
@Column(name = "forename") | ||
val forename: String, | ||
|
||
@Column(name = "surname") | ||
val surname: String, | ||
|
||
@Column(name = "officer_code", columnDefinition = "char(7)") | ||
val code: String, | ||
|
||
@Column(name = "probation_area_id") | ||
val probationAreaId: Long, | ||
|
||
@Column(name = "start_date", updatable = false) | ||
val startDate: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@CreatedDate | ||
@Column(name = "created_datetime", updatable = false) | ||
val createdDateTime: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@LastModifiedDate | ||
@Column(name = "last_updated_datetime") | ||
val lastModifiedDate: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@Column(name = "private", columnDefinition = "NUMBER", nullable = false) | ||
var privateStaff: Boolean = false, | ||
|
||
@CreatedBy | ||
@Column(name = "created_by_user_id", updatable = false) | ||
var createdByUserId: Long = 0, | ||
|
||
@LastModifiedBy | ||
@Column(name = "last_updated_user_id") | ||
var lastModifiedUserId: Long = 0, | ||
|
||
@Version | ||
@Column(name = "row_version") | ||
val version: Long = 0 | ||
) { | ||
fun isUnallocated() = code.endsWith("U") | ||
} |
47 changes: 47 additions & 0 deletions
47
libs/prison-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/PrisonStaffTeam.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,47 @@ | ||
package uk.gov.justice.digital.hmpps.entity | ||
|
||
import jakarta.persistence.* | ||
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 java.io.Serializable | ||
import java.time.ZonedDateTime | ||
|
||
@EntityListeners(AuditingEntityListener::class) | ||
@Entity | ||
@Table(name = "staff_team") | ||
@IdClass(StaffTeamId::class) | ||
class PrisonStaffTeam( | ||
|
||
@Id | ||
@Column(name = "staff_id") | ||
val staffId: Long, | ||
|
||
@Id | ||
@Column(name = "team_id") | ||
val teamId: Long, | ||
|
||
@CreatedBy | ||
@Column(name = "created_by_user_id", updatable = false) | ||
var createdByUserId: Long = 0, | ||
|
||
@LastModifiedBy | ||
@Column(name = "last_updated_user_id") | ||
val lastModifiedUserId: Long = 0, | ||
|
||
@CreatedDate | ||
@Column(name = "created_datetime", updatable = false) | ||
val createdDateTime: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@LastModifiedDate | ||
@Column(name = "last_updated_datetime") | ||
val lastModifiedDate: ZonedDateTime = ZonedDateTime.now(), | ||
|
||
@Version | ||
@Column(name = "row_version") | ||
val version: Long = 0 | ||
) | ||
|
||
data class StaffTeamId(val staffId: Long = 0, val teamId: Long = 0) : Serializable |
21 changes: 21 additions & 0 deletions
21
libs/prison-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/PrisonTeam.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,21 @@ | ||
package uk.gov.justice.digital.hmpps.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import org.hibernate.annotations.Immutable | ||
|
||
@Immutable | ||
@Entity(name = "PrisonTeam") | ||
@Table(name = "team") | ||
class PrisonTeam( | ||
|
||
@Id | ||
@Column(name = "team_id") | ||
val id: Long, | ||
|
||
@Column(name = "code", columnDefinition = "char(6)") | ||
val code: String | ||
|
||
) |
37 changes: 37 additions & 0 deletions
37
libs/prison-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Provider.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,37 @@ | ||
package uk.gov.justice.digital.hmpps.entity | ||
|
||
import jakarta.persistence.* | ||
import org.hibernate.annotations.Immutable | ||
|
||
@Immutable | ||
@Entity(name = "Provider") | ||
@Table(name = "probation_area") | ||
class Provider( | ||
@Id | ||
@Column(name = "probation_area_id") | ||
val id: Long, | ||
|
||
@Column(name = "code", columnDefinition = "char(3)") | ||
val code: String, | ||
|
||
@OneToOne | ||
@JoinColumn( | ||
name = "institution_id", | ||
referencedColumnName = "institution_id", | ||
updatable = false | ||
) | ||
val institution: Prison? = null | ||
) | ||
|
||
@Immutable | ||
@Entity(name = "Prison") | ||
@Table(name = "r_institution") | ||
class Prison( | ||
@Id | ||
@Column(name = "institution_id") | ||
val id: Long, | ||
|
||
@Column(name = "nomis_cde_code") | ||
val nomisCode: String | ||
|
||
) |
4 changes: 4 additions & 0 deletions
4
.../main/kotlin/uk/gov/justice/digital/hmpps/exceptions/InvalidEstablishmentCodeException.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,4 @@ | ||
package uk.gov.justice.digital.hmpps.exceptions | ||
|
||
class InvalidEstablishmentCodeException(establishmentCode: String) : | ||
RuntimeException("Invalid establishment: $establishmentCode") |
3 changes: 3 additions & 0 deletions
3
...ff/src/main/kotlin/uk/gov/justice/digital/hmpps/exceptions/StaffCodeExhaustedException.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,3 @@ | ||
package uk.gov.justice.digital.hmpps.exceptions | ||
|
||
class StaffCodeExhaustedException(code: String) : RuntimeException("Officer codes exhausted for: $code") |
5 changes: 5 additions & 0 deletions
5
libs/prison-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/model/StaffName.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,5 @@ | ||
package uk.gov.justice.digital.hmpps.model | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
|
||
data class StaffName(@NotBlank val forename: String, @NotBlank val surname: String) |
8 changes: 8 additions & 0 deletions
8
.../src/main/kotlin/uk/gov/justice/digital/hmpps/repository/PrisonProbationAreaRepository.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,8 @@ | ||
package uk.gov.justice.digital.hmpps.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import uk.gov.justice.digital.hmpps.entity.Provider | ||
|
||
interface PrisonProbationAreaRepository : JpaRepository<Provider, Long> { | ||
fun findByInstitutionNomisCode(nomisCode: String): Provider? | ||
} |
30 changes: 30 additions & 0 deletions
30
...on-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/repository/PrisonStaffRepository.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,30 @@ | ||
package uk.gov.justice.digital.hmpps.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
import uk.gov.justice.digital.hmpps.entity.PrisonStaff | ||
import uk.gov.justice.digital.hmpps.exception.NotFoundException | ||
|
||
interface PrisonStaffRepository : JpaRepository<PrisonStaff, Long> { | ||
fun findTopByProbationAreaIdAndForenameIgnoreCaseAndSurnameIgnoreCase( | ||
probationAreaId: Long, | ||
forename: String, | ||
surname: String | ||
): PrisonStaff? | ||
|
||
@Query( | ||
""" | ||
select officer_code from staff | ||
where regexp_like(officer_code, ?1, 'i') | ||
order by officer_code desc | ||
fetch next 1 rows only | ||
""", | ||
nativeQuery = true | ||
) | ||
fun getLatestStaffReference(regex: String): String? | ||
|
||
fun findByCode(code: String): PrisonStaff? | ||
} | ||
|
||
fun PrisonStaffRepository.getByCode(code: String) = | ||
findByCode(code) ?: throw NotFoundException("Staff", "code", code) |
7 changes: 7 additions & 0 deletions
7
...taff/src/main/kotlin/uk/gov/justice/digital/hmpps/repository/PrisonStaffTeamRepository.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,7 @@ | ||
package uk.gov.justice.digital.hmpps.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import uk.gov.justice.digital.hmpps.entity.PrisonStaffTeam | ||
import uk.gov.justice.digital.hmpps.entity.StaffTeamId | ||
|
||
interface PrisonStaffTeamRepository : JpaRepository<PrisonStaffTeam, StaffTeamId> |
8 changes: 8 additions & 0 deletions
8
...son-staff/src/main/kotlin/uk/gov/justice/digital/hmpps/repository/PrisonTeamRepository.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,8 @@ | ||
package uk.gov.justice.digital.hmpps.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import uk.gov.justice.digital.hmpps.entity.PrisonTeam | ||
|
||
interface PrisonTeamRepository : JpaRepository<PrisonTeam, Long> { | ||
fun findByCode(code: String): PrisonTeam? | ||
} |
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
6 changes: 3 additions & 3 deletions
6
...ns/delius/service/OfficerCodeGenerator.kt → ...tal/hmpps/service/OfficerCodeGenerator.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
Oops, something went wrong.