From 9beaa5ab7d8dcdf288b97bfc94537faf94fc6b4a Mon Sep 17 00:00:00 2001 From: Ugur Cenar Date: Mon, 20 Nov 2023 13:31:39 +0100 Subject: [PATCH 1/3] Upgrade pdfgen-core --- build.gradle.kts | 3 ++- src/main/kotlin/no/nav/pdfgen/Bootstrap.kt | 15 ++++++++------- .../kotlin/no/nav/pdfgen/PDFGenEnvironment.kt | 7 +++++++ .../kotlin/no/nav/pdfgen/api/GeneratePdfApi.kt | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/no/nav/pdfgen/PDFGenEnvironment.kt diff --git a/build.gradle.kts b/build.gradle.kts index aa06955..c065efb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ val junitJupiterVersion = "5.10.1" val verapdfVersion = "1.24.1" val ktfmtVersion = "0.44" val testcontainersVersion= "1.19.2" -val pdfgencoreVersion = "1.0.3" +val pdfgencoreVersion = "local-build" plugins { @@ -68,6 +68,7 @@ tasks { repositories { mavenCentral() + mavenLocal() maven { url = uri("https://github-package-registry-mirror.gc.nav.no/cached/maven-release") } diff --git a/src/main/kotlin/no/nav/pdfgen/Bootstrap.kt b/src/main/kotlin/no/nav/pdfgen/Bootstrap.kt index 9240687..16362e8 100644 --- a/src/main/kotlin/no/nav/pdfgen/Bootstrap.kt +++ b/src/main/kotlin/no/nav/pdfgen/Bootstrap.kt @@ -30,8 +30,9 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import no.nav.pdfgen.api.setupGeneratePdfApi -import no.nav.pdfgen.core.PDFgen -import no.nav.pdfgen.core.template.loadTemplates +import no.nav.pdfgen.core.Environment +import no.nav.pdfgen.core.PDFGenCore + import org.slf4j.Logger import org.slf4j.LoggerFactory import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider @@ -39,17 +40,17 @@ import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider val log: Logger = LoggerFactory.getLogger("pdfgen") fun main() { - initializeApplication(8080).start(wait = true) + initializeApplication(8580).start(wait = true) } fun initializeApplication(port: Int): ApplicationEngine { System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider") VeraGreenfieldFoundryProvider.initialise() - PDFgen.init(no.nav.pdfgen.core.Environment()) + val environment = Environment() + PDFGenCore.init(environment) - val env = no.nav.pdfgen.core.Environment() - val templates = loadTemplates() + val templates = environment.templates val collectorRegistry: CollectorRegistry = CollectorRegistry.defaultRegistry XRLog.setLoggerImpl(Slf4jLogger()) @@ -91,7 +92,7 @@ fun initializeApplication(port: Int): ApplicationEngine { } } } - setupGeneratePdfApi(env) + setupGeneratePdfApi() } } } diff --git a/src/main/kotlin/no/nav/pdfgen/PDFGenEnvironment.kt b/src/main/kotlin/no/nav/pdfgen/PDFGenEnvironment.kt new file mode 100644 index 0000000..970c49a --- /dev/null +++ b/src/main/kotlin/no/nav/pdfgen/PDFGenEnvironment.kt @@ -0,0 +1,7 @@ +package no.nav.pdfgen + +data class PDFGenEnvironment( + val disablePdfGet: Boolean = System.getenv("DISABLE_PDF_GET")?.let { it == "true" } ?: false, + val enableHtmlEndpoint: Boolean = + System.getenv("ENABLE_HTML_ENDPOINT")?.let { it == "true" } ?: false, +) diff --git a/src/main/kotlin/no/nav/pdfgen/api/GeneratePdfApi.kt b/src/main/kotlin/no/nav/pdfgen/api/GeneratePdfApi.kt index f275eee..6675271 100644 --- a/src/main/kotlin/no/nav/pdfgen/api/GeneratePdfApi.kt +++ b/src/main/kotlin/no/nav/pdfgen/api/GeneratePdfApi.kt @@ -16,7 +16,7 @@ import io.ktor.server.routing.post import io.ktor.server.routing.route import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import no.nav.pdfgen.core.Environment +import no.nav.pdfgen.PDFGenEnvironment import no.nav.pdfgen.core.OPENHTMLTOPDF_RENDERING_SUMMARY import no.nav.pdfgen.core.pdf.createHtml import no.nav.pdfgen.core.pdf.createHtmlFromTemplateData @@ -25,7 +25,7 @@ import no.nav.pdfgen.log import java.io.ByteArrayOutputStream import java.io.InputStream -fun Routing.setupGeneratePdfApi(env: Environment) { +fun Routing.setupGeneratePdfApi(env: PDFGenEnvironment = PDFGenEnvironment()) { route("/api/v1/genpdf") { if (!env.disablePdfGet) { get("/{applicationName}/{template}") { From 0295fc6aa5394512c1d58963f82f37e5011bef27 Mon Sep 17 00:00:00 2001 From: Ugur Cenar Date: Wed, 22 Nov 2023 11:57:58 +0100 Subject: [PATCH 2/3] Upgrade pdfgen-core version --- README.md | 2 ++ build.gradle.kts | 2 +- src/main/kotlin/no/nav/pdfgen/Bootstrap.kt | 18 +++++++++++++----- .../{PDFGenEnvironment.kt => Environment.kt} | 4 +++- .../kotlin/no/nav/pdfgen/api/GeneratePdfApi.kt | 4 ++-- src/main/resources/logback-test.xml | 1 + src/test/kotlin/no/nav/pdfgen/PdfGenITest.kt | 3 ++- src/test/kotlin/no/nav/pdfgen/RenderingTest.kt | 3 ++- 8 files changed, 26 insertions(+), 11 deletions(-) rename src/main/kotlin/no/nav/pdfgen/{PDFGenEnvironment.kt => Environment.kt} (57%) diff --git a/README.md b/README.md index 4f38a63..1cf23b4 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ The template and data directory structure both follow the `//