Skip to content

Commit

Permalink
CAS-1178 - setup documents data for cas1 team (#4367)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkhawkins authored Oct 31, 2024
1 parent b2a4fb3 commit 9c4bad5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import uk.gov.justice.digital.hmpps.integrations.delius.caseload.CaseloadReposit
import uk.gov.justice.digital.hmpps.integrations.delius.contact.outcome.ContactOutcomeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.type.ContactTypeCode
import uk.gov.justice.digital.hmpps.integrations.delius.contact.type.ContactTypeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.DocumentRepository
import uk.gov.justice.digital.hmpps.integrations.delius.location.OfficeLocationRepository
import uk.gov.justice.digital.hmpps.integrations.delius.nonstatutoryintervention.entity.*
import uk.gov.justice.digital.hmpps.integrations.delius.person.BoroughRepository
Expand Down Expand Up @@ -69,9 +68,9 @@ class DataLoader(
private val probationCaseDataLoader: ProbationCaseDataLoader,
private val lduRepository: LduRepository,
private val staffUserRepository: StaffUserRepository,
private val documentRepository: DocumentRepository,
private val boroughRepository: BoroughRepository,
private val referralBookingDataLoader: ReferralBookingDataLoader,
private val documentDataLoader: DocumentDataLoader,

) : ApplicationListener<ApplicationReadyEvent> {

Expand Down Expand Up @@ -228,11 +227,9 @@ class DataLoader(
eventRepository.save(ANOTHER_EVENT)
referralRepository.save(ReferralGenerator.EXISTING_REFERRAL)

documentRepository.save(DocumentGenerator.EVENT_DOC)
documentRepository.save(DocumentGenerator.PERSON_DOC)

probationCaseDataLoader.loadData()
referralBookingDataLoader.loadData()
documentDataLoader.loadData()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package uk.gov.justice.digital.hmpps.data

import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.data.generator.DocumentGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.DocumentRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocumentType
import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository
import java.util.*

@Component
class DocumentDataLoader(
private val personRepository: PersonRepository,
private val documentRepository: DocumentRepository,
private val eventRepository: EventRepository
) {
fun loadData() {
documentRepository.save(DocumentGenerator.EVENT_DOC)
documentRepository.save(DocumentGenerator.PERSON_DOC)

val person = personRepository.findByCrnAndSoftDeletedIsFalse(ProbationCaseGenerator.CASE_X320741.crn)!!

documentRepository.save(
DocumentGenerator.generatePersonDoc(
person = person,
name = "Random offender document.pdf",
alfrescoId = UUID.randomUUID().toString(),
documentType = DocumentType.DOCUMENT
)
)

val personEvent = PersonGenerator.generateEvent(
"1",
person.id
).apply(eventRepository::save)

listOf(
Pair("CPS pack.pdf", DocumentType.CPS_PACK),
Pair("Conviction document.pdf", DocumentType.PREVIOUS_CONVICTION)
).forEach {
documentRepository.save(
DocumentGenerator.generateEventDoc(
person = person,
event = personEvent,
name = it.first,
alfrescoId = UUID.randomUUID().toString(),
documentType = it.second,
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,40 @@ object DocumentGenerator {

fun generateEventDoc(
event: Event = PersonGenerator.ANOTHER_EVENT,
id: Long = IdGenerator.getAndIncrement()
person: Person = PersonGenerator.DEFAULT,
id: Long = IdGenerator.getAndIncrement(),
name: String = "test.doc",
alfrescoId: String = "uuid1",
documentType: DocumentType = DocumentType.DOCUMENT
): EventDocument {
val doc = EventDocument(event.toDocEvent())
doc.id = id
doc.person = PersonGenerator.DEFAULT
doc.name = "test.doc"
doc.person = person
doc.name = name
doc.primaryKeyId = doc.event?.id!!
doc.alfrescoId = "uuid1"
doc.alfrescoId = alfrescoId
doc.lastSaved = ZonedDateTime.now().minusDays(7)
doc.dateProduced = null
doc.type = DocumentType.DOCUMENT
doc.type = documentType
return doc
}

fun generatePersonDoc(
id: Long = IdGenerator.getAndIncrement()
id: Long = IdGenerator.getAndIncrement(),
person: Person = PersonGenerator.DEFAULT,
name: String = "offender.doc",
alfrescoId: String = "uuid2",
documentType: DocumentType = DocumentType.DOCUMENT
): OffenderDocument {
val doc = OffenderDocument()
doc.id = id
doc.person = PersonGenerator.DEFAULT
doc.name = "offender.doc"
doc.primaryKeyId = PersonGenerator.DEFAULT.id
doc.alfrescoId = "uuid2"
doc.person = person
doc.name = name
doc.primaryKeyId = person.id
doc.alfrescoId = alfrescoId
doc.lastSaved = ZonedDateTime.now().minusDays(7)
doc.dateProduced = null
doc.type = DocumentType.DOCUMENT
doc.type = documentType

return doc
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Handler(
.filter { defendant ->
defendant.offences.any { offence ->
offence.judicialResults.any { judicialResult ->
judicialResult.label == "Remanded in custody"
judicialResult.isConvictedResult == true && judicialResult.label == "Remanded in custody"
}
}
}
Expand Down

0 comments on commit 9c4bad5

Please sign in to comment.