From 462fe2c8771e108abc02e5b64ea227bc4a72d467 Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Mon, 18 Sep 2023 14:55:00 +0200 Subject: [PATCH] Oppdatering for Sigrunstub --- .../sigrunstub/SigrunStubClient.java | 72 ++++++++++++++---- .../sigrunstub/SigrunStubConsumer.java | 11 +++ .../command/SigrunstubDeleteCommand.java | 4 +- .../command/SigurunstubPostCommand.java | 9 +-- .../command/SigurunstubPutCommand.java | 56 ++++++++++++++ .../dto/PensjonsgivendeForFolketrygden.java | 23 ++++++ .../sigrunstub/dto/SigrunstubResponse.java | 37 ++++++++- .../domain/resultset/RsDollyBestilling.java | 9 +++ .../dolly/domain/resultset/SystemTyper.java | 2 + .../RsPensjonsgivendeForFolketrygden.java | 23 ++++++ .../BestillingSigrunStubStatusMapper.java | 76 ++++++++++++++----- .../sigrunstub/SigrunStubClientTest.java | 4 +- .../sigrunstub/SigrunStubConsumerTest.java | 6 +- 13 files changed, 281 insertions(+), 51 deletions(-) create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPutCommand.java create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/PensjonsgivendeForFolketrygden.java create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/sigrunstub/RsPensjonsgivendeForFolketrygden.java diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClient.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClient.java index a9c6371160f..af40ea922f3 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClient.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClient.java @@ -5,6 +5,7 @@ import ma.glasnost.orika.MapperFacade; import no.nav.dolly.bestilling.ClientFuture; import no.nav.dolly.bestilling.ClientRegister; +import no.nav.dolly.bestilling.sigrunstub.dto.PensjonsgivendeForFolketrygden; import no.nav.dolly.bestilling.sigrunstub.dto.SigrunstubResponse; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling; @@ -18,12 +19,18 @@ import reactor.core.publisher.Mono; import java.util.List; +import java.util.stream.Collectors; + +import static java.util.Objects.isNull; @Log4j2 @Service @RequiredArgsConstructor public class SigrunStubClient implements ClientRegister { + private static final String LIGNET_INNTEKT = "SIGRUN_LIGNET:"; + private static final String PENSJONSGIVENDE_INNTEKT = "SIGRUN_PENSJONSGIVENDE:"; + private final SigrunStubConsumer sigrunStubConsumer; private final ErrorStatusDecoder errorStatusDecoder; private final MapperFacade mapperFacade; @@ -32,20 +39,40 @@ public class SigrunStubClient implements ClientRegister { @Override public Flux gjenopprett(RsDollyUtvidetBestilling bestilling, DollyPerson dollyPerson, BestillingProgress progress, boolean isOpprettEndre) { - if (!bestilling.getSigrunstub().isEmpty()) { - - var context = MappingContextUtils.getMappingContext(); - context.setProperty("ident", dollyPerson.getIdent()); - - var skattegrunnlag = - mapperFacade.mapAsList(bestilling.getSigrunstub(), OpprettSkattegrunnlag.class, context); - - return Flux.from(deleteSkattegrunnlag(dollyPerson.getIdent(), isOpprettEndre) - .flatMap(deletedStatus -> sigrunStubConsumer.createSkattegrunnlag(skattegrunnlag)) - .map(this::getStatus) - .map(resultat -> futurePersist(progress, resultat))); - } - return Flux.empty(); + return Flux.from(Flux.merge( + Flux.just(bestilling) + .filter(bestilling1 -> !bestilling1.getSigrunstub().isEmpty()) + .map(RsDollyUtvidetBestilling::getSigrunstub) + .flatMap(lignetInntekt -> { + + var context = MappingContextUtils.getMappingContext(); + context.setProperty("ident", dollyPerson.getIdent()); + + var skattegrunnlag = + mapperFacade.mapAsList(lignetInntekt, OpprettSkattegrunnlag.class, context); + + return Flux.from(deleteSkattegrunnlag(dollyPerson.getIdent(), isOpprettEndre) + .flatMap(deletedStatus -> sigrunStubConsumer.createSkattegrunnlag(skattegrunnlag)) + .map(this::getStatus)) + .map(status -> LIGNET_INNTEKT + status); + }), + Flux.just(bestilling) + .filter(bestilling2 -> !bestilling2.getSigrunstubPensjonsgivende().isEmpty()) + .map(RsDollyUtvidetBestilling::getSigrunstubPensjonsgivende) + .flatMap(pensjonsgivende -> { + + var context = MappingContextUtils.getMappingContext(); + context.setProperty("ident", dollyPerson.getIdent()); + + var skattegrunnlag = + mapperFacade.mapAsList(pensjonsgivende, PensjonsgivendeForFolketrygden.class, context); + + return sigrunStubConsumer.updatePensjonsgivendeInntekt(skattegrunnlag) + .map(this::getStatus) + .map(status -> PENSJONSGIVENDE_INNTEKT + status); + })) + .collect(Collectors.joining(",")) + .map(resultat -> futurePersist(progress, resultat))); } private ClientFuture futurePersist(BestillingProgress progress, String status) { @@ -72,7 +99,20 @@ private Mono deleteSkattegrunnlag(String ident, boolean oppr private String getStatus(SigrunstubResponse response) { - return response.getStatus().is2xxSuccessful() ? "OK" : - errorStatusDecoder.getErrorText(response.getStatus(), response.getMelding()); + return isNull(response.getErrorStatus()) ? + getStatus(response.getOpprettelseTilbakemeldingsListe()) : + ErrorStatusDecoder.encodeStatus(errorStatusDecoder.getErrorText(response.getErrorStatus(), response.getMelding())); + } + + private static String getStatus(List tilbakemeldinger) { + + return tilbakemeldinger.stream() + .allMatch(SigrunstubResponse.OpprettelseTilbakemelding::isOK) ? "OK" : + String.format("Feil: %s", ErrorStatusDecoder.encodeStatus( + tilbakemeldinger.stream() + .filter(SigrunstubResponse.OpprettelseTilbakemelding::isError) + .map(SigrunstubResponse.OpprettelseTilbakemelding::getMessage) + .distinct() + .collect(Collectors.joining(", ")))); } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumer.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumer.java index 71a8fe98d43..468bdfe58b2 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumer.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumer.java @@ -5,6 +5,8 @@ import no.nav.dolly.bestilling.ConsumerStatus; import no.nav.dolly.bestilling.sigrunstub.command.SigrunstubDeleteCommand; import no.nav.dolly.bestilling.sigrunstub.command.SigurunstubPostCommand; +import no.nav.dolly.bestilling.sigrunstub.command.SigurunstubPutCommand; +import no.nav.dolly.bestilling.sigrunstub.dto.PensjonsgivendeForFolketrygden; import no.nav.dolly.bestilling.sigrunstub.dto.SigrunstubResponse; import no.nav.dolly.config.credentials.SigrunstubProxyProperties; import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag; @@ -69,6 +71,15 @@ public Mono createSkattegrunnlag(List .flatMap(token -> new SigurunstubPostCommand(webClient, request, token.getTokenValue()).call()); } + @Timed(name = "providers", tags = { "operation", "sigrun_createPensjonsgivendeInntekt" }) + public Mono updatePensjonsgivendeInntekt(List request) { + + log.info("Put til Sigrunstub med data {}", request); + + return tokenService.exchange(serviceProperties) + .flatMap(token -> new SigurunstubPutCommand(webClient, request, token.getTokenValue()).call()); + } + @Override public String serviceUrl() { return serviceProperties.getUrl(); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigrunstubDeleteCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigrunstubDeleteCommand.java index 01a09454b88..edfc42dcb91 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigrunstubDeleteCommand.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigrunstubDeleteCommand.java @@ -44,12 +44,12 @@ public Mono call() { .toBodilessEntity() .map(resultat -> SigrunstubResponse.builder() .ident(ident) - .status(HttpStatus.valueOf(resultat.getStatusCode().value())) + .errorStatus(HttpStatus.valueOf(resultat.getStatusCode().value())) .build()) .doOnError(WebClientFilter::logErrorMessage) .onErrorResume(error -> Mono.just(SigrunstubResponse.builder() .ident(ident) - .status(WebClientFilter.getStatus(error)) + .errorStatus(WebClientFilter.getStatus(error)) .melding(WebClientFilter.getMessage(error)) .build())) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPostCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPostCommand.java index e71db8211d2..908d5cb3367 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPostCommand.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPostCommand.java @@ -6,7 +6,6 @@ import no.nav.dolly.util.RequestHeaderUtil; import no.nav.dolly.util.WebClientFilter; import no.nav.testnav.libs.securitycore.config.UserConstant; -import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; @@ -43,15 +42,11 @@ public Mono call() { .header(HEADER_NAV_CONSUMER_ID, CONSUMER) .header(AUTHORIZATION, "Bearer " + token) .header(UserConstant.USER_HEADER_JWT, getUserJwt()) - .bodyValue(request) .retrieve() - .toBodilessEntity() - .map(resultat -> SigrunstubResponse.builder() - .status(HttpStatus.valueOf(resultat.getStatusCode().value())) - .build()) + .bodyToMono(SigrunstubResponse.class) .doOnError(WebClientFilter::logErrorMessage) .onErrorResume(error -> Mono.just(SigrunstubResponse.builder() - .status(WebClientFilter.getStatus(error)) + .errorStatus(WebClientFilter.getStatus(error)) .melding(WebClientFilter.getMessage(error)) .build())) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPutCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPutCommand.java new file mode 100644 index 00000000000..86a3b56a364 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/command/SigurunstubPutCommand.java @@ -0,0 +1,56 @@ +package no.nav.dolly.bestilling.sigrunstub.command; + +import lombok.RequiredArgsConstructor; +import no.nav.dolly.bestilling.sigrunstub.dto.PensjonsgivendeForFolketrygden; +import no.nav.dolly.bestilling.sigrunstub.dto.SigrunstubResponse; +import no.nav.dolly.util.RequestHeaderUtil; +import no.nav.dolly.util.WebClientFilter; +import no.nav.testnav.libs.securitycore.config.UserConstant; +import org.springframework.web.reactive.function.client.WebClient; +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 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.TokenXUtil.getUserJwt; +import static org.springframework.http.HttpHeaders.ACCEPT; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +@RequiredArgsConstructor +public class SigurunstubPutCommand implements Callable> { + + private static final String CONSUMER = "Dolly"; + private static final String SIGRUN_STUB_OPPRETT_GRUNNLAG = "/api/v1/pensjonsgivendeInntektforfolketrygden"; + + private final WebClient webClient; + private final List request; + private final String token; + + @Override + public Mono call() { + + return webClient.post().uri(uriBuilder -> uriBuilder + .path(SIGRUN_STUB_OPPRETT_GRUNNLAG) + .build()) + .header(ACCEPT, APPLICATION_JSON_VALUE) + .header(HEADER_NAV_CALL_ID, RequestHeaderUtil.getNavCallId()) + .header(HEADER_NAV_CONSUMER_ID, CONSUMER) + .header(AUTHORIZATION, "Bearer " + token) + .header(UserConstant.USER_HEADER_JWT, getUserJwt()) + .bodyValue(request) + .retrieve() + .bodyToMono(SigrunstubResponse.class) + .doOnError(WebClientFilter::logErrorMessage) + .onErrorResume(error -> Mono.just(SigrunstubResponse.builder() + .errorStatus(WebClientFilter.getStatus(error)) + .melding(WebClientFilter.getMessage(error)) + .build())) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)); + } +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/PensjonsgivendeForFolketrygden.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/PensjonsgivendeForFolketrygden.java new file mode 100644 index 00000000000..28a13bce30b --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/PensjonsgivendeForFolketrygden.java @@ -0,0 +1,23 @@ +package no.nav.dolly.bestilling.sigrunstub.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PensjonsgivendeForFolketrygden { + + private String inntektsaar; + @Schema(description = "Liste av map som beskrevet i /api/v1/pensjonsgivendeinntektforfolketrygden/kodeverk") + private List> pensjonsgivendeInntekt; + private String personidentifikator; + private String testdataEier; +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/SigrunstubResponse.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/SigrunstubResponse.java index 84d180a4eec..fd631e548b1 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/SigrunstubResponse.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/dto/SigrunstubResponse.java @@ -6,13 +6,48 @@ import lombok.NoArgsConstructor; import org.springframework.http.HttpStatus; +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; + @Data @Builder @NoArgsConstructor @AllArgsConstructor public class SigrunstubResponse { - private HttpStatus status; + private HttpStatus errorStatus; private String melding; private String ident; + + List opprettelseTilbakemeldingsListe; + + public List getOpprettelseTilbakemeldingsListe() { + + if (isNull(opprettelseTilbakemeldingsListe)) { + opprettelseTilbakemeldingsListe = new ArrayList<>(); + } + return opprettelseTilbakemeldingsListe; + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class OpprettelseTilbakemelding { + + private String message; + private String personident; + private Integer status; + + public boolean isOK() { + return nonNull(status) && status == 200; + } + + public boolean isError() { + return nonNull(status) && status != 200; + } + } } \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/RsDollyBestilling.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/RsDollyBestilling.java index a6092fd82aa..509438f1785 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/RsDollyBestilling.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/RsDollyBestilling.java @@ -20,6 +20,7 @@ import no.nav.dolly.domain.resultset.pdldata.PdlPersondata; import no.nav.dolly.domain.resultset.pensjon.PensjonData; import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag; +import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden; import no.nav.dolly.domain.resultset.skjerming.RsSkjerming; import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding; import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging; @@ -56,6 +57,7 @@ public class RsDollyBestilling { private List instdata; private List aareg; private List sigrunstub; + private List sigrunstubPensjonsgivende; private InntektMultiplierWrapper inntektstub; private Arenadata arenaforvalter; private RsUdiPerson udistub; @@ -91,6 +93,13 @@ public List getSigrunstub() { return sigrunstub; } + public List getSigrunstubPensjonsgivende() { + if (isNull(sigrunstubPensjonsgivende)) { + sigrunstubPensjonsgivende = new ArrayList<>(); + } + return sigrunstubPensjonsgivende; + } + public List getInstdata() { if (isNull(instdata)) { instdata = new ArrayList<>(); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/SystemTyper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/SystemTyper.java index 294d2a0eef2..325d1327814 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/SystemTyper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/SystemTyper.java @@ -14,6 +14,8 @@ public enum SystemTyper { INST2("Institusjonsopphold (INST2)"), KRRSTUB("Digital kontaktinformasjon (DKIF)"), SIGRUNSTUB("Skatteinntekt grunnlag (SIGRUN)"), + SIGRUN_LIGNET("Lignet skatteinntekt (Sigrunstub)"), + SIGRUN_PENSJONSGIVENDE("Pensjonsgivende inntekt (Sigrunstub)"), ARENA("Arena fagsystem"), ARENA_BRUKER("Arena bruker"), ARENA_AAP("Arena AAP ytelse"), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/sigrunstub/RsPensjonsgivendeForFolketrygden.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/sigrunstub/RsPensjonsgivendeForFolketrygden.java new file mode 100644 index 00000000000..47e36daaf9e --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/sigrunstub/RsPensjonsgivendeForFolketrygden.java @@ -0,0 +1,23 @@ +package no.nav.dolly.domain.resultset.sigrunstub; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class RsPensjonsgivendeForFolketrygden { + + private String inntektsaar; + @Schema(description = "Liste av map som beskrevet i /api/v1/pensjonsgivendeinntektforfolketrygden/kodeverk") + private List> pensjonsgivendeInntekt; + private String testdataEier; +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingSigrunStubStatusMapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingSigrunStubStatusMapper.java index 952325d38f2..8714ea6a1a4 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingSigrunStubStatusMapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingSigrunStubStatusMapper.java @@ -4,43 +4,79 @@ import lombok.NoArgsConstructor; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsStatusRapport; +import no.nav.dolly.domain.resultset.SystemTyper; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static no.nav.dolly.domain.resultset.SystemTyper.SIGRUNSTUB; -import static no.nav.dolly.mapper.AbstractRsStatusMiljoeIdentForhold.decodeMsg; -import static no.nav.dolly.util.ListUtil.listOf; +import static no.nav.dolly.domain.resultset.SystemTyper.SIGRUN_LIGNET; +import static no.nav.dolly.domain.resultset.SystemTyper.SIGRUN_PENSJONSGIVENDE; import static org.apache.commons.lang3.StringUtils.isNotBlank; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class BestillingSigrunStubStatusMapper { + private static final String SIGRUNSTUB = "SIGRUNSTUB"; + private static final String LIGNET_INNTEKT = "SIGRUN_LIGNET"; + private static final String PENSJONSGIVENDE_INNTEKT = "SIGRUN_PENSJONSGIVENDE"; + public static List buildSigrunStubStatusMap(List progressList) { - Map> statusMap = new HashMap<>(); + //melding //status //ident + Map>> statusMap = new HashMap<>(); progressList.forEach(progress -> { if (isNotBlank(progress.getSigrunstubStatus())) { - if (statusMap.containsKey(progress.getSigrunstubStatus())) { - statusMap.get(progress.getSigrunstubStatus()).add(progress.getIdent()); - } else { - statusMap.put(progress.getSigrunstubStatus(), listOf(progress.getIdent())); - } + List.of(progress.getSigrunstubStatus().split(",")) + .forEach(entry -> insertArtifact(entry, progress.getIdent(), statusMap)); } }); - return statusMap.isEmpty() ? emptyList() : - singletonList(RsStatusRapport.builder().id(SIGRUNSTUB).navn(SIGRUNSTUB.getBeskrivelse()) - .statuser(statusMap.entrySet().stream() - .map(entry -> RsStatusRapport.Status.builder() - .melding(decodeMsg(entry.getKey())) - .identer(entry.getValue()) - .build()) - .toList()) - .build()); + var statusRapporter = new ArrayList(); + statusRapporter.addAll(extractStatus(statusMap, LIGNET_INNTEKT, SIGRUN_LIGNET)); + statusRapporter.addAll(extractStatus(statusMap, PENSJONSGIVENDE_INNTEKT, SIGRUN_PENSJONSGIVENDE)); + statusRapporter.addAll(extractStatus(statusMap, SIGRUNSTUB, SystemTyper.SIGRUNSTUB)); + + return statusRapporter; + } + + private static void insertArtifact(String entry, String ident, Map>> msgStatusIdents) { + + var meldingStatus = entry.split(":"); + var melding = meldingStatus.length > 1 ? meldingStatus[0] : SIGRUNSTUB; + var status = meldingStatus.length > 1 ? meldingStatus[1] : meldingStatus[0]; + + if (msgStatusIdents.containsKey(melding)) { + if (msgStatusIdents.get(melding).containsKey(status)) { + msgStatusIdents.get(melding).get(status).add((ident)); + } else { + msgStatusIdents.get(melding).put(status, new ArrayList<>(List.of(ident))); + } + } else { + var statusMap = new HashMap>(); + statusMap.put(status, new ArrayList<>(List.of(ident))); + msgStatusIdents.put(melding, statusMap); + } + } + + private static List extractStatus(Map>> meldStatusIdents, String clientId, SystemTyper type) { + + return meldStatusIdents.containsKey(clientId) ? + Collections.singletonList(RsStatusRapport.builder() + .id(type) + .navn(type.getBeskrivelse()) + .statuser( + meldStatusIdents.get(clientId).entrySet().stream() + .map(entry -> + RsStatusRapport.Status.builder() + .melding(entry.getKey()) + .identer(entry.getValue()) + .build()) + .toList()) + .build()) : + Collections.emptyList(); } } diff --git a/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClientTest.java b/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClientTest.java index c63c6d79710..dead4103c62 100644 --- a/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClientTest.java +++ b/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubClientTest.java @@ -77,7 +77,7 @@ void gjenopprett_sigrunstub_feiler() { var progress = new BestillingProgress(); when(sigrunStubConsumer.createSkattegrunnlag(anyList())).thenReturn(Mono.just(SigrunstubResponse.builder() - .status(HttpStatus.BAD_REQUEST) + .errorStatus(HttpStatus.BAD_REQUEST) .melding("Feil ...") .build())); when(errorStatusDecoder.getErrorText(eq(HttpStatus.BAD_REQUEST), anyString())).thenReturn("Feil:"); @@ -106,7 +106,7 @@ void gjenopprett_sigrunstub_ok() { .thenReturn(request.getSigrunstub()); when(sigrunStubConsumer.createSkattegrunnlag(anyList())).thenReturn(Mono.just(SigrunstubResponse.builder() - .status(HttpStatus.OK) + .errorStatus(HttpStatus.OK) .build())); when(sigrunStubConsumer.deleteSkattegrunnlag(IDENT)).thenReturn(Mono.just(new SigrunstubResponse())); diff --git a/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumerTest.java b/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumerTest.java index 02e9d7606da..d77ac670d91 100644 --- a/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumerTest.java +++ b/apps/dolly-backend/src/test/java/no/nav/dolly/bestilling/sigrunstub/SigrunStubConsumerTest.java @@ -79,7 +79,7 @@ void createSkattegrunnlag() { StepVerifier.create(sigrunStubConsumer.createSkattegrunnlag(singletonList(this.skattegrunnlag))) .expectNext(SigrunstubResponse.builder() - .status(HttpStatus.OK) + .errorStatus(HttpStatus.OK) .build()) .verifyComplete(); } @@ -91,7 +91,7 @@ void createSkattegrunnlag_kasterSigrunExceptionHvisKallKasterClientException() t StepVerifier.create(sigrunStubConsumer.createSkattegrunnlag(singletonList(skattegrunnlag))) .expectNext(SigrunstubResponse.builder() - .status(HttpStatus.BAD_REQUEST) + .errorStatus(HttpStatus.BAD_REQUEST) .melding("[{\"grunnlag\":[],\"inntektsaar\":\"1978\",\"svalbardGrunnlag\":[]}]") .build()) .verifyComplete(); @@ -104,7 +104,7 @@ void deleteSkattegrunnlag_Ok() { StepVerifier.create(sigrunStubConsumer.deleteSkattegrunnlag(List.of(IDENT))) .expectNext(SigrunstubResponse.builder() - .status(HttpStatus.OK) + .errorStatus(HttpStatus.OK) .ident(IDENT) .build()) .verifyComplete();