diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index c6bc90c7be..f743202bfa 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -12,6 +12,7 @@ import uk.gov.justice.digital.hmpps.data.generator.CaseloadGenerator import uk.gov.justice.digital.hmpps.data.generator.ContactOutcomeGenerator import uk.gov.justice.digital.hmpps.data.generator.ContactTypeGenerator import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator +import uk.gov.justice.digital.hmpps.data.generator.DocumentGenerator import uk.gov.justice.digital.hmpps.data.generator.NsiStatusGenerator import uk.gov.justice.digital.hmpps.data.generator.NsiTypeGenerator import uk.gov.justice.digital.hmpps.data.generator.OfficeLocationGenerator @@ -35,6 +36,7 @@ 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.NsiStatusCode import uk.gov.justice.digital.hmpps.integrations.delius.nonstatutoryintervention.entity.NsiStatusRepository @@ -84,7 +86,8 @@ class DataLoader( private val referralRepository: ReferralRepository, private val probationCaseDataLoader: ProbationCaseDataLoader, private val lduRepository: LduRepository, - private val staffUserRepository: StaffUserRepository + private val staffUserRepository: StaffUserRepository, + private val documentRepository: DocumentRepository ) : ApplicationListener { @PostConstruct @@ -192,6 +195,8 @@ class DataLoader( eventRepository.save(ANOTHER_EVENT) referralRepository.save(ReferralGenerator.EXISTING_REFERRAL) + documentRepository.save(DocumentGenerator.EVENT_DOC) + probationCaseDataLoader.loadData() } } diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt new file mode 100644 index 0000000000..8183fb69a7 --- /dev/null +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt @@ -0,0 +1,31 @@ +package uk.gov.justice.digital.hmpps.data.generator + +import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.Event +import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocEvent +import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocumentType +import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.EventDocument +import uk.gov.justice.digital.hmpps.integrations.delius.person.Person +import java.time.ZonedDateTime + +object DocumentGenerator { + val EVENT_DOC = generateEventDoc() + + fun generateEventDoc( + event: Event = PersonGenerator.ANOTHER_EVENT, + id: Long = IdGenerator.getAndIncrement() + ): EventDocument { + val doc = EventDocument(event.toDocEvent()) + doc.id = id + doc.person = PersonGenerator.DEFAULT + doc.name = "test.doc" + doc.primaryKeyId = doc.event?.id!! + doc.alfrescoId = "uuid1" + doc.lastSaved = ZonedDateTime.now().minusDays(7) + doc.dateProduced = null + doc.type = DocumentType.DOCUMENT + return doc + } + + private fun Event.toDocEvent() = + DocEvent(id, Person(personId, "", false ), true, number, null, null) +} diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt new file mode 100644 index 0000000000..364ef10df7 --- /dev/null +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt @@ -0,0 +1,58 @@ +package uk.gov.justice.digital.hmpps + +import com.github.tomakehurst.wiremock.WireMockServer +import org.hamcrest.Matchers +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import org.springframework.test.web.servlet.result.MockMvcResultMatchers +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.header +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import org.springframework.util.ResourceUtils +import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator +import uk.gov.justice.digital.hmpps.security.withOAuth2Token + +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +internal class DocIntegrationTest { + @Autowired + lateinit var mockMvc: MockMvc + + @Autowired + lateinit var wireMockserver: WireMockServer + + @Test + fun `document is downloaded`() { + mockMvc.perform( + get("/document/A000001/uuid1").accept("application/octet-stream").withOAuth2Token(wireMockserver) + ) + .andExpect(status().is2xxSuccessful) + .andExpect(header().string("Content-Type", "application/octet-stream")) + .andExpect( + header().string( + "Content-Disposition", + "attachment; filename=\"=?UTF-8?Q?test.doc?=\"; filename*=UTF-8''test.doc" + ) + ) + .andExpect(header().doesNotExist("Custom-Alfresco-Header")) + .andExpect(content().bytes(ResourceUtils.getFile("classpath:simulations/__files/document.pdf").readBytes())) + } + + @Test + fun `list documents`() { + mockMvc.perform(get("/document/${PersonGenerator.DEFAULT.crn}/all").withOAuth2Token(wireMockserver)) + .andExpect(status().isOk) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].id",Matchers.equalTo("uuid1"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].level",Matchers.equalTo("Conviction"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].eventNumber",Matchers.equalTo("8"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].filename",Matchers.equalTo("test.doc"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].typeCode",Matchers.equalTo("EVENT"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].typeDescription",Matchers.equalTo("Event"))) + + + } +} diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/DocumentController.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/DocumentController.kt index d7b8a8c89d..04226247b7 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/DocumentController.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/DocumentController.kt @@ -34,7 +34,7 @@ class DocumentController(private val documentService: DocumentService) { to a probation practitioner """ ) - @GetMapping + @GetMapping(value = ["/all"]) fun findDocuments(@PathVariable crn: String): List = documentService.getDocumentsByCrn(crn) } diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/Document.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/Document.kt index bc0db27497..8c5793a13e 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/Document.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/Document.kt @@ -34,7 +34,7 @@ abstract class Document : Relatable { @ManyToOne @JoinColumn(name = "offender_id") - open val person: Person? = null + open var person: Person? = null @Column(name = "primary_key_id") open var primaryKeyId: Long = 0 diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/PersonDocument.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/PersonDocument.kt index e1bdf0370d..8994dc0bce 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/PersonDocument.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/document/entity/PersonDocument.kt @@ -2,18 +2,10 @@ package uk.gov.justice.digital.hmpps.integrations.delius.document.entity import java.time.ZonedDateTime -data class PersonDocument( - val id: String?, - val name: String, - val relatedTo: RelatedTo, - val dateSaved: ZonedDateTime?, - val dateCreated: ZonedDateTime?, - val sensitive: Boolean -) - data class APDocument( val id: String?, val level: String, + val eventNumber: String?, val filename: String, val typeCode: String, val typeDescription: String, diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/DocumentService.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/DocumentService.kt index 861e08ec2e..79f770d83c 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/DocumentService.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/DocumentService.kt @@ -51,8 +51,9 @@ class DocumentService( APDocument( it.alfrescoId, if (it.findRelatedTo().event == null) "Offender" else "Conviction", + it.findRelatedTo().event?.eventNumber, it.name, - it.findRelatedTo().name, + it.findRelatedTo().type.name, it.findRelatedTo().description, it.createdDate, it.lastSaved, diff --git a/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt b/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt index 86ae03197b..4bd02378ef 100644 --- a/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt +++ b/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt @@ -22,7 +22,7 @@ internal class DocumentIntegrationTest { @Test fun `document is downloaded`() { - mockMvc.perform(get("/document/X000004/uuid1").accept("application/octet-stream").withOAuth2Token(wireMockserver)) + mockMvc.perform(get("/document/A000001/uuid1").accept("application/octet-stream").withOAuth2Token(wireMockserver)) .andExpect(status().is2xxSuccessful) .andExpect(header().string("Content-Type", "application/octet-stream")) .andExpect(header().string("Content-Disposition", "attachment; filename=\"=?UTF-8?Q?doc1?=\"; filename*=UTF-8''doc1"))