Skip to content

Commit

Permalink
Merge branch 'feature/ufoeretrygd' of https://github.com/navikt/testn…
Browse files Browse the repository at this point in the history
…orge into feature/ufoeretrygd
  • Loading branch information
betsytraran committed Sep 18, 2023
2 parents 578df87 + 152d661 commit d7ae0c9
Show file tree
Hide file tree
Showing 56 changed files with 1,052 additions and 537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public Aap115Response(HttpStatus status, String miljoe, String feilmelding, List

super(status, miljoe, feilmelding);
this.nyeAap115 = nyeAap115;
this.nyeAapFeilList = nyeAapFeilList;
this.nyeAap115FeilList = nyeAapFeilList;
}

@Schema(description = "Liste over opprettede AAP-115")
private List<Aap115> nyeAap115;

@Schema(description = "Liste over AAP-115 hvor oppretting feilet")
private List<Aap115Feil> nyeAapFeilList;
private List<Aap115Feil> nyeAap115FeilList;

public List<Aap115> getNyeAap115() {

Expand All @@ -42,12 +42,12 @@ public List<Aap115> getNyeAap115() {
return nyeAap115;
}

public List<Aap115Feil> getNyeAapFeilList() {
public List<Aap115Feil> getNyeAap115FeilList() {

if (isNull(nyeAapFeilList)) {
nyeAapFeilList = new ArrayList<>();
if (isNull(nyeAap115FeilList)) {
nyeAap115FeilList = new ArrayList<>();
}
return nyeAapFeilList;
return nyeAap115FeilList;
}

@Data
Expand All @@ -58,7 +58,7 @@ public static class Aap115Feil {

private String personident;
private String miljoe;
private String nyAapFeilstatus;
private String nyAap115Feilstatus;
private String melding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ private Mono<String> getAap115Status(Aap115Response response) {
"OK" :
encodeStatus(ArenaUtils.AVSLAG + nyAap115.getBegrunnelse()))
.collect(Collectors.joining()),
Flux.fromIterable(response.getNyeAapFeilList())
Flux.fromIterable(response.getNyeAap115FeilList())
.map(aap115Feil ->
encodeStatus(String.format(ArenaUtils.STATUS_FMT, aap115Feil.getNyAapFeilstatus(), aap115Feil.getMelding())))
encodeStatus(String.format(ArenaUtils.STATUS_FMT, aap115Feil.getNyAap115Feilstatus(), aap115Feil.getMelding())))
.collect(Collectors.joining()))

.collect(Collectors.joining());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.inntektsmelding.domain.InntektsmeldingRequest;
import no.nav.dolly.bestilling.inntektsmelding.domain.TransaksjonMappingDTO;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.jpa.TransaksjonMapping;
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
Expand Down Expand Up @@ -96,7 +97,10 @@ private Flux<String> postInntektsmelding(boolean isSendMelding,
.map(dokument -> TransaksjonMapping.builder()
.ident(inntektsmeldingRequest.getArbeidstakerFnr())
.bestillingId(bestillingid)
.transaksjonId(toJson(dokument))
.transaksjonId(toJson(TransaksjonMappingDTO.builder()
.request(inntektsmeldingRequest)
.dokument(dokument)
.build()))
.datoEndret(LocalDateTime.now())
.miljoe(inntektsmeldingRequest.getMiljoe())
.system(INNTKMELD.name())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package no.nav.dolly.bestilling.inntektsmelding.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TransaksjonMappingDTO {

private InntektsmeldingRequest request;
private InntektsmeldingResponse.Dokument dokument;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import no.nav.testnav.libs.dto.kontoregisterservice.v1.OppdaterKontoRequestDTO;
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;
Expand All @@ -44,6 +47,12 @@ public KontoregisterConsumer(
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.exchangeStrategies(getJacksonStrategy(objectMapper))
.clientConnector(new ReactorClientHttpConnector(
HttpClient.create(ConnectionProvider.builder("custom")
.maxConnections(10)
.pendingAcquireMaxCount(10000)
.pendingAcquireTimeout(Duration.ofMinutes(15))
.build())))
.build();
}

Expand Down Expand Up @@ -88,5 +97,4 @@ public String serviceUrl() {
public String consumerName() {
return "testnav-kontoregister-person-proxy";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.pdldata.PdlDataConsumer;
import no.nav.dolly.bestilling.pensjonforvalter.domain.*;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AlderspensjonRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonPersonRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonPoppInntektRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonSamboerRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonSamboerResponse;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonSivilstandWrapper;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonTpForholdRequest;
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.domain.PdlPerson;
import no.nav.dolly.domain.PdlPersonBolk;
Expand All @@ -21,6 +30,7 @@
import no.nav.dolly.domain.resultset.dolly.DollyPerson;
import no.nav.dolly.domain.resultset.pensjon.PensjonData;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.mapper.MappingContextUtils;
import no.nav.dolly.service.TransaksjonMappingService;
import no.nav.dolly.util.IdentTypeUtil;
import no.nav.dolly.util.TransactionHelperService;
Expand Down Expand Up @@ -64,6 +74,7 @@ public class PensjonforvalterClient implements ClientRegister {
private static final String PEN_ALDERSPENSJON = "AP#";
private static final String PEN_UFORETRYGD = "Ufoer#";
private static final String PERIODE = "/periode/";
private static final String TPS_NOT_READY = "Oppretting ikke utført da TPS mangler persondata.";

private final PensjonforvalterConsumer pensjonforvalterConsumer;
private final MapperFacade mapperFacade;
Expand Down Expand Up @@ -148,15 +159,17 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
dollyPerson.getIdent(),
bestilteMiljoer.get(),
isOpprettEndre,
bestillingId)
bestillingId,
progress.getIsTpsSyncEnv())
.map(response -> PEN_ALDERSPENSJON + decodeStatus(response, dollyPerson.getIdent())),

lagreUforetrygd(bestilling1.getPensjonforvalter(),
persondata,
dollyPerson.getIdent(),
bestilteMiljoer.get(),
isOpprettEndre,
bestillingId)
bestillingId,
progress.getIsTpsSyncEnv())
.map(response -> PEN_UFORETRYGD + decodeStatus(response, dollyPerson.getIdent())),

lagreInntekt(bestilling1.getPensjonforvalter(), dollyPerson, bestilteMiljoer.get())
Expand Down Expand Up @@ -280,7 +293,8 @@ private Flux<PensjonforvalterResponse> opprettPersoner(String hovedperson, Set<S

private Flux<PensjonforvalterResponse> lagreAlderspensjon(PensjonData pensjonData, List<PdlPersonBolk.PersonBolk> relasjoner,
String ident, Set<String> miljoer,
boolean isOpprettEndre, Long bestillingId) {
boolean isOpprettEndre, Long bestillingId,
List<String> isTpsSyncEnv) {

return Flux.just(true)
.filter(pensjon -> nonNull(pensjonData) && nonNull(pensjonData.getAlderspensjon()))
Expand All @@ -290,29 +304,38 @@ private Flux<PensjonforvalterResponse> lagreAlderspensjon(PensjonData pensjonDat

if (isOpprettEndre || !transaksjonMappingService.existAlready(PEN_AP, ident, miljoe)) {

var context = new MappingContext.Factory().getContext();
context.setProperty(IDENT, ident);
context.setProperty(MILJOER, List.of(miljoe));
context.setProperty("relasjoner", relasjoner);
return Flux.just(mapperFacade.map(alderspensjon, AlderspensjonRequest.class, context))
.flatMap(alderspensjonRequest -> pensjonforvalterConsumer.lagreAlderspensjon(alderspensjonRequest)
.map(response -> {
response.getStatus().forEach(status -> {
if (status.getResponse().isResponse2xx()) {
saveAPTransaksjonId(ident, status.getMiljo(), bestillingId,
PEN_AP, alderspensjonRequest);
}
});
return response;
}));
if (isTpsSyncEnv.contains(miljoe)) {

var context = new MappingContext.Factory().getContext();
context.setProperty(IDENT, ident);
context.setProperty(MILJOER, List.of(miljoe));
context.setProperty("relasjoner", relasjoner);
return Flux.just(mapperFacade.map(alderspensjon, AlderspensjonRequest.class, context))
.flatMap(alderspensjonRequest -> pensjonforvalterConsumer.lagreAlderspensjon(alderspensjonRequest)
.map(response -> {
response.getStatus().forEach(status -> {
if (status.getResponse().isResponse2xx()) {
saveAPTransaksjonId(ident, status.getMiljo(), bestillingId,
PEN_AP, alderspensjonRequest);
}
});
return response;
}));

} else {
return getStatus(miljoe, 503, TPS_NOT_READY);
}

} else {
return getOkStatus(miljoe);
return getStatus(miljoe, 200, "OK");
}
}));
}

private Flux<PensjonforvalterResponse> lagreUforetrygd(PensjonData pensjonforvalter, List<PdlPersonBolk.PersonBolk> persondata,
String ident, Set<String> miljoer, boolean isOpprettEndre, Long bestillingId) {
private Flux<PensjonforvalterResponse> lagreUforetrygd(PensjonData pensjonforvalter,
List<PdlPersonBolk.PersonBolk> persondata,
String ident, Set<String> miljoer, boolean isOpprettEndre,
Long bestillingId, List<String> isTpsSyncEnv) {

return Flux.just(true)
.filter(pensjon -> nonNull(pensjonforvalter) && nonNull(pensjonforvalter.getUforetrygd()))
Expand All @@ -322,44 +345,52 @@ private Flux<PensjonforvalterResponse> lagreUforetrygd(PensjonData pensjonforval

if (isOpprettEndre || !transaksjonMappingService.existAlready(PEN_UT, ident, miljoe)) {

var context = new MappingContext.Factory().getContext();
context.setProperty(IDENT, ident);
context.setProperty(MILJOER, List.of(miljoe));
context.setProperty("persondata", persondata);
return Flux.just(mapperFacade.map(uforetrygd, PensjonUforetrygdRequest.class, context))
.flatMap(request -> pensjonforvalterConsumer.lagreUforetrygd(request)
.map(response -> {
response.getStatus().stream()
.filter(status -> status.getResponse().isResponse2xx())
.forEach(status ->
saveAPTransaksjonId(ident, status.getMiljo(), bestillingId,
PEN_UT, request));
return response;
}));
if (isTpsSyncEnv.contains(miljoe)) {

var context = MappingContextUtils.getMappingContext();
context.setProperty(IDENT, ident);
context.setProperty(MILJOER, List.of(miljoe));
context.setProperty("persondata", persondata);
return Flux.just(mapperFacade.map(uforetrygd, PensjonUforetrygdRequest.class, context))
.flatMap(request -> pensjonforvalterConsumer.lagreUforetrygd(request)
.map(response -> {
response.getStatus().stream()
.filter(status -> status.getResponse().isResponse2xx())
.forEach(status ->
saveAPTransaksjonId(ident, status.getMiljo(), bestillingId,
PEN_UT, request));
return response;
}));

} else {
return getStatus(miljoe, 503, TPS_NOT_READY);
}

} else {
return getOkStatus(miljoe);
return getStatus(miljoe, 200, "OK");
}
}));
}

private static Flux<PensjonforvalterResponse> getOkStatus(String miljoe) {
private static Flux<PensjonforvalterResponse> getStatus(String miljoe, Integer status, String reasonPhrase) {

return Flux.just(PensjonforvalterResponse.builder()
.status(List.of(PensjonforvalterResponse.ResponseEnvironment.builder()
.miljo(miljoe)
.response(PensjonforvalterResponse.Response.builder()
.httpStatus(PensjonforvalterResponse.HttpStatus.builder()
.status(200)
.reasonPhrase("OK")
.status(status)
.reasonPhrase(reasonPhrase)
.build())
.message(reasonPhrase)
.build())
.build()))
.build());
}

private void saveAPTransaksjonId(String ident, String miljoe, Long bestillingId, SystemTyper type, Object vedtak) {

log.info("lagrer transaksjon for {} i {} ", ident, miljoe);
log.info("Lagrer transaksjon for {} i {} ", ident, miljoe);

transaksjonMappingService.save(
TransaksjonMapping.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PensjonUforetrygdRequest {
private UforeType minimumInntektForUforhetType;
private String saksbehandler;
private String attesterer;
private Integer navEnhetId;
private String navEnhetId;
private Barnetillegg barnetilleggDetaljer;
private List<String> miljoer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package no.nav.dolly.bestilling.personservice;

import io.netty.channel.ChannelOption;
import no.nav.dolly.bestilling.ConsumerStatus;
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.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.Mono;
import reactor.netty.http.client.HttpClient;

import java.util.Set;

Expand All @@ -28,6 +31,8 @@ public PersonServiceConsumer(
this.tokenService = tokenService;
this.serviceProperties = serverProperties;
this.webClient = webClientBuilder
.clientConnector(new ReactorClientHttpConnector(HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)))
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Loading

0 comments on commit d7ae0c9

Please sign in to comment.