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

Add AFP offentlig fields to PensjonData #3623

Merged
merged 16 commits into from
Sep 20, 2024
Merged
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
Expand Up @@ -10,4 +10,4 @@ public static void main(String[] args) {

SpringApplication.run(DollyBackendApplicationStarter.class, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.AfpOffentligRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AlderspensjonRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AlderspensjonSoknadRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AlderspensjonVedtakRequest;
Expand Down Expand Up @@ -87,6 +88,7 @@ public class PensjonforvalterClient implements ClientRegister {
private static final String PEN_ALDERSPENSJON = "AP#";
private static final String PEN_UFORETRYGD = "Ufoer#";
private static final String PEN_PENSJONSAVTALE = "Pensjonsavtale#";
private static final String PEN_AFP_OFFENTLIG = "AfpOffentlig#";
private static final String PERIODE = "/periode/";

private final PensjonforvalterConsumer pensjonforvalterConsumer;
Expand Down Expand Up @@ -165,7 +167,10 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
.map(response -> TP_FORHOLD + decodeStatus(response, dollyPerson.getIdent())),

lagrePensjonsavtale(pensjon, dollyPerson.getIdent(), bestilteMiljoer.get())
.map(response -> PEN_PENSJONSAVTALE + decodeStatus(response, dollyPerson.getIdent()))
.map(response -> PEN_PENSJONSAVTALE + decodeStatus(response, dollyPerson.getIdent())),

lagreAfpOffentlig(pensjon, dollyPerson.getIdent(), bestilteMiljoer.get())
.map(response -> PEN_AFP_OFFENTLIG + decodeStatus(response, dollyPerson.getIdent()))
)
.collectList()
.doOnNext(statusResultat::addAll)
Expand Down Expand Up @@ -210,6 +215,7 @@ public void release(List<String> identer) {

pensjonforvalterConsumer.sletteTpForhold(identer);
pensjonforvalterConsumer.slettePensjonsavtale(identer);
pensjonforvalterConsumer.sletteAfpOffentlig(identer);
}

public static PensjonforvalterResponse mergePensjonforvalterResponses(List<PensjonforvalterResponse> responser) {
Expand Down Expand Up @@ -540,6 +546,21 @@ private Flux<PensjonforvalterResponse> lagrePensjonsavtale(PensjonData pensjon,
}));
}

private Flux<PensjonforvalterResponse> lagreAfpOffentlig(PensjonData pensjonData, String ident, Set<String> miljoer) {

return Flux.just(pensjonData)
.filter(PensjonData::hasAfpOffentlig)
.map(PensjonData::getAfpOffentlig)
.flatMap(pensjon -> Flux.fromIterable(miljoer)
.flatMap(miljoe -> {

var context = MappingContextUtils.getMappingContext();
context.setProperty(IDENT, ident);
var request = mapperFacade.map(pensjon, AfpOffentligRequest.class, context);
return pensjonforvalterConsumer.lagreAfpOffentlig(request, miljoe);
}));
}

private String decodeStatus(PensjonforvalterResponse response, String ident) {

log.info("Mottatt status på {} fra Pensjon-Testdata-Facade: {}", ident, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import no.nav.dolly.bestilling.pensjonforvalter.command.AnnullerSamboerCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.HentMiljoerCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.HentSamboerCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.LagreAfpOffentligCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.LagreAlderspensjonCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.LagreGenerertPoppInntektCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.LagrePensjonsavtaleCommand;
Expand All @@ -16,8 +17,10 @@
import no.nav.dolly.bestilling.pensjonforvalter.command.LagreUforetrygdCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.OpprettPersonCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.PensjonHentVedtakCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.SletteAfpOffentligCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.SlettePensjonsavtaleCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.SletteTpForholdCommand;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AfpOffentligRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AlderspensjonRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonPersonRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonPoppGenerertInntektRequest;
Expand Down Expand Up @@ -66,30 +69,30 @@ public PensjonforvalterConsumer(
.build();
}

@Timed(name = "providers", tags = { "operation", "pen_getMiljoer" })
@Timed(name = "providers", tags = {"operation", "pen_getMiljoer"})
public Mono<Set<String>> getMiljoer() {

return tokenService.exchange(serverProperties)
.flatMap(token -> new HentMiljoerCommand(webClient, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "popp_lagreInntekt" })
@Timed(name = "providers", tags = {"operation", "popp_lagreInntekt"})
public Flux<PensjonforvalterResponse> lagreInntekter(PensjonPoppInntektRequest pensjonPoppInntektRequest) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagrePoppInntektCommand(webClient, token.getTokenValue(),
pensjonPoppInntektRequest).call());
}

@Timed(name = "providers", tags = { "operation", "popp_lagreGenerertInntekt" })
@Timed(name = "providers", tags = {"operation", "popp_lagreGenerertInntekt"})
public Flux<PensjonforvalterResponse> lagreGenererteInntekter(PensjonPoppGenerertInntektRequest pensjonPoppGenerertInntektRequest) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagreGenerertPoppInntektCommand(webClient, token.getTokenValue(),
pensjonPoppGenerertInntektRequest).call());
}

@Timed(name = "providers", tags = { "operation", "pen_opprettPerson" })
@Timed(name = "providers", tags = {"operation", "pen_opprettPerson"})
public Flux<PensjonforvalterResponse> opprettPerson(PensjonPersonRequest pensjonPersonRequest,
Set<String> miljoer) {

Expand All @@ -99,52 +102,52 @@ public Flux<PensjonforvalterResponse> opprettPerson(PensjonPersonRequest pensjon
.doOnNext(response -> log.info("Opprettet person for {}: {}", pensjonPersonRequest.getFnr(), response));
}

@Timed(name = "providers", tags = { "operation", "pen_hentSamboer" })
@Timed(name = "providers", tags = {"operation", "pen_hentSamboer"})
public Flux<PensjonSamboerResponse> hentSamboer(String ident, String miljoe) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new HentSamboerCommand(webClient, ident, miljoe, token.getTokenValue()).call())
.doOnNext(response -> log.info("Pensjon samboer for {} i {} hentet {}", ident, miljoe, response));
}

@Timed(name = "providers", tags = { "operation", "pen_opprettSamboer" })
@Timed(name = "providers", tags = {"operation", "pen_opprettSamboer"})
public Flux<PensjonforvalterResponse> lagreSamboer(PensjonSamboerRequest pensjonSamboerRequest,
String miljoe) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagreSamboerCommand(webClient, pensjonSamboerRequest, miljoe, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "pen_opprettSamboer" })
@Timed(name = "providers", tags = {"operation", "pen_opprettSamboer"})
public Flux<PensjonforvalterResponse> annullerSamboer(String periodeId, String miljoe) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new AnnullerSamboerCommand(webClient, periodeId, miljoe, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "pen_lagreAlderspensjon" })
@Timed(name = "providers", tags = {"operation", "pen_lagreAlderspensjon"})
public Flux<PensjonforvalterResponse> lagreAlderspensjon(AlderspensjonRequest request) {

return tokenService.exchange(serverProperties)
.flatMapMany(token ->
new LagreAlderspensjonCommand(webClient, token.getTokenValue(), request).call());
}

@Timed(name = "providers", tags = { "operation", "pen_lagreUforetrygd" })
@Timed(name = "providers", tags = {"operation", "pen_lagreUforetrygd"})
public Flux<PensjonforvalterResponse> lagreUforetrygd(PensjonUforetrygdRequest request) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagreUforetrygdCommand(webClient, token.getTokenValue(), request).call());
}

@Timed(name = "providers", tags = { "operation", "pen_lagreTpForhold" })
@Timed(name = "providers", tags = {"operation", "pen_lagreTpForhold"})
public Flux<PensjonforvalterResponse> lagreTpForhold(PensjonTpForholdRequest pensjonTpForholdRequest) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagreTpForholdCommand(webClient, token.getTokenValue(), pensjonTpForholdRequest).call());
}

@Timed(name = "providers", tags = { "operation", "pen_sletteTpForhold" })
@Timed(name = "providers", tags = {"operation", "pen_sletteTpForhold"})
public void sletteTpForhold(List<String> identer) {

tokenService.exchange(serverProperties)
Expand All @@ -156,21 +159,21 @@ public void sletteTpForhold(List<String> identer) {
.subscribe(response -> log.info("Slettet mot PESYS (tp) i alle miljoer"));
}

@Timed(name = "providers", tags = { "operation", "pen_lagreTpYtelse" })
@Timed(name = "providers", tags = {"operation", "pen_lagreTpYtelse"})
public Flux<PensjonforvalterResponse> lagreTpYtelse(PensjonTpYtelseRequest pensjonTpYtelseRequest) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagreTpYtelseCommand(webClient, token.getTokenValue(), pensjonTpYtelseRequest).call());
}

@Timed(name = "providers", tags = { "operation", "pen_lagrePensjpnsavtale" })
@Timed(name = "providers", tags = {"operation", "pen_lagrePensjpnsavtale"})
public Flux<PensjonforvalterResponse> lagrePensjonsavtale(PensjonsavtaleRequest pensjonsavtaleRequest) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagrePensjonsavtaleCommand(webClient, pensjonsavtaleRequest, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "pen_slettePensjpnsavtale" })
@Timed(name = "providers", tags = {"operation", "pen_slettePensjpnsavtale"})
public void slettePensjonsavtale(List<String> identer) {

tokenService.exchange(serverProperties)
Expand All @@ -180,15 +183,35 @@ public void slettePensjonsavtale(List<String> identer) {
.subscribe(resultat -> log.info("Slettet pensjonsavtaler (PEN), alle miljøer"));
}

@Timed(name = "providers", tags = { "operation", "pen_hentVedtak" })
@Timed(name = "providers", tags = {"operation", "pen_hentVedtak"})
public Flux<PensjonVedtakResponse> hentVedtak(String ident, String miljoe) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new PensjonHentVedtakCommand(webClient, ident, miljoe, token.getTokenValue()).call())
.flatMapMany(token -> new PensjonHentVedtakCommand(webClient, ident, miljoe, token.getTokenValue()).call())
.doOnNext(response -> log.info("Pensjon vedtak for ident {}, miljoe {} mottatt {}",
ident, miljoe, response));
}

@Timed(name = "providers", tags = {"operation", "pen_lagreAfpOffentlig"})
public Flux<PensjonforvalterResponse> lagreAfpOffentlig(AfpOffentligRequest afpOffentligRequest, String miljoe) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new LagreAfpOffentligCommand(webClient, afpOffentligRequest, miljoe, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = {"operation", "pen_sletteAfpOffentlig"})
public void sletteAfpOffentlig(List<String> identer) {

tokenService.exchange(serverProperties)
.flatMapMany(token -> Flux.from(getMiljoer())
.flatMap(Flux::fromIterable)
.flatMap(miljoe -> Flux.fromIterable(identer)
.map(ident -> new SletteAfpOffentligCommand(webClient, ident, miljoe, token.getTokenValue()).call()))
.flatMap(Flux::from))
.collectList()
.subscribe(resultat -> log.info("Slettet AfpOffentlig (PEN), alle miljøer"));
}

@Override
public String serviceUrl() {
return serverProperties.getUrl();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package no.nav.dolly.bestilling.pensjonforvalter.command;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AfpOffentligRequest;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonforvalterResponse;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.concurrent.Callable;

import static no.nav.dolly.domain.CommonKeysAndUtils.CONSUMER;
import static no.nav.dolly.domain.CommonKeysAndUtils.HEADER_NAV_CALL_ID;
import static no.nav.dolly.domain.CommonKeysAndUtils.HEADER_NAV_CONSUMER_ID;
import static no.nav.dolly.util.CallIdUtil.generateCallId;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

@Slf4j
@RequiredArgsConstructor
public class LagreAfpOffentligCommand implements Callable<Mono<PensjonforvalterResponse>> {
private static final String PEN_AFP_OFFENTLIG_URL = "/{miljoe}/api/mock-oppsett/{ident}";

private final WebClient webClient;
private final AfpOffentligRequest afpOffentligRequest;
private final String miljoe;
private final String token;

public Mono<PensjonforvalterResponse> call() {

var ident = afpOffentligRequest
.getMocksvar().stream()
.map(AfpOffentligRequest.AfpOffentligStub::getFnr)
.findFirst().orElse(null);

var callId = generateCallId();
log.info("Pensjon afp-offentlig {} {}, callId: {}", miljoe, afpOffentligRequest, callId);

return webClient
.put()
.uri(uriBuilder -> uriBuilder
.path(PEN_AFP_OFFENTLIG_URL)
.build(miljoe, ident))
.header(AUTHORIZATION, "Bearer " + token)
.header(HEADER_NAV_CALL_ID, callId)
.header(HEADER_NAV_CONSUMER_ID, CONSUMER)
.bodyValue(afpOffentligRequest)
.retrieve()
.toBodilessEntity()
.map(response -> pensjonforvalterResponse(miljoe, ident, HttpStatus.valueOf(response.getStatusCode().value())))
.doOnError(WebClientFilter::logErrorMessage)
.onErrorResume(error -> Mono.just(pensjonforvalterResponseFromError(miljoe, ident, error)));
}

private static PensjonforvalterResponse pensjonforvalterResponse(String miljoe, String ident, HttpStatus status) {

var miljoeResponse = PensjonforvalterResponse.ResponseEnvironment.builder()
.miljo(miljoe)
.response(PensjonforvalterResponse.Response.builder()
.httpStatus(PensjonforvalterResponse.HttpStatus.builder()
.status(status.value())
.reasonPhrase(status.getReasonPhrase())
.build())
.path(PEN_AFP_OFFENTLIG_URL.replace("{miljoe}", miljoe).replace("{ident}", ident))
.build())
.build();

return PensjonforvalterResponse.builder()
.status(Collections.singletonList(miljoeResponse))
.build();
}

private static PensjonforvalterResponse pensjonforvalterResponseFromError(String miljoe, String ident, Throwable error) {

var miljoeResponse = PensjonforvalterResponse.ResponseEnvironment.builder()
.miljo(miljoe)
.response(PensjonforvalterResponse.Response.builder()
.httpStatus(PensjonforvalterResponse.HttpStatus.builder()
.status(WebClientFilter.getStatus(error).value())
.reasonPhrase(WebClientFilter.getStatus(error).getReasonPhrase())
.build())
.message(WebClientFilter.getMessage(error))
.path(PEN_AFP_OFFENTLIG_URL.replace("{miljoe}", miljoe).replace("{ident}", ident))
.build())
.build();

return PensjonforvalterResponse.builder()
.status(Collections.singletonList(miljoeResponse))
.build();
}
}
Loading