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
- Loading branch information
Showing
20 changed files
with
527 additions
and
30 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
22 changes: 22 additions & 0 deletions
22
...-case-and-delius/src/dev/resources/simulations/__files/get_documents_grouped_C123456.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,22 @@ | ||
{ | ||
"documents": [], | ||
"convictions": [ | ||
{ | ||
"convictionId": "83", | ||
"documents": [ | ||
{ | ||
"id": "alfrescoId", | ||
"documentName": "filename.txt", | ||
"type": { | ||
"code": "CONVICTION_DOCUMENT", | ||
"description": "Sentence related" | ||
}, | ||
"lastModifiedAt": "2024-08-08T15:56:02.88685", | ||
"createdAt": "2024-08-08T15:56:02.88684", | ||
"parentPrimaryKeyId": 83, | ||
"reportDocumentDates": {} | ||
} | ||
] | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-documents.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,17 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"urlPathTemplate": "/secure/offenders/crn/{crn}/documents/grouped" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "get_documents_grouped_C123456.json" | ||
} | ||
} | ||
] | ||
} |
49 changes: 49 additions & 0 deletions
49
...elius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentsIntegrationTest.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 | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
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.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.model.OffenderDocuments | ||
import uk.gov.justice.digital.hmpps.api.resource.advice.ErrorResponse | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class DocumentsIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `call documents grouped by CRN`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
|
||
val response = mockMvc | ||
.perform(get("/probation-case/$crn/documents/grouped").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<OffenderDocuments>() | ||
|
||
assertThat(response.documents.size, equalTo(0)) | ||
assertThat(response.convictions.size, equalTo(1)) | ||
} | ||
|
||
@Test | ||
fun `call documents grouped by CRN invalid filter`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
|
||
val response = mockMvc | ||
.perform(get("/probation-case/$crn/documents/grouped?type=INVALID").withToken()) | ||
.andExpect(status().isBadRequest) | ||
.andReturn().response.contentAsJson<ErrorResponse>() | ||
|
||
assertThat(response.developerMessage, equalTo("type of INVALID was not valid")) | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Documents.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,38 @@ | ||
package uk.gov.justice.digital.hmpps.api.model | ||
|
||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
data class OffenderDocumentDetail( | ||
val id: String? = null, | ||
val documentName: String? = null, | ||
val author: String? = null, | ||
val type: KeyValue, | ||
val extendedDescription: String? = null, | ||
val lastModifiedAt: LocalDateTime? = null, | ||
val createdAt: LocalDateTime? = null, | ||
val parentPrimaryKeyId: Long? = null, | ||
val subType: KeyValue? = null, | ||
val reportDocumentDates: ReportDocumentDates? = null | ||
) | ||
|
||
data class ReportDocumentDates( | ||
val requestedDate: LocalDate? = null, | ||
val requiredDate: LocalDate? = null, | ||
val completedDate: LocalDateTime? = null | ||
) | ||
|
||
data class ConvictionDocuments( | ||
val convictionId: String, | ||
val documents: List<OffenderDocumentDetail> = emptyList() | ||
) | ||
|
||
data class OffenderDocuments( | ||
val documents: List<OffenderDocumentDetail> = emptyList(), | ||
val convictions: List<ConvictionDocuments> = emptyList(), | ||
) | ||
|
||
data class DocumentFilter( | ||
val type: String? = null, | ||
val subtype: String? = 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
2 changes: 1 addition & 1 deletion
2
...s/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/Compare.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package uk.gov.justice.digital.hmpps.api.proxy | ||
|
||
data class Compare( | ||
val params: Map<String, Any>, | ||
val params: Map<String, Any?>, | ||
val uri: String | ||
) |
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
19 changes: 19 additions & 0 deletions
19
...-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/DocumentResource.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,19 @@ | ||
package uk.gov.justice.digital.hmpps.api.resource | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.* | ||
import uk.gov.justice.digital.hmpps.api.model.DocumentFilter | ||
import uk.gov.justice.digital.hmpps.integrations.delius.service.DocumentService | ||
|
||
@RestController | ||
@RequestMapping("probation-case/{crn}/documents") | ||
@PreAuthorize("hasRole('PROBATION_API__COURT_CASE__CASE_DETAIL')") | ||
class DocumentResource(private val documentService: DocumentService) { | ||
|
||
@GetMapping("/grouped") | ||
fun getOffenderDocumentsGrouped( | ||
@PathVariable crn: String, | ||
@RequestParam(required = false) type: String?, | ||
@RequestParam(required = false) subType: String?, | ||
) = documentService.getDocumentsGroupedFor(crn, DocumentFilter(type, subType)) | ||
} |
11 changes: 10 additions & 1 deletion
11
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/advice/ControllerAdvice.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.