Skip to content

Commit

Permalink
Fjernet boilerplate fra orgnummer-service 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 67d6f45 commit 4195b7a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package no.nav.registre.orgnrservice.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 testnavMiljoerService;
private ServerProperties testnavOrganisasjonService;

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package no.nav.registre.orgnrservice.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.orgnrservice.config.credentials.MiljoerServiceProperties;
import no.nav.registre.orgnrservice.config.credentials.OrganisasjonServiceProperties;
import no.nav.registre.orgnrservice.config.Consumers;
import no.nav.registre.orgnrservice.consumer.command.GetOrganisasjonCommand;
import no.nav.registre.orgnrservice.consumer.command.MiljoerCommand;
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 @@ -25,22 +25,22 @@ public class OrganisasjonConsumer {
private final WebClient organisasjonWebClient;
private final WebClient miljoerWebClient;
private final TokenExchange tokenExchange;
private final MiljoerServiceProperties miljoerServiceProperties;
private final OrganisasjonServiceProperties organisasjonServiceProperties;
private final ServerProperties miljoerServerProperties;
private final ServerProperties organisasjonServerProperties;

public OrganisasjonConsumer(
MiljoerServiceProperties miljoerServiceProperties,
OrganisasjonServiceProperties organisasjonServiceProperties,
Consumers consumers,
TokenExchange tokenExchange) {

this.miljoerServiceProperties = miljoerServiceProperties;
this.organisasjonServiceProperties = organisasjonServiceProperties;
miljoerServerProperties = consumers.getTestnavMiljoerService();
organisasjonServerProperties = consumers.getTestnavOrganisasjonService();
this.tokenExchange = tokenExchange;
this.organisasjonWebClient = WebClient.builder()
.baseUrl(organisasjonServiceProperties.getUrl())
this.organisasjonWebClient = WebClient
.builder()
.baseUrl(organisasjonServerProperties.getUrl())
.build();
this.miljoerWebClient = WebClient.builder()
.baseUrl(miljoerServiceProperties.getUrl())
this.miljoerWebClient = WebClient
.builder()
.baseUrl(miljoerServerProperties.getUrl())
.build();
}

Expand All @@ -52,8 +52,8 @@ private static boolean supportedEnv(String miljoe) {
public boolean finnesOrgnrIEreg(String orgnummer) {

var organisasjoner =
Mono.zip(tokenExchange.exchange(miljoerServiceProperties),
tokenExchange.exchange(organisasjonServiceProperties))
Mono.zip(tokenExchange.exchange(miljoerServerProperties),
tokenExchange.exchange(organisasjonServerProperties))
.flatMapMany(token -> new MiljoerCommand(miljoerWebClient, token.getT1().getTokenValue()).call()
.flatMapMany(miljoer -> Flux.fromIterable(Arrays.asList(miljoer))
.filter(OrganisasjonConsumer::supportedEnv)
Expand Down
1 change: 0 additions & 1 deletion apps/orgnummer-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ consumers:
name: testnav-organisasjon-service
cluster: dev-gcp
namespace: dolly
threads: 5
testnav-miljoer-service:
url: http://testnav-miljoer-service.dolly.svc.cluster.local
name: testnav-miljoer-service
Expand Down

0 comments on commit 4195b7a

Please sign in to comment.