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 60a79ba9c9d..8391c23a4a2 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 @@ -99,6 +99,7 @@ private Mono deleteSkattegrunnlag(String ident, boolean oppr private String getStatus(SigrunstubResponse response) { + log.info("Response fra Sigrunstub med data {} ", response); return isNull(response.getErrorStatus()) ? getStatus(response.getOpprettelseTilbakemeldingsListe()) : ErrorStatusDecoder.encodeStatus(errorStatusDecoder.getErrorText(response.getErrorStatus(), response.getMelding())); 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 468bdfe58b2..26885d3c392 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 @@ -45,7 +45,7 @@ public SigrunStubConsumer( .build(); } - @Timed(name = "providers", tags = { "operation", "sigrun_deleteGrunnlag" }) + @Timed(name = "providers", tags = {"operation", "sigrun_deleteGrunnlag"}) public Flux deleteSkattegrunnlag(List identer) { return tokenService.exchange(serviceProperties) @@ -55,14 +55,14 @@ public Flux deleteSkattegrunnlag(List identer) { .flatMap(Flux::from)); } - @Timed(name = "providers", tags = { "operation", "sigrun_deleteGrunnlag" }) + @Timed(name = "providers", tags = {"operation", "sigrun_deleteGrunnlag"}) public Mono deleteSkattegrunnlag(String ident) { return tokenService.exchange(serviceProperties) .flatMap(token -> new SigrunstubDeleteCommand(webClient, ident, token.getTokenValue()).call()); } - @Timed(name = "providers", tags = { "operation", "sigrun_createGrunnlag" }) + @Timed(name = "providers", tags = {"operation", "sigrun_createGrunnlag"}) public Mono createSkattegrunnlag(List request) { log.info("Post til Sigrunstub med data {}", request); @@ -71,7 +71,7 @@ public Mono createSkattegrunnlag(List .flatMap(token -> new SigurunstubPostCommand(webClient, request, token.getTokenValue()).call()); } - @Timed(name = "providers", tags = { "operation", "sigrun_createPensjonsgivendeInntekt" }) + @Timed(name = "providers", tags = {"operation", "sigrun_createPensjonsgivendeInntekt"}) public Mono updatePensjonsgivendeInntekt(List request) { log.info("Put til Sigrunstub med data {}", request); 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 index 46863bbf330..9b98e0d72a8 100644 --- 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 @@ -25,7 +25,7 @@ public class SigurunstubPutCommand implements Callable> { private static final String CONSUMER = "Dolly"; - private static final String SIGRUN_STUB_OPPRETT_GRUNNLAG = "/api/v1/pensjonsgivendeInntektforfolketrygden"; + private static final String SIGRUN_STUB_OPPRETT_GRUNNLAG = "/api/v1/pensjonsgivendeinntektforfolketrygden"; private final WebClient webClient; private final List request; @@ -34,7 +34,7 @@ public class SigurunstubPutCommand implements Callable> @Override public Mono call() { - return webClient.post().uri(uriBuilder -> uriBuilder + return webClient.put().uri(uriBuilder -> uriBuilder .path(SIGRUN_STUB_OPPRETT_GRUNNLAG) .build()) .header(ACCEPT, APPLICATION_JSON_VALUE) 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 index 28a13bce30b..618ae198c25 100644 --- 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 @@ -1,14 +1,12 @@ package no.nav.dolly.bestilling.sigrunstub.dto; +import com.fasterxml.jackson.databind.JsonNode; 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 @@ -17,7 +15,7 @@ public class PensjonsgivendeForFolketrygden { private String inntektsaar; @Schema(description = "Liste av map som beskrevet i /api/v1/pensjonsgivendeinntektforfolketrygden/kodeverk") - private List> pensjonsgivendeInntekt; + private JsonNode pensjonsgivendeInntekt; private String personidentifikator; private String testdataEier; } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/mapper/SigrunstubDataMapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/mapper/SigrunstubDataMapper.java index 9fd0519ffad..f6c30ef5b58 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/mapper/SigrunstubDataMapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sigrunstub/mapper/SigrunstubDataMapper.java @@ -1,10 +1,16 @@ package no.nav.dolly.bestilling.sigrunstub.mapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import ma.glasnost.orika.CustomMapper; import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.MappingContext; +import no.nav.dolly.bestilling.sigrunstub.dto.PensjonsgivendeForFolketrygden; import no.nav.dolly.domain.resultset.sigrunstub.KodeverknavnGrunnlag; import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag; +import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden; import no.nav.dolly.mapper.MappingStrategy; import org.springframework.stereotype.Component; @@ -12,13 +18,18 @@ import static java.lang.String.format; import static no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag.Tjeneste.BEREGNET_SKATT; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +@Slf4j @Component +@RequiredArgsConstructor public class SigrunstubDataMapper implements MappingStrategy { private static final String OPPGJOER_DATO_NAVN = "skatteoppgjoersdato"; private static final String OPPGJOER_DATO_VERDI = "%4d-05-01"; + private final ObjectMapper objectMapper; + @Override public void register(MapperFactory factory) { @@ -49,5 +60,27 @@ private void addOppgjoersdato(List spesifiktGrunnlag, Inte }) .byDefault() .register(); + + factory.classMap(RsPensjonsgivendeForFolketrygden.class, PensjonsgivendeForFolketrygden.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(RsPensjonsgivendeForFolketrygden kilde, PensjonsgivendeForFolketrygden destinasjon, MappingContext context) { + + destinasjon.setPersonidentifikator((String) context.getProperty("ident")); + + destinasjon.setTestdataEier(isNotBlank(kilde.getTestdataEier()) ? kilde.getTestdataEier() : "Dolly"); + + try { + destinasjon.setPensjonsgivendeInntekt( + objectMapper.readTree( + objectMapper.writeValueAsString(kilde.getPensjonsgivendeInntekt()))); + } catch (JsonProcessingException e) { + log.error("Feilet å gjøre {} om til JSON", kilde.getPensjonsgivendeInntekt()); + } + } + }) + .exclude("pensjonsgivendeInntekt") + .byDefault() + .register(); } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/BestilteKriterier.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/BestilteKriterier.java index 05ba4439c3e..de7bbd444fb 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/BestilteKriterier.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/BestilteKriterier.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; @@ -42,6 +43,7 @@ public class BestilteKriterier { private RsDigitalKontaktdata krrstub; private RsUdiPerson udistub; private List sigrunstub; + private List sigrunstubPensjonsgivende; private Arenadata arenaforvalter; private PdlPersondata pdldata; private List instdata; diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java index 0aaac96db0a..3a13e2d5b1a 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java @@ -21,6 +21,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; @@ -88,6 +89,7 @@ public static class RsBestilling { private List instdata; private List aareg; private List sigrunstub; + private List sigrunstubPensjonsgivende; private InntektMultiplierWrapper inntektstub; private Arenadata arenaforvalter; private RsUdiPerson udistub; @@ -104,4 +106,4 @@ public static class RsBestilling { private RsSkjerming skjerming; private ArbeidsplassenCVDTO arbeidsplassenCV; } -} +} \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java index 8c65bbe31aa..37eb53ec785 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java @@ -21,6 +21,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; @@ -82,6 +83,7 @@ public static class RsBestilling { private List instdata; private List aareg; private List sigrunstub; + private List sigrunstubPensjonsgivende; private InntektMultiplierWrapper inntektstub; private Arenadata arenaforvalter; private RsUdiPerson udistub; diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java index 3093de2eea1..f06db0581d9 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java @@ -108,6 +108,7 @@ public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus, .instdata(bestillingRequest.getInstdata()) .inntektstub(bestillingRequest.getInntektstub()) .sigrunstub(bestillingRequest.getSigrunstub()) + .sigrunstubPensjonsgivende(bestillingRequest.getSigrunstubPensjonsgivende()) .udistub(bestillingRequest.getUdistub()) .pensjonforvalter(bestillingRequest.getPensjonforvalter()) .inntektsmelding(bestillingRequest.getInntektsmelding()) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java index 50ac37aff06..53adbed7ec9 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java @@ -383,13 +383,6 @@ public void slettBestillingByTestIdent(String ident) { }); } - public List fetchBestillingerByTestident(String ident) { - - var bestillinger = bestillingRepository.findBestillingerByIdent(ident); - return bestillinger.stream().map(Bestilling::getId).toList(); - } - - @Transactional public void swapIdent(String oldIdent, String newIdent) { bestillingRepository.swapIdent(oldIdent, newIdent); @@ -401,6 +394,7 @@ public String getBestKriterier(RsDollyBestilling request) { .krrstub(request.getKrrstub()) .udistub(request.getUdistub()) .sigrunstub(request.getSigrunstub()) + .sigrunstubPensjonsgivende(request.getSigrunstubPensjonsgivende()) .arenaforvalter(request.getArenaforvalter()) .pdldata(request.getPdldata()) .instdata(request.getInstdata()) 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 dead4103c62..3f60322e5d5 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 @@ -22,6 +22,8 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import java.util.List; + import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; @@ -91,7 +93,7 @@ void gjenopprett_sigrunstub_feiler() { .assertNext(status -> { verify(transactionHelperService, times(1)) .persister(any(BestillingProgress.class), any(), statusCaptor.capture()); - assertThat(statusCaptor.getValue(), Matchers.is(equalTo("Feil:"))); + assertThat(statusCaptor.getValue(), Matchers.is(equalTo("SIGRUN_LIGNET:Feil="))); }) .verifyComplete(); } @@ -106,7 +108,9 @@ void gjenopprett_sigrunstub_ok() { .thenReturn(request.getSigrunstub()); when(sigrunStubConsumer.createSkattegrunnlag(anyList())).thenReturn(Mono.just(SigrunstubResponse.builder() - .errorStatus(HttpStatus.OK) + .opprettelseTilbakemeldingsListe(List.of(SigrunstubResponse.OpprettelseTilbakemelding.builder() + .status(200) + .build())) .build())); when(sigrunStubConsumer.deleteSkattegrunnlag(IDENT)).thenReturn(Mono.just(new SigrunstubResponse())); @@ -117,7 +121,7 @@ void gjenopprett_sigrunstub_ok() { .assertNext(status -> { verify(transactionHelperService, times(1)) .persister(any(BestillingProgress.class), any(), statusCaptor.capture()); - assertThat(statusCaptor.getValue(), Matchers.is(equalTo("OK"))); + assertThat(statusCaptor.getValue(), Matchers.is(equalTo("SIGRUN_LIGNET:OK"))); }) .verifyComplete(); 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 d77ac670d91..e7dba30ebce 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 @@ -3,10 +3,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.client.WireMock; +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; -import no.nav.dolly.errorhandling.ErrorStatusDecoder; import no.nav.testnav.libs.securitycore.domain.AccessToken; import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange; import org.junit.jupiter.api.BeforeEach; @@ -31,6 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.matching; import static com.github.tomakehurst.wiremock.client.WireMock.ok; import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; import static java.util.Collections.singletonList; @@ -48,14 +49,13 @@ class SigrunStubConsumerTest { @MockBean private TokenExchange tokenService; - @MockBean - private ErrorStatusDecoder errorStatusDecoder; - @Autowired private SigrunStubConsumer sigrunStubConsumer; private OpprettSkattegrunnlag skattegrunnlag; + private PensjonsgivendeForFolketrygden pensjonsgivendeForFolketrygden; + private static String asJsonString(final Object object) throws JsonProcessingException { return new ObjectMapper().writeValueAsString(object); } @@ -70,6 +70,10 @@ void setup() { skattegrunnlag = OpprettSkattegrunnlag.builder() .inntektsaar("1978") .build(); + + pensjonsgivendeForFolketrygden = PensjonsgivendeForFolketrygden.builder() + .inntektsaar("1978") + .build(); } @Test @@ -77,13 +81,31 @@ void createSkattegrunnlag() { stubOpprettSkattegrunnlagOK(); - StepVerifier.create(sigrunStubConsumer.createSkattegrunnlag(singletonList(this.skattegrunnlag))) + StepVerifier.create(sigrunStubConsumer.createSkattegrunnlag(singletonList(skattegrunnlag))) .expectNext(SigrunstubResponse.builder() - .errorStatus(HttpStatus.OK) + .opprettelseTilbakemeldingsListe(List.of(SigrunstubResponse.OpprettelseTilbakemelding.builder() + .inntektsaar("1978") + .status(200) + .build())) .build()) .verifyComplete(); } + @Test + void createPensjonsgivendeOK() { + + stubOpprettPensjongivendeOK(); + + StepVerifier.create(sigrunStubConsumer.updatePensjonsgivendeInntekt(singletonList(pensjonsgivendeForFolketrygden))) + .expectNext(SigrunstubResponse.builder() + .opprettelseTilbakemeldingsListe(List.of(SigrunstubResponse.OpprettelseTilbakemelding.builder() + .inntektsaar("1978") + .status(200) + .build())) + .build()) + .verifyComplete(); + } + @Test void createSkattegrunnlag_kasterSigrunExceptionHvisKallKasterClientException() throws Exception { @@ -114,7 +136,15 @@ private void stubOpprettSkattegrunnlagOK() { stubFor(post(urlPathMatching("(.*)/sigrunstub/api/v1/lignetinntekt")) .willReturn(ok() - .withBody("{}") + .withBody("{\"opprettelseTilbakemeldingsListe\":[{\"status\":200}]}") + .withHeader("Content-Type", "application/json"))); + } + + private void stubOpprettPensjongivendeOK() { + + stubFor(put(urlPathMatching("(.*)/sigrunstub/api/v1/pensjonsgivendeinntektforfolketrygden")) + .willReturn(ok() + .withBody("{\"opprettelseTilbakemeldingsListe\":[{\"status\":200}]}") .withHeader("Content-Type", "application/json"))); }