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

hentIdenter #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package no.nav.dagpenger.pdl

import no.nav.dagpenger.pdl.entity.IdentInformasjon
import no.nav.dagpenger.pdl.entity.Identliste

class PDLIdentliste(identliste: Identliste) {
class PDLException(msg: String?) : RuntimeException(msg)

val identer: List<PDLIdent> = identliste.identer.map { ident -> PDLIdent(ident) }
}

class PDLIdent(identInformasjon: IdentInformasjon) {
enum class PDLIdentGruppe {
AKTORID,
FOLKEREGISTERIDENT,
NPID,
}

val ident: String = identInformasjon.ident
val gruppe: PDLIdentGruppe = PDLIdentGruppe.valueOf(identInformasjon.gruppe.toString())
val historisk: Boolean = identInformasjon.historisk
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import kotlinx.coroutines.runBlocking
import no.nav.dagpenger.pdl.adapter.KtorHttpClientAdapter
import no.nav.dagpenger.pdl.adapter.proxyAwareHttpClient
import no.nav.dagpenger.pdl.dto.ForelderBarnRelasjonRolle
import no.nav.dagpenger.pdl.dto.IdentGruppe
import no.nav.dagpenger.pdl.queries.hentIdenter
import no.nav.dagpenger.pdl.queries.hentPerson
import no.nav.dagpenger.pdl.queries.hentPersonBolk

Expand All @@ -18,6 +20,13 @@ interface PersonOppslag {
fnr: String,
headersMap: Map<String, String>,
): PDLPerson

fun hentIdenter(
ident: String,
grupper: List<String>,
historikk: Boolean,
headersMap: Map<String, String>,
): PDLIdentliste
}

interface PersonOppslagBolk {
Expand Down Expand Up @@ -133,5 +142,23 @@ fun createPersonOppslag(
): PDLPerson {
return runBlocking { hentPerson(fnr, headersMap) }
}

override fun hentIdenter(
ident: String,
grupper: List<String>,
historikk: Boolean,
headersMap: Map<String, String>,
): PDLIdentliste {
val pdlContext = pdlContextOf(KtorHttpClientAdapter(url, headersMap, httpClient))

val pdlGrupper = grupper.map { gruppe -> IdentGruppe.valueOf(gruppe) }

return runBlocking {
pdlContext.query { hentIdenter(ident, pdlGrupper, historikk) }
.hentIdenter
?.let(::PDLIdentliste)
?: throw PDLIdentliste.PDLException("Ukjent feil")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.nav.dagpenger.pdl.queries

import no.nav.dagpenger.pdl.dto.IdentGruppe
import no.nav.dagpenger.pdl.entity.IdentlisteProjection
import no.nav.dagpenger.pdl.entity.MatrikkeladresseProjection
import no.nav.dagpenger.pdl.entity.PersonProjection
import no.nav.dagpenger.pdl.entity.QueryProjection
Expand All @@ -21,6 +23,16 @@ fun QueryProjection.hentPerson(fnr: String) {
}
}

fun QueryProjection.hentIdenter(
ident: String,
grupper: List<IdentGruppe>? = null,
historikk: Boolean? = null,
) {
hentIdenter(ident, grupper, historikk) {
identerDetailsFragment()
}
}

fun MatrikkeladresseProjection.matrikkeladresseDetailsFragment() {
matrikkelId()
bruksenhetsnummer()
Expand Down Expand Up @@ -172,3 +184,11 @@ fun PersonProjection.personDetailsFragment() {
}
}
}

fun IdentlisteProjection.identerDetailsFragment() {
identer {
ident()
gruppe()
historisk()
}
}
43 changes: 43 additions & 0 deletions pdl-klient/src/test/kotlin/no/nav/dagpenger/pdl/ClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ class ClientTest {
}
}

@Test
fun `Bruk token x for å hente ut identifikatorer`() {
val accessToken =
tokenXClient.tokenExchange(
token = """""",
audience = "",
).access_token

val client =
createPersonOppslag(
url = "https://pdl-api.dev.intern.nav.no/graphql",
httpClient = httpClient,
)
runBlocking {
client.hentIdenter(
ident = "01038401226",
grupper = emptyList(),
historikk = false,
headersMap = mapOf(HttpHeaders.Authorization to "Bearer $accessToken"),
)
}
}

@Test
fun `Bruk azure ad client credentials for å hente ut personer`() {
val client =
Expand Down Expand Up @@ -129,4 +152,24 @@ class ClientTest {
).also { println(it) }
}
}

@Test
fun `Bruk azure ad client credentials for å hente ut identifikatorer`() {
val personOppslag =
createPersonOppslag(
url = "https://pdl-api.dev.intern.nav.no/graphql",
httpClient = httpClient,
)
runBlocking {
personOppslag.hentIdenter(
"14108009241",
emptyList(),
true,
mapOf(
HttpHeaders.Authorization to
"Bearer ${azureAdClient.clientCredentials("api://dev-fss.pdl.pdl-api/.default").access_token}",
),
).also { println(it) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package no.nav.dagpenger.pdl

import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.mockk.every
import io.mockk.mockk
import no.nav.dagpenger.pdl.dto.IdentGruppe
import no.nav.dagpenger.pdl.entity.IdentInformasjon
import no.nav.dagpenger.pdl.entity.Identliste
import org.junit.jupiter.api.Test

class PDLIdentlisteTest {
@Test
fun `kan opprette PDLIdentliste`() {
val identInformasjon1 = mockk<IdentInformasjon>()
every { identInformasjon1.ident } returns "1"
every { identInformasjon1.gruppe } returns IdentGruppe.AKTORID
every { identInformasjon1.historisk } returns true

val identInformasjon2 = mockk<IdentInformasjon>()
every { identInformasjon2.ident } returns "2"
every { identInformasjon2.gruppe } returns IdentGruppe.NPID
every { identInformasjon2.historisk } returns true

val identInformasjon3 = mockk<IdentInformasjon>()
every { identInformasjon3.ident } returns "3"
every { identInformasjon3.gruppe } returns IdentGruppe.FOLKEREGISTERIDENT
every { identInformasjon3.historisk } returns false

val identliste = mockk<Identliste>()
every { identliste.identer } returns listOf(identInformasjon1, identInformasjon2, identInformasjon3)

val pdlIdentliste = PDLIdentliste(identliste)

pdlIdentliste.identer shouldNotBe null
pdlIdentliste.identer.size shouldBe 3
pdlIdentliste.identer[0].ident shouldBe "1"
pdlIdentliste.identer[0].gruppe shouldBe PDLIdent.PDLIdentGruppe.AKTORID
pdlIdentliste.identer[0].historisk shouldBe true
pdlIdentliste.identer[1].ident shouldBe "2"
pdlIdentliste.identer[1].gruppe shouldBe PDLIdent.PDLIdentGruppe.NPID
pdlIdentliste.identer[1].historisk shouldBe true
pdlIdentliste.identer[2].ident shouldBe "3"
pdlIdentliste.identer[2].gruppe shouldBe PDLIdent.PDLIdentGruppe.FOLKEREGISTERIDENT
pdlIdentliste.identer[2].historisk shouldBe false
}
}
Loading