@@ -2,18 +2,15 @@ package no.nav.klage.document.api
2
2
3
3
import io.swagger.v3.oas.annotations.Operation
4
4
import io.swagger.v3.oas.annotations.tags.Tag
5
+ import no.nav.klage.document.api.views.DocumentVersionView
5
6
import no.nav.klage.document.api.views.DocumentView
6
7
import no.nav.klage.document.config.SecurityConfiguration.Companion.ISSUER_AAD
7
- import no.nav.klage.document.domain.Document
8
+ import no.nav.klage.document.domain.DocumentVersion
8
9
import no.nav.klage.document.service.DocumentService
10
+ import no.nav.klage.document.util.TokenUtil
9
11
import no.nav.klage.document.util.getLogger
10
12
import no.nav.klage.document.util.getSecureLogger
11
13
import no.nav.security.token.support.core.api.ProtectedWithClaims
12
- import no.nav.security.token.support.core.context.TokenValidationContextHolder
13
- import org.springframework.http.HttpHeaders
14
- import org.springframework.http.HttpStatus
15
- import org.springframework.http.MediaType
16
- import org.springframework.http.ResponseEntity
17
14
import org.springframework.web.bind.annotation.*
18
15
import java.util.*
19
16
@@ -23,7 +20,7 @@ import java.util.*
23
20
@RequestMapping(" /documents" )
24
21
class DocumentController (
25
22
private val documentService : DocumentService ,
26
- private val tokenValidationContextHolder : TokenValidationContextHolder
23
+ private val tokenUtil : TokenUtil ,
27
24
) {
28
25
29
26
companion object {
@@ -63,10 +60,13 @@ class DocumentController(
63
60
summary = " Get document" ,
64
61
description = " Get document"
65
62
)
66
- @GetMapping(" /{documentId}" )
67
- fun getDocument (@PathVariable(" documentId" ) documentId : UUID ): DocumentView {
68
- log(" getDocument called with id $documentId " )
69
- return mapToDocumentView(documentService.getDocument(documentId))
63
+ @GetMapping(" /{documentId}" , " /{documentId}/versions/{version}" )
64
+ fun getDocument (
65
+ @PathVariable(" documentId" ) documentId : UUID ,
66
+ @PathVariable(" version" , required = false ) version : Int? ,
67
+ ): DocumentView {
68
+ log(" getDocument called with id $documentId and version $version " )
69
+ return mapToDocumentView(documentService.getDocument(documentId = documentId, version = version))
70
70
}
71
71
72
72
@Operation(
@@ -80,43 +80,42 @@ class DocumentController(
80
80
}
81
81
82
82
@Operation(
83
- summary = " Generer PDF " ,
84
- description = " Generer PDF "
83
+ summary = " Get document versions " ,
84
+ description = " Get document versions "
85
85
)
86
- @ResponseBody
87
- @GetMapping(" /{documentId}/pdf" )
88
- fun getDocumentAsPDF (
89
- @PathVariable(" documentId" ) documentId : UUID
90
- ): ResponseEntity <ByteArray > {
91
- log(" getDocumentAsPDF with id : $documentId " )
86
+ @GetMapping(" /{documentId}/versions" )
87
+ fun getDocumentVersions (@PathVariable(" documentId" ) documentId : UUID ): List <DocumentVersionView > {
88
+ log(" getDocumentVersions called with id $documentId " )
89
+ val documentVersions = documentService.getDocumentVersions(documentId = documentId)
92
90
93
- val pdfDocument = documentService.getDocumentAsPDF(documentId)
94
-
95
- val responseHeaders = HttpHeaders ()
96
- responseHeaders.contentType = MediaType .APPLICATION_PDF
97
- responseHeaders.add(" Content-Disposition" , " inline; filename=${pdfDocument.filename} .pdf" )
98
- return ResponseEntity (
99
- pdfDocument.bytes,
100
- responseHeaders,
101
- HttpStatus .OK
102
- )
91
+ return documentVersions.map {
92
+ mapToDocumentVersionView(it)
93
+ }
103
94
}
104
95
105
- private fun mapToDocumentView (document : Document ): DocumentView =
96
+ private fun mapToDocumentView (documentVersion : DocumentVersion ): DocumentView =
106
97
DocumentView (
107
- id = document.id,
108
- json = document.json,
109
- created = document.created,
110
- modified = document.modified
98
+ id = documentVersion.documentId,
99
+ documentId = documentVersion.documentId,
100
+ version = documentVersion.version,
101
+ json = documentVersion.json,
102
+ authorNavIdent = documentVersion.authorNavIdent,
103
+ created = documentVersion.created,
104
+ modified = documentVersion.modified
105
+ )
106
+
107
+ private fun mapToDocumentVersionView (documentVersion : DocumentVersion ): DocumentVersionView =
108
+ DocumentVersionView (
109
+ documentId = documentVersion.documentId,
110
+ version = documentVersion.version,
111
+ authorNavIdent = documentVersion.authorNavIdent,
112
+ created = documentVersion.created,
113
+ modified = documentVersion.modified
111
114
)
112
115
113
116
private fun log (message : String ) {
114
117
logger.debug(message)
115
- secureLogger.debug(" {}. On-behalf-of: {}" , message, getIdent())
118
+ secureLogger.debug(" {}. On-behalf-of: {}" , message, tokenUtil. getIdent())
116
119
}
117
120
118
- fun getIdent (): String? =
119
- tokenValidationContextHolder.tokenValidationContext.getJwtToken(ISSUER_AAD )
120
- .jwtTokenClaims?.get(" NAVident" )?.toString()
121
-
122
121
}
0 commit comments