-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toggle på å gå mot Saf direkte enn via dp-proxy
- Loading branch information
Showing
13 changed files
with
187 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/JournalPostQuery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package no.nav.dagpenger.mottak.behov.journalpost | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import no.nav.dagpenger.mottak.behov.GraphqlQuery | ||
|
||
internal data class JournalPostQuery( | ||
@JsonIgnore val journalpostId: String, | ||
) : GraphqlQuery( | ||
//language=Graphql | ||
query = | ||
""" | ||
query(${'$'}journalpostId: String!) { | ||
journalpost(journalpostId: ${'$'}journalpostId) { | ||
journalstatus | ||
journalpostId | ||
journalfoerendeEnhet | ||
datoOpprettet | ||
behandlingstema | ||
bruker { | ||
type | ||
id | ||
} | ||
relevanteDatoer { | ||
dato | ||
datotype | ||
} | ||
dokumenter { | ||
tittel | ||
dokumentInfoId | ||
brevkode | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
variables = | ||
mapOf( | ||
"journalpostId" to journalpostId, | ||
), | ||
) |
5 changes: 5 additions & 0 deletions
5
mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/JournalpostArkiv.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package no.nav.dagpenger.mottak.behov.journalpost | ||
|
||
internal interface JournalpostArkiv { | ||
suspend fun hentJournalpost(journalpostId: String): SafGraphQL.Journalpost | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/SafProxyClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package no.nav.dagpenger.mottak.behov.journalpost | ||
|
||
import com.natpryce.konfig.Configuration | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.plugins.ClientRequestException | ||
import io.ktor.client.request.header | ||
import io.ktor.client.request.request | ||
import io.ktor.client.request.setBody | ||
import io.ktor.client.statement.bodyAsText | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.HttpStatusCode | ||
import mu.KotlinLogging | ||
import no.nav.dagpenger.mottak.Config.dpProxyTokenProvider | ||
import no.nav.dagpenger.mottak.Config.dpProxyUrl | ||
|
||
internal class SafProxyClient(config: Configuration) : JournalpostArkiv, SøknadsArkiv { | ||
companion object { | ||
private val logger = KotlinLogging.logger {} | ||
} | ||
|
||
private val tokenProvider = config.dpProxyTokenProvider | ||
private val dpProxyUrl = config.dpProxyUrl() | ||
|
||
private val proxyJoarkClient = | ||
HttpClient { | ||
expectSuccess = true | ||
} | ||
|
||
private val proxySøknadsDataClient = | ||
HttpClient { | ||
expectSuccess = true | ||
} | ||
|
||
override suspend fun hentJournalpost(journalpostId: String): SafGraphQL.Journalpost = | ||
proxyJoarkClient.request("$dpProxyUrl//proxy/v1/saf/graphql") { | ||
header("Content-Type", "application/json") | ||
header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}") | ||
method = HttpMethod.Post | ||
setBody(JournalPostQuery(journalpostId).toJson()) | ||
}.let { | ||
SafGraphQL.Journalpost.fromGraphQlJson(it.bodyAsText()) | ||
} | ||
|
||
override suspend fun hentSøknadsData( | ||
journalpostId: String, | ||
dokumentInfoId: String, | ||
): SafGraphQL.SøknadsData = | ||
try { | ||
proxySøknadsDataClient.request("$dpProxyUrl/proxy/v1/saf/rest/hentdokument/$journalpostId/$dokumentInfoId/ORIGINAL") { | ||
header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}") | ||
method = HttpMethod.Get | ||
}.let { | ||
SafGraphQL.SøknadsData.fromJson(it.bodyAsText()) | ||
} | ||
} catch (exception: ClientRequestException) { | ||
if (exception.response.status == HttpStatusCode.NotFound) { | ||
logger.warn(exception) { "Fant ikke dokumentInfo for journalpostId $journalpostId med dokumentinfoId $dokumentInfoId" } | ||
SafGraphQL.SøknadsData.fromJson("{}") | ||
} else { | ||
throw exception | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/SøknadsArkiv.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package no.nav.dagpenger.mottak.behov.journalpost | ||
|
||
internal interface SøknadsArkiv { | ||
suspend fun hentSøknadsData( | ||
journalpostId: String, | ||
dokumentInfoId: String, | ||
): SafGraphQL.SøknadsData | ||
} |
32 changes: 32 additions & 0 deletions
32
mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/UnleashSafClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package no.nav.dagpenger.mottak.behov.journalpost | ||
|
||
import com.natpryce.konfig.Configuration | ||
import io.getunleash.Unleash | ||
|
||
internal class UnleashSafClient(config: Configuration, private val unleash: Unleash) : JournalpostArkiv, SøknadsArkiv { | ||
private val proxy = SafProxyClient(config) | ||
private val safClient = SafClient(config) | ||
|
||
companion object { | ||
const val TOGGLE = "bruk-saf-client" | ||
} | ||
|
||
override suspend fun hentJournalpost(journalpostId: String): SafGraphQL.Journalpost { | ||
return if (unleash.isEnabled(TOGGLE)) { | ||
safClient.hentJournalpost(journalpostId) | ||
} else { | ||
proxy.hentJournalpost(journalpostId) | ||
} | ||
} | ||
|
||
override suspend fun hentSøknadsData( | ||
journalpostId: String, | ||
dokumentInfoId: String, | ||
): SafGraphQL.SøknadsData { | ||
return if (unleash.isEnabled(TOGGLE)) { | ||
safClient.hentSøknadsData(journalpostId, dokumentInfoId) | ||
} else { | ||
proxy.hentSøknadsData(journalpostId, dokumentInfoId) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters