Skip to content

Commit

Permalink
Legg til hentPersonBolk for effektiv beskyttelseshenting (#1274)
Browse files Browse the repository at this point in the history
* Legg til hentPersonBolk for effektiv beskyttelseshenting

* Fjerne en del imports
  • Loading branch information
jolarsen authored Mar 29, 2023
1 parent b88921a commit 65c61bb
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@
import no.nav.vedtak.sikkerhet.oidc.validator.OidcTokenValidator;
import no.nav.vedtak.sikkerhet.oidc.validator.OidcTokenValidatorConfig;
import no.nav.vedtak.sikkerhet.oidc.validator.OidcTokenValidatorResult;
import org.jose4j.jwt.MalformedClaimException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import java.lang.reflect.Method;
import java.time.Instant;
import java.util.Optional;

/**
* Bruksanvisning inntil alle er over og det evt samles her:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
package no.nav.vedtak.felles.integrasjon.person;

import java.net.HttpURLConnection;
import java.net.http.HttpRequest;
import java.util.List;
import java.util.Set;

import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequest;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult;

import no.nav.pdl.*;
import no.nav.pdl.GeografiskTilknytning;
import no.nav.pdl.GeografiskTilknytningResponseProjection;
import no.nav.pdl.HentGeografiskTilknytningQueryRequest;
import no.nav.pdl.HentGeografiskTilknytningQueryResponse;
import no.nav.pdl.HentIdenterBolkQueryRequest;
import no.nav.pdl.HentIdenterBolkQueryResponse;
import no.nav.pdl.HentIdenterBolkResult;
import no.nav.pdl.HentIdenterBolkResultResponseProjection;
import no.nav.pdl.HentIdenterQueryRequest;
import no.nav.pdl.HentIdenterQueryResponse;
import no.nav.pdl.HentPersonBolkQueryRequest;
import no.nav.pdl.HentPersonBolkQueryResponse;
import no.nav.pdl.HentPersonBolkResult;
import no.nav.pdl.HentPersonBolkResultResponseProjection;
import no.nav.pdl.HentPersonQueryRequest;
import no.nav.pdl.HentPersonQueryResponse;
import no.nav.pdl.Identliste;
import no.nav.pdl.IdentlisteResponseProjection;
import no.nav.pdl.Person;
import no.nav.pdl.PersonResponseProjection;
import no.nav.vedtak.felles.integrasjon.rest.RestClient;
import no.nav.vedtak.felles.integrasjon.rest.RestConfig;
import no.nav.vedtak.felles.integrasjon.rest.RestRequest;
import no.nav.vedtak.felles.integrasjon.rest.TokenFlow;

import java.net.HttpURLConnection;
import java.net.http.HttpRequest;
import java.util.List;
import java.util.Set;

public abstract class AbstractPersonKlient implements Persondata {

private static Set<TokenFlow> REQUIRED_TOKEN = Set.of(TokenFlow.ADAPTIVE_ADD_CONSUMER);
Expand Down Expand Up @@ -66,6 +85,11 @@ public Person hentPerson(HentPersonQueryRequest q, PersonResponseProjection p, b
}
}

@Override
public List<HentPersonBolkResult> hentPersonBolk(HentPersonBolkQueryRequest q, HentPersonBolkResultResponseProjection p) {
return query(q, p, HentPersonBolkQueryResponse.class).hentPersonBolk();
}

@Override
public Identliste hentIdenter(HentIdenterQueryRequest q, IdentlisteResponseProjection p) {
return query(q, p, HentIdenterQueryResponse.class).hentIdenter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import no.nav.pdl.HentIdenterBolkResult;
import no.nav.pdl.HentIdenterBolkResultResponseProjection;
import no.nav.pdl.HentIdenterQueryRequest;
import no.nav.pdl.HentPersonBolkQueryRequest;
import no.nav.pdl.HentPersonBolkResult;
import no.nav.pdl.HentPersonBolkResultResponseProjection;
import no.nav.pdl.HentPersonQueryRequest;
import no.nav.pdl.IdentGruppe;
import no.nav.pdl.IdentInformasjon;
Expand Down Expand Up @@ -61,6 +64,8 @@ public interface Persondata {

Person hentPerson(HentPersonQueryRequest q, PersonResponseProjection p, boolean ignoreNotFound);

List<HentPersonBolkResult> hentPersonBolk(HentPersonBolkQueryRequest q, HentPersonBolkResultResponseProjection p);

GeografiskTilknytning hentGT(HentGeografiskTilknytningQueryRequest q, GeografiskTilknytningResponseProjection p);

<T extends GraphQLResult<?>> T query(GraphQLOperationRequest q, GraphQLResponseProjection p, Class<T> clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@

import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLError;

import no.nav.pdl.AdressebeskyttelseGradering;
import no.nav.pdl.AdressebeskyttelseResponseProjection;
import no.nav.pdl.HentIdenterBolkQueryRequest;
import no.nav.pdl.HentIdenterBolkQueryResponse;
import no.nav.pdl.HentIdenterBolkResultResponseProjection;
import no.nav.pdl.HentIdenterQueryRequest;
import no.nav.pdl.HentIdenterQueryResponse;
import no.nav.pdl.HentPersonBolkQueryRequest;
import no.nav.pdl.HentPersonBolkQueryResponse;
import no.nav.pdl.HentPersonBolkResultResponseProjection;
import no.nav.pdl.HentPersonQueryRequest;
import no.nav.pdl.HentPersonQueryResponse;
import no.nav.pdl.IdentInformasjon;
Expand Down Expand Up @@ -79,6 +84,28 @@ void skal_returnere_person() {
assertThat(rq.validateDelayedHeaders(Set.of("Authorization", "Nav-Consumer-Token", "Nav-Consumer-Id"))).isTrue();
}

@Test
void skal_returnere_bolk_med_person() {
var resource = getClass().getClassLoader().getResource("pdl/personBolkResponse.json");
var response = DefaultJsonMapper.fromJson(resource, HentPersonBolkQueryResponse.class);
when(restClient.send(any(RestRequest.class), any())).thenReturn(response);


var query = new HentPersonBolkQueryRequest();
query.setIdenter(List.of("12345678901"));
var projection = new HentPersonBolkResultResponseProjection()
.person(new PersonResponseProjection()
.navn(new NavnResponseProjection().fornavn())
.adressebeskyttelse(new AdressebeskyttelseResponseProjection().gradering()));

var personer = pdlKlient.hentPersonBolk(query, projection);

assertThat(personer).hasSize(1);
assertThat(personer.get(0).getIdent()).isEqualTo("12345678901");
assertThat(personer.get(0).getPerson().getAdressebeskyttelse()).hasSize(1);
assertThat(personer.get(0).getPerson().getAdressebeskyttelse().get(0).getGradering()).isEqualTo(AdressebeskyttelseGradering.UGRADERT);
}

@Test
void skal_returnere_ident() {
var resource = getClass().getClassLoader().getResource("pdl/identerResponse.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"data": {
"hentPersonBolk": [
{
"ident": "12345678901",
"person": {
"navn": [
{
"fornavn": "Jul",
"etternavn": "Nissen",
"mellomnavn": "E."
}
],
"adressebeskyttelse": [
{
"gradering": "UGRADERT"
}
]
}
}
]
}
}

0 comments on commit 65c61bb

Please sign in to comment.