Skip to content

Commit

Permalink
Add new files and mappings to Endringsmelding service
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krharum committed Mar 11, 2024
1 parent 71d4f8e commit 6809a0a
Show file tree
Hide file tree
Showing 44 changed files with 1,197 additions and 185 deletions.
2 changes: 2 additions & 0 deletions apps/endringsmelding-service/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public class Consumers {

private ServerProperties tpsForvalterenProxy;
private ServerProperties tpsMessagingService;

private ServerProperties adresseService;
private ServerProperties genererNavnService;
private ServerProperties identPool;
}
Original file line number Diff line number Diff line change
@@ -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<List<VegadresseDTO>> getVegadresse() {

return tokenExchange.exchange(serverProperties)
.flatMapMany(token -> new VegadresseServiceCommand(webClient, token.getTokenValue()).call())
.collectList();

}
}
Original file line number Diff line number Diff line change
@@ -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<List<NavnDTO>> getNavn() {

return tokenExchange.exchange(serverProperties)
.flatMapMany(token -> new GenererNavnServiceCommand(webClient, 1, token.getTokenValue()).call())
.collectList();
}
}
Original file line number Diff line number Diff line change
@@ -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<List<String>> acquireIdents(HentIdenterRequest request) {

return tokenExchange.exchange(serverProperties)
.flatMap(token -> new IdentpoolPostCommand(webClient, request,
token.getTokenValue()).call());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,14 +53,14 @@ public TpsForvalterConsumer(
public Mono<Status> sendFoedselsmelding(FoedselsmeldingDTO dto, Set<String> 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<Status> sendDoedsmelding(no.nav.testnav.libs.dto.endringsmelding.v1.DoedsmeldingDTO dto, Set<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -49,4 +65,52 @@ public Flux<PersonMiljoeDTO> hentMiljoer(String ident) {
.exchange(serverProperties)
.flatMapMany(accessToken -> new GetIdentEnvironmentsCommand(webClient, ident, accessToken.getTokenValue()).call());
}

public Flux<PersonMiljoeDTO> getPersondata(String ident, Set<String> miljoer) {

return accessTokenService
.exchange(serverProperties)
.flatMapMany(accessToken -> new GetPersondataCommand(webClient, ident, miljoer, accessToken.getTokenValue()).call());
}

public Flux<AdressehistorikkDTO> getAdressehistorikk(String ident, LocalDate aksjonsdato, Set<String> miljoer) {

return getAdressehistorikk(AdressehistorikkRequest.builder()
.ident(ident)
.aksjonsdato(aksjonsdato)
.build(),
miljoer);
}

public Flux<AdressehistorikkDTO> getAdressehistorikk(AdressehistorikkRequest request, Set<String> miljoer) {

return accessTokenService
.exchange(serverProperties)
.flatMapMany(accessToken ->
new GetAdressehistorikkCommand(webClient, request, miljoer, accessToken.getTokenValue()).call());
}

public Flux<DoedsmeldingResponse> sendKansellerDoedsmelding(PersonDTO person, Set<String> miljoer) {

return accessTokenService
.exchange(serverProperties)
.flatMapMany(accessToken ->
new SendKansellerDoedsmeldingCommand(webClient, person, miljoer, accessToken.getTokenValue()).call());
}

public Flux<DoedsmeldingResponse> sendDoedsmelding(DoedsmeldingRequest request, Set<String> miljoer) {

return accessTokenService
.exchange(serverProperties)
.flatMapMany(accessToken ->
new SendDoedsmeldingCommand(webClient, request, miljoer, accessToken.getTokenValue()).call());
}

public Mono<FoedselsmeldingResponse> sendFoedselsmelding(FoedselsmeldingRequest person, Set<String> miljoer) {

return accessTokenService
.exchange(serverProperties)
.flatMap(accessToken ->
new SendFoedselsmeldingCommand(webClient, person, miljoer, accessToken.getTokenValue()).call());
}
}
Original file line number Diff line number Diff line change
@@ -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<Flux<NavnDTO>> {

private static final String NAVN_URL = "/api/v1/navn";

private final WebClient webClient;
private final Integer antall;
private final String token;

@Override
public Flux<NavnDTO> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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<Flux<AdressehistorikkDTO>> {

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<String> miljoer;
private final String token;

@Override
public Flux<AdressehistorikkDTO> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Flux<PersonMiljoeDTO>> {

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<String> miljoer;
private final String token;

@Override
public Flux<PersonMiljoeDTO> 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);
}
}
Loading

0 comments on commit 6809a0a

Please sign in to comment.