Skip to content

Commit

Permalink
PI-1505 DPS probation document endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Oct 20, 2023
1 parent a3e6bfa commit 8d1146d
Show file tree
Hide file tree
Showing 28 changed files with 1,013 additions and 26 deletions.
3 changes: 3 additions & 0 deletions projects/dps-and-delius/.trivyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Suppressed as we do not process any untrusted YML content
# Note: this will be resolved in Spring Boot 3.2: https://github.com/spring-projects/spring-boot/issues/35982
CVE-2022-1471 exp:2023-12-01
1 change: 1 addition & 0 deletions projects/dps-and-delius/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.openfeign)
implementation(libs.springdoc)

dev(project(":libs:dev-tools"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
package uk.gov.justice.digital.hmpps.data

import jakarta.annotation.PostConstruct
import jakarta.persistence.EntityManager
import jakarta.transaction.Transactional
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.data.generator.DocumentGenerator
import uk.gov.justice.digital.hmpps.data.generator.EventGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
import uk.gov.justice.digital.hmpps.user.AuditUserRepository

@Component
@ConditionalOnProperty("seed.database")
class DataLoader(
private val auditUserRepository: AuditUserRepository
private val auditUserRepository: AuditUserRepository,
private val entityManager: EntityManager
) : ApplicationListener<ApplicationReadyEvent> {

@PostConstruct
fun saveAuditUser() {
auditUserRepository.save(UserGenerator.AUDIT_USER)
}

@Transactional
override fun onApplicationEvent(are: ApplicationReadyEvent) {
// Perform dev/test database setup here, using JPA repositories and generator classes...
entityManager.persist(PersonGenerator.DEFAULT)
entityManager.persist(EventGenerator.EVENT.mainOffence.offence)
entityManager.persist(EventGenerator.EVENT)
entityManager.persist(EventGenerator.EVENT.mainOffence)
entityManager.persist(EventGenerator.DISPOSAL.lengthUnits)
entityManager.persist(EventGenerator.DISPOSAL.type)
entityManager.persist(EventGenerator.DISPOSAL)
entityManager.persist(EventGenerator.INSTITUTION)
entityManager.persist(EventGenerator.CUSTODY)
entityManager.persist(EventGenerator.COURT)
entityManager.persist(EventGenerator.COURT_APPEARANCE.outcome)
entityManager.persist(EventGenerator.COURT_APPEARANCE)
entityManager.persist(EventGenerator.COURT_REPORT_TYPE)
entityManager.persist(EventGenerator.COURT_REPORT)
entityManager.persist(EventGenerator.INSTITUTIONAL_REPORT_TYPE)
entityManager.persist(EventGenerator.INSTITUTIONAL_REPORT)
entityManager.persist(EventGenerator.CONTACT_TYPE)
entityManager.persist(EventGenerator.CONTACT)
entityManager.persist(EventGenerator.NSI_TYPE)
entityManager.persist(EventGenerator.NSI)
entityManager.persist(DocumentGenerator.OFFENDER)
entityManager.persist(DocumentGenerator.PREVIOUS_CONVICTIONS)
entityManager.persist(DocumentGenerator.EVENT)
entityManager.persist(DocumentGenerator.CPS_PACK)
entityManager.persist(DocumentGenerator.ADDRESSASSESSMENT)
entityManager.persist(DocumentGenerator.PERSONALCONTACT)
entityManager.persist(DocumentGenerator.PERSONAL_CIRCUMSTANCE)
entityManager.persist(DocumentGenerator.COURT_REPORT)
entityManager.persist(DocumentGenerator.INSTITUTIONAL_REPORT)
entityManager.persist(DocumentGenerator.OFFENDER_CONTACT)
entityManager.persist(DocumentGenerator.EVENT_CONTACT)
entityManager.persist(DocumentGenerator.OFFENDER_NSI)
entityManager.persist(DocumentGenerator.EVENT_NSI)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package uk.gov.justice.digital.hmpps.data.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.time.LocalDate

@Entity
data class AddressAssessment(@Id val addressAssessmentId: Long, val assessmentDate: LocalDate)

@Entity
data class ApprovedPremisesReferral(@Id val approvedPremisesReferralId: Long, val referralDate: LocalDate, val eventId: Long?)

@Entity
data class Assessment(@Id val assessmentId: Long, val assessmentTypeId: Long, val referralId: Long?, val assessmentDate: LocalDate)

@Entity
@Table(name = "r_assessment_type")
data class AssessmentType(@Id val assessmentTypeId: Long, val description: String)

@Entity
data class CaseAllocation(@Id val caseAllocationId: Long, val eventId: Long)

@Entity
data class Contact(@Id val contactId: Long, val contactTypeId: Long, val eventId: Long?, val contactDate: LocalDate)

@Entity
@Table(name = "r_contact_type")
data class ContactType(@Id val contactTypeId: Long, val description: String)

@Entity
data class Court(@Id val courtId: Long, val courtName: String)

@Entity
@Table(name = "r_court_report_type")
data class CourtReportType(@Id val courtReportTypeId: Long, val description: String)

@Entity
data class CourtReport(@Id val courtReportId: Long, val courtReportTypeId: Long, val courtAppearanceId: Long, val dateRequested: LocalDate)

@Entity
data class InstitutionalReport(@Id val institutionalReportId: Long, val institutionReportTypeId: Long, val institutionId: Long, val establishment: String, val custodyId: Long, val dateRequested: LocalDate)

@Entity
data class Nsi(@Id val nsiId: Long, val nsiTypeId: Long, val eventId: Long?, val referralDate: LocalDate)

@Entity
@Table(name = "r_nsi_type")
data class NsiType(@Id val nsiTypeId: Long, val description: String)

@Entity
data class PersonalCircumstance(@Id val personalCircumstanceId: Long, val circumstanceTypeId: Long, val startDate: LocalDate)

@Entity
@Table(name = "r_circumstance_type")
data class PersonalCircumstanceType(@Id val circumstanceTypeId: Long, val codeDescription: String)

@Entity
data class PersonalContact(@Id val personalContactId: Long, val relationshipTypeId: Long, val relationship: String)

@Entity
data class Referral(@Id val referralId: Long, val referralTypeId: Long, val referralDate: LocalDate, val eventId: Long)

@Entity
@Table(name = "r_referral_type")
data class ReferralType(@Id val referralTypeId: Long, val description: String)

@Entity
data class UpwAppointment(@Id val upwAppointmentId: Long, val upwDetailsId: Long, val upwProjectId: Long, val appointmentDate: LocalDate)

@Entity
data class UpwDetails(@Id val upwDetailsId: Long, val disposalId: Long)

@Entity
data class UpwProject(@Id val upwProjectId: Long, val disposalId: Long, val name: String)

@Entity
@Table(name = "user_")
data class User(
@Id
@Column(name = "user_id")
val userId: Long,
val forename: String,
val surname: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.entity.Document
import java.time.ZonedDateTime
import java.util.UUID

object DocumentGenerator {
val OFFENDER = generate("OFFENDER", primaryKeyId = PersonGenerator.DEFAULT.id, alfrescoId = "uuid1")
val PREVIOUS_CONVICTIONS = generate("OFFENDER", "PREVIOUS_CONVICTION", primaryKeyId = PersonGenerator.DEFAULT.id)
val EVENT = generate("EVENT", primaryKeyId = EventGenerator.EVENT.id)
val CPS_PACK = generate("EVENT", "CPS_PACK", primaryKeyId = EventGenerator.EVENT.id)
val ADDRESSASSESSMENT = generate("ADDRESSASSESSMENT")
val PERSONALCONTACT = generate("PERSONALCONTACT")
val PERSONAL_CIRCUMSTANCE = generate("PERSONAL_CIRCUMSTANCE")
val COURT_REPORT = generate("COURT_REPORT", primaryKeyId = EventGenerator.COURT_REPORT.courtReportId)
val INSTITUTIONAL_REPORT = generate("INSTITUTIONAL_REPORT", primaryKeyId = EventGenerator.INSTITUTIONAL_REPORT.institutionalReportId)
val OFFENDER_CONTACT = generate("CONTACT")
val EVENT_CONTACT = generate("CONTACT", primaryKeyId = EventGenerator.CONTACT.contactId)
val OFFENDER_NSI = generate("NSI")
val EVENT_NSI = generate("NSI", primaryKeyId = EventGenerator.NSI.nsiId)

fun generate(tableName: String, type: String = "DOCUMENT", primaryKeyId: Long = 0, alfrescoId: String = UUID.randomUUID().toString()) = Document(
id = IdGenerator.getAndIncrement(),
personId = PersonGenerator.DEFAULT.id,
alfrescoId = alfrescoId,
primaryKeyId = primaryKeyId,
name = "$tableName-related document",
type = type,
tableName = tableName,
createdAt = ZonedDateTime.now(),
createdByUserId = 0,
lastUpdatedUserId = 0,
softDeleted = false
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.entity.Contact
import uk.gov.justice.digital.hmpps.data.entity.ContactType
import uk.gov.justice.digital.hmpps.data.entity.Court
import uk.gov.justice.digital.hmpps.data.entity.CourtReport
import uk.gov.justice.digital.hmpps.data.entity.CourtReportType
import uk.gov.justice.digital.hmpps.data.entity.InstitutionalReport
import uk.gov.justice.digital.hmpps.data.entity.Nsi
import uk.gov.justice.digital.hmpps.data.entity.NsiType
import uk.gov.justice.digital.hmpps.entity.CourtAppearance
import uk.gov.justice.digital.hmpps.entity.Custody
import uk.gov.justice.digital.hmpps.entity.Disposal
import uk.gov.justice.digital.hmpps.entity.DisposalType
import uk.gov.justice.digital.hmpps.entity.Event
import uk.gov.justice.digital.hmpps.entity.Institution
import uk.gov.justice.digital.hmpps.entity.MainOffence
import uk.gov.justice.digital.hmpps.entity.Offence
import uk.gov.justice.digital.hmpps.entity.ReferenceData
import uk.gov.justice.digital.hmpps.set
import java.time.LocalDate
import java.time.ZonedDateTime

object EventGenerator {
val EVENT = Event(
id = IdGenerator.getAndIncrement(),
person = PersonGenerator.DEFAULT,
referralDate = LocalDate.now(),
mainOffence = MainOffence(
id = IdGenerator.getAndIncrement(),
offence = Offence(
id = IdGenerator.getAndIncrement(),
subCategoryDescription = "Burglary"
)
),
courtAppearances = listOf()
).also { it.mainOffence.set("event", it) }
val DISPOSAL = Disposal(
id = IdGenerator.getAndIncrement(),
event = EVENT,
type = DisposalType(
id = IdGenerator.getAndIncrement(),
description = "Sentenced"
),
length = 6,
lengthUnits = ReferenceData(IdGenerator.getAndIncrement(), "M", "Months")
)
val INSTITUTION = Institution(
id = IdGenerator.getAndIncrement(),
name = "test institution",
establishment = "Y"
)
val CUSTODY = Custody(
id = IdGenerator.getAndIncrement(),
disposal = DISPOSAL,
institution = INSTITUTION
)

val COURT = Court(courtId = IdGenerator.getAndIncrement(), courtName = "test court")
val COURT_REPORT_TYPE = CourtReportType(courtReportTypeId = IdGenerator.getAndIncrement(), description = "court report type")
val COURT_APPEARANCE = CourtAppearance(
id = IdGenerator.getAndIncrement(),
date = ZonedDateTime.now(),
courtId = COURT.courtId,
event = EVENT,
outcome = ReferenceData(IdGenerator.getAndIncrement(), "TEST", "Community Order")
)
val COURT_REPORT = CourtReport(
courtReportId = IdGenerator.getAndIncrement(),
courtReportTypeId = COURT_REPORT_TYPE.courtReportTypeId,
courtAppearanceId = COURT_APPEARANCE.id,
dateRequested = LocalDate.of(2000, 1, 1)
)

val INSTITUTIONAL_REPORT_TYPE = ReferenceData(IdGenerator.getAndIncrement(), "IR", "institutional report type")
val INSTITUTIONAL_REPORT = InstitutionalReport(
institutionalReportId = IdGenerator.getAndIncrement(),
institutionId = INSTITUTION.id,
institutionReportTypeId = INSTITUTIONAL_REPORT_TYPE.id,
custodyId = CUSTODY.id,
establishment = "Y",
dateRequested = LocalDate.of(2000, 1, 2)
)

val CONTACT_TYPE = ContactType(contactTypeId = IdGenerator.getAndIncrement(), description = "contact type")
val CONTACT = Contact(
contactId = IdGenerator.getAndIncrement(),
contactTypeId = CONTACT_TYPE.contactTypeId,
eventId = EVENT.id,
contactDate = LocalDate.of(2000, 1, 3)
)

val NSI_TYPE = NsiType(nsiTypeId = IdGenerator.getAndIncrement(), description = "nsi type")
val NSI = Nsi(
nsiId = IdGenerator.getAndIncrement(),
nsiTypeId = NSI_TYPE.nsiTypeId,
eventId = EVENT.id,
referralDate = LocalDate.of(2000, 1, 4)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.entity.Person

object PersonGenerator {
val DEFAULT = Person(
id = IdGenerator.getAndIncrement(),
forename = "First",
secondName = "Middle",
thirdName = null,
surname = "Last",
crn = "A000001",
nomisId = "A0001AA",
events = listOf(),
softDeleted = false
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo3hw1/oChbttEOxEH4NUDrH+Y
n2x0DavAmDjMbhcSiQ6+/t8Nz/N03BauWzFOGBtftnQrHfnF+O7RAKj8zMjcbIq4
QrYeXEpnaFCGEwTtOBpxvSEWPrLEpr1gCarBQZDp67ag+SYqrDgkn2Vme/dMvMUQ
xUO3DT6jg9921J6TlwIDAQAB
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+DhFN5a7rx/KAKw9zX4dlONZY
YGrWPqjRaRlH91aLo/btXVWeXxwBiaAu1RSctoixnW0S5Wm0mpCieRjmSQH/COgC
OAsouUsuBFUy8ohKiTpQaaOPNA8KDNMNhKQ0KT7KPPCGCB1BNvVgtZInwhyVKzTL
UfvD+V/JnSwldl9uBQIDAQAB
-----END PUBLIC KEY-----
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJwcm9iYXRpb24taW50ZWdyYXRpb24tZGV2IiwiZ3JhbnRfdHlwZSI6ImNsaWVudF9jcmVkZW50aWFscyIsInVzZXJfbmFtZSI6InByb2JhdGlvbi1pbnRlZ3JhdGlvbi1kZXYiLCJzY29wZSI6WyJyZWFkIiwid3JpdGUiXSwiYXV0aF9zb3VyY2UiOiJub25lIiwiaXNzIjoiaHR0cHM6Ly9zaWduLWluLWRldi5obXBwcy5zZXJ2aWNlLmp1c3RpY2UuZ292LnVrL2F1dGgvaXNzdWVyIiwiZXhwIjo5OTk5OTk5OTk5LCJhdXRob3JpdGllcyI6WyJST0xFX0VYQU1QTEUiLCJST0xFX1dPUktMT0FEX1JFQUQiLCJST0xFX0FMTE9DQVRJT05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read write",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"request": {
"method": "GET",
"urlPath": "/alfresco/fetch/uuid1"
},
"response": {
"headers": {
"Content-Type": "application/octet-stream",
"Content-Disposition": "attachment; filename=\"doc1\"; filename*=UTF-8''doc1",
"Custom-Alfresco-Header": "should be ignored"
},
"status": 200,
"bodyFileName": "document.pdf"
}
}
Loading

0 comments on commit 8d1146d

Please sign in to comment.