Skip to content

Commit 9af16dc

Browse files
committed
Support for versions.
Removed unused code.
1 parent 3c6e179 commit 9af16dc

File tree

15 files changed

+426
-217
lines changed

15 files changed

+426
-217
lines changed

deploy/nais.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ spec:
6666
rules:
6767
- application: kabal-frontend
6868
- application: kabal-api
69-
outbound:
70-
rules:
71-
- application: kabal-json-to-pdf
7269
azure:
7370
application:
7471
enabled: true

src/main/kotlin/no/nav/klage/document/api/DocumentController.kt

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ package no.nav.klage.document.api
22

33
import io.swagger.v3.oas.annotations.Operation
44
import io.swagger.v3.oas.annotations.tags.Tag
5+
import no.nav.klage.document.api.views.DocumentVersionView
56
import no.nav.klage.document.api.views.DocumentView
67
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
89
import no.nav.klage.document.service.DocumentService
10+
import no.nav.klage.document.util.TokenUtil
911
import no.nav.klage.document.util.getLogger
1012
import no.nav.klage.document.util.getSecureLogger
1113
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
1714
import org.springframework.web.bind.annotation.*
1815
import java.util.*
1916

@@ -23,7 +20,7 @@ import java.util.*
2320
@RequestMapping("/documents")
2421
class DocumentController(
2522
private val documentService: DocumentService,
26-
private val tokenValidationContextHolder: TokenValidationContextHolder
23+
private val tokenUtil: TokenUtil,
2724
) {
2825

2926
companion object {
@@ -63,10 +60,13 @@ class DocumentController(
6360
summary = "Get document",
6461
description = "Get document"
6562
)
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))
7070
}
7171

7272
@Operation(
@@ -80,43 +80,42 @@ class DocumentController(
8080
}
8181

8282
@Operation(
83-
summary = "Generer PDF",
84-
description = "Generer PDF"
83+
summary = "Get document versions",
84+
description = "Get document versions"
8585
)
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)
9290

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+
}
10394
}
10495

105-
private fun mapToDocumentView(document: Document): DocumentView =
96+
private fun mapToDocumentView(documentVersion: DocumentVersion): DocumentView =
10697
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
111114
)
112115

113116
private fun log(message: String) {
114117
logger.debug(message)
115-
secureLogger.debug("{}. On-behalf-of: {}", message, getIdent())
118+
secureLogger.debug("{}. On-behalf-of: {}", message, tokenUtil.getIdent())
116119
}
117120

118-
fun getIdent(): String? =
119-
tokenValidationContextHolder.tokenValidationContext.getJwtToken(ISSUER_AAD)
120-
.jwtTokenClaims?.get("NAVident")?.toString()
121-
122121
}

src/main/kotlin/no/nav/klage/document/api/views/DocumentView.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ import java.time.LocalDateTime
44
import java.util.*
55

66
data class DocumentView(
7-
val id: UUID,
87
val json: String,
8+
val documentId: UUID,
9+
val id: UUID,
10+
val version: Int,
11+
val authorNavIdent: String?,
912
val created: LocalDateTime,
1013
val modified: LocalDateTime
1114
)
15+
16+
data class DocumentVersionView(
17+
val documentId: UUID,
18+
val version: Int,
19+
val authorNavIdent: String?,
20+
val created: LocalDateTime,
21+
val modified: LocalDateTime,
22+
)

src/main/kotlin/no/nav/klage/document/clients/KabalJsonToPdfClient.kt

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/main/kotlin/no/nav/klage/document/config/KabalJsonToPdfClientConfiguration.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/kotlin/no/nav/klage/document/domain/Document.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import java.util.*
1212
class Document(
1313
@Id
1414
val id: UUID = UUID.randomUUID(),
15-
@Column(name = "json")
16-
var json: String,
1715
@Column(name = "created")
1816
val created: LocalDateTime,
1917
@Column(name = "modified")
20-
var modified: LocalDateTime
18+
var modified: LocalDateTime,
2119
) {
2220
override fun equals(other: Any?): Boolean {
2321
if (this === other) return true
@@ -35,7 +33,7 @@ class Document(
3533
}
3634

3735
override fun toString(): String {
38-
return "Document(id=$id, json='$json', created=$created, modified=$modified)"
36+
return "Document(id=$id, created=$created, modified=$modified)"
3937
}
4038

4139
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package no.nav.klage.document.domain
2+
3+
import jakarta.persistence.Column
4+
import jakarta.persistence.Entity
5+
import jakarta.persistence.Id
6+
import jakarta.persistence.IdClass
7+
import jakarta.persistence.Table
8+
import java.time.LocalDateTime
9+
import java.util.*
10+
11+
@Entity
12+
@Table(name = "document_version", schema = "klage")
13+
@IdClass(DocumentVersionId::class)
14+
class DocumentVersion(
15+
@Id
16+
val documentId: UUID,
17+
@Id
18+
val version: Int,
19+
@Column(name = "json")
20+
var json: String,
21+
@Column(name = "created")
22+
val created: LocalDateTime,
23+
@Column(name = "modified")
24+
var modified: LocalDateTime,
25+
@Column(name = "author_nav_ident")
26+
var authorNavIdent: String,
27+
) {
28+
override fun equals(other: Any?): Boolean {
29+
if (this === other) return true
30+
if (javaClass != other?.javaClass) return false
31+
32+
other as DocumentVersion
33+
34+
if (documentId != other.documentId) return false
35+
if (version != other.version) return false
36+
37+
return true
38+
}
39+
40+
override fun hashCode(): Int {
41+
return documentId.hashCode()
42+
}
43+
44+
override fun toString(): String {
45+
return "Document(id=$documentId, version=$version, json='$json', created=$created, modified=$modified, authorNavIdent='$authorNavIdent')"
46+
}
47+
48+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package no.nav.klage.document.domain
2+
3+
import jakarta.persistence.Embeddable
4+
import java.io.Serializable
5+
import java.util.*
6+
7+
@Embeddable
8+
data class DocumentVersionId(
9+
val documentId: UUID,
10+
val version: Int = 1,
11+
): Serializable

src/main/kotlin/no/nav/klage/document/domain/PDFDocument.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package no.nav.klage.document.repositories
22

33
import no.nav.klage.document.domain.Document
4+
import no.nav.klage.document.domain.DocumentVersion
5+
import no.nav.klage.document.domain.DocumentVersionId
46
import org.springframework.data.jpa.repository.JpaRepository
7+
import org.springframework.data.jpa.repository.Query
58
import java.util.*
69

710
interface DocumentRepository : JpaRepository<Document, UUID>

0 commit comments

Comments
 (0)