From 3cdf4284c81fa93775754676d5eb725d9b2bd87a Mon Sep 17 00:00:00 2001 From: Cato Olsen Date: Thu, 26 Oct 2023 10:12:34 +0200 Subject: [PATCH] Fjernet boilerplate fra testnorge-statisk-data-forvalter sin bruk av ServerProperties. --- .../sdforvalter/config/Consumers.java | 38 ++++++++++++++++ .../config/credentials/AaregProperties.java | 11 ----- .../GenererNavnServiceProperties.java | 12 ------ .../credentials/KodeverkProperties.java | 12 ------ ...rganisasjonFasteDataServiceProperties.java | 17 -------- .../OrganisasjonServiceProperties.java | 17 -------- .../PersonFasteDataServiceProperties.java | 16 ------- .../credentials/PersonServiceProperties.java | 10 ----- .../credentials/TpsfProxyProperties.java | 10 ----- .../consumer/rs/aareg/AaregConsumer.java | 13 +++--- .../rs/credential/HodejegerenProperties.java | 10 ----- .../rs/credential/TestnorgeTpProperties.java | 10 ----- .../rs/hodejegeren/HodejegerenConsumer.java | 18 ++++---- .../rs/kodeverk/KodeverkConsumer.java | 14 +++--- .../consumer/rs/navn/GenererNavnConsumer.java | 16 ++++--- .../rs/organisasjon/OrganisasjonConsumer.java | 10 ++--- .../OrganisasjonFasteDataConsumer.java | 9 ++-- .../consumer/rs/person/PersonConsumer.java | 43 +++++++++---------- .../rs/person/PersonFasteDataConsumer.java | 10 ++--- .../consumer/rs/tp/TpConsumer.java | 13 +++--- .../consumer/rs/tpsf/TpsfConsumer.java | 19 ++++---- .../consumer/rs/tpsf/TpsfConsumerTest.java | 4 +- 22 files changed, 126 insertions(+), 206 deletions(-) create mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/Consumers.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/AaregProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/GenererNavnServiceProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/KodeverkProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonFasteDataServiceProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonServiceProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonFasteDataServiceProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonServiceProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/TpsfProxyProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/HodejegerenProperties.java delete mode 100644 apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/TestnorgeTpProperties.java diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/Consumers.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/Consumers.java new file mode 100644 index 00000000000..e7fe0e1b255 --- /dev/null +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/Consumers.java @@ -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}. + *

+ * Husk at Spring Boot bruker relaxed binding + * 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; + +} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/AaregProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/AaregProperties.java deleted file mode 100644 index 70a98aaa803..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/AaregProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-aareg-proxy") -public class AaregProperties extends ServerProperties{ -} \ No newline at end of file diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/GenererNavnServiceProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/GenererNavnServiceProperties.java deleted file mode 100644 index 37e498d53da..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/GenererNavnServiceProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.generer-navn-service") -public class GenererNavnServiceProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/KodeverkProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/KodeverkProperties.java deleted file mode 100644 index a42e74eca20..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/KodeverkProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.kodeverk") -public class KodeverkProperties extends ServerProperties{ -} - diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonFasteDataServiceProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonFasteDataServiceProperties.java deleted file mode 100644 index fb19f4d219b..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonFasteDataServiceProperties.java +++ /dev/null @@ -1,17 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Setter -@Getter -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-organisasjon-faste-data-service") -public class OrganisasjonFasteDataServiceProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonServiceProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonServiceProperties.java deleted file mode 100644 index 1b58d35ebfe..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/OrganisasjonServiceProperties.java +++ /dev/null @@ -1,17 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Setter -@Getter -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-organisasjon-service") -public class OrganisasjonServiceProperties extends ServerProperties { - private Integer threads; -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonFasteDataServiceProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonFasteDataServiceProperties.java deleted file mode 100644 index 33d80b30f30..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonFasteDataServiceProperties.java +++ /dev/null @@ -1,16 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Setter -@Getter -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-person-faste-data-service") -public class PersonFasteDataServiceProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonServiceProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonServiceProperties.java deleted file mode 100644 index d02ffb95707..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/PersonServiceProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.person") -public class PersonServiceProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/TpsfProxyProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/TpsfProxyProperties.java deleted file mode 100644 index 7f84201113d..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/config/credentials/TpsfProxyProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.registre.sdforvalter.config.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.tps-forvalteren-proxy") -public class TpsfProxyProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/aareg/AaregConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/aareg/AaregConsumer.java index 1d61e0d03ce..b28f5abb52d 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/aareg/AaregConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/aareg/AaregConsumer.java @@ -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; @@ -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() @@ -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(); diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/HodejegerenProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/HodejegerenProperties.java deleted file mode 100644 index 11483468ab7..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/HodejegerenProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.registre.sdforvalter.consumer.rs.credential; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnorge-hodejegeren") -public class HodejegerenProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/TestnorgeTpProperties.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/TestnorgeTpProperties.java deleted file mode 100644 index 17330942b89..00000000000 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/credential/TestnorgeTpProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.registre.sdforvalter.consumer.rs.credential; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnorge-tp") -public class TestnorgeTpProperties extends ServerProperties { -} diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/hodejegeren/HodejegerenConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/hodejegeren/HodejegerenConsumer.java index 3fbaa80c4e0..d37b86bcca5 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/hodejegeren/HodejegerenConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/hodejegeren/HodejegerenConsumer.java @@ -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; @@ -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(); } @@ -36,13 +36,13 @@ public HodejegerenConsumer( * @return En liste med fnr som eksisterer i gruppen */ public List getPlaygroupFnrs(Long playgroupId) { - return tokenExchange.exchange(serviceProperties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetAlleIdenterCommand(playgroupId, webClient, accessToken.getTokenValue()).call()) .block(); } public List getLivingFnrs(Long playgroupId, String environment) { - return tokenExchange.exchange(serviceProperties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetLevendeIdenterCommand(playgroupId, environment, webClient, accessToken.getTokenValue()).call()) .block(); } diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/kodeverk/KodeverkConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/kodeverk/KodeverkConsumer.java index 7b706fcbef4..5ff4997c148 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/kodeverk/KodeverkConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/kodeverk/KodeverkConsumer.java @@ -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; @@ -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(); } diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/navn/GenererNavnConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/navn/GenererNavnConsumer.java index d3e643e9371..a5b1777416e 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/navn/GenererNavnConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/navn/GenererNavnConsumer.java @@ -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; @@ -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(); } diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonConsumer.java index 41c92d4344f..4f4e19f2b6f 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonConsumer.java @@ -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; @@ -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 diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonFasteDataConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonFasteDataConsumer.java index 20d19157066..0ac80b476b4 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonFasteDataConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/organisasjon/OrganisasjonFasteDataConsumer.java @@ -1,7 +1,7 @@ package no.nav.registre.sdforvalter.consumer.rs.organisasjon; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.sdforvalter.config.credentials.OrganisasjonFasteDataServiceProperties; +import no.nav.registre.sdforvalter.config.Consumers; import no.nav.registre.sdforvalter.consumer.rs.navn.GenererNavnConsumer; import no.nav.registre.sdforvalter.consumer.rs.organisasjon.command.SaveOrganisasjonFasteDataCommand; import no.nav.registre.sdforvalter.consumer.rs.organisasjon.domain.OrgTree; @@ -9,6 +9,7 @@ import no.nav.registre.sdforvalter.domain.EregListe; import no.nav.testnav.libs.dto.generernavnservice.v1.NavnDTO; import no.nav.testnav.libs.dto.organisasjonfastedataservice.v1.Gruppe; +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; @@ -19,16 +20,16 @@ @Component public class OrganisasjonFasteDataConsumer { private final WebClient webClient; - private final OrganisasjonFasteDataServiceProperties serverProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; private final GenererNavnConsumer genererNavnConsumer; public OrganisasjonFasteDataConsumer( - OrganisasjonFasteDataServiceProperties serverProperties, + Consumers consumers, TokenExchange tokenExchange, GenererNavnConsumer genererNavnConsumer) { - this.serverProperties = serverProperties; + serverProperties = consumers.getTestnavOrganisasjonFasteDataService(); this.tokenExchange = tokenExchange; this.webClient = WebClient .builder() diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonConsumer.java index e7239759ffd..33a3cc9dff6 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonConsumer.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.sdforvalter.config.credentials.PersonServiceProperties; +import no.nav.registre.sdforvalter.config.Consumers; import no.nav.registre.sdforvalter.domain.TpsIdent; import no.nav.registre.sdforvalter.domain.TpsIdentListe; import no.nav.registre.sdforvalter.domain.person.Person; @@ -13,12 +13,10 @@ import no.nav.testnav.libs.securitycore.domain.AccessToken; 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.MediaType; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.stereotype.Component; - import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; @@ -37,32 +35,33 @@ public class PersonConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; private final Executor executor; public PersonConsumer( - ObjectMapper objectMapper, @Value("${consumers.person.threads}") Integer threads, - PersonServiceProperties personServiceProperties, + ObjectMapper objectMapper, + Consumers consumers, TokenExchange tokenExchange) { - - this.serviceProperties = personServiceProperties; + serverProperties = consumers.getPerson(); this.tokenExchange = tokenExchange; - - ExchangeStrategies jacksonStrategy = ExchangeStrategies.builder() - .codecs(config -> { - config.defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }).build(); - + ExchangeStrategies jacksonStrategy = ExchangeStrategies + .builder() + .codecs( + config -> { + config + .defaultCodecs() + .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); + config + .defaultCodecs() + .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); + }) + .build(); this.webClient = WebClient .builder() .exchangeStrategies(jacksonStrategy) - .baseUrl(personServiceProperties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); - - this.executor = Executors.newFixedThreadPool(threads); + this.executor = Executors.newFixedThreadPool(serverProperties.getThreads()); } private CompletableFuture hentPerson(String ident, AccessToken accessToken) { @@ -74,7 +73,7 @@ private CompletableFuture hentPerson(String ident, AccessToken accessTok } public List hentPersoner(Set identer) { - AccessToken accessToken = tokenExchange.exchange(serviceProperties).block(); + AccessToken accessToken = tokenExchange.exchange(serverProperties).block(); List personer = new ArrayList<>(); var futures = identer.stream().map(ident -> hentPerson(ident, accessToken)).toList(); for (CompletableFuture future : futures) { @@ -90,7 +89,7 @@ public List hentPersoner(Set identer) { } public void opprettPersoner(TpsIdentListe identer) { - AccessToken accessToken = tokenExchange.exchange(serviceProperties).block(); + AccessToken accessToken = tokenExchange.exchange(serverProperties).block(); List> futures = identer.stream().map(ident -> CompletableFuture.supplyAsync(() -> { try { new CreatePersonCommand(webClient, ident.toDTO(), accessToken.getTokenValue(), ident.getOpprinnelse()).call().block(); diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonFasteDataConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonFasteDataConsumer.java index cb41c578550..8a901395312 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonFasteDataConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/person/PersonFasteDataConsumer.java @@ -1,12 +1,13 @@ package no.nav.registre.sdforvalter.consumer.rs.person; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.sdforvalter.config.credentials.PersonFasteDataServiceProperties; +import no.nav.registre.sdforvalter.config.Consumers; import no.nav.registre.sdforvalter.consumer.rs.person.command.SavePersonFasteDataCommand; import no.nav.registre.sdforvalter.domain.TpsIdent; import no.nav.registre.sdforvalter.domain.TpsIdentListe; import no.nav.testnav.libs.dto.personservice.v1.Gruppe; import no.nav.testnav.libs.securitycore.domain.AccessToken; +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; @@ -18,14 +19,13 @@ @Component public class PersonFasteDataConsumer { private final WebClient webClient; - private final PersonFasteDataServiceProperties serverProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public PersonFasteDataConsumer( - PersonFasteDataServiceProperties serverProperties, + Consumers consumers, TokenExchange tokenExchange) { - - this.serverProperties = serverProperties; + serverProperties = consumers.getTestnavPersonFasteDataService(); this.tokenExchange = tokenExchange; this.webClient = WebClient .builder() diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tp/TpConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tp/TpConsumer.java index ba3853f299c..3748743c1a6 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tp/TpConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tp/TpConsumer.java @@ -1,7 +1,7 @@ package no.nav.registre.sdforvalter.consumer.rs.tp; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.sdforvalter.consumer.rs.credential.TestnorgeTpProperties; +import no.nav.registre.sdforvalter.config.Consumers; import no.nav.registre.sdforvalter.consumer.rs.tp.command.OpprettPersonerTpCommand; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; @@ -18,17 +18,16 @@ public class TpConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; public TpConsumer( TokenExchange tokenExchange, - TestnorgeTpProperties serviceProperties) { - this.serviceProperties = serviceProperties; + Consumers consumers) { + serverProperties = consumers.getTestnorgeTp(); this.tokenExchange = tokenExchange; - this.webClient = WebClient .builder() - .baseUrl(serviceProperties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } @@ -38,7 +37,7 @@ public TpConsumer( * @return true hvis den ble lagret i tp, false hvis de ikke ble lagret */ public boolean send(List data, String environment) { - var response = tokenExchange.exchange(serviceProperties) + var response = tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new OpprettPersonerTpCommand(webClient, data, environment, accessToken.getTokenValue()).call()) .block(); diff --git a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumer.java b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumer.java index d120dd300ee..649fd3ad0f0 100644 --- a/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumer.java +++ b/apps/testnorge-statisk-data-forvalter/src/main/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumer.java @@ -1,11 +1,12 @@ package no.nav.registre.sdforvalter.consumer.rs.tpsf; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.sdforvalter.config.credentials.TpsfProxyProperties; +import no.nav.registre.sdforvalter.config.Consumers; import no.nav.registre.sdforvalter.consumer.rs.tpsf.command.GetMeldingsIdsCommand; import no.nav.registre.sdforvalter.consumer.rs.tpsf.command.PostSendSkdMeldingerTpsCommand; import no.nav.registre.sdforvalter.consumer.rs.tpsf.request.SendToTpsRequest; import no.nav.registre.sdforvalter.consumer.rs.tpsf.response.SkdMeldingerTilTpsRespons; +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; @@ -18,15 +19,15 @@ public class TpsfConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final TpsfProxyProperties serviceProperties; + private final ServerProperties serverProperties; public TpsfConsumer( - TpsfProxyProperties serviceProperties, + Consumers consumers, TokenExchange tokenExchange) { - - this.serviceProperties = serviceProperties; - this.webClient = WebClient.builder() - .baseUrl(serviceProperties.getUrl()) + serverProperties = consumers.getTpsForvalterenProxy(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .build(); this.tokenExchange = tokenExchange; } @@ -36,12 +37,12 @@ private Mono sendSkdmeldingerToTps( SendToTpsRequest sendToTpsRequest) { log.info("Sender skd-meldinger med avspillergruppe {} til tps", gruppeId); - return tokenExchange.exchange(serviceProperties).flatMap(accessToken -> + return tokenExchange.exchange(serverProperties).flatMap(accessToken -> new PostSendSkdMeldingerTpsCommand(gruppeId, sendToTpsRequest, webClient, accessToken.getTokenValue()).call()); } private Mono> getMeldingIdsFromAvspillergruppe(Long gruppeId) { - return tokenExchange.exchange(serviceProperties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetMeldingsIdsCommand(gruppeId, webClient, accessToken.getTokenValue()).call()); } diff --git a/apps/testnorge-statisk-data-forvalter/src/test/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumerTest.java b/apps/testnorge-statisk-data-forvalter/src/test/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumerTest.java index 6cffe12e070..3b197209171 100644 --- a/apps/testnorge-statisk-data-forvalter/src/test/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumerTest.java +++ b/apps/testnorge-statisk-data-forvalter/src/test/java/no/nav/registre/sdforvalter/consumer/rs/tpsf/TpsfConsumerTest.java @@ -1,7 +1,7 @@ package no.nav.registre.sdforvalter.consumer.rs.tpsf; -import no.nav.registre.sdforvalter.config.credentials.TpsfProxyProperties; import no.nav.testnav.libs.securitycore.domain.AccessToken; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.junit.Before; import org.junit.Test; @@ -52,7 +52,7 @@ public class TpsfConsumerTest { @Before public void before() { - when(tokenService.exchange(ArgumentMatchers.any(TpsfProxyProperties.class))).thenReturn(Mono.just(new AccessToken("token"))); + when(tokenService.exchange(ArgumentMatchers.any(ServerProperties.class))).thenReturn(Mono.just(new AccessToken("token"))); } @Test