Skip to content

Commit

Permalink
Bytt til M2M token mot syfo
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikpe committed Nov 12, 2024
1 parent 285d861 commit 98e21aa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit
class IsoppfolgingstilfelleClient(
private val baseUrl: String,
private val tokenProvider: TokenProvider,
clientEngine: HttpClientEngine = CIO.create(),
clientEngine: HttpClientEngine,
) {
private val log = LoggerFactory.getLogger(javaClass)
private val personIdentHeader = "nav-personident"
Expand All @@ -40,23 +40,23 @@ class IsoppfolgingstilfelleClient(
.recordStats()
.build()

suspend fun erSykmeldtMedArbeidsgiver(
norskIdent: NorskIdent,
obo: AccessType.OBO,
): Either<OppfolgingstilfelleError, Boolean> {
suspend fun erSykmeldtMedArbeidsgiver(norskIdent: NorskIdent): Either<OppfolgingstilfelleError, Boolean> {
erSykmeldtMedArbeidsgiverCache.getIfPresent(norskIdent)?.let { return@erSykmeldtMedArbeidsgiver it.right() }

return hentOppfolgingstilfeller(norskIdent, obo)
return hentOppfolgingstilfeller(norskIdent)
.map { oppfolgingstilfeller ->
oppfolgingstilfeller
.filter { it.gyldigForDato(LocalDate.now()) }
.firstOrNull { it.arbeidstakerAtTilfelleEnd } != null
}
.onRight {
erSykmeldtMedArbeidsgiverCache.put(norskIdent, it)
}
}

private suspend fun hentOppfolgingstilfeller(norskIdent: NorskIdent, obo: AccessType.OBO): Either<OppfolgingstilfelleError, List<OppfolgingstilfelleDTO>> {
val response = client.get("$baseUrl/api/internad/v1/oppfolgingstilfelle/personident") {
bearerAuth(tokenProvider.exchange(obo))
private suspend fun hentOppfolgingstilfeller(norskIdent: NorskIdent): Either<OppfolgingstilfelleError, List<OppfolgingstilfelleDTO>> {
val response = client.get("$baseUrl/api/system/v1/oppfolgingstilfelle/personident") {
bearerAuth(tokenProvider.exchange(AccessType.M2M))
header(personIdentHeader, norskIdent.value)
contentType(ContentType.Application.Json)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BrukerService(
val deferredSisteVedtak = async { veilarbvedtaksstotteClient.hentSiste14AVedtak(fnr, obo) }
val deferredPdlPerson = async { pdlClient.hentPerson(PdlIdent(fnr.value), obo) }
val deferredBrukersGeografiskeEnhet = async { hentBrukersGeografiskeEnhet(fnr, obo) }
val deferredErSykmeldtMedArbeidsgiver = async { isoppfolgingstilfelleClient.erSykmeldtMedArbeidsgiver(fnr, obo) }
val deferredErSykmeldtMedArbeidsgiver = async { isoppfolgingstilfelleClient.erSykmeldtMedArbeidsgiver(fnr) }

val erUnderOppfolging = deferredErUnderOppfolging.await()
.getOrElse {
Expand Down Expand Up @@ -141,7 +141,11 @@ class BrukerService(
val erSykmeldtMedArbeidsgiver = deferredErSykmeldtMedArbeidsgiver.await()
.getOrElse {
when (it) {
OppfolgingstilfelleError.Forbidden -> false
OppfolgingstilfelleError.Forbidden ->
throw StatusException(
HttpStatusCode.InternalServerError,
"Manglet tilgang til å hente oppfølgingstilfeller.",
)
OppfolgingstilfelleError.Error ->
throw StatusException(
HttpStatusCode.InternalServerError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BrukerServiceTest : FunSpec({
coEvery { veilarboppfolgingClient.hentOppfolgingsenhet(fnr1, any()) } returns mockOppfolgingsenhet().right()

coEvery { veilarboppfolgingClient.hentManuellStatus(fnr1, any()) } returns mockManuellStatus().right()
coEvery { isoppfolgingstilfelleClient.erSykmeldtMedArbeidsgiver(fnr1, any()) } returns true.right()
coEvery { isoppfolgingstilfelleClient.erSykmeldtMedArbeidsgiver(fnr1) } returns true.right()

coEvery { veilarbvedtaksstotteClient.hentSiste14AVedtak(fnr1, any()) } answers {
VedtakDto(innsatsgruppe = VedtakDto.Innsatsgruppe.STANDARD_INNSATS).right()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"method": "GET",
"urlPattern": "/isoppfolgingstilfelle/api/internad/v1/oppfolgingstilfelle/personident"
"urlPattern": "/isoppfolgingstilfelle/api/system/v1/oppfolgingstilfelle/personident"
},
"response": {
"status": 200,
Expand Down

0 comments on commit 98e21aa

Please sign in to comment.