Skip to content

Commit

Permalink
PI-1555 added document endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister committed Oct 12, 2023
1 parent ab8fe13 commit adfba0a
Show file tree
Hide file tree
Showing 36 changed files with 1,252 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ generic-service:
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer
INTEGRATIONS_APPROVED-PREMISES-API_URL: https://approved-premises-api-dev.hmpps.service.justice.gov.uk

INTEGRATIONS_ALFRESCO_URL: https://alfresco.test.delius.probation.hmpps.dsd.io/alfresco/service/noms-spg/
LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG

generic-prometheus-alerts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ generic-service:
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer
INTEGRATIONS_APPROVED-PREMISES-API_URL: https://approved-premises-api-preprod.hmpps.service.justice.gov.uk
INTEGRATIONS_ALFRESCO_URL: https://alfresco.pre-prod.delius.probation.hmpps.dsd.io/alfresco/service/noms-spg/

generic-prometheus-alerts:
businessHoursOnly: true
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ generic-service:
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer
INTEGRATIONS_APPROVED-PREMISES-API_URL: https://approved-premises-api.hmpps.service.justice.gov.uk
INTEGRATIONS_ALFRESCO_URL: https://alfresco.probation.service.justice.gov.uk/alfresco/service/noms-spg/
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ANOTHER_EVENT
import uk.gov.justice.digital.hmpps.data.generator.PersonManagerGenerator
import uk.gov.justice.digital.hmpps.data.generator.ProbationAreaGenerator
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
Expand Down Expand Up @@ -188,6 +189,7 @@ class DataLoader(
caseloadRepository.save(CaseloadGenerator.generate(person, TeamGenerator.APPROVED_PREMISES_TEAM))
caseloadRepository.save(CaseloadGenerator.generate(person, TeamGenerator.UNALLOCATED))

eventRepository.save(ANOTHER_EVENT)
referralRepository.save(ReferralGenerator.EXISTING_REFERRAL)

probationCaseDataLoader.loadData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.nonstatutoryintervention
import uk.gov.justice.digital.hmpps.integrations.delius.nonstatutoryintervention.entity.NsiType

object NsiTypeGenerator {
fun generate(code: String, id: Long = IdGenerator.getAndIncrement()) = NsiType(id, code)
fun generate(code: String, id: Long = IdGenerator.getAndIncrement()) = NsiType(id, code, "description of $code")
}

object NsiStatusGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.time.ZonedDateTime
object PersonGenerator {
val DEFAULT = generate(crn = "A000001")
val EVENT = generateEvent("7", DEFAULT.id)
val ANOTHER_EVENT = generateEvent("8", DEFAULT.id)
fun generate(
crn: String,
id: Long = IdGenerator.getAndIncrement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object ReferralGenerator {

fun generateReferral(
person: Person = PersonGenerator.DEFAULT,
eventId: Long = IdGenerator.getAndIncrement(),
eventId: Long = PersonGenerator.ANOTHER_EVENT.id,
approvedPremises: ApprovedPremises = ApprovedPremisesGenerator.DEFAULT,
referralDate: LocalDate = LocalDate.now(),
expectedArrivalDate: LocalDate? = LocalDate.now().plusDays(1),
Expand Down
Binary file not shown.
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import org.springframework.cloud.openfeign.EnableFeignClients
import org.springframework.context.annotation.Configuration
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager
import uk.gov.justice.digital.hmpps.config.feign.FeignConfig
import uk.gov.justice.digital.hmpps.integrations.alfresco.AlfrescoClient
import uk.gov.justice.digital.hmpps.integrations.approvedpremises.ApprovedPremisesApiClient

@Configuration
@EnableFeignClients(clients = [ApprovedPremisesApiClient::class])
@EnableFeignClients(clients = [ApprovedPremisesApiClient::class, AlfrescoClient::class])
class FeignOAuth2Config(
authorizedClientManager: OAuth2AuthorizedClientManager
) : FeignConfig(authorizedClientManager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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("/document/{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.
Used to support the 'Document List' view of the HMPPS Workforce service
which is used to give detailed information on the case when allocating
to a probation practitioner
"""
)
@GetMapping
fun findDocuments(@PathVariable crn: String): List<APDocument> =
documentService.getDocumentsByCrn(crn)
}
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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Referral(
@Column(name = "offender_id")
val personId: Long,

@Column(name = "event_id")
val eventId: Long,
val approvedPremisesId: Long,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Contact(
@JoinColumn(name = "offender_id", nullable = false)
val person: Person,

@Column(name = "event_id")
val eventId: Long? = null,

@Lob
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uk.gov.justice.digital.hmpps.integrations.delius.document

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.Document

interface DocumentRepository : JpaRepository<Document, Long> {
@Query("select d.name from Document d where d.person.crn = :crn and d.alfrescoId = :alfrescoId")
fun findNameByPersonCrnAndAlfrescoId(crn: String, alfrescoId: String): String?

fun findAllByPersonIdAndSoftDeletedIsFalse(personId: Long): List<Document>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.gov.justice.digital.hmpps.integrations.delius.document.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.ReferenceData

@Entity
@Immutable
@Table(name = "approved_premises_referral")
class ApprovedPremisesReferral(
@Id
@Column(name = "approved_premises_referral_id")
val id: Long,

@JoinColumn(name = "event_id", insertable = false, updatable = false)
@ManyToOne
val event: DocEvent,

@JoinColumn(name = "referral_category_id", insertable = false, updatable = false)
@ManyToOne
val category: ReferenceData

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.digital.hmpps.integrations.delius.document.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable

@Entity
@Immutable
@Table(name = "case_allocation")
class CaseAllocationDoc(
@Id
@Column(name = "case_allocation_id")
val id: Long,

@JoinColumn(name = "event_id", insertable = false, updatable = false)
@ManyToOne
val event: DocEvent
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package uk.gov.justice.digital.hmpps.integrations.delius.document.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable

@Entity
@Immutable
@Table(name = "court_report")
class CourtReportDoc(
@Id
@Column(name = "court_report_id")
val id: Long,

@JoinColumn(name = "court_appearance_id", insertable = false, updatable = false)
@ManyToOne
val documentCourtAppearance: DocumentCourtAppearance? = null,

@ManyToOne
@JoinColumn(name = "court_report_type_id", updatable = false)
val type: CourtReportType
)

@Immutable
@Entity
@Table(name = "r_court_report_type")
class CourtReportType(
@Id
@Column(name = "court_report_type_id")
val id: Long,

val description: String
)

@Entity
@Immutable
@Table(name = "court_appearance")
class DocumentCourtAppearance(

@Id
@Column(name = "court_appearance_id")
val id: Long,

@JoinColumn(name = "event_id", insertable = false, updatable = false)
@ManyToOne
val event: DocEvent
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.gov.justice.digital.hmpps.integrations.delius.document.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable

@Entity
@Immutable
class AddressAssessment(
@Id
@Column(name = "address_assessment_id")
var id: Long,

@ManyToOne
@JoinColumn(name = "offender_address_id", insertable = false, updatable = false)
val personAddress: DocPersonAddress?
)

@Entity
@Table(name = "offender_address")
@Immutable
class DocPersonAddress(
@Id
@Column(name = "offender_address_id")
var id: Long,
val buildingName: String?,
val addressNumber: String?,
val streetName: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package uk.gov.justice.digital.hmpps.integrations.delius.document.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable

@Entity
@Immutable
@Table(name = "contact")
class DocContact(
@Id
@Column(name = "contact_id", updatable = false)
val id: Long = 0,

@JoinColumn(name = "event_id", insertable = false, updatable = false)
@ManyToOne
val event: DocEvent?,

@ManyToOne
@JoinColumn(name = "contact_type_id", updatable = false)
val type: DocContactType
)

@Immutable
@Entity
@Table(name = "r_contact_type")
class DocContactType(
@Id
@Column(name = "contact_type_id")
val id: Long,

val description: String
)
Loading

0 comments on commit adfba0a

Please sign in to comment.