Skip to content

Commit

Permalink
Fjernet boilerplate fra person-export-api sin bruk av ServerProperties.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc3092 committed Oct 26, 2023
1 parent 4195b7a commit 066112c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package no.nav.testnav.apps.personexportapi.config;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import static lombok.AccessLevel.PACKAGE;

/**
* Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}.
* <br/><br/>
* Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a>
* mellom configuration properties og field names.
*
* @see ServerProperties
*/
@Configuration
@ConfigurationProperties(prefix = "consumers")
@NoArgsConstructor(access = PACKAGE)
@Getter
@Setter(PACKAGE)
public class Consumers {

private ServerProperties kodeverk;
private ServerProperties tpsForvalter;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.List;
import java.util.Map;

import no.nav.testnav.apps.personexportapi.config.Consumers;
import no.nav.testnav.apps.personexportapi.consumer.command.GetKodeverkCommand;
import no.nav.testnav.apps.personexportapi.consumer.credential.KodeverkProperties;
import no.nav.testnav.apps.personexportapi.consumer.response.KodeverkBetydningerResponse;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
Expand All @@ -25,16 +25,16 @@ public class KodeverkConsumer {

private final WebClient webClient;
private final TokenExchange tokenExchange;
private final ServerProperties properties;
private final ServerProperties serverProperties;

public KodeverkConsumer(
TokenExchange tokenExchange,
KodeverkProperties serviceProperties) {

Consumers consumers) {
this.tokenExchange = tokenExchange;
this.properties = serviceProperties;
this.webClient = WebClient.builder()
.baseUrl(serviceProperties.getUrl())
serverProperties = consumers.getKodeverk();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.codecs(configurer -> configurer
.defaultCodecs()
.maxInMemorySize(16 * 1024 * 1024))
Expand All @@ -55,7 +55,7 @@ public String getKodeverkOppslag(String kodeverk, String verdi) {
@Cacheable(sync = true)
public Map<String, List<KodeverkBetydningerResponse.Betydning>> getKodeverkByName(String kodeverk) {

var kodeverkResponse = tokenExchange.exchange(properties)
var kodeverkResponse = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetKodeverkCommand(webClient, accessToken.getTokenValue(), kodeverk).call())
.block();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package no.nav.testnav.apps.personexportapi.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.personexportapi.config.Consumers;
import no.nav.testnav.apps.personexportapi.consumer.command.GetTpsfGrupperCommand;
import no.nav.testnav.apps.personexportapi.consumer.command.GetTpsfMeldingerFromPageCommand;
import no.nav.testnav.apps.personexportapi.consumer.credential.TpsfProperties;
import no.nav.testnav.apps.personexportapi.consumer.dto.GruppeDTO;
import no.nav.testnav.apps.personexportapi.domain.Person;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
Expand All @@ -32,26 +31,25 @@
public class TpsfConsumer {
private final WebClient webClient;
private final TokenExchange tokenExchange;
private final ServerProperties properties;
private final ServerProperties serverProperties;
private final ExecutorService executorService;

public TpsfConsumer(
TokenExchange tokenExchange,
TpsfProperties serviceProperties,
@Value("${consumers.tps-forvalter.threads}") Integer threads) {

Consumers consumers) {
this.tokenExchange = tokenExchange;
this.properties = serviceProperties;
this.webClient = WebClient.builder()
.baseUrl(properties.getUrl())
serverProperties = consumers.getTpsForvalter();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
this.executorService = Executors.newFixedThreadPool(threads);
this.executorService = Executors.newFixedThreadPool(serverProperties.getThreads());
}

private GruppeDTO getGruppe(String avspillingsgruppe) {
log.info("Henter avspillingsgruppe med id {}...", avspillingsgruppe);

var list = tokenExchange.exchange(properties)
var list = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetTpsfGrupperCommand(webClient, accessToken.getTokenValue()).call())
.block();

Expand All @@ -71,7 +69,7 @@ private int getNumberOfPages(String avspillingsgruppe) {

private CompletableFuture<List<Person>> getPersonFromPage(String avspillingsgruppe, int page, int numberOfPages) {
return CompletableFuture.supplyAsync(
() -> tokenExchange.exchange(properties)
() -> tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetTpsfMeldingerFromPageCommand(
webClient, accessToken.getTokenValue(), avspillingsgruppe, page).call())
.block(),
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 066112c

Please sign in to comment.