Skip to content

Commit

Permalink
Fjernet boilerplate fra testnorge-statisk-data-forvalter sin bruk av …
Browse files Browse the repository at this point in the history
…ServerProperties.
  • Loading branch information
rfc3092 committed Oct 26, 2023
1 parent 8eac3b7 commit 3cdf428
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 206 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package no.nav.registre.sdforvalter.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 testnavAaregProxy;
private ServerProperties genererNavnService;
private ServerProperties testnorgeHodejegeren;
private ServerProperties kodeverk;
private ServerProperties testnavOrganisasjonFasteDataService;
private ServerProperties testnavOrganisasjonService;
private ServerProperties testnavPersonFasteDataService;
private ServerProperties person;
private ServerProperties testnorgeTp;
private ServerProperties tpsForvalterenProxy;

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package no.nav.registre.sdforvalter.consumer.rs.aareg;

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.sdforvalter.config.credentials.AaregProperties;
import no.nav.registre.sdforvalter.config.Consumers;
import no.nav.registre.sdforvalter.consumer.rs.aareg.command.GetArbeidsforholdCommand;
import no.nav.registre.sdforvalter.consumer.rs.aareg.command.PostArbeidsforholdCommand;
import no.nav.registre.sdforvalter.consumer.rs.aareg.response.ArbeidsforholdRespons;
import no.nav.testnav.libs.dto.aareg.v1.Arbeidsforhold;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
Expand All @@ -16,13 +17,13 @@
public class AaregConsumer {
private final WebClient webClient;
private final TokenExchange tokenExchange;
private final AaregProperties properties;
private final ServerProperties serverProperties;

public AaregConsumer(
AaregProperties serverProperties,
Consumers consumers,
TokenExchange tokenExchange
) {
this.properties = serverProperties;
serverProperties = consumers.getTestnavAaregProxy();
this.tokenExchange = tokenExchange;
this.webClient = WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder()
Expand All @@ -35,14 +36,14 @@ public AaregConsumer(
}

public ArbeidsforholdRespons opprettArbeidsforhold(Arbeidsforhold arbeidsforhold, String miljoe) {
return tokenExchange.exchange(properties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostArbeidsforholdCommand(
webClient, miljoe, arbeidsforhold, accessToken.getTokenValue()).call())
.block();
}

public ArbeidsforholdRespons hentArbeidsforhold(String ident, String miljoe) {
return tokenExchange.exchange(properties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetArbeidsforholdCommand(
webClient, miljoe, ident, accessToken.getTokenValue()).call())
.block();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.registre.sdforvalter.consumer.rs.hodejegeren;

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.sdforvalter.consumer.rs.credential.HodejegerenProperties;
import no.nav.registre.sdforvalter.config.Consumers;
import no.nav.registre.sdforvalter.consumer.rs.hodejegeren.command.GetAlleIdenterCommand;
import no.nav.registre.sdforvalter.consumer.rs.hodejegeren.command.GetLevendeIdenterCommand;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
Expand All @@ -17,17 +17,17 @@ public class HodejegerenConsumer {

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

public HodejegerenConsumer(
HodejegerenProperties serviceProperties,
Consumers consumers,
TokenExchange tokenExchange
) {
this.serviceProperties = serviceProperties;
serverProperties = consumers.getTestnorgeHodejegeren();
this.tokenExchange = tokenExchange;

this.webClient = WebClient.builder()
.baseUrl(serviceProperties.getUrl())
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
}

Expand All @@ -36,13 +36,13 @@ public HodejegerenConsumer(
* @return En liste med fnr som eksisterer i gruppen
*/
public List<String> getPlaygroupFnrs(Long playgroupId) {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetAlleIdenterCommand(playgroupId, webClient, accessToken.getTokenValue()).call())
.block();
}

public List<String> getLivingFnrs(Long playgroupId, String environment) {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetLevendeIdenterCommand(playgroupId, environment, webClient, accessToken.getTokenValue()).call())
.block();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.nav.registre.sdforvalter.consumer.rs.kodeverk;

import no.nav.registre.sdforvalter.config.credentials.KodeverkProperties;
import no.nav.registre.sdforvalter.config.Consumers;
import no.nav.registre.sdforvalter.consumer.rs.kodeverk.command.GetYrkerKodeverkCommand;
import no.nav.registre.sdforvalter.consumer.rs.kodeverk.response.KodeverkResponse;
import org.springframework.stereotype.Component;
Expand All @@ -12,15 +12,19 @@ public class KodeverkConsumer {
private final WebClient webClient;

public KodeverkConsumer(
KodeverkProperties serverProperties
Consumers consumers
) {
this.webClient = WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder()
this.webClient = WebClient
.builder()
.exchangeStrategies(ExchangeStrategies
.builder()
.codecs(configurer -> configurer
.defaultCodecs()
.maxInMemorySize(16 * 1024 * 1024))
.build())
.baseUrl(serverProperties.getUrl())
.baseUrl(consumers
.getKodeverk()
.getUrl())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package no.nav.registre.sdforvalter.consumer.rs.navn;

import no.nav.registre.sdforvalter.config.credentials.GenererNavnServiceProperties;
import no.nav.registre.sdforvalter.config.Consumers;
import no.nav.testnav.libs.commands.generernavnservice.v1.GenererNavnCommand;
import no.nav.testnav.libs.dto.generernavnservice.v1.NavnDTO;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -11,15 +12,16 @@
public class GenererNavnConsumer {

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

public GenererNavnConsumer(GenererNavnServiceProperties properties,
TokenExchange tokenExchange) {

public GenererNavnConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
this.tokenExchange = tokenExchange;
this.properties = properties;
this.webClient = WebClient.builder()
properties = consumers.getGenererNavnService();
this.webClient = WebClient
.builder()
.baseUrl(properties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package no.nav.registre.sdforvalter.consumer.rs.organisasjon;

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.sdforvalter.config.credentials.OrganisasjonServiceProperties;
import no.nav.registre.sdforvalter.config.Consumers;
import no.nav.registre.sdforvalter.domain.status.ereg.Organisasjon;
import no.nav.testnav.libs.commands.organisasjonservice.v1.GetOrganisasjonCommand;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -18,15 +19,14 @@
@Component
public class OrganisasjonConsumer {
private final WebClient webClient;
private final OrganisasjonServiceProperties serverProperties;
private final ServerProperties serverProperties;
private final TokenExchange tokenExchange;
private final Executor executor;

public OrganisasjonConsumer(
OrganisasjonServiceProperties serverProperties,
Consumers consumers,
TokenExchange tokenExchange) {

this.serverProperties = serverProperties;
serverProperties = consumers.getTestnavOrganisasjonService();
this.tokenExchange = tokenExchange;
this.executor = Executors.newFixedThreadPool(serverProperties.getThreads());
this.webClient = WebClient
Expand Down
Loading

0 comments on commit 3cdf428

Please sign in to comment.