Skip to content

Commit

Permalink
Add support for fetching pension decisions #deploy-test-dolly-backend
Browse files Browse the repository at this point in the history
Introduced `PensjonHentVedtakCommand` to fetch pension decisions and integrated it into `PensjonforvalterClient` and `PensjonforvalterConsumer`. Also added a new method in `TransaksjonMappingRepository` and `TransaksjonMappingService` for deleting records by ident, environment, and system.
  • Loading branch information
krharum committed Aug 28, 2024
1 parent 0531110 commit 0ed36a6
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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.PensjonVedtakResponse.SakType;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonforvalterResponse;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonsavtaleRequest;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
Expand Down Expand Up @@ -411,36 +412,39 @@ private Flux<PensjonforvalterResponse> lagreUforetrygd(PensjonData pensjondata,
.filter(PensjonData::hasUforetrygd)
.map(PensjonData::getUforetrygd)
.flatMap(uforetrygd -> Flux.fromIterable(miljoer)
.flatMap(miljoe -> {

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

var context = MappingContextUtils.getMappingContext();
context.setProperty(IDENT, ident);
context.setProperty(MILJOER, List.of(miljoe));
context.setProperty(NAV_ENHET, navEnhetNr);
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, new AtomicReference<>(request)));
return response;
}));

} else {
return getStatus(miljoe, 200, "OK");
}
}));
.flatMap(miljoe -> pensjonforvalterConsumer.hentVedtak(ident, miljoe)
.collectList()
.map(vedtak -> {
if (vedtak.stream().noneMatch(entry -> entry.getSakType() == SakType.UT &&
entry.getSisteOppdatering().contains("opprettet"))) {

var context = MappingContextUtils.getMappingContext();
context.setProperty(IDENT, ident);
context.setProperty(MILJOER, List.of(miljoe));
context.setProperty(NAV_ENHET, navEnhetNr);
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, new AtomicReference<>(request)));
return response;
}));
} else {
return getStatus(miljoe, 200, "OK");
}
})))
.flatMap(Flux::from);
}

@SuppressWarnings("java:S3740")
private void saveAPTransaksjonId(String ident, String miljoe, Long bestillingId, SystemTyper
type, AtomicReference vedtak) {

log.info("Lagrer transaksjon for {} i {} ", ident, miljoe);
transaksjonMappingService.delete(ident, miljoe, type.name());

transaksjonMappingService.save(
TransaksjonMapping.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import no.nav.dolly.bestilling.pensjonforvalter.command.LagreTpYtelseCommand;
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.SlettePensjonsavtaleCommand;
import no.nav.dolly.bestilling.pensjonforvalter.command.SletteTpForholdCommand;
import no.nav.dolly.bestilling.pensjonforvalter.domain.AlderspensjonRequest;
Expand All @@ -26,6 +27,7 @@
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.PensjonVedtakResponse;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonforvalterResponse;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonsavtaleRequest;
import no.nav.dolly.config.Consumers;
Expand Down Expand Up @@ -171,13 +173,22 @@ public Flux<PensjonforvalterResponse> lagrePensjonsavtale(PensjonsavtaleRequest
@Timed(name = "providers", tags = { "operation", "pen_slettePensjpnsavtale" })
public void slettePensjonsavtale(List<String> identer) {

var test = tokenService.exchange(serverProperties)
tokenService.exchange(serverProperties)
.flatMapMany(token -> Flux.fromIterable(identer)
.flatMap(ident -> new SlettePensjonsavtaleCommand(webClient, ident, token.getTokenValue()).call()))
.collectList()
.subscribe(resultat -> log.info("Slettet pensjonsavtaler (PEN), alle miljøer"));
}

@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())
.doOnNext(response -> log.info("Pensjon vedtak for ident {}, miljoe {} mottatt {}",
ident, miljoe, response));
}

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

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.pensjonforvalter.domain.PensjonVedtakResponse;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import no.nav.testnav.libs.securitycore.config.UserConstant;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

import java.time.Duration;
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 no.nav.dolly.util.TokenXUtil.getUserJwt;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

@Slf4j
@RequiredArgsConstructor
public class PensjonHentVedtakCommand implements Callable<Flux<PensjonVedtakResponse>> {

private static final String VEDTAK_URL = "/api/v2/vedtak";

private final WebClient webClient;
private final String ident;
private final String miljoe;
private final String token;

@Override
public Flux<PensjonVedtakResponse> call() {

var callId = generateCallId();
log.info("Pensjon hente vedtak for ident {}, miljoe {}, callId {}", ident, miljoe, callId);

return webClient
.get()
.uri(uriBuilder -> uriBuilder
.path(VEDTAK_URL)
.queryParam("miljo", miljoe)
.build())
.header(AUTHORIZATION, "Bearer " + token)
.header(UserConstant.USER_HEADER_JWT, getUserJwt())
.header(HEADER_NAV_CALL_ID, callId)
.header(HEADER_NAV_CONSUMER_ID, CONSUMER)
.header("fnr", ident)
.retrieve()
.bodyToFlux(PensjonVedtakResponse.class)
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5))
.filter(WebClientFilter::is5xxException))
.doOnError(WebClientFilter::logErrorMessage)
.onErrorResume(Exception.class, error -> Mono.empty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package no.nav.dolly.bestilling.pensjonforvalter.domain;

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

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

public enum SakType {AP, UT}

private String sakId;
private SakType sakType;
private String vedtakStatus;
private String sisteOppdatering;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface TransaksjonMappingRepository extends CrudRepository<Transaksjon
@Modifying
int deleteAllByIdent(String ident);

@Modifying
int deleteByIdentAndMiljoeAndSystem(String ident, String miljoe, String system);

@Modifying
@Query(value = "delete from TransaksjonMapping tm where tm.bestillingId in " +
"(select b.id from Bestilling b where b.gruppe.id = :gruppeId)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public void slettTransaksjonMappingByTestident(String ident) {
transaksjonMappingRepository.deleteAllByIdent(ident);
}

@Transactional
public void delete(String ident, String miljoe, String system) {

transaksjonMappingRepository.deleteByIdentAndMiljoeAndSystem(ident, miljoe, system);
}

private RsTransaksjonMapping toDTO(TransaksjonMapping transaksjonMapping) {

JsonNode innhold;
Expand Down

0 comments on commit 0ed36a6

Please sign in to comment.