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

Flytt tiltakspenger-dokument inn i vedtak #634

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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
9 changes: 2 additions & 7 deletions .nais/nais.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ spec:
outbound:
rules:
- application: tiltakspenger-tiltak
- application: tiltakspenger-dokument
- application: utsjekk
namespace: helved
external:
- host: {{ urlPdl }}
- host: {{ urlSkjerming }}
- host: {{ urlJoark }}
- host: {{ urlDokdist }}
inbound:
rules:
- application: tiltakspenger-saksbehandler
Expand All @@ -79,12 +80,6 @@ spec:
permissions:
roles:
- "lage_hendelser"
- application: tiltakspenger-vedtak-rivers
namespace: tpts
cluster: {{ cluster }}
permissions:
roles:
- "lage_hendelser"
env:
{{#each azure.groups}}
- name: {{this.name}}
Expand Down
2 changes: 2 additions & 0 deletions .nais/vars/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cluster: dev-gcp
tenant: trygdeetaten.no
urlPdl: pdl-api.dev-fss-pub.nais.io
urlSkjerming: skjermede-personer-pip.intern.dev.nav.no
urlJoark: dokarkiv.dev-fss-pub.nais.io
urlDokdist: dokdistfordeling.dev-fss-pub.nais.io
azure:
groups:
- name: ROLE_SAKSBEHANDLER
Expand Down
2 changes: 2 additions & 0 deletions .nais/vars/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cluster: prod-gcp
tenant: nav.no
urlPdl: pdl-api.prod-fss-pub.nais.io
urlSkjerming: skjermede-personer-pip.intern.nav.no
urlJoark: dokarkiv.prod-fss-pub.nais.io
urlDokdist: dokdistfordeling.prod-fss-pub.nais.io
azure:
groups:
- name: ROLE_SAKSBEHANDLER
Expand Down
6 changes: 5 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ dependencies {
// Helved/Utsjekk/Utbetaling
implementation("no.nav.utsjekk.kontrakter:iverksett:$iverksettVersjon")

// DIV
// TODO post-mvp jah: Fjern denne når meldekort er over på pdfgen
implementation("org.apache.pdfbox:pdfbox:2.0.28")


// Arrow
implementation("io.arrow-kt:arrow-core:1.2.4")

testImplementation(platform("org.junit:junit-bom:5.11.1"))
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/kotlin/no/nav/tiltakspenger/vedtak/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import no.nav.tiltakspenger.vedtak.db.DataSourceSetup
import no.nav.tiltakspenger.vedtak.jobber.TaskExecutor
import no.nav.tiltakspenger.vedtak.routes.vedtakApi
import no.nav.tiltakspenger.vedtak.tilgang.JWTInnloggetSaksbehandlerProvider
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

fun main() {
System.setProperty("logback.configurationFile", Configuration.logbackConfigurationFile())
Expand Down Expand Up @@ -49,17 +51,23 @@ fun main() {
RunCheckFactory(
leaderPodLookup =
object : LeaderPodLookup {
override fun amITheLeader(localHostName: String): Either<LeaderPodLookupFeil, Boolean> = true.right()
override fun amITheLeader(localHostName: String): Either<LeaderPodLookupFeil, Boolean> =
true.right()
},
)
}

val stoppableTasks =
TaskExecutor.startJob(
initialDelay = if (Configuration.isNais()) 1.minutes else 1.seconds,
runCheckFactory = runCheckFactory,
tasks =
listOf { _ ->
listOf { correlationId ->
applicationContext.utbetalingContext.opprettUtbetalingsvedtakService.opprettUtbetalingsvedtak()
// applicationContext.utbetalingContext.sendUtbetalingerService.send(correlationId)
// applicationContext.utbetalingContext.journalførUtbetalingsvedtakService.journalfør(correlationId)
applicationContext.førstegangsbehandlingContext.journalførVedtaksbrevService.journalfør(correlationId)
applicationContext.førstegangsbehandlingContext.distribuerVedtaksbrevService.distribuer(correlationId)
},
)

Expand Down
49 changes: 37 additions & 12 deletions app/src/main/kotlin/no/nav/tiltakspenger/vedtak/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ object Configuration {
"ROLE_STRENGT_FORTROLIG" to "5ef775f2-61f8-4283-bf3d-8d03f428aa14",
"ROLE_SKJERMING" to "dbe4ad45-320b-4e9a-aaa1-73cca4ee124d",
"ROLE_DRIFT" to "c511113e-5b22-49e7-b9c4-eeb23b01f518",
"PDL_SCOPE" to "api://localhost:8091/.default",
"PDL_SCOPE" to "localhost",
"PDL_ENDPOINT_URL" to "https://localhost:8091/graphql",
"SKJERMING_SCOPE" to "localhost",
"SKJERMING_URL" to "http://host.docker.internal:8091",
"TILTAK_SCOPE" to "localhost",
"TILTAK_URL" to "http://host.docker.internal:8091",
"UTBETALING_SCOPE" to "localhost",
"UTBETALING_URL" to "http://localhost:8091",
"DOKUMENT_SCOPE" to "localhost",
"DOKUMENT_URL" to "http://localhost:8091",
"JOARK_SCOPE" to "localhost",
"JOARK_URL" to "http://localhost:8091",
"DOKDIST_SCOPE" to "localhost",
"DOKDIST_URL" to "http://localhost:8091",
"PDFGEN_SCOPE" to "localhost",
"PDFGEN_URL" to "http://localhost:8091",
"NAIS_APP_IMAGE" to "http://localhost8080:githubhash",
"AZURE_APP_CLIENT_ID" to "tiltakspenger-vedtak",
"AZURE_APP_CLIENT_SECRET" to "secret",
"AZURE_APP_WELL_KNOWN_URL" to "http://localhost:2222",
"AZURE_APP_WELL_KNOWN_URL" to "http://host.docker.internal:6969/azure/.well-known/openid-configuration",
"AZURE_OPENID_CONFIG_ISSUER" to "http://host.docker.internal:6969/azure",
"AZURE_OPENID_CONFIG_JWKS_URI" to "http://host.docker.internal:6969/azure/jwks",
"DB_USERNAME" to "postgres",
Expand All @@ -92,8 +96,12 @@ object Configuration {
"TILTAK_URL" to "http://tiltakspenger-tiltak",
"UTBETALING_SCOPE" to "api://dev-gcp.helved.utsjekk/.default",
"UTBETALING_URL" to "http://utsjekk.helved",
"DOKUMENT_SCOPE" to "api://dev-gcp.tpts.tiltakspenger-dokument/.default",
"DOKUMENT_URL" to "http://tiltakspenger-dokument",
"JOARK_SCOPE" to "api://dev-fss.teamdokumenthandtering.dokarkiv-q1/.default",
"JOARK_URL" to "https://dokarkiv.dev-fss-pub.nais.io",
"DOKDIST_SCOPE" to "api://dev-fss.teamdokumenthandtering.saf-q1/.default",
"DOKDIST_URL" to "https://dokdistfordeling-q1.dev-fss-pub.nais.io",
"PDFGEN_SCOPE" to "api://dev-gcp.tpts.tiltakspenger-pdfgen/.default",
"PDFGEN_URL" to "http://tiltakspenger-pdfgen",
),
)
private val prodProperties =
Expand All @@ -108,8 +116,12 @@ object Configuration {
"TILTAK_URL" to "http://tiltakspenger-tiltak",
"UTBETALING_SCOPE" to "api://prod-gcp.helved.utsjekk/.default",
"UTBETALING_URL" to "http://utsjekk.helved",
"DOKUMENT_SCOPE" to "api://prod-gcp.tpts.tiltakspenger-dokument/.default",
"DOKUMENT_URL" to "http://tiltakspenger-dokument",
"JOARK_SCOPE" to "api://prod-fss.teamdokumenthandtering.dokarkiv/.default",
"JOARK_URL" to "https://dokarkiv.prod-fss-pub.nais.io",
"DOKDIST_SCOPE" to "api://prod-fss.teamdokumenthandtering.saf/.default",
"DOKDIST_URL" to "https://dokdistfordeling.prod-fss-pub.nais.io",
"PDFGEN_SCOPE" to "api://prod-gcp.tpts.tiltakspenger-pdfgen/.default",
"PDFGEN_URL" to "http://tiltakspenger-pdfgen",
),
)

Expand Down Expand Up @@ -198,8 +210,20 @@ object Configuration {
wellknownUrl = wellknownUrl,
)

fun oauthConfigDokument(
scope: String = config()[Key("DOKUMENT_SCOPE", stringType)],
fun oauthConfigJoark(
scope: String = config()[Key("JOARK_SCOPE", stringType)],
clientId: String = config()[Key("AZURE_APP_CLIENT_ID", stringType)],
clientSecret: String = config()[Key("AZURE_APP_CLIENT_SECRET", stringType)],
wellknownUrl: String = config()[Key("AZURE_APP_WELL_KNOWN_URL", stringType)],
) = AzureTokenProvider.OauthConfig(
scope = scope,
clientId = clientId,
clientSecret = clientSecret,
wellknownUrl = wellknownUrl,
)

fun oauthConfigDokdist(
scope: String = config()[Key("DOKDIST_SCOPE", stringType)],
clientId: String = config()[Key("AZURE_APP_CLIENT_ID", stringType)],
clientSecret: String = config()[Key("AZURE_APP_CLIENT_SECRET", stringType)],
wellknownUrl: String = config()[Key("AZURE_APP_WELL_KNOWN_URL", stringType)],
Expand Down Expand Up @@ -228,8 +252,9 @@ object Configuration {

fun tiltakClientConfig(baseUrl: String = config()[Key("TILTAK_URL", stringType)]) = ClientConfig(baseUrl = baseUrl)

fun dokumentClientConfig(baseUrl: String = config()[Key("DOKUMENT_URL", stringType)]) = ClientConfig(baseUrl = baseUrl)

fun joarkClientConfig(baseUrl: String = config()[Key("JOARK_URL", stringType)]) = ClientConfig(baseUrl = baseUrl)
fun dokdistClientConfig(baseUrl: String = config()[Key("DOKDIST_URL", stringType)]) = ClientConfig(baseUrl = baseUrl)
fun pdfgenClientConfig(baseUrl: String = config()[Key("PDFGEN_URL", stringType)]) = ClientConfig(baseUrl = baseUrl)
fun utbetalingClientConfig(baseUrl: String = config()[Key("UTBETALING_URL", stringType)]) = ClientConfig(baseUrl = baseUrl)

fun isNais() = applicationProfile() != Profile.LOCAL
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package no.nav.tiltakspenger.vedtak.clients.dokdist

import arrow.core.Either
import arrow.core.flatten
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.future.await
import kotlinx.coroutines.withContext
import mu.KotlinLogging
import no.nav.tiltakspenger.distribusjon.domene.DistribusjonId
import no.nav.tiltakspenger.distribusjon.ports.DokdistGateway
import no.nav.tiltakspenger.distribusjon.ports.KunneIkkeDistribuereDokument
import no.nav.tiltakspenger.felles.journalføring.JournalpostId
import no.nav.tiltakspenger.felles.sikkerlogg
import no.nav.tiltakspenger.libs.common.AccessToken
import no.nav.tiltakspenger.libs.common.CorrelationId
import java.net.URI
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration

class DokdistHttpClient(
baseUrl: String,
private val getToken: suspend () -> AccessToken,
connectTimeout: Duration = 1.seconds,
private val timeout: Duration = 1.seconds,
) : DokdistGateway {

private val log = KotlinLogging.logger {}

private val client =
java.net.http.HttpClient
.newBuilder()
.connectTimeout(connectTimeout.toJavaDuration())
.followRedirects(java.net.http.HttpClient.Redirect.NEVER)
.build()

private val uri = URI.create("$baseUrl/rest/v1/distribuerjournalpost")

override suspend fun distribuerDokument(
journalpostId: JournalpostId,
correlationId: CorrelationId,
): Either<KunneIkkeDistribuereDokument, DistribusjonId> {
return withContext(Dispatchers.IO) {
val jsonPayload = journalpostId.toDokdistRequest()
Either
.catch {
val request = createRequest(jsonPayload, correlationId)
val httpResponse = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).await()
httpResponse.body().dokdistResponseToDomain(log)
}.mapLeft {
// Either.catch slipper igjennom CancellationException som er ønskelig.
log.error(it) { "Feil ved kall til dokdist. journalpostId: $journalpostId. Se sikkerlogg for detaljer." }
sikkerlogg.error(it) { "Feil ved kall til dokdist. journalpostId: $journalpostId. . jsonPayload: $jsonPayload, uri: $uri" }
KunneIkkeDistribuereDokument
}.flatten()
}
}

private suspend fun createRequest(
jsonPayload: String,
correlationId: CorrelationId,
): HttpRequest? =
HttpRequest
.newBuilder()
.uri(uri)
.timeout(timeout.toJavaDuration())
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("Authorization", "Bearer ${getToken().value}")
.header("Nav-CallId", correlationId.value)
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package no.nav.tiltakspenger.vedtak.clients.dokdist

import no.nav.tiltakspenger.felles.journalføring.JournalpostId
import no.nav.tiltakspenger.vedtak.routes.serialize

private data class DokdistRequest(
val journalpostId: String,
val bestillendeFagsystem: String = "IND",
val dokumentProdApp: String = "Tiltakspenger",
val distribusjonstype: DistribusjonsType = DistribusjonsType.VEDTAK,
val distribusjonstidspunkt: Distribusjonstidspunkt = Distribusjonstidspunkt.KJERNETID,
) {
enum class DistribusjonsType {
VEDTAK,
VIKTIG,
ANNET,
}

enum class Distribusjonstidspunkt {
UMIDDELBART,
KJERNETID,
}
}

fun JournalpostId.toDokdistRequest(): String {
return DokdistRequest(
journalpostId = this.toString(),
).let {
serialize(it)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package no.nav.tiltakspenger.vedtak.clients.dokdist

import arrow.core.Either
import mu.KLogger
import no.nav.tiltakspenger.distribusjon.domene.DistribusjonId
import no.nav.tiltakspenger.distribusjon.ports.KunneIkkeDistribuereDokument
import no.nav.tiltakspenger.vedtak.db.deserialize

private data class DokdistResponse(
val bestillingsId: String,
)

internal fun String.dokdistResponseToDomain(log: KLogger): Either<KunneIkkeDistribuereDokument, DistribusjonId> {
return Either.catch { DistribusjonId(deserialize<DokdistResponse>(this).bestillingsId) }
.mapLeft {
log.error(it) { "Kunne ikke deserialisere respons fra dokdist. forventet 'bestillingsId'. jsonResponse: $this" }
KunneIkkeDistribuereDokument
}
}
Loading
Loading