Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hent RTF dokument #561

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>

<!-- language -->
<java.version>21</java.version>
<kotlin.version>1.9.22</kotlin.version>
<kotlin.version>2.0.0</kotlin.version>

<!-- dependent versions other than from spring-boot -->
<bidrag-felles.version>2024.04.15.133925</bidrag-felles.version>
<bidrag-felles.version>2024.07.10.131205</bidrag-felles.version>
<logback.encoder.version>7.4</logback.encoder.version>
<springdoc-openapi-ui.version>2.3.0</springdoc-openapi-ui.version>
<springframework-cloud.version>4.1.0</springframework-cloud.version>
Expand All @@ -36,7 +36,7 @@
<kotlin-logging-jvm.version>3.0.5</kotlin-logging-jvm.version>

<!-- build -->
<build-helper-maven.version>3.4.0</build-helper-maven.version>
<build-helper-maven.version>3.5.0</build-helper-maven.version>
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.surefire.version>2.22.0</maven.surefire.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -51,6 +51,11 @@
<name>GitHub felles Apache Maven Packages for navikt</name>
<url>https://maven.pkg.github.com/navikt/maven-release/</url>
</repository>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<dependencyManagement>
Expand Down Expand Up @@ -143,13 +148,13 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.4.14</version>
<version>1.5.6</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
<version>1.5.6</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -269,6 +274,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand All @@ -289,14 +305,14 @@
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>src/main/kotlin</source>
<source>target/generated-sources/annotations</source>
</sourceDirs>
</configuration>
</execution>
Expand All @@ -309,7 +325,7 @@
<configuration>
<sourceDirs>
<source>src/test/java</source>
<source>src/test/kotlin</source>
<source>target/generated-test-sources/test-annotations</source>
</sourceDirs>
</configuration>
</execution>
Expand Down Expand Up @@ -420,6 +436,34 @@
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ class BidragDokumentConsumer(
fun hentDokument(
journalpostId: String?,
dokumentreferanse: String?,
rtf: Boolean = false,
): ResponseEntity<ByteArray> {
if (journalpostId.isNullOrEmpty()) return hentDokument(dokumentreferanse)
if (journalpostId.isNullOrEmpty()) return hentDokument(dokumentreferanse, rtf)
val dokumentReferanseUrl =
if (!dokumentreferanse.isNullOrEmpty()) "/$dokumentreferanse" else ""
val dokumentUrl = String.format(PATH_HENT_DOKUMENT, journalpostId) + dokumentReferanseUrl
val rtfQuery = if (rtf) "?rtf=true" else ""
val dokumentUrl = String.format(PATH_HENT_DOKUMENT, journalpostId) + dokumentReferanseUrl + rtfQuery
return restTemplate.exchange(
dokumentUrl,
HttpMethod.GET,
Expand Down Expand Up @@ -226,8 +228,12 @@ class BidragDokumentConsumer(
).body
}

fun hentDokument(dokumentreferanse: String?): ResponseEntity<ByteArray> {
val dokumentUrl = String.format(PATH_HENT_DOKUMENT_REFERANSE, dokumentreferanse)
fun hentDokument(
dokumentreferanse: String?,
rtf: Boolean = false,
): ResponseEntity<ByteArray> {
val rtfQuery = if (rtf) "?rtf=true" else ""
val dokumentUrl = String.format(PATH_HENT_DOKUMENT_REFERANSE, dokumentreferanse) + rtfQuery
return restTemplate.exchange(
dokumentUrl,
HttpMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,37 @@ class DokumentController(private val dokumentService: DokumentService) {
return dokumentService.hentDokumentMetadata(dokument)
}

@GetMapping(
*[
"/dokument/rtf/{journalpostId}/{dokumentreferanse}", "/dokument/rtf/{journalpostId}",
"/dokumentreferanse/rtf/{dokumentreferanse}",
],
)
fun hentDokumentRTF(
@PathVariable journalpostId: String?,
@PathVariable(required = false) dokumentreferanse: String?,
@RequestParam(required = false) resizeToA4: Boolean,
@RequestParam(required = false, defaultValue = "true") optimizeForPrint: Boolean,
): ResponseEntity<ByteArray> {
log.info("Henter RTF dokument med journalpostId=$journalpostId og dokumentreferanse=$dokumentreferanse, resizeToA4=$resizeToA4")
val dokument = DokumentRef(journalpostId, dokumentreferanse, null)
val response =
dokumentService.hentDokumentRTF(dokument)
return response
}

@GetMapping(*["/dokument/{journalpostId}/{dokumentreferanse}", "/dokument/{journalpostId}", "/dokumentreferanse/{dokumentreferanse}"])
fun hentDokument(
@PathVariable journalpostId: String?,
@PathVariable(required = false) dokumentreferanse: String?,
@RequestParam(required = false) resizeToA4: Boolean,
@RequestParam(required = false, defaultValue = "true") optimizeForPrint: Boolean,
): ResponseEntity<ByteArray> {
log.info("Henter dokument med journalpostId=$journalpostId og dokumentreferanse=$dokumentreferanse, resizeToA4=$resizeToA4")
@RequestParam("rtf", required = false) rtfFile: Boolean = false,
): ResponseEntity<ByteArray> {
log.info("Henter dokument med journalpostId=$journalpostId og dokumentreferanse=$dokumentreferanse, resizeToA4=$resizeToA4, rtfFile=$rtfFile")
val dokument = DokumentRef(journalpostId, dokumentreferanse, null)
val response =
dokumentService.hentDokument(dokument, DocumentProperties(resizeToA4, optimizeForPrint))
if (rtfFile) dokumentService.hentDokumentRTF(dokument) else dokumentService.hentDokument(dokument, DocumentProperties(resizeToA4, optimizeForPrint))

response.body
?.also {
Expand Down Expand Up @@ -96,10 +116,11 @@ class DokumentController(private val dokumentService: DokumentService) {
@RequestParam(required = false) resizeToA4: Boolean,
): ResponseEntity<ByteArray> {
log.info("Henter dokumenter $dokumentreferanseList med resizeToA4=$resizeToA4, optimizeForPrint=$optimizeForPrint")
val response = dokumentService.hentDokumenter(
dokumentreferanseList,
DocumentProperties(resizeToA4, optimizeForPrint),
)
val response =
dokumentService.hentDokumenter(
dokumentreferanseList,
DocumentProperties(resizeToA4, optimizeForPrint),
)

response.body?.also {
log.info(
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/no/nav/bidrag/dokument/service/DokumentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ class DokumentService(
.body(response.body?.let { PDFDokumentProcessor().process(it, documentProperties) })
}

@Timed("hentDokument")
fun hentDokumentRTF(_dokumentRef: DokumentRef): ResponseEntity<ByteArray> {
val response = bidragJournalpostConsumer.hentDokument(_dokumentRef.journalpostId, _dokumentRef.dokumentId, true)
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.header(HttpHeaders.CONTENT_DISPOSITION, response.headers.contentDisposition.toString())
.body(response.body)
}

@Timed("erFerdigstilt")
fun erFerdigstilt(
dokumentreferanse: String,
): ResponseEntity<Boolean> {
fun erFerdigstilt(dokumentreferanse: String): ResponseEntity<Boolean> {
return bidragJournalpostConsumer.erFerdigstilt(dokumentreferanse)
}

Expand All @@ -88,9 +95,12 @@ class DokumentService(
return hentDokumenterData(dokumenter, documentProperties)
}

private fun hentDokumentData(dokument: DokumentRef): ResponseEntity<ByteArray> {
private fun hentDokumentData(
dokument: DokumentRef,
rtf: Boolean = false,
): ResponseEntity<ByteArray> {
return if (dokument.erForKilde(Kilde.MIDLERTIDLIG_BREVLAGER)) {
bidragJournalpostConsumer.hentDokument(dokument.journalpostId, dokument.dokumentId)
bidragJournalpostConsumer.hentDokument(dokument.journalpostId, dokument.dokumentId, rtf)
} else if (dokument.erForKilde(Kilde.FORSENDELSE)) {
bidragForsendelseConsumer.hentDokument(dokument.journalpostId, dokument.dokumentId)
} else {
Expand Down Expand Up @@ -137,12 +147,13 @@ class DokumentService(
documentProperties: DocumentProperties,
): ByteArray {
documentProperties.numberOfDocuments = dokumentList.size
val dokumentBytes = dokumentList.map {
hentDokument(
it,
DocumentProperties(documentProperties, dokumentList.indexOf(it)),
).body!!
}
val dokumentBytes =
dokumentList.map {
hentDokument(
it,
DocumentProperties(documentProperties, dokumentList.indexOf(it)),
).body!!
}
return PDFDokumentMerger.merge(dokumentBytes, documentProperties)
}

Expand All @@ -155,7 +166,8 @@ class DokumentService(
return DokumentRef(
journalpostId = dokument.journalpostId,
dokumentId = dokument.dokumentreferanse,
kilde = when (dokument.arkivsystem) {
kilde =
when (dokument.arkivsystem) {
DokumentArkivSystemDto.MIDLERTIDLIG_BREVLAGER -> Kilde.MIDLERTIDLIG_BREVLAGER
DokumentArkivSystemDto.JOARK -> Kilde.JOARK
DokumentArkivSystemDto.BIDRAG -> Kilde.FORSENDELSE
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/no/nav/bidrag/dokument/CorrelationIdFilterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ internal class CorrelationIdFilterTest {
)
} returns HttpResponse.from(HttpStatus.I_AM_A_TEAPOT)
val response =
securedTestRestTemplate.getForEntity<JournalpostResponse>("http://localhost:$port/bidrag-dokument/journal/BID-123?saksnummer=777")
securedTestRestTemplate
.getForEntity<JournalpostResponse>("http://localhost:$port/bidrag-dokument/journal/BID-123?saksnummer=777")
assertSoftly {
Assertions.assertThat(response).extracting { it.statusCode }
Assertions
.assertThat(response)
.extracting { it.statusCode }
.isEqualTo(HttpStatus.I_AM_A_TEAPOT);
{
val loggingEventCaptor = ArgumentCaptor.forClass(ILoggingEvent::class.java)
Mockito.verify(appenderMock, Mockito.atLeastOnce())
Mockito
.verify(appenderMock, Mockito.atLeastOnce())
.doAppend(loggingEventCaptor.capture())
}
}
Expand Down
Loading