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.
Merge remote-tracking branch 'origin/main' into ab_PI-1441
- Loading branch information
Showing
125 changed files
with
3,071 additions
and
133 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
.idea/runConfigurations/arns_and_oasys.xml → .idea/runConfigurations/dps_and_delius.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
...nd-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.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.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.document.entity.OffenderDocument | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.Person | ||
import java.time.ZonedDateTime | ||
|
||
object DocumentGenerator { | ||
val EVENT_DOC = generateEventDoc() | ||
val PERSON_DOC = generatePersonDoc() | ||
|
||
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 | ||
} | ||
|
||
fun generatePersonDoc( | ||
id: Long = IdGenerator.getAndIncrement() | ||
): OffenderDocument { | ||
val doc = OffenderDocument() | ||
doc.id = id | ||
doc.person = PersonGenerator.DEFAULT | ||
doc.name = "offender.doc" | ||
doc.primaryKeyId = PersonGenerator.DEFAULT.id | ||
doc.alfrescoId = "uuid2" | ||
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) | ||
} |
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
Binary file added
BIN
+14.5 KB
projects/approved-premises-and-delius/src/dev/resources/simulations/__files/document.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
projects/approved-premises-and-delius/src/dev/resources/simulations/mappings/alfresco.json
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,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" | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.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 | ||
|
||
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("/documents/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("/documents/${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"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.equalTo("uuid2"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].level", Matchers.equalTo("Offender"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].filename", Matchers.equalTo("offender.doc"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].typeCode", Matchers.equalTo("PERSON"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].typeDescription", Matchers.equalTo("Person"))) | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/DocumentController.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.controller | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.APDocument | ||
import uk.gov.justice.digital.hmpps.service.DocumentService | ||
|
||
@RestController | ||
@Tag(name = "Documents") | ||
@RequestMapping("/documents/{crn}") | ||
@PreAuthorize("hasRole('ROLE_APPROVED_PREMISES_STAFF')") | ||
class DocumentController(private val documentService: DocumentService) { | ||
|
||
@GetMapping(value = ["/{id}"]) | ||
@Operation(summary = "Download document content") | ||
fun downloadDocument( | ||
@PathVariable crn: String, | ||
@PathVariable id: String | ||
) = documentService.downloadDocument(crn, id) | ||
|
||
@PreAuthorize("hasRole('ROLE_APPROVED_PREMISES_STAFF')") | ||
@Operation( | ||
summary = "List of documents held in Delius for the probation case", | ||
description = """List of documents available in Delius for the probation | ||
case identified by the CRN provided in the request. Document list | ||
includes summary information on the type and purpose of document held. | ||
""" | ||
) | ||
@GetMapping(value = ["/all"]) | ||
fun findDocuments(@PathVariable crn: String): List<APDocument> = | ||
documentService.getDocumentsByCrn(crn) | ||
} |
25 changes: 25 additions & 0 deletions
25
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/alfresco/AlfrescoClient.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,25 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.alfresco | ||
|
||
import feign.RequestInterceptor | ||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.core.io.Resource | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import uk.gov.justice.digital.hmpps.security.ServiceContext | ||
|
||
@FeignClient(name = "alfresco", url = "\${integrations.alfresco.url}", configuration = [AlfrescoFeignConfig::class]) | ||
interface AlfrescoClient { | ||
@GetMapping(value = ["/fetch/{id}"]) | ||
fun getDocument(@PathVariable id: String): ResponseEntity<Resource> | ||
} | ||
|
||
class AlfrescoFeignConfig { | ||
@Bean | ||
fun requestInterceptor() = RequestInterceptor { template -> | ||
template.header("X-DocRepository-Remote-User", "N00") | ||
template.header("X-DocRepository-Real-Remote-User", ServiceContext.servicePrincipal()!!.username) | ||
template.header("Content-Type: multipart/form-data") | ||
} | ||
} |
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.