Skip to content

Commit

Permalink
Fjernet boilerplate fra organisasjon-mottak-service sin bruk av Serve…
Browse files Browse the repository at this point in the history
…rProperties.
  • Loading branch information
rfc3092 committed Oct 26, 2023
1 parent 066112c commit 8eae964
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package no.nav.registre.testnorge.organisasjonmottak.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 jenkinsBatchStatusService;
private ServerProperties jenkins;
private ServerProperties organisasjonBestillingService;

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.nav.registre.testnorge.organisasjonmottak.consumer;

import no.nav.registre.testnorge.organisasjonmottak.config.properties.JenkinsBatchStatusServiceProperties;
import no.nav.registre.testnorge.organisasjonmottak.config.Consumers;
import no.nav.registre.testnorge.organisasjonmottak.consumer.command.RegisterEregBestillingCommand;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
Expand All @@ -11,21 +11,21 @@
public class JenkinsBatchStatusConsumer {
private final WebClient webClient;
private final TokenExchange tokenExchange;
private final ServerProperties properties;
private final ServerProperties serverProperties;

public JenkinsBatchStatusConsumer(
JenkinsBatchStatusServiceProperties properties,
Consumers consumers,
TokenExchange tokenExchange) {

this.properties = properties;
serverProperties = consumers.getJenkinsBatchStatusService();
this.tokenExchange = tokenExchange;
this.webClient = WebClient.builder()
.baseUrl(properties.getUrl())
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
}

public void registerBestilling(String uuid, String miljo, Long itemId) {
var accessToken = tokenExchange.exchange(properties).block();
var accessToken = tokenExchange.exchange(serverProperties).block();
new RegisterEregBestillingCommand(webClient, accessToken.getTokenValue(), uuid, miljo, itemId).run();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.registre.testnorge.organisasjonmottak.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.testnorge.organisasjonmottak.config.properties.JenkinsServiceProperties;
import no.nav.registre.testnorge.organisasjonmottak.config.Consumers;
import no.nav.registre.testnorge.organisasjonmottak.consumer.command.StartBEREG007Command;
import no.nav.registre.testnorge.organisasjonmottak.domain.Flatfil;
import no.nav.testnav.libs.commands.GetCrumbCommand;
Expand All @@ -21,29 +21,28 @@ public class JenkinsConsumer {
private final Environment env;
private final WebClient webClient;
private final TokenExchange tokenExchange;
private final ServerProperties properties;
private final ServerProperties serverProperties;
private final OrganisasjonBestillingConsumer organisasjonBestillingConsumer;

public JenkinsConsumer(
Environment env,
JenkinsServiceProperties properties,
Consumers consumers,
TokenExchange tokenExchange,
JenkinsBatchStatusConsumer jenkinsBatchStatusConsumer,
OrganisasjonBestillingConsumer organisasjonBestillingConsumer) {

this.organisasjonBestillingConsumer = organisasjonBestillingConsumer;
this.properties = properties;
serverProperties = consumers.getJenkins();
this.tokenExchange = tokenExchange;
this.jenkinsBatchStatusConsumer = jenkinsBatchStatusConsumer;
this.env = env;
this.webClient = WebClient
.builder()
.baseUrl(properties.getUrl())
.baseUrl(serverProperties.getUrl())
.build();
}

public void send(Flatfil flatFile, String miljo, Set<String> uuids) {
var accessToken = tokenExchange.exchange(properties).block();
var accessToken = tokenExchange.exchange(serverProperties).block();

var server = env.getProperty("JENKINS_SERVER_" + miljo.toUpperCase());
if (server == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.registre.testnorge.organisasjonmottak.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.testnorge.organisasjonmottak.config.properties.OrganisasjonBestillingServiceProperties;
import no.nav.registre.testnorge.organisasjonmottak.config.Consumers;
import no.nav.registre.testnorge.organisasjonmottak.consumer.command.RegisterBestillingCommand;
import no.nav.testnav.libs.dto.organiasjonbestilling.v2.OrderDTO;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
Expand All @@ -14,17 +14,16 @@
public class OrganisasjonBestillingConsumer {
private final WebClient webClient;
private final TokenExchange tokenExchange;
private final ServerProperties properties;
private final ServerProperties serverProperties;

public OrganisasjonBestillingConsumer(
OrganisasjonBestillingServiceProperties properties,
Consumers consumers,
TokenExchange tokenExchange) {

this.properties = properties;
serverProperties = consumers.getOrganisasjonBestillingService();
this.tokenExchange = tokenExchange;
this.webClient = WebClient
.builder()
.baseUrl(properties.getUrl())
.baseUrl(serverProperties.getUrl())
.build();
}

Expand All @@ -37,7 +36,7 @@ public void registerBestilling(String uuid, String miljo, Long queueId) {
.uuid(uuid)
.build();

var order = tokenExchange.exchange(properties)
var order = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new RegisterBestillingCommand(webClient, accessToken.getTokenValue(), orderDTO).call())
.block();
log.info("Ordre med id:{} opprettet.", order.getId());
Expand Down

0 comments on commit 8eae964

Please sign in to comment.