Skip to content

Commit

Permalink
Merge pull request #4782 from navikt/feature/pdfgen
Browse files Browse the repository at this point in the history
Feature/pdfgen
  • Loading branch information
sondrele authored Dec 12, 2024
2 parents 5d8129a + 634c017 commit b49154b
Show file tree
Hide file tree
Showing 42 changed files with 512 additions and 337 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/deploy-pdfgen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Deploy pdfgen

on:
push:
paths:
- .github/workflows/deploy-pdfgen.yaml
- mulighetsrommet-pdfgen/**
workflow_dispatch:
inputs:
environment:
type: choice
description: Environment
required: true
default: dev
options:
- dev
- dev_and_prod

jobs:
ci:
name: CI
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: ./.github/actions/lint-yaml
with:
path: mulighetsrommet-pdfgen/.nais
- name: docker-build-push
uses: nais/docker-build-push@v0
id: docker-build-push
if: github.event_name == 'push' && github.ref_name == 'main' || github.event_name == 'workflow_dispatch'
with:
team: team-mulighetsrommet
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
docker_context: mulighetsrommet-pdfgen
image_suffix: pdfgen

deploy-dev:
name: Deploy (dev)
runs-on: ubuntu-latest
needs: [ci]
if: github.event_name == 'push' && github.ref_name == 'main' || github.event_name == 'workflow_dispatch'
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: dev-gcp
RESOURCE: mulighetsrommet-pdfgen/.nais/nais-dev.yaml
VAR: image=${{ needs.ci.outputs.image }}

deploy-prod:
name: Deploy (prod)
runs-on: ubuntu-latest
needs: [ci, deploy-dev]
if: github.event_name == 'push' && github.ref_name == 'main' || github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'dev_and_prod'
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: prod-gcp
RESOURCE: mulighetsrommet-pdfgen/.nais/nais-prod.yaml
VAR: image=${{ needs.ci.outputs.image }}
16 changes: 16 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ services:
POSTGRES_USER: "valp"
POSTGRES_PASSWORD: "valp"

pdfgen:
image: "ghcr.io/navikt/pdfgen:2.0.61"
restart: "always"
ports:
- "8888:8080"
profiles:
- dev
environment:
# Gjør det mulig å benytte mockdata under lokal utvikling
DISABLE_PDF_GET: false
volumes:
- ./mulighetsrommet-pdfgen/templates:/app/templates
- ./mulighetsrommet-pdfgen/fonts:/app/fonts
- ./mulighetsrommet-pdfgen/data:/app/data
- ./mulighetsrommet-pdfgen/resources:/app/resources

# ZooKeeper is used to track the status of nodes in the Kafka cluster and maintain a list of Kafka topics and messages.
zookeeper:
image: confluentinc/cp-zookeeper:7.5.3
Expand Down
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ arrow-core-serialization = { module = "io.arrow-kt:arrow-core-serialization", ve
assertj-db = "org.assertj:assertj-db:2.0.2"

caffeine = "com.github.ben-manes.caffeine:caffeine:3.1.8"
pdfgen-core = "no.nav.pdfgen:pdfgen-core:1.1.36"
verapdf = "org.verapdf:validation-model:1.26.1"
handlebars = "com.github.jknack:handlebars:4.4.0"

dbScheduler = "com.github.kagkarlsson:db-scheduler:15.0.0"

Expand Down
1 change: 1 addition & 0 deletions mulighetsrommet-api/.nais/nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ spec:
- tiltaksgjennomforing-read
outbound:
rules:
- application: pdfgen
- application: mulighetsrommet-arena-adapter
- application: tiltakshistorikk
- application: poao-tilgang
Expand Down
1 change: 1 addition & 0 deletions mulighetsrommet-api/.nais/nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ spec:
- tiltaksgjennomforing-read
outbound:
rules:
- application: pdfgen
- application: mulighetsrommet-arena-adapter
- application: tiltakshistorikk
- application: poao-tilgang
Expand Down
3 changes: 0 additions & 3 deletions mulighetsrommet-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.arrow.core)
implementation(libs.arrow.core.serialization)
implementation(libs.pdfgen.core)
implementation(libs.verapdf)
implementation(libs.handlebars)

// Logging
implementation(libs.bundles.logging)
Expand Down
27 changes: 0 additions & 27 deletions mulighetsrommet-api/data/refusjon-kvittering.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class AppConfig(
val poaoTilgang: ServiceClientConfig,
val arenaAdapter: ServiceClientConfig,
val tiltakshistorikk: ServiceClientConfig,
val pdfgen: ServiceClientConfig,
val msGraphConfig: ServiceClientConfig,
val isoppfolgingstilfelleConfig: ServiceClientConfig,
val norg2: Norg2Config,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package no.nav.mulighetsrommet.api.pdfgen

import io.ktor.client.*
import io.ktor.client.engine.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.Serializable
import no.nav.mulighetsrommet.api.refusjon.model.RefusjonKravAft
import no.nav.mulighetsrommet.api.tilsagn.model.ArrangorflateTilsagn
import no.nav.mulighetsrommet.tokenprovider.AccessType
import no.nav.mulighetsrommet.tokenprovider.TokenProvider

class PdfGenClient(
clientEngine: HttpClientEngine = CIO.create(),
private val baseUrl: String,
private val tokenProvider: TokenProvider,
) {
private val client = HttpClient(clientEngine) {
install(ContentNegotiation) {
json()
}
}

suspend fun getRefusjonKvittering(refusjon: RefusjonKravAft, tilsagn: List<ArrangorflateTilsagn>): ByteArray {
@Serializable
data class PdfData(
val refusjon: RefusjonKravAft,
val tilsagn: List<ArrangorflateTilsagn>,
)

return downloadPdf(
app = "refusjon",
template = "kvittering",
body = PdfData(refusjon, tilsagn),
)
}

suspend fun refusjonJournalpost(refusjon: RefusjonKravAft, tilsagn: List<ArrangorflateTilsagn>): ByteArray {
@Serializable
data class PdfData(
val refusjon: RefusjonKravAft,
val tilsagn: List<ArrangorflateTilsagn>,
)

return downloadPdf(
app = "refusjon",
template = "journalpost",
body = PdfData(refusjon, tilsagn),
)
}

private suspend inline fun <reified T> downloadPdf(app: String, template: String, body: T): ByteArray {
return client
.post {
url("$baseUrl/api/v1/genpdf/$app/$template")
bearerAuth(tokenProvider.exchange(AccessType.M2M))
contentType(ContentType.Application.Json)
setBody(body)
}
.bodyAsBytes()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import no.nav.mulighetsrommet.api.navenhet.NavEnhetService
import no.nav.mulighetsrommet.api.navenhet.NavEnheterSyncService
import no.nav.mulighetsrommet.api.navenhet.db.NavEnhetRepository
import no.nav.mulighetsrommet.api.navenhet.task.SynchronizeNorgEnheter
import no.nav.mulighetsrommet.api.pdfgen.PdfGenClient
import no.nav.mulighetsrommet.api.refusjon.HentAdressebeskyttetPersonBolkPdlQuery
import no.nav.mulighetsrommet.api.refusjon.RefusjonService
import no.nav.mulighetsrommet.api.refusjon.db.DeltakerForslagRepository
Expand Down Expand Up @@ -256,6 +257,13 @@ private fun services(appConfig: AppConfig) = module {
clientEngine = appConfig.engine,
)
}
single {
PdfGenClient(
clientEngine = appConfig.engine,
baseUrl = appConfig.pdfgen.url,
tokenProvider = cachedTokenProvider.withScope(appConfig.pdfgen.scope),
)
}
single {
VeilarbvedtaksstotteClient(
baseUrl = appConfig.veilarbvedtaksstotteConfig.url,
Expand Down Expand Up @@ -435,7 +443,7 @@ private fun tasks(config: TaskConfig) = module {
single { SynchronizeNavAnsatte(config.synchronizeNavAnsatte, get(), get()) }
single { SynchronizeUtdanninger(config.synchronizeUtdanninger, get(), get()) }
single { GenerateRefusjonskrav(config.generateRefusjonskrav, get()) }
single { JournalforRefusjonskrav(get(), get(), get(), get(), get()) }
single { JournalforRefusjonskrav(get(), get(), get(), get(), get(), get()) }
single {
val updateTiltaksgjennomforingStatus = UpdateTiltaksgjennomforingStatus(
get(),
Expand Down
Loading

0 comments on commit b49154b

Please sign in to comment.