From 6809a0a0e7b5a09adb8c1064e46d4d0ddabecb0b Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Mon, 11 Mar 2024 09:15:48 +0100 Subject: [PATCH] Add new files and mappings to Endringsmelding service Removed the TranslittereringUtil file and added several new classes to handle mapping and service consumption functionality. New logic is distributed over twelve newly introduced files, which include the FoedselsmeldingRequestMapper and KjoennFraIdentUtility. Additionally, several configuration adjustments were made in application-dev.yml and Consumers.java. --- apps/endringsmelding-service/config.yml | 2 + .../config/Consumers.java | 4 +- .../consumer/AdresseServiceConsumer.java | 38 +++++ .../consumer/GenererNavnServiceConsumer.java | 38 +++++ .../consumer/IdentPoolConsumer.java | 38 +++++ .../consumer/TpsForvalterConsumer.java | 8 +- .../consumer/TpsMessagingConsumer.java | 64 +++++++++ .../command/GenererNavnServiceCommand.java | 38 +++++ .../command/GetAdressehistorikkCommand.java | 44 ++++++ .../command/GetPersondataCommand.java | 41 ++++++ .../command/IdentpoolPostCommand.java | 46 ++++++ .../command/SendDoedsmeldingCommand.java | 39 +++--- .../command/SendDoedsmeldingOldCommand.java | 47 +++++++ .../command/SendFoedselsmeldingCommand.java | 37 +++-- .../SendFoedselsmeldingOldCommand.java | 47 +++++++ .../SendKansellerDoedsmeldingCommand.java | 45 ++++++ .../command/VegadresseServiceCommand.java | 56 ++++++++ .../consumer/dto/HentIdenterRequest.java | 37 +++++ .../SkdEndringsmeldingerController.java | 60 ++++++++ .../mapper/AdressehistorikkMapper.java | 89 ++++++++++++ .../mapper/FoedselsmeldingRequestMapper.java | 73 ++++++++++ .../mapper/IdentpoolRequestMapper.java | 44 ++++++ .../service/DoedsmeldingService.java | 64 +++++++++ .../service/FoedselsmeldingService.java | 44 ++++++ .../utility/KjoennFraIdentUtility.java | 15 ++ .../src/main/resources/application-dev.yml | 10 ++ .../src/main/resources/application-prod.yml | 9 ++ .../src/main/resources/application.yml | 19 ++- apps/generer-navn-service/config.yml | 2 + apps/testnav-ident-pool/config.yml | 2 + .../utils/TranslittereringUtil.java | 131 ------------------ .../v1/FoedselsmeldingDTO.java | 1 + .../dto/endringsmelding/v2/AdresseFra.java | 7 + .../endringsmelding/v2/DoedsmeldingDTO.java | 18 +++ .../v2/FoedselsmeldingDTO.java | 22 +++ .../v2/FoedselsmeldingResponseDTO.java | 20 +++ .../dto/endringsmelding/v2/Identtype.java | 8 ++ .../v2/KansellerDoedsmeldingDTO.java | 15 ++ .../libs/dto/endringsmelding/v2/Kjoenn.java | 7 + .../tpsmessagingservice/v1/AdresseDTO.java | 2 + .../v1/AdressehistorikkDTO.java | 35 +++++ .../v1/GateadresseDTO.java | 6 +- .../v1/MatrikkeladresseDTO.java | 4 +- .../tpsmessagingservice/v1/PersonDTO.java | 6 + 44 files changed, 1197 insertions(+), 185 deletions(-) create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/AdresseServiceConsumer.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/GenererNavnServiceConsumer.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/IdentPoolConsumer.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GenererNavnServiceCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetAdressehistorikkCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetPersondataCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/IdentpoolPostCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingOldCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingOldCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendKansellerDoedsmeldingCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/VegadresseServiceCommand.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/dto/HentIdenterRequest.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/controller/SkdEndringsmeldingerController.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/AdressehistorikkMapper.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/FoedselsmeldingRequestMapper.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/IdentpoolRequestMapper.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/DoedsmeldingService.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/FoedselsmeldingService.java create mode 100644 apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/utility/KjoennFraIdentUtility.java create mode 100644 apps/endringsmelding-service/src/main/resources/application-dev.yml create mode 100644 apps/endringsmelding-service/src/main/resources/application-prod.yml delete mode 100644 apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/TranslittereringUtil.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/AdresseFra.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/DoedsmeldingDTO.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingDTO.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingResponseDTO.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Identtype.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/KansellerDoedsmeldingDTO.java create mode 100644 libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Kjoenn.java diff --git a/apps/endringsmelding-service/config.yml b/apps/endringsmelding-service/config.yml index 0eb96c908cb..7ce9bb5f3c8 100644 --- a/apps/endringsmelding-service/config.yml +++ b/apps/endringsmelding-service/config.yml @@ -28,6 +28,8 @@ spec: outbound: rules: - application: testnav-tps-messaging-service + - application: testnav-ident-pool + - application: generer-navn-service external: - host: tps-forvalteren-proxy.dev-fss-pub.nais.io liveness: diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/config/Consumers.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/config/Consumers.java index 0b633903ee0..67a149f36c7 100644 --- a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/config/Consumers.java +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/config/Consumers.java @@ -26,5 +26,7 @@ public class Consumers { private ServerProperties tpsForvalterenProxy; private ServerProperties tpsMessagingService; - + private ServerProperties adresseService; + private ServerProperties genererNavnService; + private ServerProperties identPool; } diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/AdresseServiceConsumer.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/AdresseServiceConsumer.java new file mode 100644 index 00000000000..d9234331567 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/AdresseServiceConsumer.java @@ -0,0 +1,38 @@ +package no.nav.testnav.endringsmeldingservice.consumer; + +import no.nav.testnav.endringsmeldingservice.config.Consumers; +import no.nav.testnav.endringsmeldingservice.consumer.command.VegadresseServiceCommand; +import no.nav.testnav.libs.dto.adresseservice.v1.VegadresseDTO; +import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Service +public class AdresseServiceConsumer { + private final WebClient webClient; + private final TokenExchange tokenExchange; + private final ServerProperties serverProperties; + + public AdresseServiceConsumer( + TokenExchange tokenExchange, + Consumers consumers) { + this.tokenExchange = tokenExchange; + serverProperties = consumers.getAdresseService(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) + .build(); + } + + public Mono> getVegadresse() { + + return tokenExchange.exchange(serverProperties) + .flatMapMany(token -> new VegadresseServiceCommand(webClient, token.getTokenValue()).call()) + .collectList(); + + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/GenererNavnServiceConsumer.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/GenererNavnServiceConsumer.java new file mode 100644 index 00000000000..905d09107e1 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/GenererNavnServiceConsumer.java @@ -0,0 +1,38 @@ +package no.nav.testnav.endringsmeldingservice.consumer; + +import no.nav.testnav.endringsmeldingservice.config.Consumers; +import no.nav.testnav.endringsmeldingservice.consumer.command.GenererNavnServiceCommand; +import no.nav.testnav.libs.dto.generernavnservice.v1.NavnDTO; +import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Service +public class GenererNavnServiceConsumer { + + private final WebClient webClient; + private final TokenExchange tokenExchange; + private final ServerProperties serverProperties; + + public GenererNavnServiceConsumer( + TokenExchange tokenExchange, + Consumers consumers) { + this.tokenExchange = tokenExchange; + serverProperties = consumers.getGenererNavnService(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) + .build(); + } + + public Mono> getNavn() { + + return tokenExchange.exchange(serverProperties) + .flatMapMany(token -> new GenererNavnServiceCommand(webClient, 1, token.getTokenValue()).call()) + .collectList(); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/IdentPoolConsumer.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/IdentPoolConsumer.java new file mode 100644 index 00000000000..76c17363321 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/IdentPoolConsumer.java @@ -0,0 +1,38 @@ +package no.nav.testnav.endringsmeldingservice.consumer; + +import no.nav.testnav.endringsmeldingservice.config.Consumers; +import no.nav.testnav.endringsmeldingservice.consumer.command.IdentpoolPostCommand; +import no.nav.testnav.endringsmeldingservice.consumer.dto.HentIdenterRequest; +import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Service +public class IdentPoolConsumer { + + private final WebClient webClient; + private final TokenExchange tokenExchange; + private final ServerProperties serverProperties; + + public IdentPoolConsumer( + TokenExchange tokenExchange, + Consumers consumers) { + this.tokenExchange = tokenExchange; + serverProperties = consumers.getIdentPool(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) + .build(); + } + + public Mono> acquireIdents(HentIdenterRequest request) { + + return tokenExchange.exchange(serverProperties) + .flatMap(token -> new IdentpoolPostCommand(webClient, request, + token.getTokenValue()).call()); + } +} \ No newline at end of file diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsForvalterConsumer.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsForvalterConsumer.java index c35e4f060e6..952856c6331 100644 --- a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsForvalterConsumer.java +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsForvalterConsumer.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import no.nav.testnav.endringsmeldingservice.config.Consumers; -import no.nav.testnav.endringsmeldingservice.consumer.command.SendDoedsmeldingCommand; -import no.nav.testnav.endringsmeldingservice.consumer.command.SendFoedselsmeldingCommand; +import no.nav.testnav.endringsmeldingservice.consumer.command.SendDoedsmeldingOldCommand; +import no.nav.testnav.endringsmeldingservice.consumer.command.SendFoedselsmeldingOldCommand; import no.nav.testnav.endringsmeldingservice.consumer.dto.DoedsmeldingDTO; import no.nav.testnav.endringsmeldingservice.consumer.request.FoedselsmeldingRequest; import no.nav.testnav.endringsmeldingservice.domain.Status; @@ -53,14 +53,14 @@ public TpsForvalterConsumer( public Mono sendFoedselsmelding(FoedselsmeldingDTO dto, Set miljoer) { return accessTokenService .exchange(serverProperties) - .flatMap(accessToken -> new SendFoedselsmeldingCommand(webClient, new FoedselsmeldingRequest(dto, miljoer), accessToken.getTokenValue()).call()) + .flatMap(accessToken -> new SendFoedselsmeldingOldCommand(webClient, new FoedselsmeldingRequest(dto, miljoer), accessToken.getTokenValue()).call()) .map(Status::new); } public Mono sendDoedsmelding(no.nav.testnav.libs.dto.endringsmelding.v1.DoedsmeldingDTO dto, Set miljoer) { return accessTokenService .exchange(serverProperties) - .flatMap(accessToken -> new SendDoedsmeldingCommand(webClient, new DoedsmeldingDTO(dto, miljoer), accessToken.getTokenValue()).call()) + .flatMap(accessToken -> new SendDoedsmeldingOldCommand(webClient, new DoedsmeldingDTO(dto, miljoer), accessToken.getTokenValue()).call()) .map(Status::new); } } diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsMessagingConsumer.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsMessagingConsumer.java index dbed99e80e6..c9ff96018da 100644 --- a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsMessagingConsumer.java +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/TpsMessagingConsumer.java @@ -2,7 +2,19 @@ import com.fasterxml.jackson.databind.ObjectMapper; import no.nav.testnav.endringsmeldingservice.config.Consumers; +import no.nav.testnav.endringsmeldingservice.consumer.command.GetAdressehistorikkCommand; import no.nav.testnav.endringsmeldingservice.consumer.command.GetIdentEnvironmentsCommand; +import no.nav.testnav.endringsmeldingservice.consumer.command.GetPersondataCommand; +import no.nav.testnav.endringsmeldingservice.consumer.command.SendDoedsmeldingCommand; +import no.nav.testnav.endringsmeldingservice.consumer.command.SendFoedselsmeldingCommand; +import no.nav.testnav.endringsmeldingservice.consumer.command.SendKansellerDoedsmeldingCommand; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingResponse; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO; import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonMiljoeDTO; import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; import no.nav.testnav.libs.securitycore.domain.ServerProperties; @@ -13,6 +25,10 @@ import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.LocalDate; +import java.util.Set; @Component public class TpsMessagingConsumer { @@ -49,4 +65,52 @@ public Flux hentMiljoer(String ident) { .exchange(serverProperties) .flatMapMany(accessToken -> new GetIdentEnvironmentsCommand(webClient, ident, accessToken.getTokenValue()).call()); } + + public Flux getPersondata(String ident, Set miljoer) { + + return accessTokenService + .exchange(serverProperties) + .flatMapMany(accessToken -> new GetPersondataCommand(webClient, ident, miljoer, accessToken.getTokenValue()).call()); + } + + public Flux getAdressehistorikk(String ident, LocalDate aksjonsdato, Set miljoer) { + + return getAdressehistorikk(AdressehistorikkRequest.builder() + .ident(ident) + .aksjonsdato(aksjonsdato) + .build(), + miljoer); + } + + public Flux getAdressehistorikk(AdressehistorikkRequest request, Set miljoer) { + + return accessTokenService + .exchange(serverProperties) + .flatMapMany(accessToken -> + new GetAdressehistorikkCommand(webClient, request, miljoer, accessToken.getTokenValue()).call()); + } + + public Flux sendKansellerDoedsmelding(PersonDTO person, Set miljoer) { + + return accessTokenService + .exchange(serverProperties) + .flatMapMany(accessToken -> + new SendKansellerDoedsmeldingCommand(webClient, person, miljoer, accessToken.getTokenValue()).call()); + } + + public Flux sendDoedsmelding(DoedsmeldingRequest request, Set miljoer) { + + return accessTokenService + .exchange(serverProperties) + .flatMapMany(accessToken -> + new SendDoedsmeldingCommand(webClient, request, miljoer, accessToken.getTokenValue()).call()); + } + + public Mono sendFoedselsmelding(FoedselsmeldingRequest person, Set miljoer) { + + return accessTokenService + .exchange(serverProperties) + .flatMap(accessToken -> + new SendFoedselsmeldingCommand(webClient, person, miljoer, accessToken.getTokenValue()).call()); + } } diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GenererNavnServiceCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GenererNavnServiceCommand.java new file mode 100644 index 00000000000..6953946a4e8 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GenererNavnServiceCommand.java @@ -0,0 +1,38 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.dto.generernavnservice.v1.NavnDTO; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.concurrent.Callable; + +@RequiredArgsConstructor +public class GenererNavnServiceCommand implements Callable> { + + private static final String NAVN_URL = "/api/v1/navn"; + + private final WebClient webClient; + private final Integer antall; + private final String token; + + @Override + public Flux call() { + + return webClient + .get() + .uri(builder -> builder.path(NAVN_URL).queryParam("antall", antall).build()) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .retrieve() + .bodyToFlux(NavnDTO.class) + .doOnError(WebClientFilter::logErrorMessage) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)); + } +} \ No newline at end of file diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetAdressehistorikkCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetAdressehistorikkCommand.java new file mode 100644 index 00000000000..8b4c950049a --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetAdressehistorikkCommand.java @@ -0,0 +1,44 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkRequest; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.Set; +import java.util.concurrent.Callable; + +@RequiredArgsConstructor +public class GetAdressehistorikkCommand implements Callable> { + + private static final String ADRESSE_HIST_URL = "/api/v1/personer/adressehistorikk"; + private static final String MILJOER = "miljoer"; + + private final WebClient webClient; + private final AdressehistorikkRequest request; + private final Set miljoer; + private final String token; + + @Override + public Flux call() { + + return webClient + .post() + .uri(builder -> builder.path(ADRESSE_HIST_URL) + .queryParam(MILJOER, miljoer) + .build()) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .body(BodyInserters.fromValue(request)) + .retrieve() + .bodyToFlux(AdressehistorikkDTO.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)) + .doOnError(WebClientFilter::logErrorMessage); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetPersondataCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetPersondataCommand.java new file mode 100644 index 00000000000..63c7c8dd37c --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/GetPersondataCommand.java @@ -0,0 +1,41 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonMiljoeDTO; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.Set; +import java.util.concurrent.Callable; + +@RequiredArgsConstructor +public class GetPersondataCommand implements Callable> { + + private static final String PERSON_DATA_URL = "/api/v1/personer/{ident}"; + private static final String MILJOER = "miljoer"; + + private final WebClient webClient; + private final String ident; + private final Set miljoer; + private final String token; + + @Override + public Flux call() { + + return webClient + .get() + .uri(builder -> builder.path(PERSON_DATA_URL) + .queryParam(MILJOER, miljoer) + .build(ident)) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .retrieve() + .bodyToFlux(PersonMiljoeDTO.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)) + .doOnError(WebClientFilter::logErrorMessage); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/IdentpoolPostCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/IdentpoolPostCommand.java new file mode 100644 index 00000000000..5e682ab1bfa --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/IdentpoolPostCommand.java @@ -0,0 +1,46 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import no.nav.testnav.endringsmeldingservice.consumer.dto.HentIdenterRequest; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.BodyInserters; +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.Arrays; +import java.util.List; +import java.util.concurrent.Callable; + +@Slf4j +@RequiredArgsConstructor +public class IdentpoolPostCommand implements Callable>> { + + private static final String ACQUIRE_IDENTS_URL = "/api/v1/identifikator"; + + private final WebClient webClient; + private final HentIdenterRequest body; + private final String token; + + @Override + public Mono> call() { + return webClient + .post() + .uri(builder -> builder.path(ACQUIRE_IDENTS_URL).build()) + .body(BodyInserters.fromValue(body)) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .retrieve() + .bodyToMono(String[].class) + .map(Arrays::asList) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException) + .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> + new InternalError("Identpool: antall repeterende forsøk nådd"))) + .doOnError(WebClientFilter::logErrorMessage); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingCommand.java index 34739353b95..9ef9c0bd681 100644 --- a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingCommand.java +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingCommand.java @@ -1,47 +1,44 @@ package no.nav.testnav.endringsmeldingservice.consumer.command; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.endringsmeldingservice.consumer.dto.DoedsmeldingDTO; -import no.nav.testnav.endringsmeldingservice.consumer.response.EndringsmeldingResponse; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse; import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; import java.time.Duration; +import java.util.Set; import java.util.concurrent.Callable; -@Slf4j @RequiredArgsConstructor -public class SendDoedsmeldingCommand implements Callable> { +public class SendDoedsmeldingCommand implements Callable> { + + private static final String DOEDSMELDING_URL = "/api/v1/personer/doedsmelding"; + private static final String MILJOER = "miljoer"; + private final WebClient webClient; - private final DoedsmeldingDTO dto; + private final DoedsmeldingRequest request; + private final Set miljoer; private final String token; @Override - public Mono call() { + public Mono call() { + return webClient .post() - .uri("/api/v1/tpsmelding/doedsmelding") + .uri(builder -> builder.path(DOEDSMELDING_URL) + .queryParam(MILJOER, miljoer) + .build()) .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) - .body(BodyInserters.fromPublisher(Mono.just(dto), DoedsmeldingDTO.class)) + .body(BodyInserters.fromValue(request)) .retrieve() - .bodyToMono(EndringsmeldingResponse.class) + .bodyToMono(DoedsmeldingResponse.class) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) .filter(WebClientFilter::is5xxException)) - .doOnError(error -> { - if (error instanceof WebClientResponseException) { - log.error( - "Feil ved innsendelse av dødsmelding. Feilmelding: {}.", - ((WebClientResponseException) error).getResponseBodyAsString() - ); - } else { - log.error("Feil ved innsendelse av dødsmelding.", error); - } - }); + .doOnError(WebClientFilter::logErrorMessage); } } diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingOldCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingOldCommand.java new file mode 100644 index 00000000000..ef314c3f595 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendDoedsmeldingOldCommand.java @@ -0,0 +1,47 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import no.nav.testnav.endringsmeldingservice.consumer.dto.DoedsmeldingDTO; +import no.nav.testnav.endringsmeldingservice.consumer.response.EndringsmeldingResponse; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.concurrent.Callable; + +@Slf4j +@RequiredArgsConstructor +public class SendDoedsmeldingOldCommand implements Callable> { + private final WebClient webClient; + private final DoedsmeldingDTO dto; + private final String token; + + @Override + public Mono call() { + return webClient + .post() + .uri("/api/v1/tpsmelding/doedsmelding") + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .body(BodyInserters.fromPublisher(Mono.just(dto), DoedsmeldingDTO.class)) + .retrieve() + .bodyToMono(EndringsmeldingResponse.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)) + .doOnError(error -> { + if (error instanceof WebClientResponseException) { + log.error( + "Feil ved innsendelse av dødsmelding. Feilmelding: {}.", + ((WebClientResponseException) error).getResponseBodyAsString() + ); + } else { + log.error("Feil ved innsendelse av dødsmelding.", error); + } + }); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingCommand.java index 96a95f5a0c6..abb2d14229a 100644 --- a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingCommand.java +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingCommand.java @@ -1,47 +1,44 @@ package no.nav.testnav.endringsmeldingservice.consumer.command; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.endringsmeldingservice.consumer.request.FoedselsmeldingRequest; -import no.nav.testnav.endringsmeldingservice.consumer.response.EndringsmeldingResponse; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingResponse; import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; import java.time.Duration; +import java.util.Set; import java.util.concurrent.Callable; -@Slf4j @RequiredArgsConstructor -public class SendFoedselsmeldingCommand implements Callable> { +public class SendFoedselsmeldingCommand implements Callable> { + + private static final String FOEDSELSMELDING_URL = "/api/v1/personer/foedselsmelding"; + private static final String MILJOER = "miljoer"; + private final WebClient webClient; private final FoedselsmeldingRequest request; + private final Set miljoer; private final String token; @Override - public Mono call() { + public Mono call() { + return webClient .post() - .uri("/api/v1/tpsmelding/foedselsmelding") + .uri(builder -> builder.path(FOEDSELSMELDING_URL) + .queryParam(MILJOER, miljoer) + .build()) .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) - .body(BodyInserters.fromPublisher(Mono.just(request), FoedselsmeldingRequest.class)) + .body(BodyInserters.fromValue(request)) .retrieve() - .bodyToMono(EndringsmeldingResponse.class) + .bodyToMono(FoedselsmeldingResponse.class) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) .filter(WebClientFilter::is5xxException)) - .doOnError(error -> { - if (error instanceof WebClientResponseException) { - log.error( - "Feil ved innsendelse av fødseslmelding. Feilmelding: {}.", - ((WebClientResponseException) error).getResponseBodyAsString() - ); - } else { - log.error("Feil ved innsendelse av fødseslmelding.", error); - } - }); + .doOnError(WebClientFilter::logErrorMessage); } } diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingOldCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingOldCommand.java new file mode 100644 index 00000000000..3ca70f1e1c2 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendFoedselsmeldingOldCommand.java @@ -0,0 +1,47 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import no.nav.testnav.endringsmeldingservice.consumer.request.FoedselsmeldingRequest; +import no.nav.testnav.endringsmeldingservice.consumer.response.EndringsmeldingResponse; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.concurrent.Callable; + +@Slf4j +@RequiredArgsConstructor +public class SendFoedselsmeldingOldCommand implements Callable> { + private final WebClient webClient; + private final FoedselsmeldingRequest request; + private final String token; + + @Override + public Mono call() { + return webClient + .post() + .uri("/api/v1/tpsmelding/foedselsmelding") + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .body(BodyInserters.fromPublisher(Mono.just(request), FoedselsmeldingRequest.class)) + .retrieve() + .bodyToMono(EndringsmeldingResponse.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)) + .doOnError(error -> { + if (error instanceof WebClientResponseException) { + log.error( + "Feil ved innsendelse av fødseslmelding. Feilmelding: {}.", + ((WebClientResponseException) error).getResponseBodyAsString() + ); + } else { + log.error("Feil ved innsendelse av fødseslmelding.", error); + } + }); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendKansellerDoedsmeldingCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendKansellerDoedsmeldingCommand.java new file mode 100644 index 00000000000..7e446f23ced --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/SendKansellerDoedsmeldingCommand.java @@ -0,0 +1,45 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.web.reactive.function.BodyInserters; +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.Set; +import java.util.concurrent.Callable; + +@RequiredArgsConstructor +public class SendKansellerDoedsmeldingCommand implements Callable> { + + private static final String DOEDSMELDING_URL = "/api/v1/personer/doedsmelding"; + private static final String MILJOER = "miljoer"; + + private final WebClient webClient; + private final PersonDTO person; + private final Set miljoer; + private final String token; + + @Override + public Mono call() { + + return webClient + .method(HttpMethod.DELETE) + .uri(builder -> builder.path(DOEDSMELDING_URL) + .queryParam(MILJOER, miljoer) + .build()) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .body(BodyInserters.fromValue(person)) + .retrieve() + .bodyToMono(DoedsmeldingResponse.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)) + .doOnError(WebClientFilter::logErrorMessage); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/VegadresseServiceCommand.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/VegadresseServiceCommand.java new file mode 100644 index 00000000000..3702d40ba65 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/command/VegadresseServiceCommand.java @@ -0,0 +1,56 @@ +package no.nav.testnav.endringsmeldingservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.dto.adresseservice.v1.VegadresseDTO; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import reactor.core.Exceptions; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.concurrent.Callable; + +@RequiredArgsConstructor +public class VegadresseServiceCommand implements Callable> { + + private static final String ADRESSER_VEG_URL = "/api/v1/adresser/veg"; + + private final WebClient webClient; + private final String token; + + @Override + public Flux call() { + + return webClient + .get() + .uri(builder -> builder.path(ADRESSER_VEG_URL).build()) + .header("antall", "1") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .retrieve() + .bodyToFlux(VegadresseDTO.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)) + .onErrorResume(throwable -> throwable instanceof WebClientResponseException.NotFound || + throwable instanceof WebClientResponseException.BadRequest || + Exceptions.isRetryExhausted(throwable), + throwable -> Mono.just(defaultAdresse())); + } + + public static VegadresseDTO defaultAdresse() { + + return VegadresseDTO.builder() + .matrikkelId("285693617") + .adressenavn("FYRSTIKKALLÉEN") + .postnummer("0661") + .husnummer(2) + .kommunenummer("0301") + .poststed("Oslo") + .build(); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/dto/HentIdenterRequest.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/dto/HentIdenterRequest.java new file mode 100644 index 00000000000..0e0f5df9eea --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/consumer/dto/HentIdenterRequest.java @@ -0,0 +1,37 @@ +package no.nav.testnav.endringsmeldingservice.consumer.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.validation.constraints.NotNull; +import java.time.LocalDate; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class HentIdenterRequest { + + private Identtype identtype; + private LocalDate foedtEtter; + private LocalDate foedtFoer; + private Kjoenn kjoenn; + + @NotNull + private int antall; + private String rekvirertAv; + private Boolean syntetisk; + + public enum Identtype { + FNR, + DNR, + BOST + } + + public enum Kjoenn { + KVINNE, + MANN + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/controller/SkdEndringsmeldingerController.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/controller/SkdEndringsmeldingerController.java new file mode 100644 index 00000000000..a812a6d342c --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/controller/SkdEndringsmeldingerController.java @@ -0,0 +1,60 @@ +package no.nav.testnav.endringsmeldingservice.controller; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.endringsmeldingservice.service.DoedsmeldingService; +import no.nav.testnav.endringsmeldingservice.service.FoedselsmeldingService; +import no.nav.testnav.libs.dto.endringsmelding.v2.FoedselsmeldingDTO; +import no.nav.testnav.libs.dto.endringsmelding.v2.FoedselsmeldingResponseDTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +import java.util.Set; + +@RestController +@RequestMapping("/api/v2/endringsmelding") +@RequiredArgsConstructor +public class SkdEndringsmeldingerController { + + private final FoedselsmeldingService foedselsmeldingService; + private final DoedsmeldingService doedsmeldingService; + + @PostMapping("/foedeselsmelding") + public Mono sendFoedselsmelding( + @RequestHeader Set miljoer, + @RequestBody FoedselsmeldingDTO dto) { + + return foedselsmeldingService.sendFoedselsmelding(dto, miljoer); + } + +// @PostMapping("/doedsmelding") +// public Mono> sendFoedselsmelding( +// @RequestHeader Set miljoer, +// @RequestBody DoedsmeldingDTO doedsmelding) { +// +// return doedsmeldingService.sendDoedsmelding(doedsmelding, miljoer) +// .map(status -> { +// if (!status.isOk()) { +// return ResponseEntity.badRequest().body(status.getErrors()); +// } +// return ResponseEntity.ok(status.getPersonId()); +// }); +// } +// +// @DeleteMapping("/doedsmelding") +// public Mono> kansellerFoedselsmelding( +// @RequestHeader Set miljoer, +// @RequestBody KansellerDoedsmeldingDTO kansellerDoedsmelding) { +// +// return doedsmeldingService.sendKansellerDoedsmelding(kansellerDoedsmelding.getIdent(), miljoer) +// .map(status -> { +// if (!status.isOk()) { +// return ResponseEntity.badRequest().body(status.getErrors()); +// } +// return ResponseEntity.ok(status.getPersonId()); +// }); +// } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/AdressehistorikkMapper.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/AdressehistorikkMapper.java new file mode 100644 index 00000000000..0ca22a441fc --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/AdressehistorikkMapper.java @@ -0,0 +1,89 @@ +package no.nav.testnav.endringsmeldingservice.mapper; + +import lombok.experimental.UtilityClass; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdresseDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.GateadresseDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.MatrikkeladresseDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonMiljoeDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PostadresseDTO; + +import java.time.LocalDate; + +@UtilityClass +public class AdressehistorikkMapper { + + public static PersonDTO mapHistorikk(AdressehistorikkDTO.PersonData person) { + + return PersonDTO.builder() + .ident(person.getIdent()) + .identtype(person.getIdentType()) + .boadresse(mapBoadresse(person)) + .postadresse(person.getPostAdresse().stream() + .map(postadresse -> PostadresseDTO.builder() + .postLinje1(postadresse.getAdresse1()) + .postLinje2(postadresse.getAdresse2()) + .postLinje3(postadresse.getAdresse3()) + .postLand(postadresse.getLand()) + .build() + ) + .findFirst() + .orElse(null) + ) + .build(); + } + + public static AdresseDTO mapBoadresse(AdressehistorikkDTO.PersonData person) { + + return (AdresseDTO) person.getBostedsAdresse().stream() + .map(boadresse -> { + + if ("OFFA".equals(boadresse.getAdresseType())) { + return GateadresseDTO.builder() + .gatekode(boadresse.getOffAdresse().getGatekode()) + .adresse(boadresse.getOffAdresse().getGateNavn()) + .husnummer(boadresse.getOffAdresse().getHusnr()) + .husbokstav(boadresse.getOffAdresse().getBokstav()) + .bolignr(boadresse.getBolignr()) + .flyttedato(boadresse.getDatoFom().atStartOfDay()) + .postnr(boadresse.getPostnr()) + .kommunenr(boadresse.getKommunenr()) + .tilleggsadresse(boadresse.getTilleggsAdresseSKD()) + .build(); + } else { + + return MatrikkeladresseDTO.builder() + .mellomnavn(boadresse.getMatrAdresse().getMellomAdresse()) + .gardsnr(boadresse.getMatrAdresse().getGardsnr()) + .bruksnr(boadresse.getMatrAdresse().getBruksnr()) + .festenr(boadresse.getMatrAdresse().getFestenr()) + .undernr(boadresse.getMatrAdresse().getUndernr()) + .bolignr(boadresse.getBolignr()) + .flyttedato(boadresse.getDatoFom().atStartOfDay()) + .postnr(boadresse.getPostnr()) + .kommunenr(boadresse.getKommunenr()) + .tilleggsadresse(boadresse.getTilleggsAdresseSKD()); + } + }) + .findFirst() + .orElse(null); + } + + public static AdressehistorikkRequest buildAdresseRequest(PersonMiljoeDTO person) { + + return AdressehistorikkRequest.builder() + .ident(person.getIdent()) + .aksjonsdato(person.getPerson().getDoedsdato().toLocalDate().minusDays(1)) + .build(); + } + + public static AdressehistorikkRequest buildAdresseRequest(String ident, LocalDate aksjonsdato) { + + return AdressehistorikkRequest.builder() + .ident(ident) + .aksjonsdato(aksjonsdato) + .build(); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/FoedselsmeldingRequestMapper.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/FoedselsmeldingRequestMapper.java new file mode 100644 index 00000000000..612aa32831a --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/FoedselsmeldingRequestMapper.java @@ -0,0 +1,73 @@ +package no.nav.testnav.endringsmeldingservice.mapper; + +import lombok.experimental.UtilityClass; +import no.nav.testnav.endringsmeldingservice.utility.KjoennFraIdentUtility; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdresseDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.GateadresseDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO; +import no.nav.testnav.libs.dto.adresseservice.v1.VegadresseDTO; +import no.nav.testnav.libs.dto.endringsmelding.v2.FoedselsmeldingDTO; +import no.nav.testnav.libs.dto.generernavnservice.v1.NavnDTO; +import reactor.util.function.Tuple5; + +import java.util.List; + +import static java.util.Objects.nonNull; +import static no.nav.testnav.endringsmeldingservice.mapper.AdressehistorikkMapper.mapBoadresse; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +@UtilityClass +public class FoedselsmeldingRequestMapper { + + public static FoedselsmeldingRequest map(FoedselsmeldingDTO fodselsmelding, Tuple5, List, List, + List, List> opplysninger) { + + return FoedselsmeldingRequest.builder() + .barn(PersonDTO.builder() + .ident(opplysninger.getT1().getFirst()) + .identtype(fodselsmelding.getIdenttype().name()) + .fornavn(opplysninger.getT2().getFirst().getAdjektiv()) + .mellomnavn(opplysninger.getT2().getFirst().getAdverb()) + .etternavn(opplysninger.getT2().getFirst().getSubstantiv()) + .boadresse(mapAdresse(fodselsmelding, opplysninger.getT3(), opplysninger.getT4(), opplysninger.getT5())) + .kjonn(KjoennFraIdentUtility.get(opplysninger.getT1().getFirst())) + .build()) + .mor(PersonDTO.builder() + .ident(fodselsmelding.getIdentMor()) + .build()) + .far(isNotBlank(fodselsmelding.getIdentFar()) ? + PersonDTO.builder() + .ident(fodselsmelding.getIdentFar()) + .build() : null) + .build(); + } + + private static AdresseDTO mapAdresse(FoedselsmeldingDTO foedselsmelding, List vegadresse, + List morsadresser, List farsadresser) { + + return switch (foedselsmelding.getAdresseFra()) { + + case LAG_NY_ADRESSE -> mapAdresse(vegadresse.getFirst()); + case ARV_FRA_MORS -> mapBoadresse(morsadresser.getFirst().getPersondata()); + case ARV_FRA_FARS -> nonNull(farsadresser) && !farsadresser.isEmpty() ? + mapBoadresse(farsadresser.getFirst().getPersondata()) : + mapAdresse(vegadresse.getFirst()); + }; + } + + private static AdresseDTO mapAdresse(VegadresseDTO vegadresse) { + + return GateadresseDTO.builder() + .adressetype(AdresseDTO.Adressetype.GATE) + .adresse(vegadresse.getAdressenavn()) + .gatekode(vegadresse.getAdressekode()) + .husnummer(vegadresse.getHusnummer().toString()) + .husbokstav(vegadresse.getHusbokstav()) + .postnr(vegadresse.getPostnummer()) + .kommunenr(vegadresse.getKommunenummer()) + .tilleggsadresse(vegadresse.getTilleggsnavn()) + .build(); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/IdentpoolRequestMapper.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/IdentpoolRequestMapper.java new file mode 100644 index 00000000000..f5f049a7dbb --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/mapper/IdentpoolRequestMapper.java @@ -0,0 +1,44 @@ +package no.nav.testnav.endringsmeldingservice.mapper; + +import lombok.experimental.UtilityClass; +import no.nav.testnav.endringsmeldingservice.consumer.dto.HentIdenterRequest; +import no.nav.testnav.endringsmeldingservice.consumer.dto.HentIdenterRequest.Identtype; +import no.nav.testnav.libs.dto.endringsmelding.v2.FoedselsmeldingDTO; +import no.nav.testnav.libs.dto.endringsmelding.v2.Kjoenn; + +import java.security.SecureRandom; +import java.util.Random; + +import static java.util.Objects.isNull; +import static no.nav.testnav.endringsmeldingservice.consumer.dto.HentIdenterRequest.Kjoenn.KVINNE; +import static no.nav.testnav.endringsmeldingservice.consumer.dto.HentIdenterRequest.Kjoenn.MANN; + +@UtilityClass +public class IdentpoolRequestMapper { + + private static final Random random = new SecureRandom(); + + public HentIdenterRequest convert(FoedselsmeldingDTO fodselsmelding) { + + return HentIdenterRequest.builder() + .identtype(Identtype.valueOf(fodselsmelding.getIdenttype().name())) + .foedtFoer(fodselsmelding.getFoedselsdato()) + .foedtEtter(fodselsmelding.getFoedselsdato()) + .kjoenn(convertKjoenn(fodselsmelding.getKjoenn())) + .rekvirertAv("TEMS") // testnav-endringsmelding-service + .antall(1) + .build(); + } + private HentIdenterRequest.Kjoenn convertKjoenn(Kjoenn kjoenn) { + + if (isNull(kjoenn)) { + return random.nextBoolean() ? MANN : KVINNE; + } + + return switch (kjoenn) { + case GUTT -> MANN; + case JENTE -> KVINNE; + case UKJENT -> random.nextBoolean() ? MANN : KVINNE; + }; + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/DoedsmeldingService.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/DoedsmeldingService.java new file mode 100644 index 00000000000..40e2a20e9c7 --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/DoedsmeldingService.java @@ -0,0 +1,64 @@ +package no.nav.testnav.endringsmeldingservice.service; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.endringsmeldingservice.consumer.TpsMessagingConsumer; +import no.nav.testnav.endringsmeldingservice.mapper.AdressehistorikkMapper; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingRequest; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonMiljoeDTO; +import no.nav.testnav.libs.dto.endringsmelding.v2.DoedsmeldingDTO; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; + +import java.util.Set; + +import static no.nav.testnav.endringsmeldingservice.mapper.AdressehistorikkMapper.buildAdresseRequest; + +@Service +@RequiredArgsConstructor +public class DoedsmeldingService { + + private final TpsMessagingConsumer tpsMessagingConsumer; + + public Flux sendKansellerDoedsmelding(String ident, Set miljoer) { + + return tpsMessagingConsumer.getPersondata(ident, miljoer) + .filter(PersonMiljoeDTO::isOk) + .filter(persondata -> persondata.getPerson().isDoed()) + .flatMap(persondata -> tpsMessagingConsumer.getAdressehistorikk(buildAdresseRequest(persondata), + Set.of(persondata.getMiljoe())) + .map(AdressehistorikkDTO::getPersondata) + .map(AdressehistorikkMapper::mapHistorikk) + .flatMap(person -> + tpsMessagingConsumer.sendKansellerDoedsmelding(person, Set.of(persondata.getMiljoe())))); + } + + public Flux sendDoedsmelding(DoedsmeldingDTO doedsmelding, Set miljoer) { + + return tpsMessagingConsumer.getPersondata(doedsmelding.getIdent(), miljoer) + .filter(PersonMiljoeDTO::isOk) + .flatMap(persondata -> { + + if (persondata.getPerson().isDoed()) { + return tpsMessagingConsumer.getAdressehistorikk(buildAdresseRequest(persondata), + Set.of(persondata.getMiljoe())) + .map(AdressehistorikkDTO::getPersondata) + .map(AdressehistorikkMapper::mapHistorikk) + .flatMap(person -> + tpsMessagingConsumer.sendKansellerDoedsmelding(person, Set.of(persondata.getMiljoe()))) + .flatMap(response -> tpsMessagingConsumer.sendDoedsmelding(DoedsmeldingRequest.builder() + .ident(doedsmelding.getIdent()) + .doedsdato(doedsmelding.getDoedsdato()) + .build(), Set.of(persondata.getMiljoe()))); + + } else { + return tpsMessagingConsumer.sendDoedsmelding(DoedsmeldingRequest.builder() + .ident(doedsmelding.getIdent()) + .doedsdato(doedsmelding.getDoedsdato()) + .build(), Set.of(persondata.getMiljoe())); + + } + }); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/FoedselsmeldingService.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/FoedselsmeldingService.java new file mode 100644 index 00000000000..35a7057ab7b --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/service/FoedselsmeldingService.java @@ -0,0 +1,44 @@ +package no.nav.testnav.endringsmeldingservice.service; + +import lombok.RequiredArgsConstructor; +import no.nav.testnav.endringsmeldingservice.consumer.AdresseServiceConsumer; +import no.nav.testnav.endringsmeldingservice.consumer.GenererNavnServiceConsumer; +import no.nav.testnav.endringsmeldingservice.consumer.IdentPoolConsumer; +import no.nav.testnav.endringsmeldingservice.consumer.TpsMessagingConsumer; +import no.nav.testnav.endringsmeldingservice.mapper.FoedselsmeldingRequestMapper; +import no.nav.testnav.endringsmeldingservice.mapper.IdentpoolRequestMapper; +import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO; +import no.nav.testnav.libs.dto.endringsmelding.v2.FoedselsmeldingDTO; +import no.nav.testnav.libs.dto.endringsmelding.v2.FoedselsmeldingResponseDTO; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.Set; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class FoedselsmeldingService { + + private final IdentPoolConsumer identPoolConsumer; + private final GenererNavnServiceConsumer genererNavnServiceConsumer; + private final AdresseServiceConsumer adresseServiceConsumer; + private final TpsMessagingConsumer tpsMessagingConsumer; + + public Mono sendFoedselsmelding(FoedselsmeldingDTO request, Set miljoer) { + + return Mono.zip(identPoolConsumer.acquireIdents( + IdentpoolRequestMapper.convert(request)), + genererNavnServiceConsumer.getNavn(), + adresseServiceConsumer.getVegadresse(), + tpsMessagingConsumer.getAdressehistorikk(request.getIdentMor(), request.getFoedselsdato(), miljoer).collectList(), + tpsMessagingConsumer.getAdressehistorikk(request.getIdentFar(), request.getFoedselsdato(), miljoer).collectList()) + .flatMap(opplysninger -> Mono.just(FoedselsmeldingRequestMapper.map(request, opplysninger)) + .flatMap(foedselsmelding -> tpsMessagingConsumer.sendFoedselsmelding(foedselsmelding, + opplysninger.getT4().stream().map(AdressehistorikkDTO::getMiljoe).collect(Collectors.toSet())))) + .map(response -> FoedselsmeldingResponseDTO.builder() + .ident(response.getIdent()) + .miljoStatus(response.getMiljoStatus()) + .build()); + } +} diff --git a/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/utility/KjoennFraIdentUtility.java b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/utility/KjoennFraIdentUtility.java new file mode 100644 index 00000000000..7876fef778e --- /dev/null +++ b/apps/endringsmelding-service/src/main/java/no/nav/testnav/endringsmeldingservice/utility/KjoennFraIdentUtility.java @@ -0,0 +1,15 @@ +package no.nav.testnav.endringsmeldingservice.utility; + +import lombok.experimental.UtilityClass; + +import static java.lang.Integer.parseInt; + +@UtilityClass +public class KjoennFraIdentUtility { + + public String get(String ident){ + + int kjoennNummer = parseInt(ident.substring(8,9)); + return kjoennNummer % 2 == 0 ? "K" : "M"; + } +} \ No newline at end of file diff --git a/apps/endringsmelding-service/src/main/resources/application-dev.yml b/apps/endringsmelding-service/src/main/resources/application-dev.yml new file mode 100644 index 00000000000..749d6f813ed --- /dev/null +++ b/apps/endringsmelding-service/src/main/resources/application-dev.yml @@ -0,0 +1,10 @@ + +consumers: + adresse-service: + url: https://testnav-adresse-service.intern.dev.nav.no + generer-navn-service: + url: https://generer-navn-service.intern.dev.nav.no + ident-pool: + url: https://testnav-ident-pool.intern.dev.nav.no + tps-messaging-service: + url: https://testnav-tps-messaging-service.intern.dev.nav.no \ No newline at end of file diff --git a/apps/endringsmelding-service/src/main/resources/application-prod.yml b/apps/endringsmelding-service/src/main/resources/application-prod.yml new file mode 100644 index 00000000000..894f2d09e4e --- /dev/null +++ b/apps/endringsmelding-service/src/main/resources/application-prod.yml @@ -0,0 +1,9 @@ + +spring: + security: + oauth2: + resourceserver: + tokenx: + issuer-uri: ${TOKEN_X_ISSUER} + jwk-set-uri: ${TOKEN_X_JWKS_URI} + accepted-audience: ${TOKEN_X_CLIENT_ID} \ No newline at end of file diff --git a/apps/endringsmelding-service/src/main/resources/application.yml b/apps/endringsmelding-service/src/main/resources/application.yml index 40398f5dfe6..6b234af6b85 100644 --- a/apps/endringsmelding-service/src/main/resources/application.yml +++ b/apps/endringsmelding-service/src/main/resources/application.yml @@ -12,10 +12,6 @@ spring: issuer-uri: ${AAD_ISSUER_URI}/v2.0 jwk-set-uri: ${AAD_ISSUER_URI}/discovery/v2.0/keys accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} - tokenx: - issuer-uri: ${TOKEN_X_ISSUER} - jwk-set-uri: ${TOKEN_X_JWKS_URI} - accepted-audience: ${TOKEN_X_CLIENT_ID} springdoc: swagger-ui: @@ -33,6 +29,21 @@ consumers: cluster: dev-gcp namespace: dolly name: testnav-tps-messaging-service + ident-pool: + url: http://testnav-ident-pool.dolly.svc.cluster.local + cluster: dev-gcp + namespace: dolly + name: testnav-ident-pool + adresse-service: + url: http://testnav-adresse-service.dolly.svc.cluster.local + cluster: dev-gcp + namespace: dolly + name: testnav-adresse-service + generer-navn-service: + url: http://generer-navn-service.dolly.svc.cluster.local + cluster: dev-gcp + namespace: dolly + name: generer-navn-service management: endpoints: diff --git a/apps/generer-navn-service/config.yml b/apps/generer-navn-service/config.yml index 2e2ad5598d3..54cb18235ef 100644 --- a/apps/generer-navn-service/config.yml +++ b/apps/generer-navn-service/config.yml @@ -39,6 +39,8 @@ spec: cluster: dev-gcp - application: testnav-budpro-service cluster: dev-gcp + - application: testnav-endringsmelding-service + cluster: dev-gcp; tokenx: enabled: true azure: diff --git a/apps/testnav-ident-pool/config.yml b/apps/testnav-ident-pool/config.yml index 64c3d600750..db7359ec9db 100644 --- a/apps/testnav-ident-pool/config.yml +++ b/apps/testnav-ident-pool/config.yml @@ -61,6 +61,8 @@ spec: - application: app-1 namespace: plattformsikkerhet cluster: dev-gcp + - application: testnav-endringsmelding-service + cluster: dev-gcp outbound: rules: - application: testnav-tps-messaging-service diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/TranslittereringUtil.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/TranslittereringUtil.java deleted file mode 100644 index 8e6383d5fbb..00000000000 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/TranslittereringUtil.java +++ /dev/null @@ -1,131 +0,0 @@ -package no.nav.testnav.apps.tpsmessagingservice.utils; - -import com.ibm.icu.text.Transliterator; -import lombok.experimental.UtilityClass; -import lombok.val; - -import java.text.Normalizer; -import java.util.Map; -import java.util.regex.Pattern; - -import static java.util.Map.Entry; -import static java.util.Map.entry; -import static java.util.Map.ofEntries; -import static java.util.Objects.isNull; - -@UtilityClass -public class TranslittereringUtil { - - private final String LATIN_CYRILLIC = "Latin-Russian/BGN"; - private final Transliterator cyrillicToLatinTrans = Transliterator.getInstance(LATIN_CYRILLIC).getInverse(); - - private final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); - - private final Map PRINTABLE_BY_NON_PRINTABLE = ofEntries( - entry('å', '\u0001'), - entry('Å', '\u0002'), - entry('ä', '\u0003'), - entry('Ä', '\u0004'), - entry('é', '\u0005'), - entry('É', '\u0006'), - entry('è', '\u0007'), - entry('È', '\u0008'), - entry('ö', '\u000B'), - entry('Ö', '\u0010'), - entry('ü', '\u0011'), - entry('Ü', '\u0012') - ); - - /** - * Implementerer følgende regler: - *
    - *
  • {@code äöü éè æøå ÄÖÜ ÉÈ ÆØÅ} forblir uendret
  • - *
  • Folkeregisterets regler for translitterering mot DSF https://confluence.adeo.no/download/attachments/229949696/Regler%20for%20translitterering.docx
  • - *
  • DIFI sin erstatningstabell for samiske tegn https://www.difi.no/fagomrader-og-tjenester/digitalisering-og-samordning/standarder/forslag-og-utredninger/hvorfor-felles-tegnsett#Erstatningstabell
  • - *
  • Bokstavene i Unicode Basic Latin (ISO 8859-1) og noen enkeltbokstaver i Latin Extended-A og Extended-B
  • - *
- * Spesialregler for å håndtere tegn utover overstående regelsett blir laget for hvert enkelt tilfelle, se {@code convertKnownCharactersNotHandledByNormalization()}. - * Resten ignoreres/bevares. Se read-me for detaljer.
- */ - public String translitterer(String str) { - - if (isNull(str)) { - return null; - } - - final var prepared = preprocess(str); - final var normalized = pattern.matcher(Normalizer.normalize(prepared, Normalizer.Form.NFD)).replaceAll(""); - final var processed = postprocess(normalized); - String text = convertKnownCharactersNotHandledByNormalization(processed); - return cyrillicToLatinTrans.transliterate(text); - } - - private String preprocess(String str) { - // replace wanted characters with non-printable characters to save them from normalization - for (Entry entry : PRINTABLE_BY_NON_PRINTABLE.entrySet()) { - - var original = entry.getKey(); - var nonPrintable = entry.getValue(); - str = str.replace(nonPrintable.toString(), ""); - str = str.replace(original, nonPrintable); - } - return str; - } - - private String postprocess(String str) { - // replace non-printable characters with original characters after normalization - for (Entry entry : PRINTABLE_BY_NON_PRINTABLE.entrySet()) { - var original = entry.getKey(); - var nonPrintable = entry.getValue(); - str = str.replace(nonPrintable, original); - } - return str; - } - - private String convertKnownCharactersNotHandledByNormalization(String str) { - // replace characters not covered by normalization - return str - .replace('\u0189', 'D') // 'Ɖ' Afrikansk D - .replace('\u0256', 'd') // 'ɖ' Liten afrikansk d med hale - .replace('\u00D0', 'D') // 'Ð' Stor eth (islandsk) - .replace('\u00F0', 'd') // 'ð' Liten eth - .replace('\u0110', 'D') // 'Đ' Stor D med strek (samisk, slavisk, vietnamesisk, mf.) - .replace('\u0111', 'd') // 'đ' Liten d med strek - .replace('\u01E4', 'G') // 'Ǥ' Stor G med strek (samisk) - .replace('\u01E5', 'g') // Liten g med strek (samisk) - .replace('ı', 'i') // LATIN SMALL LETTER DOTLESS I U+0131 - .replace('Ł', 'L') - .replace('ł', 'l') - .replace('Ŋ', 'N') - .replace('ŋ', 'n') - .replace('Ŧ', 'T') - .replace('ŧ', 't') - .replace('Ɓ', 'B') // B med krok - .replace('ɓ', 'b') // b med krok - .replace('\u0187', 'C') // C med krok - .replace('\u0188', 'c') // c med krok - .replace('Ɗ', 'D') // D med krok - .replace('ɗ', 'd') // d med krok - .replace('Ɠ', 'G') // G med krok - .replace('ɠ', 'g') // g med krok - .replace('Ƙ', 'K') // K med krok - .replace('ƙ', 'k') // k med krok - .replace('Ƥ', 'P') // P med krok - .replace('ƥ', 'p') // p med krok - .replace('Ƭ', 'T') // T med krok - .replace('ƭ', 't') // t med krok - .replace('\u01B3', 'Y') // 'Ƴ', Y med krok U+01B3 - .replace('\u01B4', 'y') // 'ƴ', y med krok U+01B4 - .replace("Þ", "TH") - .replace("þ", "th") - .replace("ß", "ss") - .replace("⁰", "") - .replace("Ԉ", "(komi lje)") - .replace("Б", "be") // cyrillisk Komi Lje - .replace("\u001A", " ") // "substitute" control char (ascii 26) - - // strek symboler, finnes mange fler men tar en så lenge bare de vi har sett (https://en.wikipedia.org/wiki/Dash#Unicode) - .replace("–", "-") // Kort Tankestrek til Bindestrek - .replace("—", "-"); // Lang Tankestrek til Bindestrek - } -} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v1/FoedselsmeldingDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v1/FoedselsmeldingDTO.java index b489d637b77..f3ba9c037fe 100644 --- a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v1/FoedselsmeldingDTO.java +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v1/FoedselsmeldingDTO.java @@ -12,6 +12,7 @@ @AllArgsConstructor @NoArgsConstructor(force = true) public class FoedselsmeldingDTO { + String identFar; String identMor; String identtype; diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/AdresseFra.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/AdresseFra.java new file mode 100644 index 00000000000..43b8d22c0f8 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/AdresseFra.java @@ -0,0 +1,7 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +public enum AdresseFra { + LAG_NY_ADRESSE, + ARV_FRA_MORS, + ARV_FRA_FARS +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/DoedsmeldingDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/DoedsmeldingDTO.java new file mode 100644 index 00000000000..83b879d2492 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/DoedsmeldingDTO.java @@ -0,0 +1,18 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Value; + +import java.time.LocalDate; + +@Value +@Builder +@AllArgsConstructor +@NoArgsConstructor(force = true) +public class DoedsmeldingDTO { + + String ident; + LocalDate doedsdato; +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingDTO.java new file mode 100644 index 00000000000..2b7ede29057 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingDTO.java @@ -0,0 +1,22 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Value; + +import java.time.LocalDate; + +@Value +@Builder +@AllArgsConstructor +@NoArgsConstructor(force = true) +public class FoedselsmeldingDTO { + + String identFar; + String identMor; + Identtype identtype; + LocalDate foedselsdato; + Kjoenn kjoenn; + AdresseFra adresseFra; +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingResponseDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingResponseDTO.java new file mode 100644 index 00000000000..c61fce4c5c0 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/FoedselsmeldingResponseDTO.java @@ -0,0 +1,20 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class FoedselsmeldingResponseDTO { + + private String ident; + private Map miljoStatus; + + private String error; +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Identtype.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Identtype.java new file mode 100644 index 00000000000..326333c2de5 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Identtype.java @@ -0,0 +1,8 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +public enum Identtype { + + FNR, + DNR, + BOST +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/KansellerDoedsmeldingDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/KansellerDoedsmeldingDTO.java new file mode 100644 index 00000000000..cd76040f29e --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/KansellerDoedsmeldingDTO.java @@ -0,0 +1,15 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Value; + +@Value +@Builder +@AllArgsConstructor +@NoArgsConstructor(force = true) +public class KansellerDoedsmeldingDTO { + + String ident; +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Kjoenn.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Kjoenn.java new file mode 100644 index 00000000000..975a8ffd376 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/endringsmelding/v2/Kjoenn.java @@ -0,0 +1,7 @@ +package no.nav.testnav.libs.dto.endringsmelding.v2; + +public enum Kjoenn { + GUTT, + JENTE, + UKJENT +} diff --git a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdresseDTO.java b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdresseDTO.java index 9e941f3622e..e8d811c8acc 100644 --- a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdresseDTO.java +++ b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdresseDTO.java @@ -5,10 +5,12 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; import java.time.LocalDateTime; @Data +@SuperBuilder @NoArgsConstructor @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "adressetype") @JsonSubTypes({ diff --git a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdressehistorikkDTO.java b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdressehistorikkDTO.java index a8dba236f46..47920b93785 100644 --- a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdressehistorikkDTO.java +++ b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/AdressehistorikkDTO.java @@ -8,8 +8,11 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import static java.util.Objects.isNull; + @Data @Builder @NoArgsConstructor @@ -46,6 +49,38 @@ public static class PersonData { private List bostedsAdresse; private List postAdresse; private List tilleggAdresseNAV; + + public List getPersonStatus() { + + if (isNull(personStatus)) { + personStatus = new ArrayList<>(); + } + return personStatus; + } + + public List getBostedsAdresse() { + + if (isNull(bostedsAdresse)) { + bostedsAdresse = new ArrayList<>(); + } + return bostedsAdresse; + } + + public List getPostAdresse() { + + if (isNull(postAdresse)) { + postAdresse = new ArrayList<>(); + } + return postAdresse; + } + + public List getTilleggAdresseNAV() { + + if (isNull(tilleggAdresseNAV)) { + tilleggAdresseNAV = new ArrayList<>(); + } + return tilleggAdresseNAV; + } } @Data diff --git a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/GateadresseDTO.java b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/GateadresseDTO.java index d9ce3d70123..e2ccbe1ecd9 100644 --- a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/GateadresseDTO.java +++ b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/GateadresseDTO.java @@ -2,13 +2,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data -@Builder +@SuperBuilder @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor @@ -19,5 +19,7 @@ public class GateadresseDTO extends AdresseDTO { private String husnummer; + private String husbokstav; + private String gatekode; } diff --git a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/MatrikkeladresseDTO.java b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/MatrikkeladresseDTO.java index 360c6e67fb0..a26109bcee4 100644 --- a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/MatrikkeladresseDTO.java +++ b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/MatrikkeladresseDTO.java @@ -2,13 +2,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; @Data -@Builder +@SuperBuilder @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor diff --git a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/PersonDTO.java b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/PersonDTO.java index bfad5551584..5e7930b1f28 100644 --- a/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/PersonDTO.java +++ b/libs/data-transfer-search-objects/src/main/java/no/nav/testnav/libs/data/tpsmessagingservice/v1/PersonDTO.java @@ -13,6 +13,7 @@ import java.util.List; import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; @Data @Builder @@ -105,4 +106,9 @@ public List getTelefonnumre() { } return telefonnumre; } + + public boolean isDoed() { + + return nonNull(doedsdato); + } }