Skip to content

Commit

Permalink
Feature/pdl person oppslag til person service (#3299)
Browse files Browse the repository at this point in the history
PDL-person hentes fra person-service
  • Loading branch information
krharum authored Oct 4, 2023
1 parent 64373d6 commit ac0c717
Show file tree
Hide file tree
Showing 94 changed files with 501 additions and 1,333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.brregstub.domain.RolleoversiktTo;
import no.nav.dolly.bestilling.brregstub.util.BrregstubMergeUtil;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
Expand All @@ -35,7 +35,7 @@ public class BrregstubClient implements ClientRegister {
private static final String FEIL_STATUS = "Feil= ";

private final BrregstubConsumer brregstubConsumer;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;
private final MapperFacade mapperFacade;
private final TransactionHelperService transactionHelperService;

Expand Down Expand Up @@ -65,7 +65,7 @@ public void release(List<String> identer) {

private Flux<PdlPersonBolk.PersonBolk> getPersonData(String ident) {

return pdlPersonConsumer.getPdlPersoner(List.of(ident))
return personServiceConsumer.getPdlPersoner(List.of(ident))
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import no.nav.dolly.bestilling.dokarkiv.domain.DokarkivRequest;
import no.nav.dolly.bestilling.dokarkiv.domain.DokarkivResponse;
import no.nav.dolly.bestilling.dokarkiv.domain.JoarkTransaksjon;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.jpa.TransaksjonMapping;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class DokarkivClient implements ClientRegister {
private final TransaksjonMappingService transaksjonMappingService;
private final ObjectMapper objectMapper;
private final TransactionHelperService transactionHelperService;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;
private final ErrorStatusDecoder errorStatusDecoder;

@Override
Expand Down Expand Up @@ -103,7 +103,7 @@ public void release(List<String> identer) {

private Flux<PdlPersonBolk.PersonBolk> getPersonData(List<String> identer) {

return pdlPersonConsumer.getPdlPersoner(identer)
return personServiceConsumer.getPdlPersoner(identer)
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonTpYtelseRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonUforetrygdRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonforvalterResponse;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.domain.PdlPerson;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
Expand Down Expand Up @@ -80,7 +80,7 @@ public class PensjonforvalterClient implements ClientRegister {
private final MapperFacade mapperFacade;
private final ErrorStatusDecoder errorStatusDecoder;
private final TransactionHelperService transactionHelperService;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;
private final PdlDataConsumer pdlDataConsumer;
private final TransaksjonMappingService transaksjonMappingService;
private final ObjectMapper objectMapper;
Expand Down Expand Up @@ -267,7 +267,7 @@ private Flux<String> getIdenterRelasjoner(String ident) {

private Flux<PdlPersonBolk.PersonBolk> getPersonData(List<String> identer) {

return pdlPersonConsumer.getPdlPersoner(identer)
return personServiceConsumer.getPdlPersoner(identer)
.doOnNext(bolk -> {
if (isNull(bolk.getData()) || bolk.getData().getHentPersonBolk().stream()
.anyMatch(personBolk -> isNull(personBolk.getPerson()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.personservice.dto.PersonServiceResponse;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.domain.PdlPerson;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
Expand Down Expand Up @@ -51,7 +50,6 @@ public class PersonServiceClient {
private final PersonServiceConsumer personServiceConsumer;
private final ErrorStatusDecoder errorStatusDecoder;
private final TransactionHelperService transactionHelperService;
private final PdlPersonConsumer pdlPersonConsumer;
private final ObjectMapper objectMapper;

public Flux<ClientFuture> syncPerson(DollyPerson dollyPerson, BestillingProgress progress) {
Expand Down Expand Up @@ -127,7 +125,7 @@ private Flux<Map.Entry<String, Set<String>>> getIdentWithRelasjoner(DollyPerson
} else {

return Flux.concat(Flux.just(Map.entry(dollyPerson.getIdent(), new HashSet<>())),
pdlPersonConsumer.getPdlPersoner(List.of(dollyPerson.getIdent()))
personServiceConsumer.getPdlPersoner(List.of(dollyPerson.getIdent()))
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
package no.nav.dolly.bestilling.personservice;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.channel.ChannelOption;
import no.nav.dolly.bestilling.ConsumerStatus;
import no.nav.dolly.bestilling.personservice.command.PdlPersonerGetCommand;
import no.nav.dolly.bestilling.personservice.command.PersonServiceExistCommand;
import no.nav.dolly.bestilling.personservice.dto.PersonServiceResponse;
import no.nav.dolly.config.credentials.PersonServiceProperties;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.metrics.Timed;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;

import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import static java.util.Objects.isNull;
import static no.nav.dolly.util.JacksonExchangeStrategyUtil.getJacksonStrategy;

@Service
public class PersonServiceConsumer implements ConsumerStatus {

private static final int BLOCK_SIZE = 100;
private static final int MAX_RETRIES = 3;

private final TokenExchange tokenService;
private final WebClient webClient;
private final ServerProperties serviceProperties;

public PersonServiceConsumer(
TokenExchange tokenService,
PersonServiceProperties serverProperties,
WebClient.Builder webClientBuilder
) {
WebClient.Builder webClientBuilder,
ObjectMapper objectMapper) {

this.tokenService = tokenService;
this.serviceProperties = serverProperties;
this.webClient = webClientBuilder
.clientConnector(new ReactorClientHttpConnector(HttpClient.create()
.baseUrl(serverProperties.getUrl())
.exchangeStrategies(getJacksonStrategy(objectMapper))
.clientConnector(new ReactorClientHttpConnector(HttpClient.create(
ConnectionProvider.builder("custom")
.maxConnections(10)
.pendingAcquireMaxCount(5000)
.pendingAcquireTimeout(Duration.ofMinutes(15))
.build())
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)))
.baseUrl(serverProperties.getUrl())
.build();
Expand All @@ -44,6 +66,46 @@ public Mono<PersonServiceResponse> isPerson(String ident, Set<String> opplysning
.flatMap(token -> new PersonServiceExistCommand(webClient, ident, opplysningId, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = {"operation", "pdl_getPersoner"})
public Flux<PdlPersonBolk> getPdlPersoner(List<String> identer) {

return getPdlPersoner(identer, new AtomicInteger(0));
}

@Timed(name = "providers", tags = {"operation", "pdl_getPersoner"})
public Flux<PdlPersonBolk> getPdlPersonerNoRetries(List<String> identer) {

return getPdlPersoner(identer, new AtomicInteger(MAX_RETRIES));
}

@Timed(name = "providers", tags = {"operation", "pdl_getPersoner"})
public Flux<PdlPersonBolk> getPdlPersoner(List<String> identer, AtomicInteger retry) {

return tokenService.exchange(serviceProperties)
.flatMapMany(token -> Flux.range(0, identer.size() / BLOCK_SIZE + 1)
.flatMap(index -> new PdlPersonerGetCommand(webClient,
identer.subList(index * BLOCK_SIZE, Math.min((index + 1) * BLOCK_SIZE, identer.size())),
token.getTokenValue()
).call()))

.flatMap(resultat -> {

if (retry.get() < MAX_RETRIES &&
(isNull(resultat.getData()) || resultat.getData().getHentPersonBolk().stream()
.anyMatch(data -> isNull(data.getPerson())))) {

return Flux.just(true)
.doOnNext(melding ->
log.info("PDL har tomt resultat for {}, retry #{}", String.join(", ", identer),
retry.incrementAndGet()))
.delayElements(Duration.ofMillis(200))
.flatMap(delay -> getPdlPersoner(identer, new AtomicInteger(retry.get())));
} else {
return Flux.just(resultat);
}
});
}

@Override
public String serviceUrl() {
return serviceProperties.getUrl();
Expand All @@ -53,5 +115,4 @@ public String serviceUrl() {
public String consumerName() {
return "testnav-person-service";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package no.nav.dolly.bestilling.personservice.command;

import lombok.RequiredArgsConstructor;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.util.WebClientFilter;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.Callable;

import static org.springframework.http.HttpHeaders.AUTHORIZATION;

@RequiredArgsConstructor
public class PdlPersonerGetCommand implements Callable<Flux<PdlPersonBolk>> {

private static final String PERSON_SERVICE_URL = "/api/v2/personer/identer";

private final WebClient webClient;
private final List<String> identer;
private final String token;

@Override
public Flux<PdlPersonBolk> call() {

return webClient
.get()
.uri(uriBuilder -> uriBuilder
.path(PERSON_SERVICE_URL)
.queryParam("identer", identer)
.build())
.header(AUTHORIZATION, "Bearer " + token)
.retrieve()
.bodyToFlux(PdlPersonBolk.class)
.doOnError(WebClientFilter::logErrorMessage)
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5))
.filter(WebClientFilter::is5xxException))
.onErrorResume(throwable -> throwable instanceof WebClientResponseException.NotFound,
throwable -> Mono.empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import ma.glasnost.orika.MappingContext;
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.bestilling.skjermingsregister.domain.SkjermingBestilling;
import no.nav.dolly.bestilling.skjermingsregister.domain.SkjermingDataRequest;
import no.nav.dolly.bestilling.skjermingsregister.domain.SkjermingDataResponse;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class SkjermingsRegisterClient implements ClientRegister {
private final SkjermingsRegisterConsumer skjermingsRegisterConsumer;
private final ErrorStatusDecoder errorStatusDecoder;
private final MapperFacade mapperFacade;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;
private final TransactionHelperService transactionHelperService;

@Override
Expand Down Expand Up @@ -78,7 +78,7 @@ private String getStatus(SkjermingDataResponse resultat) {

private Flux<PdlPersonBolk.PersonBolk> getPersonData(String ident) {

return pdlPersonConsumer.getPdlPersoner(List.of(ident))
return personServiceConsumer.getPdlPersoner(List.of(ident))
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import ma.glasnost.orika.MappingContext;
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.bestilling.sykemelding.domain.DetaljertSykemeldingRequest;
import no.nav.dolly.bestilling.sykemelding.domain.SyntSykemeldingRequest;
import no.nav.dolly.bestilling.sykemelding.dto.Norg2EnhetResponse;
import no.nav.dolly.bestilling.sykemelding.dto.SykemeldingResponse;
import no.nav.dolly.consumer.kodeverk.KodeverkConsumer;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.jpa.TransaksjonMapping;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class SykemeldingClient implements ClientRegister {
private final MapperFacade mapperFacade;
private final ObjectMapper objectMapper;
private final TransactionHelperService transactionHelperService;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;
private final KodeverkConsumer kodeverkConsumer;
private final Norg2Consumer norg2Consumer;

Expand Down Expand Up @@ -109,7 +109,7 @@ private void setProgress(BestillingProgress progress, String status) {

private Flux<PdlPersonBolk.Data> getPerson(String ident) {

return pdlPersonConsumer.getPdlPersoner(List.of(ident))
return personServiceConsumer.getPdlPersoner(List.of(ident))
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.bestilling.tagshendelseslager.dto.HendelselagerResponse;
import no.nav.dolly.bestilling.tagshendelseslager.dto.TagsOpprettingResponse;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.domain.PdlPerson;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
Expand Down Expand Up @@ -37,7 +37,7 @@
public class TagsHendelseslagerClient implements ClientRegister {

private final TagsHendelseslagerConsumer tagsHendelseslagerConsumer;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;

@Override
public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, DollyPerson dollyPerson, BestillingProgress progress, boolean isOpprettEndre) {
Expand Down Expand Up @@ -95,7 +95,7 @@ private String getPublishStatus(List<String> identer, HendelselagerResponse resu

private Flux<String> getPdlIdenter(List<String> identer) {

return pdlPersonConsumer.getPdlPersoner(identer)
return personServiceConsumer.getPdlPersoner(identer)
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ma.glasnost.orika.MapperFacade;
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.bestilling.skjermingsregister.SkjermingUtil;
import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer;
import no.nav.dolly.domain.PdlPerson;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class TpsMessagingClient implements ClientRegister {

private final TpsMessagingConsumer tpsMessagingConsumer;
private final MapperFacade mapperFacade;
private final PdlPersonConsumer pdlPersonConsumer;
private final PersonServiceConsumer personServiceConsumer;
private final TransactionHelperService transactionHelperService;
private final TpsMiljoerConsumer tpsMiljoerConsumer;

Expand Down Expand Up @@ -160,7 +160,7 @@ private Flux<List<String>> getIdenterHovedpersonOgPartner(String ident) {

private Flux<PdlPersonBolk.PersonBolk> getPersonData(List<String> identer) {

return pdlPersonConsumer.getPdlPersoner(identer)
return personServiceConsumer.getPdlPersoner(identer)
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
Expand Down
Loading

0 comments on commit ac0c717

Please sign in to comment.