From f77c3b8d67a6efec506e46d754af9739238b77e3 Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Fri, 8 Sep 2023 13:25:12 +0200 Subject: [PATCH 01/12] Oppdatert logging og muligens rettet feil #deploy-person-service --- .../consumer/PdlApiConsumer.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/PdlApiConsumer.java b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/PdlApiConsumer.java index e428f628b8..db6029fb83 100644 --- a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/PdlApiConsumer.java +++ b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/PdlApiConsumer.java @@ -16,6 +16,7 @@ import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; +import reactor.util.function.Tuple2; import java.util.Collection; import java.util.List; @@ -86,10 +87,19 @@ private boolean isGruppe(PdlAktoer.AktoerIdent ident, String gruppe) { return isNotBlank(ident.getIdent()) && !ident.getHistorisk() && gruppe.equals(ident.getGruppe()); } + private boolean isPresent(String ident, Tuple2 pdlAktoer, Set opplysningId) { + + var statusQ1 = isPresent(ident, pdlAktoer.getT1(), "q1", opplysningId); + var statusQ2 = isPresent(ident, pdlAktoer.getT2(), "q2", opplysningId); + + log.info("Ident {}, isPresent() {}, (q1: {}, q2: {})", ident, statusQ1 && statusQ2, statusQ1, statusQ2); + return statusQ1 && statusQ2; + } + private boolean isPresent(String ident, PdlAktoer pdlAktoer, String miljoe, Set opplysningId) { var person = pdlAktoer.getData().getHentPerson(); - log.info("Sjekker ident {} med PDL opplysningId {}, sjekkes for mottatt opplysningId {}", ident, + log.info("Sjekker ident {} i miljø {}, med PDL opplysningId {}, sjekkes for mottatt opplysningId {}", ident, miljoe, nonNull(person) ? Stream.of(person.getNavn(), person.getFoedsel(), person.getFolkeregisteridentifikator(), person.getFolkeregisterpersonstatus(), person.getBostedsadresse()) .flatMap(Collection::stream) @@ -123,7 +133,6 @@ private boolean isPresent(String ident, PdlAktoer pdlAktoer, String miljoe, Set< identer.stream().anyMatch(ident2 -> isGruppe(ident2, "NPID"))); } - log.info("Ident {}, isPresent() {}, (miljo {})", ident, resultat, miljoe); return resultat; } @@ -144,12 +153,10 @@ public Mono> getAktoer(String ident) { public Mono isPerson(String ident, Set opplysningId) { - log.info("Henter ident {} fra PDL", ident); return tokenExchange .exchange(serviceProperties) - .flatMap(token -> Mono.zip(new GetPdlAktoerCommand(webClient, PDL_URL, ident, token.getTokenValue()).call(), - new GetPdlAktoerCommand(webClient, PDL_Q1_URL, ident, token.getTokenValue()).call()) - .map(tuple -> isPresent(ident, tuple.getT1(), "q2", opplysningId) && - isPresent(ident, tuple.getT2(), "q1", opplysningId))); + .flatMap(token -> Mono.zip(new GetPdlAktoerCommand(webClient, PDL_Q1_URL, ident, token.getTokenValue()).call(), + new GetPdlAktoerCommand(webClient, PDL_URL, ident, token.getTokenValue()).call()) + .map(tuple -> isPresent(ident, tuple, opplysningId))); } } From 1aece6561bb79d51f1e382826a7d0e2a21ca0766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristen=20H=C3=A6rum?= Date: Fri, 8 Sep 2023 15:13:41 +0200 Subject: [PATCH 02/12] =?UTF-8?q?Fiks=20for=20Excel=20bankkonti=20#deploy-?= =?UTF-8?q?dolly-backend=20#deploy-test-dolly-bac=E2=80=A6=20(#3271)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bugfiks for Excel bankkonti --- .../dolly/DollyBackendApplicationStarter.java | 2 +- .../KontoregisterConsumer.java | 10 +- .../consumer/pdlperson/PdlPersonConsumer.java | 8 +- .../dolly/provider/api/ExcelController.java | 27 ++- .../service/excel/BankkontoExcelService.java | 187 +++--------------- .../excel/BankkontoToPersonHelper.java | 20 +- .../nav/dolly/service/excel/ExcelService.java | 24 +-- .../service/excel/PersonExcelService.java | 177 ++++++++--------- .../src/main/resources/application.yaml | 3 + 9 files changed, 176 insertions(+), 282 deletions(-) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java b/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java index 317d2b3da4..39fb82ea03 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java @@ -9,4 +9,4 @@ public static void main(String[] args) { SpringApplication.run(DollyBackendApplicationStarter.class, args); } -} +} \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/kontoregisterservice/KontoregisterConsumer.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/kontoregisterservice/KontoregisterConsumer.java index 646b7dbc74..f58e84f6a6 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/kontoregisterservice/KontoregisterConsumer.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/kontoregisterservice/KontoregisterConsumer.java @@ -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; @@ -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(); } @@ -88,5 +97,4 @@ public String serviceUrl() { public String consumerName() { return "testnav-kontoregister-person-proxy"; } - } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/pdlperson/PdlPersonConsumer.java b/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/pdlperson/PdlPersonConsumer.java index 68a41597ad..7659debb89 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/pdlperson/PdlPersonConsumer.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/pdlperson/PdlPersonConsumer.java @@ -39,7 +39,7 @@ @Service public class PdlPersonConsumer implements ConsumerStatus { - private static final int BLOCK_SIZE = 50; + private static final int BLOCK_SIZE = 100; private static final int MAX_RETRIES = 3; private final TokenExchange tokenService; private final ServerProperties serviceProperties; @@ -79,6 +79,12 @@ public Flux getPdlPersoner(List identer) { return getPdlPersoner(identer, new AtomicInteger(0)); } + @Timed(name = "providers", tags = {"operation", "pdl_getPersoner"}) + public Flux getPdlPersonerNoRetries(List identer) { + + return getPdlPersoner(identer, new AtomicInteger(MAX_RETRIES)); + } + @Timed(name = "providers", tags = {"operation", "pdl_getPersoner"}) public Flux getPdlPersoner(List identer, AtomicInteger retry) { diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/ExcelController.java b/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/ExcelController.java index d6d5abf7ac..068fc6348e 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/ExcelController.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/ExcelController.java @@ -9,11 +9,8 @@ import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; import java.io.IOException; @@ -30,7 +27,7 @@ public class ExcelController { @SneakyThrows @GetMapping(value = "/gruppe/{gruppeId}") - public ResponseEntity getExcelsheet(@PathVariable Long gruppeId){ + public Mono> getExcelsheet(@PathVariable Long gruppeId) { var resource = excelService.getExcelWorkbook(gruppeId); @@ -39,7 +36,7 @@ public ResponseEntity getExcelsheet(@PathVariable Long gruppeId){ @SneakyThrows @GetMapping(value = "/organisasjoner") - public ResponseEntity getOrganisasjonExcelsheet(@RequestParam(required = false) String brukerId){ + public ResponseEntity getOrganisasjonExcelsheet(@RequestParam(required = false) String brukerId) { var bruker = brukerService.fetchOrCreateBruker(StringUtils.isNotBlank(brukerId) ? brukerId : getUserId(getUserInfo)); var resource = excelService.getExcelOrganisasjonerWorkbook(bruker); @@ -55,4 +52,20 @@ private ResponseEntity wrapContents(Resource resource) throws IOExcept .contentType(MediaType.parseMediaType("application/vnd.ms-excel")) .body(resource); } + + private Mono> wrapContents(Mono resource) { + + return resource + .handle((resource1, sink) -> { + try { + sink.next(ResponseEntity.ok() + .header("Content-Disposition", "attachment; filename=" + resource1.getFilename()) + .contentLength(resource1.contentLength()) + .contentType(MediaType.parseMediaType("application/vnd.ms-excel")) + .body(resource1)); + } catch (IOException e) { + sink.error(new RuntimeException(e)); + } + }); + } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoExcelService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoExcelService.java index 9bffc1565d..f7340687b5 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoExcelService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoExcelService.java @@ -1,17 +1,12 @@ package no.nav.dolly.service.excel; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import no.nav.dolly.bestilling.kontoregisterservice.KontoregisterConsumer; -import no.nav.dolly.bestilling.tpsmessagingservice.TpsMessagingConsumer; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.jpa.Testgruppe; -import no.nav.dolly.repository.BestillingRepository; -import no.nav.testnav.libs.dto.kontoregisterservice.v1.BankkontonrNorskDTO; -import no.nav.testnav.libs.dto.kontoregisterservice.v1.BankkontonrUtlandDTO; import no.nav.testnav.libs.dto.kontoregisterservice.v1.KontoDTO; -import no.nav.testnav.libs.dto.tpsmessagingservice.v1.PersonDTO; -import no.nav.testnav.libs.dto.tpsmessagingservice.v1.PersonMiljoeDTO; import org.apache.poi.ss.usermodel.IgnoredErrorType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -20,245 +15,123 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.time.LocalDateTime; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import static no.nav.dolly.service.excel.ExcelUtil.BANKKONTO_COL_WIDTHS; -import static no.nav.dolly.service.excel.ExcelUtil.BANKKONTO_FANE; -import static no.nav.dolly.service.excel.ExcelUtil.BANKKONTO_HEADER; +import static no.nav.dolly.service.excel.ExcelUtil.*; import static org.apache.commons.lang3.StringUtils.isNotBlank; +@Slf4j @Service @RequiredArgsConstructor public class BankkontoExcelService { - private static final LocalDateTime NYTT_KONTOREGISTER_FRA_DATO = LocalDateTime.of(2022, 8, 30, 0, 0); - private final TpsMessagingConsumer tpsMessagingConsumer; private final KontoregisterConsumer kontoregisterConsumer; - private final BestillingRepository bestillingRepository; - private static String getAdresse1(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getBankadresse1()) ? konto.getUtenlandskKontoInfo().getBankadresse1() : ""; } - private static String getAdresse1(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getBankAdresse1()) ? - bankkontonrUtland.getBankAdresse1().trim() : ""; - } - private static String getAdresse2(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getBankadresse2()) ? konto.getUtenlandskKontoInfo().getBankadresse2() : ""; } - private static String getAdresse2(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getBankAdresse2()) ? - bankkontonrUtland.getBankAdresse2().trim() : ""; - } - private static String getAdresse3(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getBankadresse3()) ? konto.getUtenlandskKontoInfo().getBankadresse3() : ""; } - private static String getAdresse3(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getBankAdresse3()) ? - bankkontonrUtland.getBankAdresse3().trim() : ""; - } - private static String getSwift(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getSwiftBicKode()) ? konto.getUtenlandskKontoInfo().getSwiftBicKode() : ""; } - private static String getSwift(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getSwift()) ? - bankkontonrUtland.getSwift().trim() : ""; - } - private static String getIban(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getKontonummer()) ? konto.getKontonummer() : ""; } - private static String getIban(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getIban()) ? - bankkontonrUtland.getIban().trim() : ""; - } - private static String getBanknavn(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getBanknavn()) ? konto.getUtenlandskKontoInfo().getBanknavn() : ""; } - private static String getBanknavn(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getBanknavn()) ? - bankkontonrUtland.getBanknavn().trim() : ""; - } - private static String getBankkontonrNorge(KontoDTO konto) { return nonNull(konto) && isNull(konto.getUtenlandskKontoInfo()) ? konto.getKontonummer() : ""; } - private static String getBankkontonrNorge(BankkontonrNorskDTO bankkontonrNorsk) { - - return nonNull(bankkontonrNorsk) && isNotBlank(bankkontonrNorsk.getKontonummer()) ? - bankkontonrNorsk.getKontonummer().replace(".", "") : ""; - } - private static String getBankkontonrUtland(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) ? konto.getKontonummer() : ""; } - private static String getBankkontonrUtland(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getKontonummer()) ? - bankkontonrUtland.getKontonummer().trim() : ""; - } - private static String getLandkode(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getBankLandkode()) ? konto.getUtenlandskKontoInfo().getBankLandkode() : ""; } - private static String getLandkode(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getLandkode()) ? - bankkontonrUtland.getLandkode() : ""; - } - private static String getValuta(KontoDTO konto) { return nonNull(konto) && nonNull(konto.getUtenlandskKontoInfo()) && isNotBlank(konto.getUtenlandskKontoInfo().getValutakode()) ? konto.getUtenlandskKontoInfo().getValutakode() : ""; } - private static String getValuta(BankkontonrUtlandDTO bankkontonrUtland) { - - return nonNull(bankkontonrUtland) && isNotBlank(bankkontonrUtland.getValuta()) ? - bankkontonrUtland.getValuta() : ""; - } - public Mono prepareBankkontoSheet(XSSFWorkbook workbook, Testgruppe testgruppe) { - var rows = getBankkontoDetaljer(testgruppe); - - if (!rows.isEmpty()) { - var sheet = workbook.createSheet(BANKKONTO_FANE); - - sheet.addIgnoredErrors(new CellRangeAddress(0, rows.size(), 0, BANKKONTO_HEADER.length), - IgnoredErrorType.NUMBER_STORED_AS_TEXT); + return getBankkontoDetaljer(testgruppe) + .filter(rows -> !rows.isEmpty()) + .flatMap(rows -> { - var columnNo = new AtomicInteger(0); - Arrays.stream(BANKKONTO_COL_WIDTHS) - .forEach(colWidth -> sheet.setColumnWidth(columnNo.getAndIncrement(), colWidth * 256)); + var sheet = workbook.createSheet(BANKKONTO_FANE); + sheet.addIgnoredErrors(new CellRangeAddress(0, rows.size(), 0, BANKKONTO_HEADER.length), + IgnoredErrorType.NUMBER_STORED_AS_TEXT); - ExcelService.appendRows(workbook, BANKKONTO_FANE, - Stream.of(Collections.singletonList(BANKKONTO_HEADER), rows) - .flatMap(Collection::stream) - .toList()); - } + var columnNo = new AtomicInteger(0); + Arrays.stream(BANKKONTO_COL_WIDTHS) + .forEach(colWidth -> sheet.setColumnWidth(columnNo.getAndIncrement(), colWidth * 256)); - return Mono.empty(); - } + ExcelService.appendRows(workbook, BANKKONTO_FANE, + Stream.of(Collections.singletonList(BANKKONTO_HEADER), rows) + .flatMap(Collection::stream) + .toList()); - private Mono> tpsBankkonto(List identer) { - return Flux.range(0, identer.size()) - .flatMap(index -> tpsMessagingConsumer.getPersoner(List.of(identer.get(index)), List.of("q1"))) - .filter(PersonMiljoeDTO::isOk) - .map(PersonMiljoeDTO::getPerson) - .map(person -> unpackBankkonto(person)) - .collectList(); + return Mono.empty(); + }); } - private Mono> kontoregisterBankkonto(List identer) { + private Mono> getBankkontoDetaljer(Testgruppe testgruppe) { - return Flux.fromIterable(identer) + var start = System.currentTimeMillis(); + return Flux.fromIterable(testgruppe.getBestillinger()) + .map(Bestilling::getProgresser) + .flatMap(Flux::fromIterable) + .filter(progress -> isNotBlank(progress.getKontoregisterStatus())) + .map(BestillingProgress::getIdent) + .distinct() .flatMap(ident -> kontoregisterConsumer.getKontonummer(ident) .filter(response -> HttpStatus.OK.equals(response.getStatus())) .map(response -> unpackBankkonto(response.getAktivKonto()))) - .collectList(); - } - - private List getBankkontoDetaljer(Testgruppe testgruppe) { - - var bankKontoIdenter = testgruppe.getBestillinger().stream() - .filter(bestilling -> nonNull(bestilling.getBestKriterier())) - .filter(bestilling -> bestilling.getBestKriterier().contains("Bankkonto")) - .map(Bestilling::getProgresser) - .flatMap(Collection::stream) - .collect(Collectors.teeing( - Collectors.filtering( - p -> !p.getBestilling().getSistOppdatert().isAfter(NYTT_KONTOREGISTER_FRA_DATO), - Collectors.toList() - ), - Collectors.filtering( - p -> p.getBestilling().getSistOppdatert().isAfter(NYTT_KONTOREGISTER_FRA_DATO) && - nonNull(p.getKontoregisterStatus()) && - !p.getKontoregisterStatus().contains("Feil"), - Collectors.toList() - ), - (tps, kontoregister) -> { - var result = new ConcurrentHashMap>(); - result.put("tps", tps.stream().map(BestillingProgress::getIdent).distinct().toList()); - result.put("kontoregister", kontoregister.stream().map(BestillingProgress::getIdent).distinct().toList()); - return result; - } - )); - - return List.of( - tpsBankkonto(bankKontoIdenter.get("tps")), - kontoregisterBankkonto(bankKontoIdenter.get("kontoregister")) - ) - .parallelStream() - .map(Mono::block) - .flatMap(Collection::stream) - .toList(); - } - - private Object[] unpackBankkonto(PersonDTO person) { - - return new Object[]{ - person.getIdent(), - getBankkontonrNorge(person.getBankkontonrNorsk()), - getBankkontonrUtland(person.getBankkontonrUtland()), - getBanknavn(person.getBankkontonrUtland()), - getIban(person.getBankkontonrUtland()), - getLandkode(person.getBankkontonrUtland()), - getValuta(person.getBankkontonrUtland()), - getSwift(person.getBankkontonrUtland()), - getAdresse1(person.getBankkontonrUtland()), - getAdresse2(person.getBankkontonrUtland()), - getAdresse3(person.getBankkontonrUtland()) - }; + .collectList() + .doOnNext(bankkonti -> log.info("Excel: hentet {} antall bankkonti, tid {} sekunder", bankkonti.size(), + (System.currentTimeMillis() - start) / 1000)); } private Object[] unpackBankkonto(KontoDTO konto) { @@ -277,4 +150,4 @@ private Object[] unpackBankkonto(KontoDTO konto) { getAdresse3(konto) }; } -} +} \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoToPersonHelper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoToPersonHelper.java index 1105be2432..0e4a810cd7 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoToPersonHelper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/BankkontoToPersonHelper.java @@ -10,10 +10,8 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import static java.util.Objects.isNull; -import static no.nav.dolly.service.excel.ExcelUtil.BANKKONTO_COL_WIDTHS; -import static no.nav.dolly.service.excel.ExcelUtil.BANKKONTO_FANE; -import static no.nav.dolly.service.excel.ExcelUtil.BANKKONTO_HEADER; -import static no.nav.dolly.service.excel.ExcelUtil.PERSON_FANE; +import static java.util.Objects.nonNull; +import static no.nav.dolly.service.excel.ExcelUtil.*; @UtilityClass public class BankkontoToPersonHelper { @@ -64,14 +62,16 @@ private static void appendRows(XSSFSheet personData, int startColumn, var ident = formatter.formatCellValue(bankDataRow.getCell(0)); var personDataMatchRow = getPersonDataRow(personData, ident); - for (int j = 1; j < relativeEndColumn; j++) { + if (nonNull(personDataMatchRow)) { + for (int j = 1; j < relativeEndColumn; j++) { - var dataCell = personDataMatchRow.createCell(startColumn + j); - var dataValue = formatter.formatCellValue(bankDataRow.getCell(j)); + var dataCell = personDataMatchRow.createCell(startColumn + j); + var dataValue = formatter.formatCellValue(bankDataRow.getCell(j)); - dataCell.setCellValue(dataValue); - if (dataValue.contains(",") || dataValue.length() > 25) { - dataCell.setCellStyle(wrapStyle); + dataCell.setCellValue(dataValue); + if (dataValue.contains(",") || dataValue.length() > 25) { + dataCell.setCellStyle(wrapStyle); + } } } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/ExcelService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/ExcelService.java index 62a2398d9d..39c257ee7f 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/ExcelService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/ExcelService.java @@ -5,12 +5,12 @@ import no.nav.dolly.domain.jpa.Bruker; import no.nav.dolly.exceptions.DollyFunctionalException; import no.nav.dolly.exceptions.NotFoundException; -import no.nav.dolly.repository.IdentRepository; import no.nav.dolly.repository.TestgruppeRepository; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.io.File; @@ -26,7 +26,6 @@ public class ExcelService { private final TestgruppeRepository testgruppeRepository; - private final IdentRepository identRepository; private final PersonExcelService personExcelService; private final BankkontoExcelService bankkontoExcelService; private final OrganisasjonExcelService organisasjonExcelService; @@ -57,24 +56,19 @@ protected static void appendRows(XSSFWorkbook workbook, String fane, List getExcelWorkbook(Long gruppeId) { long timestamp = System.currentTimeMillis(); var testgruppe = testgruppeRepository.findById(gruppeId) .orElseThrow(() -> new NotFoundException("Testgruppe ikke funnet for id " + gruppeId)); - var testidenter = identRepository.findByTestgruppe(testgruppe.getId()); - - var workbook = new XSSFWorkbook(); - - Mono.zip( - personExcelService.preparePersonSheet(workbook, testidenter), - bankkontoExcelService.prepareBankkontoSheet(workbook, testgruppe)) - .block(); - - BankkontoToPersonHelper.appendData(workbook); - - return convertToResource(timestamp, workbook); + return Mono.just(new XSSFWorkbook()) + .flatMap(workbook -> Flux.merge( + personExcelService.preparePersonSheet(workbook, testgruppe), + bankkontoExcelService.prepareBankkontoSheet(workbook, testgruppe)) + .collectList() + .doOnNext(resultat -> BankkontoToPersonHelper.appendData(workbook)) + .then(Mono.fromCallable(() -> convertToResource(timestamp, workbook)))); } public Resource getExcelOrganisasjonerWorkbook(Bruker bruker) { diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/PersonExcelService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/PersonExcelService.java index fa6085afab..18c84cfac6 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/PersonExcelService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/excel/PersonExcelService.java @@ -7,17 +7,11 @@ import no.nav.dolly.consumer.pdlperson.PdlPersonConsumer; import no.nav.dolly.domain.PdlPerson; import no.nav.dolly.domain.PdlPersonBolk; +import no.nav.dolly.domain.jpa.Testgruppe; import no.nav.dolly.domain.jpa.Testident; import no.nav.dolly.util.DatoFraIdentUtil; import no.nav.dolly.util.IdentTypeUtil; -import no.nav.testnav.libs.dto.pdlforvalter.v1.AdressebeskyttelseDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.BostedadresseDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.FullmaktDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.MatrikkeladresseDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.OppholdsadresseDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.SikkerhetstiltakDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.UtenlandskAdresseDTO; -import no.nav.testnav.libs.dto.pdlforvalter.v1.VegadresseDTO; +import no.nav.testnav.libs.dto.pdlforvalter.v1.*; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.IgnoredErrorType; import org.apache.poi.ss.util.CellRangeAddress; @@ -30,14 +24,9 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -45,14 +34,16 @@ import static java.util.Objects.nonNull; import static no.nav.dolly.service.excel.ExcelUtil.PERSON_FANE; import static no.nav.dolly.service.excel.ExcelUtil.appendHyperlinkRelasjon; +import static org.apache.commons.lang3.BooleanUtils.isTrue; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.trimToEmpty; @Slf4j @Service @RequiredArgsConstructor public class PersonExcelService { - private static final Object[] HEADER = {"Ident", "Identtype", "Fornavn", "Etternavn", "Alder", "Kjønn", "Foedselsdato", + private static final Object[] PERSONDATA_HEADER = {"Ident", "Identtype", "Fornavn", "Etternavn", "Alder", "Kjønn", "Foedselsdato", "Dødsdato", "Personstatus", "Statsborgerskap", "Adressebeskyttelse", "Bostedsadresse", "Kontaktadresse", "Oppholdsadresse", "Sivilstand", "Partner", "Barn", "Foreldre", "Verge", "Fullmektig", "Sikkerhetstiltak", "Brukt", "Beskrivelse"}; private static final Integer[] COL_WIDTHS = {14, 10, 20, 20, 6, 8, 12, 12, 18, 20, 20, 25, 25, 25, 25, 14, 14, 14, 14, 14, 14, 14, 20}; @@ -70,7 +61,6 @@ public class PersonExcelService { private static final int FORELDRE = 17; private static final int VERGE = 18; private static final int FULLMEKTIG = 19; - private static final int BLOCK_SIZE = 50; private final PdlPersonConsumer pdlPersonConsumer; private final KodeverkConsumer kodeverkConsumer; @@ -325,54 +315,64 @@ private static String getOppholdsadresse(OppholdsadresseDTO oppholdsadresse, Map } public Mono preparePersonSheet(XSSFWorkbook workbook, - List identer) { + Testgruppe testgruppe) { - var sheet = workbook.createSheet(PERSON_FANE); - var rows = getPersondataRowContents(identer); - sheet.addIgnoredErrors(new CellRangeAddress(0, rows.size(), 0, HEADER.length), - IgnoredErrorType.NUMBER_STORED_AS_TEXT); + return getPersondataRowContents(testgruppe) + .flatMap(rows -> { - var columnNo = new AtomicInteger(0); - Arrays.stream(COL_WIDTHS) - .forEach(colWidth -> sheet.setColumnWidth(columnNo.getAndIncrement(), colWidth * 256)); + var sheet = workbook.createSheet(PERSON_FANE); + sheet.addIgnoredErrors(new CellRangeAddress(0, rows.size(), 0, PERSONDATA_HEADER.length), + IgnoredErrorType.NUMBER_STORED_AS_TEXT); - ExcelService.appendRows(workbook, PERSON_FANE, - Stream.of(Collections.singletonList(HEADER), rows) - .flatMap(Collection::stream) - .toList()); + var columnNo = new AtomicInteger(0); + Arrays.stream(COL_WIDTHS) + .forEach(colWidth -> sheet.setColumnWidth(columnNo.getAndIncrement(), colWidth * 256)); - appendHyperlinks(workbook, rows); + ExcelService.appendRows(workbook, PERSON_FANE, + Stream.of(Collections.singletonList(PERSONDATA_HEADER), rows) + .flatMap(Collection::stream) + .toList()); - return Mono.empty(); - } + appendHyperlinks(workbook, rows); - private List identList(List hovedpersoner) { - return hovedpersoner.stream() - .map(Testident::getIdent) - .toList(); + return Mono.empty(); + }); } - private List getPersondataRowContents(List hovedpersoner) { - - var start = System.currentTimeMillis(); - var personer = new ArrayList<>(getPersoner(identList(hovedpersoner), hovedpersoner)); - - log.info("Excel: hentet alle hovedpersoner, medgått tid er {} sekunder", (System.currentTimeMillis() - start) / 1000); - start = System.currentTimeMillis(); - personer.addAll(getPersoner(Stream.of( - getIdenterForRelasjon(personer, PARTNER), - getIdenterForRelasjon(personer, BARN), - getIdenterForRelasjon(personer, FORELDRE), - getIdenterForRelasjon(personer, VERGE), - getIdenterForRelasjon(personer, FULLMEKTIG) - ) - .flatMap(Collection::stream) - .filter(ident -> hovedpersoner.stream().noneMatch(person -> person.getIdent().equals(ident))) - .distinct() - .toList(), hovedpersoner) - ); - log.info("Excel: hentet alle relasjoner, medgått tid er {} sekunder", (System.currentTimeMillis() - start) / 1000); - return personer; + private Mono> getPersondataRowContents(Testgruppe testgruppe) { + + var start = new AtomicLong(); + return Flux.just(testgruppe) + .doOnNext(gruppe -> start.set(System.currentTimeMillis())) + .map(gruppe -> testgruppe.getTestidenter()) + .flatMap(Flux::fromIterable) + .collectList() + .flatMap(testidenter -> getPersoner(testidenter) + .doOnNext(personer -> + log.info("Excel: hentet alle hovedpersoner antall {}, medgått tid er {} sekunder", + personer.size(), + (System.currentTimeMillis() - start.get()) / 1000)) + .doOnNext(personer -> start.set(System.currentTimeMillis())) + .flatMap(personer -> Flux.concat(Mono.just(personer), + getPersoner(Stream.of( + getIdenterForRelasjon(personer, PARTNER), + getIdenterForRelasjon(personer, BARN), + getIdenterForRelasjon(personer, FORELDRE), + getIdenterForRelasjon(personer, VERGE), + getIdenterForRelasjon(personer, FULLMEKTIG)) + .flatMap(Collection::stream) + .distinct() + .filter(ident -> testidenter.stream().noneMatch(person -> person.getIdent().equals(ident))) + .map(ident -> Testident.builder() + .ident(ident) + .build()) + .toList())) + .flatMap(Flux::fromIterable) + .collectList() + .doOnNext(allePersoner -> + log.info("Excel: hentet alle relasjoner, totalt antall {}, medgått tid er {} sekunder", + allePersoner.size(), + (System.currentTimeMillis() - start.get()) / 1000)))); } private void appendHyperlinks(XSSFWorkbook workbook, List persondata) { @@ -385,25 +385,27 @@ private void appendHyperlinks(XSSFWorkbook workbook, List persondata) } @SneakyThrows - private List getPersoner(List identer, List testidenter) { - - return identer.isEmpty() ? - Collections.emptyList() : - - Mono.zip(kodeverkConsumer.getKodeverkByName(LANDKODER), - kodeverkConsumer.getKodeverkByName(KOMMUNENR), - kodeverkConsumer.getKodeverkByName(POSTNUMMER)) - .flatMapMany(kodeverk -> Flux.range(0, identer.size() / BLOCK_SIZE + 1) - .flatMap(index -> pdlPersonConsumer.getPdlPersoner(identer.subList(index * BLOCK_SIZE, Math.min((index + 1) * BLOCK_SIZE, identer.size()))) - ) - .filter(personbolk -> nonNull(personbolk.getData())) - .map(PdlPersonBolk::getData) - .map(PdlPersonBolk.Data::getHentPersonBolk) - .flatMap(Flux::fromIterable) - .filter(personBolk -> nonNull(personBolk.getPerson())) - .map(person -> prepDataRow(person, kodeverk, testidenter))) - .collectList() - .block(); + private Mono> getPersoner(List testidenter) { + + return Flux.fromIterable(testidenter) + .map(Testident::getIdent) + .distinct() + .collectList() + .filter(identer -> !identer.isEmpty()) + .flatMap(identer -> + + Mono.zip(kodeverkConsumer.getKodeverkByName(LANDKODER), + kodeverkConsumer.getKodeverkByName(KOMMUNENR), + kodeverkConsumer.getKodeverkByName(POSTNUMMER)) + + .flatMap(kodeverk -> pdlPersonConsumer.getPdlPersonerNoRetries(identer) + .filter(personbolk -> nonNull(personbolk.getData())) + .map(PdlPersonBolk::getData) + .map(PdlPersonBolk.Data::getHentPersonBolk) + .flatMap(Flux::fromIterable) + .filter(personBolk -> nonNull(personBolk.getPerson())) + .map(person -> prepDataRow(person, kodeverk, testidenter)) + .collectList())); } private Object[] prepDataRow(PdlPersonBolk.PersonBolk person, Tuple3 kodeverk, List identer) { @@ -445,26 +447,21 @@ private Object[] prepDataRow(PdlPersonBolk.PersonBolk person, Tuple3 kodeverk, L } private static String getIBruk(PdlPersonBolk.PersonBolk person, List identer) { - var testident = identer.stream() - .filter(ident -> ident.getIdent().equals(person.getIdent())) - .findAny(); - if (testident.isEmpty() || (testident.get().getIBruk() == null)) { - return ""; - } - - return Boolean.TRUE.equals(testident.get().getIBruk()) ? "Ja" : "Nei"; + return identer.stream() + .anyMatch(ident -> ident.getIdent().equals(person.getIdent()) && + isTrue(ident.getIBruk())) ? + "Ja" : "Nei"; } private static String getBeskrivelse(PdlPersonBolk.PersonBolk person, List identer) { - var testident = identer.stream() + + var beskrivelse = identer.stream() .filter(ident -> ident.getIdent().equals(person.getIdent())) + .map(Testident::getBeskrivelse) + .filter(StringUtils::isNotBlank) .findAny(); - if (testident.isPresent()) { - return StringUtils.trimToEmpty(testident.get().getBeskrivelse()); - } else { - return ""; - } + return beskrivelse.isPresent() ? trimToEmpty(beskrivelse.get()) : ""; } } diff --git a/apps/dolly-backend/src/main/resources/application.yaml b/apps/dolly-backend/src/main/resources/application.yaml index d409b85478..d1782fc0e7 100644 --- a/apps/dolly-backend/src/main/resources/application.yaml +++ b/apps/dolly-backend/src/main/resources/application.yaml @@ -28,6 +28,9 @@ spring: enabled: true # Disabled by default as you should probably think twice before running Flyway-migrations locations: classpath:db/migration baseline-on-migrate: true + mvc: + async: + request-timeout: -1 jpa: properties: hibernate: From 4bc1408a7b6448c9f5a73e3be2bb478fcf17d0df Mon Sep 17 00:00:00 2001 From: Trong Huu Nguyen Date: Mon, 11 Sep 2023 14:30:48 +0200 Subject: [PATCH 03/12] chore(arbeidsplassencv-proxy): update fakedings url (#3273) The old url is deprecated and will be removed soon. --- .../arbeidsplassencvproxy/consumer/FakedingsConsumer.java | 2 +- .../arbeidsplassencv-proxy/src/main/resources/application.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/proxies/arbeidsplassencv-proxy/src/main/java/no/nav/testnav/proxies/arbeidsplassencvproxy/consumer/FakedingsConsumer.java b/proxies/arbeidsplassencv-proxy/src/main/java/no/nav/testnav/proxies/arbeidsplassencvproxy/consumer/FakedingsConsumer.java index ff8350d5b0..c439312236 100644 --- a/proxies/arbeidsplassencv-proxy/src/main/java/no/nav/testnav/proxies/arbeidsplassencvproxy/consumer/FakedingsConsumer.java +++ b/proxies/arbeidsplassencv-proxy/src/main/java/no/nav/testnav/proxies/arbeidsplassencvproxy/consumer/FakedingsConsumer.java @@ -12,7 +12,7 @@ @Service public class FakedingsConsumer { - private static final String FAKE_TOKENDINGS_URL = "https://fakedings.dev-gcp.nais.io"; + private static final String FAKE_TOKENDINGS_URL = "https://fakedings.intern.dev.nav.no"; private final WebClient webClient; public FakedingsConsumer(ObjectMapper objectMapper) { diff --git a/proxies/arbeidsplassencv-proxy/src/main/resources/application.yml b/proxies/arbeidsplassencv-proxy/src/main/resources/application.yml index 6f3d9ef07a..cc320079a5 100644 --- a/proxies/arbeidsplassencv-proxy/src/main/resources/application.yml +++ b/proxies/arbeidsplassencv-proxy/src/main/resources/application.yml @@ -31,5 +31,5 @@ consumer: fakedings-token-provider: name: fakedings namespace: plattformsikkerhet - url: https://fakedings.dev-gcp.nais.io - cluster: dev-fss \ No newline at end of file + url: https://fakedings.intern.dev.nav.no + cluster: dev-fss From 52b0b018c38aac72ecddf61f8f9500cef183b4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristen=20H=C3=A6rum?= Date: Tue, 12 Sep 2023 09:59:39 +0200 Subject: [PATCH 04/12] =?UTF-8?q?Nye=20kommunenumre=20for=20KOR2024=20#dep?= =?UTF-8?q?loy-test-pdl-forvalter=20#deploy-pdl-f=E2=80=A6=20(#3274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KOR2024 -- midlertidig fiks for nye kommunenumre --- .../consumer/kodeverk/KodeverkMapper.java | 10 ++ .../consumer/kodeverk/Kor2024NyeKommuner.java | 135 ++++++++++++++++ .../MatrikkeladresseServiceCommand.java | 12 +- .../command/VegadresseServiceCommand.java | 13 +- .../mapper/KontaktadresseMappingStrategy.java | 10 +- .../service/KontaktAdresseService.java | 2 +- .../utils/Kor2024KommuneEndringer.java | 151 ++++++++++++++++++ 7 files changed, 323 insertions(+), 10 deletions(-) create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/Kor2024NyeKommuner.java create mode 100644 apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/utils/Kor2024KommuneEndringer.java diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/KodeverkMapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/KodeverkMapper.java index 4cdaa04937..b6034fdd9e 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/KodeverkMapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/KodeverkMapper.java @@ -32,6 +32,16 @@ public Flux mapBetydningToAdjustedKodeverk(String kodeverkNavn .name(kodeverkNavn) .koder(extractKoderFromBetydninger(betydning)) .build()) + .doOnNext(kor24Adjustment -> { + if ("Kommuner".equals(kodeverkNavn)) { + kor24Adjustment.getKoder() + .forEach(kode -> { + if (Kor2024NyeKommuner.isNewKommune(kode.getValue())) { + kode.setLabel(kode.getLabel() + " (NY)"); + } + }); + } + }) .cache(Duration.ofHours(9)); } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/Kor2024NyeKommuner.java b/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/Kor2024NyeKommuner.java new file mode 100644 index 0000000000..e20bc69fb7 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/consumer/kodeverk/Kor2024NyeKommuner.java @@ -0,0 +1,135 @@ +package no.nav.dolly.consumer.kodeverk; + +import lombok.experimental.UtilityClass; + +import java.util.HashSet; +import java.util.Set; + +@UtilityClass +public class Kor2024NyeKommuner { + + private static Set KOMMUNER = new HashSet<>(); + + static { + KOMMUNER.add("1508"); // Ålesund + KOMMUNER.add("1580"); // Haram + KOMMUNER.add("3101"); // Halden + KOMMUNER.add("3103"); // Moss + KOMMUNER.add("3105"); // Sarpsborg + KOMMUNER.add("3107"); // Fredrikstad + KOMMUNER.add("3301"); // Drammen + KOMMUNER.add("3303"); // Kongsberg + KOMMUNER.add("3305"); // Ringerike + KOMMUNER.add("3110"); // Hvaler + KOMMUNER.add("3124"); // Aremark + KOMMUNER.add("3122"); // Marker + KOMMUNER.add("3118"); // Indre Østfold + KOMMUNER.add("3116"); // Skiptvet + KOMMUNER.add("3120"); // Rakkestad + KOMMUNER.add("3112"); // Råde + KOMMUNER.add("3114"); // Våler + KOMMUNER.add("3216"); // Vestby + KOMMUNER.add("3207"); // Nordre Follo + KOMMUNER.add("3218"); // Ås + KOMMUNER.add("3214"); // Frogn + KOMMUNER.add("3212"); // Nesodden + KOMMUNER.add("3201"); // Bærum + KOMMUNER.add("3203"); // Asker + KOMMUNER.add("3226"); // Aurskog-Høland + KOMMUNER.add("3224"); // Rælingen + KOMMUNER.add("3220"); // Enebakk + KOMMUNER.add("3222"); // Lørenskog + KOMMUNER.add("3205"); // Lillestrøm + KOMMUNER.add("3232"); // Nittedal + KOMMUNER.add("3230"); // Gjerdrum + KOMMUNER.add("3209"); // Ullensaker + KOMMUNER.add("3228"); // Nes + KOMMUNER.add("3240"); // Eidsvoll + KOMMUNER.add("3238"); // Nannestad + KOMMUNER.add("3242"); // Hurdal + KOMMUNER.add("3310"); // Hole + KOMMUNER.add("3320"); // Flå + KOMMUNER.add("3322"); // Nesbyen + KOMMUNER.add("3324"); // Gol + KOMMUNER.add("3326"); // Hemsedal + KOMMUNER.add("3328"); // Ål + KOMMUNER.add("3330"); // Hol + KOMMUNER.add("3332"); // Sigdal + KOMMUNER.add("3318"); // Krødsherad + KOMMUNER.add("3316"); // Modum + KOMMUNER.add("3314"); // Øvre Eiker + KOMMUNER.add("3312"); // Lier + KOMMUNER.add("3334"); // Flesberg + KOMMUNER.add("3336"); // Rollag + KOMMUNER.add("3338"); // Nore og Uvdal + KOMMUNER.add("3236"); // Jevnaker + KOMMUNER.add("3234"); // Lunner + KOMMUNER.add("3901"); // Horten + KOMMUNER.add("3903"); // Holmestrand + KOMMUNER.add("3905"); // Tønsberg + KOMMUNER.add("3907"); // Sandefjord + KOMMUNER.add("3909"); // Larvik + KOMMUNER.add("4001"); // Porsgrunn + KOMMUNER.add("4003"); // Skien + KOMMUNER.add("4005"); // Notodden + KOMMUNER.add("3911"); // Færder + KOMMUNER.add("4010"); // Siljan + KOMMUNER.add("4012"); // Bamble + KOMMUNER.add("4014"); // Kragerø + KOMMUNER.add("4016"); // Drangedal + KOMMUNER.add("4018"); // Nome + KOMMUNER.add("4020"); // Midt-Telemark + KOMMUNER.add("4026"); // Tinn + KOMMUNER.add("4024"); // Hjartdal + KOMMUNER.add("4022"); // Seljord + KOMMUNER.add("4028"); // Kviteseid + KOMMUNER.add("4030"); // Nissedal + KOMMUNER.add("4032"); // Fyresdal + KOMMUNER.add("4034"); // Tokke + KOMMUNER.add("4036"); // Vinje + KOMMUNER.add("5501"); // Tromsø + KOMMUNER.add("5503"); // Harstad + KOMMUNER.add("5601"); // Alta + KOMMUNER.add("5634"); // Vardø + KOMMUNER.add("5607"); // Vadsø + KOMMUNER.add("5603"); // Hammerfest + KOMMUNER.add("5510"); // Kvæfjord + KOMMUNER.add("5512"); // Tjeldsund + KOMMUNER.add("5514"); // Ibestad + KOMMUNER.add("5516"); // Gratangen + KOMMUNER.add("5518"); // Lavangen + KOMMUNER.add("5520"); // Bardu + KOMMUNER.add("5522"); // Salangen + KOMMUNER.add("5524"); // Målselv + KOMMUNER.add("5526"); // Sørreisa + KOMMUNER.add("5528"); // Dyrøy + KOMMUNER.add("5530"); // Senja + KOMMUNER.add("5532"); // Balsfjord + KOMMUNER.add("5534"); // Karlsøy + KOMMUNER.add("5536"); // Lyngen + KOMMUNER.add("5538"); // Storfjord + KOMMUNER.add("5540"); // Kåfjord + KOMMUNER.add("5542"); // Skjervøy + KOMMUNER.add("5544"); // Nordreisa + KOMMUNER.add("5546"); // Kvænangen + KOMMUNER.add("5612"); // Kautokeino + KOMMUNER.add("5614"); // Loppa + KOMMUNER.add("5616"); // Hasvik + KOMMUNER.add("5618"); // Måsøy + KOMMUNER.add("5620"); // Nordkapp + KOMMUNER.add("5622"); // Porsanger + KOMMUNER.add("5610"); // Karasjok + KOMMUNER.add("5624"); // Lebesby + KOMMUNER.add("5626"); // Gamvik + KOMMUNER.add("5630"); // Berlevåg + KOMMUNER.add("5628"); // Tana + KOMMUNER.add("5636"); // Nesseby + KOMMUNER.add("5632"); // Båtsfjord + KOMMUNER.add("5605"); // Sør-Varanger + } + + public static boolean isNewKommune(String kommune) { + + return KOMMUNER.contains(kommune); + } +} diff --git a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/MatrikkeladresseServiceCommand.java b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/MatrikkeladresseServiceCommand.java index 707866b8de..9291e94f6c 100644 --- a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/MatrikkeladresseServiceCommand.java +++ b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/MatrikkeladresseServiceCommand.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import no.nav.pdl.forvalter.utils.Kor2024KommuneEndringer; import no.nav.pdl.forvalter.utils.WebClientFilter; import no.nav.testnav.libs.dto.adresseservice.v1.MatrikkeladresseDTO; import org.springframework.http.HttpHeaders; @@ -15,6 +16,7 @@ import reactor.util.retry.Retry; import java.time.Duration; +import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -67,6 +69,13 @@ public Mono call() { .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) .retrieve() .bodyToMono(MatrikkeladresseDTO[].class) + .doOnNext(matrikkeladresser -> Arrays.stream(matrikkeladresser) + .forEach(matrikkeladresse -> { + matrikkeladresse.setKommunenummer(isNotBlank(query.getKommunenummer()) ? + query.getKommunenummer() : matrikkeladresse.getKommunenummer()); + matrikkeladresse.setMatrikkelId(Kor2024KommuneEndringer.isGmlKommune(query, matrikkeladresse) ? + matrikkeladresse.getMatrikkelId() : null); + })) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) .filter(WebClientFilter::is5xxException)) .onErrorResume(throwable -> throwable instanceof WebClientResponseException.NotFound || @@ -79,7 +88,8 @@ private MultiValueMap getQuery() { return new LinkedMultiValueMap<>( new LinkedHashMap<>( Map.of("matrikkelId", filterArtifact(matrikkelId), - "kommunenummer", filterArtifact(query.getKommunenummer()), + "kommunenummer", filterArtifact(isNotBlank(query.getKommunenummer()) ? + Kor2024KommuneEndringer.getKommuneNummer(query.getKommunenummer()) : null), "gaardsnummer", filterArtifact(nullcheck(query.getGaardsnummer())), "bruksnummer", filterArtifact(nullcheck(query.getBruksnummer())), "postnummer", filterArtifact(query.getPostnummer()), diff --git a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/VegadresseServiceCommand.java b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/VegadresseServiceCommand.java index ef2d97ad57..59efa626f0 100644 --- a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/VegadresseServiceCommand.java +++ b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/VegadresseServiceCommand.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import no.nav.pdl.forvalter.utils.Kor2024KommuneEndringer; import no.nav.pdl.forvalter.utils.WebClientFilter; import no.nav.testnav.libs.dto.adresseservice.v1.VegadresseDTO; import org.springframework.http.HttpHeaders; @@ -15,6 +16,7 @@ import reactor.util.retry.Retry; import java.time.Duration; +import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -53,6 +55,7 @@ private static String filterArtifact(String artifact) { @Override public Mono call() { + return webClient .get() .uri(builder -> builder.path(ADRESSER_VEG_URL).queryParams(getQuery()).build()) @@ -61,6 +64,13 @@ public Mono call() { .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) .retrieve() .bodyToMono(VegadresseDTO[].class) + .doOnNext(vegadresser -> Arrays.stream(vegadresser) + .forEach(vegadresse -> { + vegadresse.setKommunenummer(isNotBlank(query.getKommunenummer()) ? + query.getKommunenummer() : vegadresse.getKommunenummer()); + vegadresse.setMatrikkelId(Kor2024KommuneEndringer.isGmlKommune(query, vegadresse) ? + vegadresse.getMatrikkelId() : null); + })) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) .filter(WebClientFilter::is5xxException)) .onErrorResume(throwable -> throwable instanceof WebClientResponseException.NotFound || @@ -77,7 +87,8 @@ private MultiValueMap getQuery() { "husnummer", filterArtifact(query.getHusnummer()), "husbokstav", filterArtifact(query.getHusbokstav()), "postnummer", filterArtifact(query.getPostnummer()), - "kommunenummer", filterArtifact(query.getKommunenummer()), + "kommunenummer", filterArtifact(isNotBlank(query.getKommunenummer()) ? + Kor2024KommuneEndringer.getKommuneNummer(query.getKommunenummer()) : null), "bydelsnummer", filterArtifact(query.getBydelsnummer()), "tilleggsnavn", filterArtifact(query.getTilleggsnavn())) .entrySet().stream() diff --git a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/mapper/KontaktadresseMappingStrategy.java b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/mapper/KontaktadresseMappingStrategy.java index 6193cad57a..2cf6f98a6e 100644 --- a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/mapper/KontaktadresseMappingStrategy.java +++ b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/mapper/KontaktadresseMappingStrategy.java @@ -9,9 +9,6 @@ import no.nav.testnav.libs.dto.pdlforvalter.v1.KontaktadresseDTO; import org.springframework.stereotype.Component; -import static java.util.Objects.nonNull; -import static org.apache.commons.lang3.StringUtils.isNotBlank; - @Component public class KontaktadresseMappingStrategy implements MappingStrategy { @@ -24,13 +21,12 @@ public void register(MapperFactory factory) { @Override public void mapAtoB(KontaktadresseDTO kildeAdresse, PdlKontaktadresse kontaktadresse, MappingContext context) { - if (isNotBlank(kontaktadresse.getAdresseIdentifikatorFraMatrikkelen())) { - kontaktadresse.setMaster(DbVersjonDTO.Master.FREG); + if (kildeAdresse.getMaster() == DbVersjonDTO.Master.FREG) { kontaktadresse.setVegadresseForPost( mapperFacade.map(kildeAdresse.getVegadresse(), VegadresseForPost.class)); kontaktadresse.setVegadresse(null); - } else if (nonNull(kontaktadresse.getVegadresse())) { - kontaktadresse.setMaster(DbVersjonDTO.Master.PDL); + } else { + kontaktadresse.setAdresseIdentifikatorFraMatrikkelen(null); } } }) diff --git a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/KontaktAdresseService.java b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/KontaktAdresseService.java index d14ff29eaf..fb7a797309 100644 --- a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/KontaktAdresseService.java +++ b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/KontaktAdresseService.java @@ -112,7 +112,7 @@ private void handle(KontaktadresseDTO kontaktadresse, PersonDTO person) { if (nonNull(kontaktadresse.getVegadresse())) { var vegadresse = adresseServiceConsumer.getVegadresse(kontaktadresse.getVegadresse(), kontaktadresse.getAdresseIdentifikatorFraMatrikkelen()); - kontaktadresse.setAdresseIdentifikatorFraMatrikkelen(kontaktadresse.getMaster() == Master.FREG ? vegadresse.getMatrikkelId() : null); + kontaktadresse.setAdresseIdentifikatorFraMatrikkelen(vegadresse.getMatrikkelId()); mapperFacade.map(vegadresse, kontaktadresse.getVegadresse()); kontaktadresse.getVegadresse().setKommunenummer(null); diff --git a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/utils/Kor2024KommuneEndringer.java b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/utils/Kor2024KommuneEndringer.java new file mode 100644 index 0000000000..a91c5f02ca --- /dev/null +++ b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/utils/Kor2024KommuneEndringer.java @@ -0,0 +1,151 @@ +package no.nav.pdl.forvalter.utils; + +import lombok.experimental.UtilityClass; +import no.nav.testnav.libs.dto.pdlforvalter.v1.MatrikkeladresseDTO; +import no.nav.testnav.libs.dto.pdlforvalter.v1.VegadresseDTO; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.commons.lang3.StringUtils.isBlank; + +@UtilityClass +public class Kor2024KommuneEndringer { + + private static Map KOMMUNER = new HashMap<>(); + + static { + KOMMUNER.put("1508", "1507"); // Ålesund + KOMMUNER.put("1580", "1507"); // Haram + KOMMUNER.put("3101", "3001"); // Halden + KOMMUNER.put("3103", "3002"); // Moss + KOMMUNER.put("3105", "3003"); // Sarpsborg + KOMMUNER.put("3107", "3004"); // Fredrikstad + KOMMUNER.put("3301", "3005"); // Drammen + KOMMUNER.put("3303", "3006"); // Kongsberg + KOMMUNER.put("3305", "3007"); // Ringerike + KOMMUNER.put("3110", "3011"); // Hvaler + KOMMUNER.put("3124", "3012"); // Aremark + KOMMUNER.put("3122", "3013"); // Marker + KOMMUNER.put("3118", "3014"); // Indre Østfold + KOMMUNER.put("3116", "3015"); // Skiptvet + KOMMUNER.put("3120", "3016"); // Rakkestad + KOMMUNER.put("3112", "3017"); // Råde + KOMMUNER.put("3114", "3018"); // Våler + KOMMUNER.put("3216", "3019"); // Vestby + KOMMUNER.put("3207", "3020"); // Nordre Follo + KOMMUNER.put("3218", "3021"); // Ås + KOMMUNER.put("3214", "3022"); // Frogn + KOMMUNER.put("3212", "3023"); // Nesodden + KOMMUNER.put("3201", "3024"); // Bærum + KOMMUNER.put("3203", "3025"); // Asker + KOMMUNER.put("3226", "3026"); // Aurskog-Høland + KOMMUNER.put("3224", "3027"); // Rælingen + KOMMUNER.put("3220", "3028"); // Enebakk + KOMMUNER.put("3222", "3029"); // Lørenskog + KOMMUNER.put("3205", "3030"); // Lillestrøm + KOMMUNER.put("3232", "3031"); // Nittedal + KOMMUNER.put("3230", "3032"); // Gjerdrum + KOMMUNER.put("3209", "3033"); // Ullensaker + KOMMUNER.put("3228", "3034"); // Nes + KOMMUNER.put("3240", "3035"); // Eidsvoll + KOMMUNER.put("3238", "3036"); // Nannestad + KOMMUNER.put("3242", "3037"); // Hurdal + KOMMUNER.put("3310", "3038"); // Hole + KOMMUNER.put("3320", "3039"); // Flå + KOMMUNER.put("3322", "3040"); // Nesbyen + KOMMUNER.put("3324", "3041"); // Gol + KOMMUNER.put("3326", "3042"); // Hemsedal + KOMMUNER.put("3328", "3043"); // Ål + KOMMUNER.put("3330", "3044"); // Hol + KOMMUNER.put("3332", "3045"); // Sigdal + KOMMUNER.put("3318", "3046"); // Krødsherad + KOMMUNER.put("3316", "3047"); // Modum + KOMMUNER.put("3314", "3048"); // Øvre Eiker + KOMMUNER.put("3312", "3049"); // Lier + KOMMUNER.put("3334", "3050"); // Flesberg + KOMMUNER.put("3336", "3051"); // Rollag + KOMMUNER.put("3338", "3052"); // Nore og Uvdal + KOMMUNER.put("3236", "3053"); // Jevnaker + KOMMUNER.put("3234", "3054"); // Lunner + KOMMUNER.put("3901", "3801"); // Horten + KOMMUNER.put("3903", "3802"); // Holmestrand + KOMMUNER.put("3905", "3803"); // Tønsberg + KOMMUNER.put("3907", "3804"); // Sandefjord + KOMMUNER.put("3909", "3805"); // Larvik + KOMMUNER.put("4001", "3806"); // Porsgrunn + KOMMUNER.put("4003", "3807"); // Skien + KOMMUNER.put("4005", "3808"); // Notodden + KOMMUNER.put("3911", "3811"); // Færder + KOMMUNER.put("4010", "3812"); // Siljan + KOMMUNER.put("4012", "3813"); // Bamble + KOMMUNER.put("4014", "3814"); // Kragerø + KOMMUNER.put("4016", "3815"); // Drangedal + KOMMUNER.put("4018", "3816"); // Nome + KOMMUNER.put("4020", "3817"); // Midt-Telemark + KOMMUNER.put("4026", "3818"); // Tinn + KOMMUNER.put("4024", "3819"); // Hjartdal + KOMMUNER.put("4022", "3820"); // Seljord + KOMMUNER.put("4028", "3821"); // Kviteseid + KOMMUNER.put("4030", "3822"); // Nissedal + KOMMUNER.put("4032", "3823"); // Fyresdal + KOMMUNER.put("4034", "3824"); // Tokke + KOMMUNER.put("4036", "3825"); // Vinje + KOMMUNER.put("5501", "5401"); // Tromsø + KOMMUNER.put("5503", "5402"); // Harstad + KOMMUNER.put("5601", "5403"); // Alta + KOMMUNER.put("5634", "5404"); // Vardø + KOMMUNER.put("5607", "5405"); // Vadsø + KOMMUNER.put("5603", "5406"); // Hammerfest + KOMMUNER.put("5510", "5411"); // Kvæfjord + KOMMUNER.put("5512", "5412"); // Tjeldsund + KOMMUNER.put("5514", "5413"); // Ibestad + KOMMUNER.put("5516", "5414"); // Gratangen + KOMMUNER.put("5518", "5415"); // Lavangen + KOMMUNER.put("5520", "5416"); // Bardu + KOMMUNER.put("5522", "5417"); // Salangen + KOMMUNER.put("5524", "5418"); // Målselv + KOMMUNER.put("5526", "5419"); // Sørreisa + KOMMUNER.put("5528", "5420"); // Dyrøy + KOMMUNER.put("5530", "5421"); // Senja + KOMMUNER.put("5532", "5422"); // Balsfjord + KOMMUNER.put("5534", "5423"); // Karlsøy + KOMMUNER.put("5536", "5424"); // Lyngen + KOMMUNER.put("5538", "5425"); // Storfjord + KOMMUNER.put("5540", "5426"); // Kåfjord + KOMMUNER.put("5542", "5427"); // Skjervøy + KOMMUNER.put("5544", "5428"); // Nordreisa + KOMMUNER.put("5546", "5429"); // Kvænangen + KOMMUNER.put("5612", "5430"); // Kautokeino + KOMMUNER.put("5614", "5432"); // Loppa + KOMMUNER.put("5616", "5433"); // Hasvik + KOMMUNER.put("5618", "5434"); // Måsøy + KOMMUNER.put("5620", "5435"); // Nordkapp + KOMMUNER.put("5622", "5436"); // Porsanger + KOMMUNER.put("5610", "5437"); // Karasjok + KOMMUNER.put("5624", "5438"); // Lebesby + KOMMUNER.put("5626", "5439"); // Gamvik + KOMMUNER.put("5630", "5440"); // Berlevåg + KOMMUNER.put("5628", "5441"); // Tana + KOMMUNER.put("5636", "5442"); // Nesseby + KOMMUNER.put("5632", "5443"); // Båtsfjord + KOMMUNER.put("5605", "5444"); // Sør-Varanger + } + + public String getKommuneNummer(String kommuneNummer) { + + return KOMMUNER.getOrDefault(kommuneNummer, kommuneNummer); + } + + public boolean isGmlKommune(VegadresseDTO request, no.nav.testnav.libs.dto.adresseservice.v1.VegadresseDTO response) { + + return isBlank(request.getKommunenummer()) || + Kor2024KommuneEndringer.getKommuneNummer(request.getKommunenummer()).equals(request.getKommunenummer()); + } + + public boolean isGmlKommune(MatrikkeladresseDTO request, no.nav.testnav.libs.dto.adresseservice.v1.MatrikkeladresseDTO response) { + + return isBlank(request.getKommunenummer()) || + Kor2024KommuneEndringer.getKommuneNummer(request.getKommunenummer()).equals(request.getKommunenummer()); + } +} \ No newline at end of file From 190c4f26c72fc2d4e7f28fa9800aae7ef938354c Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Tue, 12 Sep 2023 15:45:10 +0200 Subject: [PATCH 05/12] Fiks for heng ved sjekk av personstatus --- .../personservice/PersonServiceConsumer.java | 5 ++++ .../command/PersonServiceExistCommand.java | 24 +++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/PersonServiceConsumer.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/PersonServiceConsumer.java index 06bbf0c1fd..5414fb502e 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/PersonServiceConsumer.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/PersonServiceConsumer.java @@ -1,5 +1,6 @@ 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; @@ -7,9 +8,11 @@ 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; @@ -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(); } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/command/PersonServiceExistCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/command/PersonServiceExistCommand.java index 8a82a206ab..be56f63403 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/command/PersonServiceExistCommand.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/personservice/command/PersonServiceExistCommand.java @@ -2,15 +2,12 @@ import lombok.RequiredArgsConstructor; import no.nav.dolly.bestilling.personservice.dto.PersonServiceResponse; -import no.nav.dolly.util.WebClientFilter; import no.nav.testnav.libs.securitycore.config.UserConstant; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; 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.Optional; import java.util.Set; import java.util.concurrent.Callable; @@ -20,10 +17,10 @@ @RequiredArgsConstructor public class PersonServiceExistCommand implements Callable> { - private final WebClient webClient; - private final String ident; - private final Set opplysningId; - private final String token; + private final WebClient webClient; + private final String ident; + private final Set opplysningId; + private final String token; private static final String PERSON_URL = "/api/v1/personer/{ident}/exists"; @@ -43,13 +40,10 @@ public Mono call() { .status(HttpStatus.valueOf(resultat.getStatusCode().value())) .exists(resultat.getBody()) .build()) - .doOnError(WebClientFilter::logErrorMessage) - .onErrorResume(error -> Mono.just(PersonServiceResponse.builder() - .ident(ident) - .status(WebClientFilter.getStatus(error)) - .feilmelding(WebClientFilter.getMessage(error)) - .build())) - .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) - .filter(WebClientFilter::is5xxException)); + .onErrorResume(throwable -> Mono.just(PersonServiceResponse.builder() + .exists(false) + .ident(ident) + .status(HttpStatus.OK) + .build())); } } \ No newline at end of file From 7418955fa60b7c95347746f96f9f63e8bfe04183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristen=20H=C3=A6rum?= Date: Wed, 13 Sep 2023 07:27:10 +0200 Subject: [PATCH 06/12] Fikset problemer for ufoeretrygd #deploy-test-dolly-backend (#3272) Fikset problemer for ufoeretrygd Tilpasning for transaksjonsmapping --- .../PensjonforvalterClient.java | 5 +- .../domain/PensjonUforetrygdRequest.java | 2 +- .../sykemelding/SykemeldingClient.java | 45 +++++------------ .../command/SykemeldingPostCommand.java | 4 +- .../command/SyntSykemeldingPostCommand.java | 4 +- .../sykemelding/dto/SykemeldingResponse.java | 15 +++++- .../domain/resultset/pensjon/PensjonData.java | 18 ++++++- .../TransaksjonMappingRepository.java | 10 ++-- .../dolly/service/RsTransaksjonMapping.java | 21 ++------ .../service/TransaksjonIdMappingStrategy.java | 22 ++++----- .../service/TransaksjonMappingService.java | 49 ++----------------- .../main/resources/pdl/pdlPersonQuery.graphql | 5 -- 12 files changed, 78 insertions(+), 122 deletions(-) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java index 96d9e20af3..f645643a66 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java @@ -21,6 +21,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; @@ -322,7 +323,7 @@ private Flux lagreUforetrygd(PensjonData pensjonforval if (isOpprettEndre || !transaksjonMappingService.existAlready(PEN_UT, ident, miljoe)) { - var context = new MappingContext.Factory().getContext(); + var context = MappingContextUtils.getMappingContext(); context.setProperty(IDENT, ident); context.setProperty(MILJOER, List.of(miljoe)); context.setProperty("persondata", persondata); @@ -359,7 +360,7 @@ private static Flux getOkStatus(String miljoe) { 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() diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/domain/PensjonUforetrygdRequest.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/domain/PensjonUforetrygdRequest.java index acecac8312..f6077ce810 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/domain/PensjonUforetrygdRequest.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/domain/PensjonUforetrygdRequest.java @@ -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 miljoer; diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/SykemeldingClient.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/SykemeldingClient.java index 5d95c8cca4..37045d1d32 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/SykemeldingClient.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/SykemeldingClient.java @@ -9,7 +9,6 @@ import no.nav.dolly.bestilling.ClientFuture; import no.nav.dolly.bestilling.ClientRegister; import no.nav.dolly.bestilling.sykemelding.domain.DetaljertSykemeldingRequest; -import no.nav.dolly.bestilling.sykemelding.domain.SykemeldingTransaksjon; import no.nav.dolly.bestilling.sykemelding.domain.SyntSykemeldingRequest; import no.nav.dolly.bestilling.sykemelding.dto.Norg2EnhetResponse; import no.nav.dolly.bestilling.sykemelding.dto.SykemeldingResponse; @@ -31,7 +30,6 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.stream.Collectors; import static java.util.Objects.nonNull; @@ -74,7 +72,7 @@ public Flux gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly .flatMap(persondata -> Flux.concat(postSyntSykemelding(sykemelding, persondata), postDetaljertSykemelding(sykemelding, persondata)) .filter(Objects::nonNull) - .map(status -> saveTransaksjonId(status, bestillingId)) + .doOnNext(status -> saveTransaksjonId(status, bestillingId)) .map(this::getStatus) .collect(Collectors.joining())) .collect(Collectors.joining()) @@ -173,38 +171,21 @@ private Mono postSyntSykemelding(RsSykemelding sykemelding, }); } - private SykemeldingResponse saveTransaksjonId(SykemeldingResponse sykemelding, Long bestillingId) { + private void saveTransaksjonId(SykemeldingResponse sykemelding, Long bestillingId) { if (sykemelding.getStatus().is2xxSuccessful()) { - if (nonNull(sykemelding.getSyntSykemeldingRequest())) { - - transaksjonMappingService.save(TransaksjonMapping.builder() - .ident(sykemelding.getSyntSykemeldingRequest().getIdent()) - .bestillingId(bestillingId) - .transaksjonId(toJson(SykemeldingTransaksjon.builder() - .orgnummer(Optional.of(sykemelding.getSyntSykemeldingRequest().getOrgnummer()) - .orElse("NA")) - .arbeidsforholdId(Optional.of(sykemelding.getSyntSykemeldingRequest().getArbeidsforholdId()) - .orElse("1")) - .build())) - .datoEndret(LocalDateTime.now()) - .system(SYKEMELDING.name()) - .build()); - } else { - transaksjonMappingService.save(TransaksjonMapping.builder() - .ident(sykemelding.getDetaljertSykemeldingRequest().getPasient().getIdent()) - .bestillingId(bestillingId) - .transaksjonId(toJson(Optional.of(sykemelding.getDetaljertSykemeldingRequest().getMottaker()) - .orElse(DetaljertSykemeldingRequest.Organisasjon.builder() - .orgNr("NA") - .build()) - .getOrgNr())) - .datoEndret(LocalDateTime.now()) - .system(SYKEMELDING.name()) - .build()); - } + + log.info("Lagrer transaksjon for {} i q1 ", sykemelding.getIdent()); + + transaksjonMappingService.save(TransaksjonMapping.builder() + .ident(sykemelding.getIdent()) + .bestillingId(bestillingId) + .transaksjonId(toJson(sykemelding.getSykemeldingRequest())) + .datoEndret(LocalDateTime.now()) + .system(SYKEMELDING.name()) + .miljoe("q1") + .build()); } - return sykemelding; } private String toJson(Object object) { diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SykemeldingPostCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SykemeldingPostCommand.java index 188404247b..d012093bac 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SykemeldingPostCommand.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SykemeldingPostCommand.java @@ -39,7 +39,9 @@ public Mono call() { .map(response -> SykemeldingResponse.builder() .status(HttpStatus.valueOf(response.getStatusCode().value())) .ident(request.getPasient().getIdent()) - .detaljertSykemeldingRequest(request) + .sykemeldingRequest(SykemeldingResponse.SykemeldingRequest.builder() + .detaljertSykemeldingRequest(request) + .build()) .build()) .doOnError(WebClientFilter::logErrorMessage) .onErrorResume(error -> Mono.just(SykemeldingResponse.builder() diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SyntSykemeldingPostCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SyntSykemeldingPostCommand.java index ed9ad7b934..a4a8fb533c 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SyntSykemeldingPostCommand.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/command/SyntSykemeldingPostCommand.java @@ -38,7 +38,9 @@ public Mono call() { .map(response -> SykemeldingResponse.builder() .status(HttpStatus.valueOf(response.getStatusCode().value())) .ident(sykemeldingRequest.getIdent()) - .syntSykemeldingRequest(sykemeldingRequest) + .sykemeldingRequest(SykemeldingResponse.SykemeldingRequest.builder() + .syntSykemeldingRequest(sykemeldingRequest) + .build()) .build()) .doOnError(WebClientFilter::logErrorMessage) .onErrorResume(error -> Mono.just(SykemeldingResponse.builder() diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/dto/SykemeldingResponse.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/dto/SykemeldingResponse.java index 84130693e3..9126e4bff3 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/dto/SykemeldingResponse.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/sykemelding/dto/SykemeldingResponse.java @@ -1,5 +1,6 @@ package no.nav.dolly.bestilling.sykemelding.dto; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -16,7 +17,17 @@ public class SykemeldingResponse { private HttpStatus status; private String avvik; - private SyntSykemeldingRequest syntSykemeldingRequest; - private DetaljertSykemeldingRequest detaljertSykemeldingRequest; + private SykemeldingRequest sykemeldingRequest; private String ident; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + @JsonInclude(JsonInclude.Include.NON_EMPTY) + public static class SykemeldingRequest { + + private SyntSykemeldingRequest syntSykemeldingRequest; + private DetaljertSykemeldingRequest detaljertSykemeldingRequest; + } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/pensjon/PensjonData.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/pensjon/PensjonData.java index 920512643a..eb4d65c2c1 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/pensjon/PensjonData.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/pensjon/PensjonData.java @@ -153,7 +153,7 @@ public static class Uforetrygd { private UforeType minimumInntektForUforhetType; private String saksbehandler; private String attesterer; - private Integer navEnhetId; + private String navEnhetId; private Barnetillegg barnetilleggDetaljer; } @@ -165,6 +165,22 @@ public static class Barnetillegg { private List forventedeInntekterSoker; private List forventedeInntekterEP; + + public List getForventedeInntekterSoker() { + + if (isNull(forventedeInntekterSoker)) { + forventedeInntekterSoker = new ArrayList<>(); + } + return forventedeInntekterSoker; + } + + public List getForventedeInntekterEP() { + + if (isNull(forventedeInntekterEP)) { + forventedeInntekterEP = new ArrayList<>(); + } + return forventedeInntekterEP; + } } @Data diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/repository/TransaksjonMappingRepository.java b/apps/dolly-backend/src/main/java/no/nav/dolly/repository/TransaksjonMappingRepository.java index baa82182c5..c539b77243 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/repository/TransaksjonMappingRepository.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/repository/TransaksjonMappingRepository.java @@ -13,11 +13,11 @@ public interface TransaksjonMappingRepository extends CrudRepository> findAllBySystemAndIdent(String system, String ident); - @Query(value = "from TransaksjonMapping t where (:bestillingId is null or " + - "t.bestillingId is null or " + - "(t.bestillingId is not null and t.bestillingId=:bestillingId)) and " + - "t.ident=:ident") - Optional> findAllByBestillingIdAndIdent(@Param("bestillingId") Long bestillingId, @Param("ident") String ident); + @Query(value = "from TransaksjonMapping t " + + " where t.ident=:ident" + + " and (:bestillingId is null " + + " or (t.bestillingId is not null and t.bestillingId=:bestillingId))") + List findAllByBestillingIdAndIdent(@Param("bestillingId") Long bestillingId, @Param("ident") String ident); @Modifying int deleteAllByIdent(String ident); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/RsTransaksjonMapping.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/RsTransaksjonMapping.java index 33b251ab94..256212199e 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/RsTransaksjonMapping.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/RsTransaksjonMapping.java @@ -1,12 +1,11 @@ package no.nav.dolly.service; -import java.time.LocalDateTime; -import java.time.LocalDate; - import com.fasterxml.jackson.annotation.JsonInclude; - +import com.fasterxml.jackson.databind.JsonNode; import lombok.Data; +import java.time.LocalDateTime; + @Data @JsonInclude(JsonInclude.Include.NON_NULL) public class RsTransaksjonMapping { @@ -16,19 +15,7 @@ public class RsTransaksjonMapping { private String ident; private String system; private String miljoe; - private TransaksjonId transaksjonId; + private JsonNode transaksjonId; private LocalDateTime datoEndret; private String status; - - @Data - @JsonInclude(JsonInclude.Include.NON_NULL) - public static class TransaksjonId { - - private String journalpostId; - private String dokumentInfoId; - private String orgnummer; - private String arbeidsforholdId; - private LocalDate iverksettelsesdato; - private Integer uttaksgrad; - } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonIdMappingStrategy.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonIdMappingStrategy.java index 65d5fdd878..3f80cccad1 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonIdMappingStrategy.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonIdMappingStrategy.java @@ -9,7 +9,6 @@ import ma.glasnost.orika.MappingContext; import no.nav.dolly.domain.jpa.TransaksjonMapping; import no.nav.dolly.mapper.MappingStrategy; -import no.nav.dolly.service.RsTransaksjonMapping.TransaksjonId; import org.springframework.stereotype.Component; @Slf4j @@ -21,17 +20,18 @@ public class TransaksjonIdMappingStrategy implements MappingStrategy { @Override public void register(MapperFactory factory) { - factory.classMap(TransaksjonMapping.class, RsTransaksjonMapping.class).customize(new CustomMapper() { - @Override - public void mapAtoB(TransaksjonMapping transaksjonMapping, RsTransaksjonMapping rsTransaksjonMapping, MappingContext context) { + factory.classMap(TransaksjonMapping.class, RsTransaksjonMapping.class).customize(new CustomMapper<>() { + @Override + public void mapAtoB(TransaksjonMapping kilde, RsTransaksjonMapping destinasjon, MappingContext context) { - try { - rsTransaksjonMapping.setTransaksjonId(objectMapper.readValue(transaksjonMapping.getTransaksjonId(), TransaksjonId.class)); - } catch (JsonProcessingException e) { - log.error("TransaksjonMapping feilet: ", e); - } - } - }) + try { + destinasjon.setTransaksjonId(objectMapper.readTree(kilde.getTransaksjonId())); + } catch (JsonProcessingException e) { + log.error("Feilet å konvertere {} til JsonNode", kilde.getTransaksjonId()); + } + } + }) + .exclude("transaksjonId") .byDefault() .register(); } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java index 72264ed30b..261c164210 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java @@ -2,52 +2,32 @@ import lombok.RequiredArgsConstructor; import ma.glasnost.orika.MapperFacade; -import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.jpa.TransaksjonMapping; import no.nav.dolly.domain.resultset.SystemTyper; import no.nav.dolly.repository.TransaksjonMappingRepository; -import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.HttpClientErrorException; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import static java.util.Collections.emptyList; import static java.util.Objects.isNull; -import static no.nav.dolly.domain.resultset.SystemTyper.AAREG; -import static no.nav.dolly.domain.resultset.SystemTyper.DOKARKIV; -import static no.nav.dolly.domain.resultset.SystemTyper.INNTKMELD; -import static no.nav.dolly.domain.resultset.SystemTyper.PEN_AP; -import static no.nav.dolly.domain.resultset.SystemTyper.SYKEMELDING; -import static org.apache.commons.lang3.StringUtils.isBlank; @Service @RequiredArgsConstructor public class TransaksjonMappingService { private final TransaksjonMappingRepository transaksjonMappingRepository; - private final BestillingProgressService bestillingProgressService; private final MapperFacade mapperFacade; + @Transactional(readOnly = true) public List getTransaksjonMapping(String system, String ident, Long bestillingId) { - final List progress = bestillingProgressService.fetchBestillingProgressByBestillingId(bestillingId); - - if (isBlank(ident) && isNull(bestillingId)) { - throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Søket trenger enten Ident eller BestillingId"); - } - List transaksjonMappingList = - transaksjonMappingRepository.findAllByBestillingIdAndIdent(bestillingId, ident).orElse(emptyList()); - List rsTransaksjonMappings = mapperFacade.mapAsList( - transaksjonMappingList.stream() - .filter(transaksjon -> isBlank(system) || transaksjon.getSystem().equals(system)) - .collect(Collectors.toList()), - RsTransaksjonMapping.class); - rsTransaksjonMappings.forEach(transaksjon -> transaksjon.setStatus(!progress.isEmpty() ? hentSystemFeilFraBestillingProgress(progress, system) : null)); - return rsTransaksjonMappings; + return transaksjonMappingRepository.findAllByBestillingIdAndIdent(bestillingId, ident).stream() + .filter(transaksjon -> isNull(system) || system.equals(transaksjon.getSystem())) + .map(transasjon -> mapperFacade.map(transasjon, RsTransaksjonMapping.class)) + .toList(); } public boolean existAlready(SystemTyper system, String ident, String miljoe) { @@ -74,23 +54,4 @@ public void slettTransaksjonMappingByTestident(String ident) { transaksjonMappingRepository.deleteAllByIdent(ident); } - - private String hentSystemFeilFraBestillingProgress(List progress, String system) { - - String status = ""; - if (SYKEMELDING.name().equals(system)) { - status = progress.get(0).getSykemeldingStatus(); - } else if (DOKARKIV.name().equals(system)) { - status = progress.get(0).getDokarkivStatus(); - } else if (INNTKMELD.name().equals(system)) { - status = progress.get(0).getInntektsmeldingStatus(); - } else if (AAREG.name().equals(system)) { - status = progress.get(0).getAaregStatus(); - } else if (PEN_AP.name().equals(system)) { - status = progress.get(0).getPensjonforvalterStatus(); - } else { - status = progress.get(0).getFeil(); - } - return isBlank(status) || status.contains("OK") ? "OK" : status; - } } diff --git a/apps/person-service/src/main/resources/pdl/pdlPersonQuery.graphql b/apps/person-service/src/main/resources/pdl/pdlPersonQuery.graphql index 105861c0c6..cac59339c6 100644 --- a/apps/person-service/src/main/resources/pdl/pdlPersonQuery.graphql +++ b/apps/person-service/src/main/resources/pdl/pdlPersonQuery.graphql @@ -16,11 +16,6 @@ query($ident1: ID!) { opplysningsId } } - folkeregisteridentifikator { - metadata { - opplysningsId - } - } folkeregisterpersonstatus { metadata { opplysningsId From 0daa4c31f2cc7b8d6e32be9f0a46783e2298479f Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Wed, 13 Sep 2023 10:07:21 +0200 Subject: [PATCH 07/12] Arena AAP115 oppdatert responseformat --- .../arenaforvalter/dto/Aap115Response.java | 14 +++++++------- .../arenaforvalter/service/ArenaAap115Service.java | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/dto/Aap115Response.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/dto/Aap115Response.java index d00dbf8f03..deb52b2639 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/dto/Aap115Response.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/dto/Aap115Response.java @@ -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 nyeAap115; @Schema(description = "Liste over AAP-115 hvor oppretting feilet") - private List nyeAapFeilList; + private List nyeAap115FeilList; public List getNyeAap115() { @@ -42,12 +42,12 @@ public List getNyeAap115() { return nyeAap115; } - public List getNyeAapFeilList() { + public List getNyeAap115FeilList() { - if (isNull(nyeAapFeilList)) { - nyeAapFeilList = new ArrayList<>(); + if (isNull(nyeAap115FeilList)) { + nyeAap115FeilList = new ArrayList<>(); } - return nyeAapFeilList; + return nyeAap115FeilList; } @Data @@ -58,7 +58,7 @@ public static class Aap115Feil { private String personident; private String miljoe; - private String nyAapFeilstatus; + private String nyAap115Feilstatus; private String melding; } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/service/ArenaAap115Service.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/service/ArenaAap115Service.java index f99f43e96e..b64cf272bb 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/service/ArenaAap115Service.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/service/ArenaAap115Service.java @@ -63,9 +63,9 @@ private Mono 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()); From 82eb9be6e7ab9223f2b4d7eab076217c9e3f48f9 Mon Sep 17 00:00:00 2001 From: Betsy Carina Traran Date: Thu, 14 Sep 2023 10:59:23 +0200 Subject: [PATCH 08/12] Fix visning arena-feil --- .../js/src/components/fagsystem/arena/visning/ArenaVisning.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/fagsystem/arena/visning/ArenaVisning.tsx b/apps/dolly-frontend/src/main/js/src/components/fagsystem/arena/visning/ArenaVisning.tsx index 4e2d66a5cc..395fc71546 100644 --- a/apps/dolly-frontend/src/main/js/src/components/fagsystem/arena/visning/ArenaVisning.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/fagsystem/arena/visning/ArenaVisning.tsx @@ -112,7 +112,7 @@ export const ArenaVisning = ({ data, ident, bestillingIdListe, loading, tilgjeng if (loading || tagsloading) { return } - if (!data && !harArenasyntTag) { + if (!data) { return null } From c92985c00fc37e83e6052b6bf9e63eb1fa31b2ed Mon Sep 17 00:00:00 2001 From: Betsy Carina Traran Date: Thu, 14 Sep 2023 12:16:02 +0200 Subject: [PATCH 09/12] Fix validation org sykemelding --- .../components/fagsystem/sykdom/form/validation.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/fagsystem/sykdom/form/validation.tsx b/apps/dolly-frontend/src/main/js/src/components/fagsystem/sykdom/form/validation.tsx index 2d851726e6..71d4b65fe3 100644 --- a/apps/dolly-frontend/src/main/js/src/components/fagsystem/sykdom/form/validation.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/fagsystem/sykdom/form/validation.tsx @@ -14,7 +14,16 @@ const testHarArbeidsforhold = (val) => { ? detaljertSykemelding?.mottaker?.orgNr : selected - const arbeidsgivere = values?.aareg?.map((arbforh) => arbforh?.arbeidsgiver?.orgnummer) + const arbeidsgivere = values?.aareg?.map((arbforh) => arbforh?.arbeidsgiver?.orgnummer) || [] + + values?.personFoerLeggTil?.aareg?.forEach((miljo) => { + miljo?.data?.forEach((arbforh) => { + const orgnr = arbforh?.arbeidsgiver?.organisasjonsnummer + if (orgnr && !arbeidsgivere?.includes(orgnr?.toString())) { + arbeidsgivere.push(orgnr) + } + }) + }) if (!arbeidsgivere?.includes(valgtArbeidsgiver?.toString())) { return this.createError({ From a8e05e9cee1bf41f21b175bfbbbdfe2dfed8980d Mon Sep 17 00:00:00 2001 From: Betsy Carina Traran Date: Thu, 14 Sep 2023 14:00:26 +0200 Subject: [PATCH 10/12] Fjern status-sjekk pa transaksjonsid --- .../fagsystem/inntektsmelding/visning/Visning.tsx | 12 ++++++------ .../components/transaksjonid/GyldigeBestillinger.tsx | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/fagsystem/inntektsmelding/visning/Visning.tsx b/apps/dolly-frontend/src/main/js/src/components/fagsystem/inntektsmelding/visning/Visning.tsx index b24aea67a6..22371d4df0 100644 --- a/apps/dolly-frontend/src/main/js/src/components/fagsystem/inntektsmelding/visning/Visning.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/fagsystem/inntektsmelding/visning/Visning.tsx @@ -31,7 +31,7 @@ export const InntektsmeldingVisning = ({ liste, ident }: InntektsmeldingVisningP const getDokumenter = (bestilling: TransaksjonId): Promise => { return JoarkDokumentService.hentJournalpost( bestilling.transaksjonId.journalpostId, - bestilling.miljoe + bestilling.miljoe, ).then((journalpost: Journalpost) => { return Promise.all( journalpost.dokumenter.map((document: Dokument) => @@ -39,13 +39,13 @@ export const InntektsmeldingVisning = ({ liste, ident }: InntektsmeldingVisningP bestilling.transaksjonId.journalpostId, document.dokumentInfoId, bestilling.miljoe, - 'ORIGINAL' + 'ORIGINAL', ).then((dokument: string) => ({ journalpostId: bestilling.transaksjonId.journalpostId, dokumentInfoId: document.dokumentInfoId, dokument, - })) - ) + })), + ), ) }) } @@ -77,7 +77,7 @@ export const InntektsmeldingVisning = ({ liste, ident }: InntektsmeldingVisningP render={(data: Array) => { if (data && data.length > 0) { const gyldigeBestillinger = liste.filter((bestilling) => - data.find((x) => (x && x.bestillingId ? x.bestillingId === bestilling.id : x)) + data.find((x) => (x && x.bestillingId ? x.bestillingId === bestilling.id : x)), ) if (gyldigeBestillinger && gyldigeBestillinger.length > 0) { @@ -129,7 +129,7 @@ InntektsmeldingVisning.filterValues = (bestillinger: Array, ident: s (bestilling: any) => bestilling.data.inntektsmelding && !tomBestilling(bestilling.data.inntektsmelding.inntekter) && - erGyldig(bestilling.id, 'INNTKMELD', ident) + erGyldig(bestilling.id, 'INNTKMELD', ident), ) } diff --git a/apps/dolly-frontend/src/main/js/src/components/transaksjonid/GyldigeBestillinger.tsx b/apps/dolly-frontend/src/main/js/src/components/transaksjonid/GyldigeBestillinger.tsx index 46d0b590ee..485127c7aa 100644 --- a/apps/dolly-frontend/src/main/js/src/components/transaksjonid/GyldigeBestillinger.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/transaksjonid/GyldigeBestillinger.tsx @@ -15,9 +15,5 @@ export const erGyldig = (bestillingId: number, system: string, ident: string) => return response.data }, []) - return ( - finnBestilling.value && - finnBestilling.value.length > 0 && - finnBestilling.value[0].status === 'OK' - ) + return finnBestilling.value && finnBestilling.value.length > 0 } From 8367076b7fa23f2818f5cfc0e97d85188ce26d57 Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Thu, 14 Sep 2023 14:26:44 +0200 Subject: [PATCH 11/12] Inntektsmelding lagt request til transaksjon_mapping --- .../inntektsmelding/InntektsmeldingClient.java | 6 +++++- .../domain/TransaksjonMappingDTO.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/domain/TransaksjonMappingDTO.java diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/InntektsmeldingClient.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/InntektsmeldingClient.java index 61320a4342..0b8c822a96 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/InntektsmeldingClient.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/InntektsmeldingClient.java @@ -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; @@ -96,7 +97,10 @@ private Flux 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()) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/domain/TransaksjonMappingDTO.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/domain/TransaksjonMappingDTO.java new file mode 100644 index 0000000000..2e12bcf1f3 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/domain/TransaksjonMappingDTO.java @@ -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; +} From 1aedee44916bb388861721a208f5d4ec5aa7e91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristen=20H=C3=A6rum?= Date: Fri, 15 Sep 2023 07:55:45 +0200 Subject: [PATCH 12/12] Feature/legge synkronisering mot tps (#3276) Synkronisering mot TPS for PEN_AP og PEN_UT --- .../dolly/DollyBackendApplicationStarter.java | 2 +- .../PensjonforvalterClient.java | 110 ++++++++----- .../service/DollyBestillingService.java | 2 + .../service/GjenopprettBestillingService.java | 10 +- .../service/GjenopprettGruppeService.java | 10 +- .../service/GjenopprettIdentService.java | 10 +- .../ImportAvPersonerFraPdlService.java | 10 +- .../service/LeggTilPaaGruppeService.java | 10 +- .../service/OppdaterPersonService.java | 10 +- .../OpprettPersonerByKriterierService.java | 22 ++- ...PersonerFraIdenterMedKriterierService.java | 22 ++- .../command/PersonGetCommand.java | 11 +- .../service/TpsPersonService.java | 151 ++++++++++++++++++ .../dolly/domain/jpa/BestillingProgress.java | 17 ++ .../dolly/domain/resultset/SystemTyper.java | 1 + .../BestillingTpsPersonStatusMapper.java | 55 +++++++ .../BestillingStatusMappingStrategy.java | 10 +- .../service/TransaksjonMappingService.java | 8 + .../V1.7.20__AlterTableBestillingProgress.sql | 6 + 19 files changed, 399 insertions(+), 78 deletions(-) create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/service/TpsPersonService.java create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingTpsPersonStatusMapper.java create mode 100644 apps/dolly-backend/src/main/resources/db/migration/V1.7.20__AlterTableBestillingProgress.sql diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java b/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java index 39fb82ea03..317d2b3da4 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java @@ -9,4 +9,4 @@ public static void main(String[] args) { SpringApplication.run(DollyBackendApplicationStarter.class, args); } -} \ No newline at end of file +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java index f645643a66..d529c920df 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/pensjonforvalter/PensjonforvalterClient.java @@ -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; @@ -65,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; @@ -149,7 +159,8 @@ public Flux gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly dollyPerson.getIdent(), bestilteMiljoer.get(), isOpprettEndre, - bestillingId) + bestillingId, + progress.getIsTpsSyncEnv()) .map(response -> PEN_ALDERSPENSJON + decodeStatus(response, dollyPerson.getIdent())), lagreUforetrygd(bestilling1.getPensjonforvalter(), @@ -157,7 +168,8 @@ public Flux gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly dollyPerson.getIdent(), bestilteMiljoer.get(), isOpprettEndre, - bestillingId) + bestillingId, + progress.getIsTpsSyncEnv()) .map(response -> PEN_UFORETRYGD + decodeStatus(response, dollyPerson.getIdent())), lagreInntekt(bestilling1.getPensjonforvalter(), dollyPerson, bestilteMiljoer.get()) @@ -281,7 +293,8 @@ private Flux opprettPersoner(String hovedperson, Set lagreAlderspensjon(PensjonData pensjonData, List relasjoner, String ident, Set miljoer, - boolean isOpprettEndre, Long bestillingId) { + boolean isOpprettEndre, Long bestillingId, + List isTpsSyncEnv) { return Flux.just(true) .filter(pensjon -> nonNull(pensjonData) && nonNull(pensjonData.getAlderspensjon())) @@ -291,29 +304,38 @@ private Flux 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 lagreUforetrygd(PensjonData pensjonforvalter, List persondata, - String ident, Set miljoer, boolean isOpprettEndre, Long bestillingId) { + private Flux lagreUforetrygd(PensjonData pensjonforvalter, + List persondata, + String ident, Set miljoer, boolean isOpprettEndre, + Long bestillingId, List isTpsSyncEnv) { return Flux.just(true) .filter(pensjon -> nonNull(pensjonforvalter) && nonNull(pensjonforvalter.getUforetrygd())) @@ -323,36 +345,44 @@ private Flux lagreUforetrygd(PensjonData pensjonforval if (isOpprettEndre || !transaksjonMappingService.existAlready(PEN_UT, ident, 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; - })); + 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 getOkStatus(String miljoe) { + private static Flux 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()); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/DollyBestillingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/DollyBestillingService.java index 23a49dc2bc..5660bc0910 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/DollyBestillingService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/DollyBestillingService.java @@ -12,6 +12,7 @@ import no.nav.dolly.bestilling.pdldata.dto.PdlResponse; import no.nav.dolly.bestilling.pensjonforvalter.PensjonforvalterClient; import no.nav.dolly.bestilling.tagshendelseslager.TagsHendelseslagerClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.jpa.Bruker; @@ -56,6 +57,7 @@ public class DollyBestillingService { protected final PdlDataConsumer pdlDataConsumer; protected final ErrorStatusDecoder errorStatusDecoder; protected final TransactionHelperService transactionHelperService; + protected final TpsPersonService tpsPersonService; public static Set getEnvironments(String miljoer) { return isNotBlank(miljoer) ? Set.of(miljoer.split(",")) : emptySet(); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettBestillingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettBestillingService.java index 01ea6c8ac7..baf8d7db3a 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettBestillingService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettBestillingService.java @@ -7,6 +7,7 @@ import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.pdldata.dto.PdlResponse; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.errorhandling.ErrorStatusDecoder; @@ -46,7 +47,8 @@ public GjenopprettBestillingService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService ) { super( identService, @@ -56,7 +58,8 @@ public GjenopprettBestillingService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.bestillingProgressService = bestillingProgressService; this.personServiceClient = personServiceClient; @@ -90,6 +93,9 @@ public void executeAsync(Bestilling bestilling) { .map(ClientFuture::get) .filter(BestillingProgress::isPdlSync) .flatMap(pdlSync -> Flux.concat( + tpsPersonService.syncPerson(dollyPerson, bestKriterier, + progress, false) + .map(ClientFuture::get), gjenopprettKlienter(dollyPerson, bestKriterier, fase2Klienter(), progress, false), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettGruppeService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettGruppeService.java index 43854168ad..9ee1f11b93 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettGruppeService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettGruppeService.java @@ -7,6 +7,7 @@ import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.pdldata.dto.PdlResponse; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyBestilling; @@ -49,7 +50,8 @@ public GjenopprettGruppeService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService ) { super( identService, @@ -59,7 +61,8 @@ public GjenopprettGruppeService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.personServiceClient = personServiceClient; } @@ -106,6 +109,9 @@ public void executeAsync(Bestilling bestilling) { .doOnNext(request -> log.info("Startet gjenopprett bestilling {} for ident: {}", request.getId(), testident.getIdent())) .flatMapSequential(bestillingRequest -> Flux.concat( + tpsPersonService.syncPerson(dollyPerson, bestillingRequest, + progress, false) + .map(ClientFuture::get), gjenopprettKlienter(dollyPerson, bestillingRequest, fase2Klienter(), progress, false), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettIdentService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettIdentService.java index 09fdcc674e..43c3dfe97e 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettIdentService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/GjenopprettIdentService.java @@ -7,6 +7,7 @@ import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.pdldata.dto.PdlResponse; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyBestilling; @@ -49,7 +50,8 @@ public GjenopprettIdentService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService ) { super( identService, @@ -59,7 +61,8 @@ public GjenopprettIdentService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.personServiceClient = personServiceClient; } @@ -108,6 +111,9 @@ public void executeAsync(Bestilling bestilling) { log.info("Startet gjenopprett bestilling {} for ident: {}", request.getId(), testident.getIdent())) .flatMap(bestillingRequest -> Flux.concat( + tpsPersonService.syncPerson(dollyPerson, bestillingRequest, + progress, false) + .map(ClientFuture::get), gjenopprettKlienter(dollyPerson, bestillingRequest, fase2Klienter(), progress, false), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/ImportAvPersonerFraPdlService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/ImportAvPersonerFraPdlService.java index 9db6d8c686..9116f7b040 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/ImportAvPersonerFraPdlService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/ImportAvPersonerFraPdlService.java @@ -6,6 +6,7 @@ import no.nav.dolly.bestilling.ClientRegister; import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyBestillingRequest; @@ -43,7 +44,8 @@ public ImportAvPersonerFraPdlService(IdentService identService, ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient) { + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService) { super( identService, bestillingService, @@ -52,7 +54,8 @@ public ImportAvPersonerFraPdlService(IdentService identService, counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.personServiceClient = personServiceClient; } @@ -82,6 +85,9 @@ public void executeAsync(Bestilling bestilling) { .filter(BestillingProgress::isPdlSync) .flatMap(pdlSync -> Flux.concat( + tpsPersonService.syncPerson(dollyPerson, bestKriterier, + progress, true) + .map(ClientFuture::get), gjenopprettKlienter(dollyPerson, bestKriterier, fase2Klienter(), progress, true), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/LeggTilPaaGruppeService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/LeggTilPaaGruppeService.java index d70afcd702..79addd9905 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/LeggTilPaaGruppeService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/LeggTilPaaGruppeService.java @@ -8,6 +8,7 @@ import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.pdldata.dto.PdlResponse; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyBestillingRequest; @@ -55,7 +56,8 @@ public LeggTilPaaGruppeService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient) { + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService) { super( identService, bestillingService, @@ -64,7 +66,8 @@ public LeggTilPaaGruppeService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.personServiceClient = personServiceClient; this.mapperFacade = mapperFacade; @@ -104,6 +107,9 @@ public void executeAsync(Bestilling bestilling) { .filter(BestillingProgress::isPdlSync) .flatMap(pdlSync -> Flux.concat( + tpsPersonService.syncPerson(dollyPerson, bestKriterier, + progress, true) + .map(ClientFuture::get), gjenopprettKlienter(dollyPerson, bestKriterier, fase2Klienter(), progress, true), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OppdaterPersonService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OppdaterPersonService.java index c3fd600822..8f88deae80 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OppdaterPersonService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OppdaterPersonService.java @@ -8,6 +8,7 @@ import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.pdldata.dto.PdlResponse; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyUpdateRequest; @@ -50,7 +51,8 @@ public OppdaterPersonService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient) { + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService) { super( identService, bestillingService, @@ -59,7 +61,8 @@ public OppdaterPersonService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.personServiceClient = personServiceClient; this.mapperFacade = mapperFacade; @@ -93,6 +96,9 @@ public void oppdaterPersonAsync(RsDollyUpdateRequest request, Bestilling bestill .filter(BestillingProgress::isPdlSync) .flatMap(pdlSync -> Flux.concat( + tpsPersonService.syncPerson(dollyPerson, request, + progress, true) + .map(ClientFuture::get), gjenopprettKlienter(dollyPerson, request, fase2Klienter(), progress, true), diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerByKriterierService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerByKriterierService.java index b3ef9a8029..aca73a1f17 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerByKriterierService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerByKriterierService.java @@ -7,6 +7,7 @@ import no.nav.dolly.bestilling.ClientRegister; import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.errorhandling.ErrorStatusDecoder; @@ -47,7 +48,8 @@ public OpprettPersonerByKriterierService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient) { + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService) { super( identService, bestillingService, @@ -56,7 +58,8 @@ public OpprettPersonerByKriterierService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.personServiceClient = personServiceClient; this.mapperFacade = mapperFacade; @@ -91,12 +94,15 @@ public void executeAsync(Bestilling bestilling) { .map(ClientFuture::get) .filter(BestillingProgress::isPdlSync) .flatMap(pdlSync -> Flux.concat( - gjenopprettKlienter(dollyPerson, bestKriterier, - fase2Klienter(), - progress, true), - gjenopprettKlienter(dollyPerson, bestKriterier, - fase3Klienter(), - progress, true)))))) + tpsPersonService.syncPerson(dollyPerson, bestKriterier, + progress, true) + .map(ClientFuture::get), + gjenopprettKlienter(dollyPerson, bestKriterier, + fase2Klienter(), + progress, true), + gjenopprettKlienter(dollyPerson, bestKriterier, + fase3Klienter(), + progress, true)))))) .onErrorResume(throwable -> { var error = errorStatusDecoder.getErrorText( WebClientFilter.getStatus(throwable), WebClientFilter.getMessage(throwable)); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerFraIdenterMedKriterierService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerFraIdenterMedKriterierService.java index 539abc25e7..2ea776b62d 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerFraIdenterMedKriterierService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/service/OpprettPersonerFraIdenterMedKriterierService.java @@ -7,6 +7,7 @@ import no.nav.dolly.bestilling.ClientRegister; import no.nav.dolly.bestilling.pdldata.PdlDataConsumer; import no.nav.dolly.bestilling.personservice.PersonServiceClient; +import no.nav.dolly.bestilling.tpsmessagingservice.service.TpsPersonService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.resultset.RsDollyBestillingRequest; @@ -48,7 +49,8 @@ public OpprettPersonerFraIdenterMedKriterierService( ErrorStatusDecoder errorStatusDecoder, PdlDataConsumer pdlDataConsumer, TransactionHelperService transactionHelperService, - PersonServiceClient personServiceClient) { + PersonServiceClient personServiceClient, + TpsPersonService tpsPersonService) { super( identService, bestillingService, @@ -57,7 +59,8 @@ public OpprettPersonerFraIdenterMedKriterierService( counterCustomRegistry, pdlDataConsumer, errorStatusDecoder, - transactionHelperService + transactionHelperService, + tpsPersonService ); this.mapperFacade = mapperFacade; this.personServiceClient = personServiceClient; @@ -94,12 +97,15 @@ public void executeAsync(Bestilling bestilling) { .map(ClientFuture::get) .filter(BestillingProgress::isPdlSync) .flatMap(pdlSync -> Flux.concat( - gjenopprettKlienter(dollyPerson, bestKriterier, - fase2Klienter(), - progress, true), - gjenopprettKlienter(dollyPerson, bestKriterier, - fase3Klienter(), - progress, true)))))) + tpsPersonService.syncPerson(dollyPerson, bestKriterier, + progress, true) + .map(ClientFuture::get), + gjenopprettKlienter(dollyPerson, bestKriterier, + fase2Klienter(), + progress, true), + gjenopprettKlienter(dollyPerson, bestKriterier, + fase3Klienter(), + progress, true)))))) .onErrorResume(throwable -> { var error = errorStatusDecoder.getErrorText( WebClientFilter.getStatus(throwable), WebClientFilter.getMessage(throwable)); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/command/PersonGetCommand.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/command/PersonGetCommand.java index ea882b9285..d79bc07256 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/command/PersonGetCommand.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/command/PersonGetCommand.java @@ -7,9 +7,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; -import reactor.util.retry.Retry; +import reactor.core.publisher.Mono; -import java.time.Duration; import java.util.List; import java.util.concurrent.Callable; @@ -36,8 +35,10 @@ public Flux call() { .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) .retrieve() .bodyToFlux(PersonMiljoeDTO.class) - .doOnError(WebClientFilter::logErrorMessage) - .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) - .filter(WebClientFilter::is5xxException)); + .onErrorResume(throwable -> Mono.just(PersonMiljoeDTO.builder() + .status("FEIL") + .melding(WebClientFilter.getStatus(throwable).getReasonPhrase()) + .utfyllendeMelding(WebClientFilter.getMessage(throwable)) + .build())); } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/service/TpsPersonService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/service/TpsPersonService.java new file mode 100644 index 0000000000..aa42e62863 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/tpsmessagingservice/service/TpsPersonService.java @@ -0,0 +1,151 @@ +package no.nav.dolly.bestilling.tpsmessagingservice.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import no.nav.dolly.bestilling.ClientFuture; +import no.nav.dolly.bestilling.tpsmessagingservice.TpsMessagingConsumer; +import no.nav.dolly.domain.jpa.BestillingProgress; +import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling; +import no.nav.dolly.domain.resultset.SystemTyper; +import no.nav.dolly.domain.resultset.dolly.DollyPerson; +import no.nav.dolly.errorhandling.ErrorStatusDecoder; +import no.nav.dolly.service.TransaksjonMappingService; +import no.nav.dolly.util.TransactionHelperService; +import no.nav.testnav.libs.dto.tpsmessagingservice.v1.PersonMiljoeDTO; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.Duration; +import java.time.LocalTime; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; + +@Slf4j +@Service +@RequiredArgsConstructor +public class TpsPersonService { + + private static final List PENSJON_MILJOER = List.of("q1", "q2"); + private static final String TPS_SYNC_START = "Info: Synkronisering mot TPS startet ... %d ms"; + private static final long TIMEOUT_MILLIES = 839; + private static final int MAX_SEKUNDER = 45; + + private final TpsMessagingConsumer tpsMessagingConsumer; + private final TransactionHelperService transactionHelperService; + private final TransaksjonMappingService transaksjonMappingService; + + public Flux syncPerson(DollyPerson dollyPerson, RsDollyUtvidetBestilling bestilling, BestillingProgress progress, boolean isOpprettEndre) { + + long startTime = System.currentTimeMillis(); + + return Flux.from(Flux.fromIterable(bestilling.getEnvironments()) + .filter(PENSJON_MILJOER::contains) + .filter(penMiljoe -> isRelevantBestilling(bestilling) && + (isOpprettEndre || !isTransaksjonMapping(dollyPerson.getIdent(), bestilling, bestilling.getEnvironments()))) + .collectList() + .filter(penMiljoer -> !penMiljoer.isEmpty()) + .flatMap(penMiljoer -> getTpsPerson(LocalTime.now().plusSeconds(MAX_SEKUNDER), LocalTime.now(), dollyPerson.getIdent(), + penMiljoer, Collections.emptyList(), progress, new AtomicInteger(0)) + .map(status -> prepareResult(dollyPerson.getIdent(), status, bestilling.getEnvironments(), startTime)) + .map(status -> futurePersist(progress, status)))); + } + + private boolean isRelevantBestilling(RsDollyUtvidetBestilling bestilling) { + + return nonNull(bestilling.getPensjonforvalter()) && + (nonNull(bestilling.getPensjonforvalter().getAlderspensjon()) || + nonNull(bestilling.getPensjonforvalter().getUforetrygd())); + } + + private boolean isTransaksjonMapping(String ident, RsDollyUtvidetBestilling bestilling, Set miljoer) { + + var transaksjoner = transaksjonMappingService.getTransaksjonMapping(ident); + + return (isNull(bestilling.getPensjonforvalter().getAlderspensjon()) || + transaksjoner.stream() + .anyMatch(transaksjon -> miljoer.stream() + .anyMatch(miljoe -> SystemTyper.PEN_AP.name().equals(transaksjon.getSystem()) && + miljoe.equals(transaksjon.getMiljoe())))) && + + (isNull(bestilling.getPensjonforvalter().getUforetrygd()) || + transaksjoner.stream() + .anyMatch(transaksjon2 -> miljoer.stream() + .anyMatch(miljoe -> SystemTyper.PEN_UT.name().equals(transaksjon2.getSystem()) && + miljoe.equals(transaksjon2.getMiljoe())))); + } + + private Mono> getTpsPerson(LocalTime tidSlutt, LocalTime tidNo, String ident, List miljoer, + List status, BestillingProgress progress, AtomicInteger counter) { + + if (tidNo.isAfter(tidSlutt) || + (status.size() == miljoer.size() && + status.stream().allMatch(PersonMiljoeDTO::isOk))) { + return Mono.just(status); + + } else { + + transactionHelperService.persister(progress, BestillingProgress::setTpsSyncStatus, + miljoer.stream() + .map(miljoe -> String.format("%s:%s", miljoe, String.format(TPS_SYNC_START, counter.get() * TIMEOUT_MILLIES))) + .collect(Collectors.joining(","))); + + return Flux.just(1) + .delayElements(Duration.ofMillis(TIMEOUT_MILLIES)) + .flatMap(delayed -> tpsMessagingConsumer.getPerson(ident, miljoer)) + .collectList() + .flatMap(resultat -> getTpsPerson(tidSlutt, LocalTime.now(), ident, miljoer, resultat, progress, + new AtomicInteger(counter.incrementAndGet()))); + } + } + + private List prepareResult(String ident, List status, Set miljoer, long startTime) { + + if (status.size() == miljoer.size()) { + log.info("Synkronisering mot TPS for {} tok {} ms.", ident, System.currentTimeMillis() - startTime); + + } else { + log.warn("Synkronisering mot TPS for {} gitt opp etter {} ms.", ident, System.currentTimeMillis() - startTime); + } + + return Stream.of(status.stream() + .filter(status1 -> StringUtils.isNotBlank(status1.getMiljoe())), + miljoer.stream() + .filter(miljoe -> status.stream().noneMatch(status1 -> miljoe.equals(status1.getMiljoe()))) + .map(miljoe -> PersonMiljoeDTO.builder() + .miljoe(miljoe) + .status("NOK") + .utfyllendeMelding(String.format("Feil: Synkronisering mot TPS gitt opp etter %d sekunder.", MAX_SEKUNDER)) + .build())) + .flatMap(Function.identity()) + .toList(); + } + + private ClientFuture futurePersist(BestillingProgress progress, List status) { + + return () -> { + + progress.setIsTpsSyncEnv(status.stream() + .filter(PersonMiljoeDTO::isOk) + .map(PersonMiljoeDTO::getMiljoe) + .toList()); + + transactionHelperService.persister(progress, BestillingProgress::setTpsSyncStatus, + status.stream() + .map(detalj -> String.format("%s:%s", detalj.getMiljoe(), + ErrorStatusDecoder.encodeStatus(detalj.isOk() ? detalj.getStatus() : + StringUtils.trimToEmpty(String.format("FEIL: %s", detalj.getUtfyllendeMelding()))))) + .collect(Collectors.joining(","))); + return progress; + }; + } +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/BestillingProgress.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/BestillingProgress.java index e29e378354..699b90d8e1 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/BestillingProgress.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/BestillingProgress.java @@ -24,7 +24,10 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import static java.util.Objects.isNull; import static org.apache.logging.log4j.util.Strings.isNotBlank; @Entity @@ -115,6 +118,9 @@ public class BestillingProgress implements Serializable { @Column(name = "PDL_PERSON_STATUS") private String pdlPersonStatus; + @Column(name = "TPS_SYNC_STATUS") + private String tpsSyncStatus; + @Column(name = "ARBEIDSPLASSENCV_STATUS") private String arbeidsplassenCVStatus; @@ -125,6 +131,17 @@ public class BestillingProgress implements Serializable { @Transient private boolean isPdlSync; + @Transient + private List isTpsSyncEnv; + + public List getIsTpsSyncEnv() { + + if (isNull(isTpsSyncEnv)) { + isTpsSyncEnv = new ArrayList<>(); + } + return isTpsSyncEnv; + } + private String feil; public BestillingProgress(Bestilling bestilling, String ident, Master master) { 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 da898d9bfb..294d2a0eef 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 @@ -42,6 +42,7 @@ public enum SystemTyper { PDL_ORDRE("Ordre til PDL"), KONTOREGISTER("Bankkontoregister"), PDL_PERSONSTATUS("Person finnes i PDL"), + TPS_STATUS("Person finnes i TPS"), ANNEN_FEIL("Annen Feil"), ARBEIDSPLASSENCV("Arbeidsplassen CV"); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingTpsPersonStatusMapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingTpsPersonStatusMapper.java new file mode 100644 index 0000000000..405473c4b0 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingTpsPersonStatusMapper.java @@ -0,0 +1,55 @@ +package no.nav.dolly.mapper; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import no.nav.dolly.domain.jpa.BestillingProgress; +import no.nav.dolly.domain.resultset.RsStatusRapport; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static no.nav.dolly.domain.resultset.SystemTyper.TPS_STATUS; +import static no.nav.dolly.mapper.AbstractRsStatusMiljoeIdentForhold.checkAndUpdateStatus; +import static no.nav.dolly.mapper.AbstractRsStatusMiljoeIdentForhold.decodeMsg; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class BestillingTpsPersonStatusMapper { + + public static List buildTpsPersonStatusMap(List progressList) { + + // status miljø ident + Map>> statusEnvIdents = new HashMap<>(); + + progressList.forEach(progress -> { + if (isNotBlank(progress.getTpsSyncStatus())) { + List.of(progress.getTpsSyncStatus().split(",")).forEach(status -> { + var environErrMsg = status.split(":", 2); + var environ = environErrMsg[0]; + if (environErrMsg.length > 1 && isNotBlank(environErrMsg[1]) && isNotBlank(progress.getIdent())) { + var errMsg = decodeMsg(environErrMsg[1]); + checkAndUpdateStatus(statusEnvIdents, progress.getIdent(), environ, errMsg); + } + }); + } + }); + + return statusEnvIdents.isEmpty() ? emptyList() : + singletonList(RsStatusRapport.builder().id(TPS_STATUS).navn(TPS_STATUS.getBeskrivelse()) + .statuser(statusEnvIdents.entrySet().stream().map(status -> RsStatusRapport.Status.builder() + .melding(status.getKey()) + .detaljert(status.getValue().entrySet().stream().map(envIdent -> RsStatusRapport.Detaljert.builder() + .miljo(envIdent.getKey()) + .identer(new ArrayList<>(envIdent.getValue())) + .build()) + .toList()) + .build()) + .toList()) + .build()); + } +} 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 2e64216960..3093de2eea 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 @@ -42,6 +42,7 @@ import static no.nav.dolly.mapper.BestillingSkjermingsRegisterStatusMapper.buildSkjermingsRegisterStatusMap; import static no.nav.dolly.mapper.BestillingSykemeldingStatusMapper.buildSykemeldingStatusMap; import static no.nav.dolly.mapper.BestillingTpsMessagingStatusMapper.buildTpsMessagingStatusMap; +import static no.nav.dolly.mapper.BestillingTpsPersonStatusMapper.buildTpsPersonStatusMap; import static no.nav.dolly.mapper.BestillingUdiStubStatusMapper.buildUdiStubStatusMap; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -76,7 +77,11 @@ public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus, bestillingStatus.setGruppeId(bestilling.getGruppe().getId()); bestillingStatus.getStatus().addAll(buildPdlForvalterStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildPdlOrdreStatusMap(progresser, objectMapper)); + bestillingStatus.getStatus().addAll(buildImportFraPdlStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildPdlPersonStatusMap(progresser)); + bestillingStatus.getStatus().addAll(buildTpsPersonStatusMap(progresser)); + bestillingStatus.getStatus().addAll(buildPensjonforvalterStatusMap(progresser)); + bestillingStatus.getStatus().addAll(buildInntektstubStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildTpsMessagingStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildKrrStubStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildMedlStatusMap(progresser)); @@ -85,18 +90,15 @@ public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus, bestillingStatus.getStatus().addAll(buildArenaStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildInstdataStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildUdiStubStatusMap(progresser)); - bestillingStatus.getStatus().addAll(buildInntektstubStatusMap(progresser)); - bestillingStatus.getStatus().addAll(buildPensjonforvalterStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildInntektsmeldingStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildBrregStubStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildDokarkivStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildHistarkStatusMap(progresser)); - bestillingStatus.getStatus().addAll(buildImportFraPdlStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildSykemeldingStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildSkjermingsRegisterStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildKontoregisterStatusMap(progresser)); - bestillingStatus.getStatus().addAll(buildAnnenFeilStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildArbeidsplassenCVStatusMap(progresser)); + bestillingStatus.getStatus().addAll(buildAnnenFeilStatusMap(progresser)); bestillingStatus.setBestilling(RsBestillingStatus.RsBestilling.builder() .pdldata(bestillingRequest.getPdldata()) .aareg(bestillingRequest.getAareg()) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java index 261c164210..00c8d2c6a3 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/TransaksjonMappingService.java @@ -30,6 +30,14 @@ public List getTransaksjonMapping(String system, String id .toList(); } + @Transactional(readOnly = true) + public List getTransaksjonMapping(String ident) { + + return transaksjonMappingRepository.findAllByBestillingIdAndIdent(null, ident).stream() + .map(transasjon -> mapperFacade.map(transasjon, RsTransaksjonMapping.class)) + .toList(); + } + public boolean existAlready(SystemTyper system, String ident, String miljoe) { return transaksjonMappingRepository.findAllBySystemAndIdent(system.name(), ident) diff --git a/apps/dolly-backend/src/main/resources/db/migration/V1.7.20__AlterTableBestillingProgress.sql b/apps/dolly-backend/src/main/resources/db/migration/V1.7.20__AlterTableBestillingProgress.sql new file mode 100644 index 0000000000..bb6f249719 --- /dev/null +++ b/apps/dolly-backend/src/main/resources/db/migration/V1.7.20__AlterTableBestillingProgress.sql @@ -0,0 +1,6 @@ +----------------------------- +-- A L T E R T A B L E S -- +----------------------------- + +alter table bestilling_progress +add column tps_sync_status varchar(1000); \ No newline at end of file