-
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.
Merge pull request #52 from navikt/dev/flytte-kotlin-clients
Dev/flytte kotlin clients
- Loading branch information
Showing
52 changed files
with
2,531 additions
and
37 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# paw-aareg-client | ||
|
||
Henter arbeidsforhold fra Arbeidsgiver- og arbeidstakerregisteret ([aareg](https://navikt.github.io/aareg/)). | ||
|
||
Se URL-er på https://github.com/navikt/aareg-services | ||
|
||
Se dokumentasjon for aareg på https://aareg-services.dev.intern.nav.no/swagger-ui/index.html | ||
|
||
### Bruk av paw-aareg-client | ||
|
||
**_gradle.build.kts_** | ||
|
||
```kts | ||
val tokenproviderVersion: String by project | ||
val aaregClientVersion: String by project | ||
|
||
dependencies { | ||
implementation("no.nav.paw:tokenprovider:$tokenproviderVersion") | ||
implementation("no.nav.paw:aareg-client:$aaregClientVersion") | ||
} | ||
``` | ||
|
||
### Klienten instansieres slik | ||
|
||
```kt | ||
import kotlinx.coroutines.runBlocking | ||
import no.nav.paw.tokenprovider.OAuth2TokenProvider | ||
import no.nav.paw.aareg.AaregClient | ||
|
||
fun main() { | ||
val url = "https://modapp-q1.adeo.no/aareg-services" | ||
val tokenProvider = OAuth2TokenProvider( | ||
// Token config | ||
) | ||
|
||
val aaregClient = AaregClient(url) { tokenProvider.getToken() } | ||
|
||
val arbeidsforhold = runBlocking { aaregClient.hentArbeidsforhold("fnr", "callId") } | ||
println(arbeidsforhold) | ||
} | ||
``` |
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,28 @@ | ||
plugins { | ||
kotlin("jvm") | ||
kotlin("plugin.serialization") | ||
} | ||
|
||
val jvmMajorVersion: String by project | ||
|
||
dependencies { | ||
api(libs.kotlinx.serialization.json) | ||
|
||
implementation(libs.ktor.client.contentNegotiation) | ||
implementation(libs.ktor.client.okhttp) | ||
implementation(libs.ktor.serialization.kotlinx.json) | ||
implementation(libs.ktor.client.logging) | ||
|
||
testImplementation(libs.bundles.testLibsWithUnitTesting) | ||
testImplementation(libs.ktor.client.mock) | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(jvmMajorVersion)) | ||
} | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
useJUnitPlatform() | ||
} |
53 changes: 53 additions & 0 deletions
53
lib/aareg-client/src/main/kotlin/no/nav/paw/aareg/AaregClient.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,53 @@ | ||
package no.nav.paw.aareg | ||
|
||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.ResponseException | ||
import io.ktor.client.request.bearerAuth | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.header | ||
import io.ktor.client.statement.bodyAsText | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.contentType | ||
import io.ktor.serialization.JsonConvertException | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.net.ConnectException | ||
|
||
/** | ||
* klient for å hente ut aktive arbeidsforhold på en person | ||
*/ | ||
|
||
class AaregClient( | ||
private val url: String, | ||
private val getAccessToken: () -> String | ||
) { | ||
private val sikkerLogger: Logger = LoggerFactory.getLogger("tjenestekall") | ||
private val logger: Logger = LoggerFactory.getLogger("paw-aareg-client") | ||
private val httpClient = createHttpClient() | ||
|
||
suspend fun hentArbeidsforhold(ident: String, callId: String): List<Arbeidsforhold> { | ||
val token = getAccessToken() | ||
try { | ||
val payload = httpClient.get(url) { | ||
contentType(ContentType.Application.Json) | ||
bearerAuth(token) | ||
header("Nav-Call-Id", callId) | ||
header("Nav-Personident", ident) | ||
}.also { | ||
logger.info("Hentet arbeidsforhold fra aareg med status=${it.status}") | ||
sikkerLogger.debug("Svar fra aareg-API: " + it.bodyAsText()) | ||
}.body<List<Arbeidsforhold>>() | ||
return payload | ||
} catch (responseException: ResponseException) { | ||
logger.error("Hente arbeidsforhold callId=[$callId] feilet med http-kode ${responseException.response.status}") | ||
throw responseException | ||
} catch (connectException: ConnectException) { | ||
logger.error("Hente arbeidsforhold callId=[$callId] feilet:", connectException) | ||
throw connectException | ||
} catch (jsonConvertException: JsonConvertException) { | ||
logger.error("Hente arbeidsforhold callId=[$callId] feilet, kunne ikke lese JSON") | ||
sikkerLogger.error("Hente arbeidsforhold callId=[$callId] feilet", jsonConvertException) | ||
throw jsonConvertException | ||
} | ||
} | ||
} |
Oops, something went wrong.