Skip to content

Commit

Permalink
Fjernet boilerplate fra synt-vedtakshistorikk-service sin bruk av Ser…
Browse files Browse the repository at this point in the history
…verProperties.
  • Loading branch information
rfc3092 committed Oct 26, 2023
1 parent 3cdf428 commit e84af9b
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package no.nav.testnav.apps.syntvedtakshistorikkservice.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 testnavArenaForvalterenProxy;
private ServerProperties testnavInntektstubProxy;
private ServerProperties testnavOrganisasjonFasteDataService;
private ServerProperties pdlApiProxy;
private ServerProperties testnavPensjonTestdataFacadeProxy;
private ServerProperties testnavPersonSearchService;
private ServerProperties syntDagpenger;
private ServerProperties syntVedtakshistorikk;

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package no.nav.testnav.apps.syntvedtakshistorikkservice.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.syntvedtakshistorikkservice.config.Consumers;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.GetArenaBrukereCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.PostArenaBrukerCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.PostDagpengerCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.PostEndreInnsatsbehovCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.PostFinnTiltakCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.PostRettighetCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.arena.SlettArenaBrukerCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.credential.ArenaForvalterenProxyProperties;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.request.arena.EndreInnsatsbehovRequest;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.request.arena.FinnTiltakRequest;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.request.arena.rettighet.RettighetRequest;
Expand Down Expand Up @@ -42,19 +42,19 @@ public class ArenaForvalterConsumer {

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

private static final String MOTTA_DAGPENGESOKNAD_PATH = "/api/v1/mottadagpengesoknad";
private static final String MOTTA_DAGPENGEVEDTAK_PATH = "/api/v1/mottadagpengevedtak";
private static final String DAGPENGEVEDTAK_PATH = "/api/v1/dagpenger";

public ArenaForvalterConsumer(
ArenaForvalterenProxyProperties serviceProperties,
Consumers consumers,
TokenExchange tokenExchange) {

this.serviceProperties = serviceProperties;
this.webClient = WebClient.builder()
.baseUrl(serviceProperties.getUrl())
serverProperties = consumers.getTestnavArenaForvalterenProxy();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
this.tokenExchange = tokenExchange;
}
Expand All @@ -63,7 +63,7 @@ public NyeBrukereResponse sendBrukereTilArenaForvalter(
List<NyBruker> nyeBrukere
) {
try {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostArenaBrukerCommand(nyeBrukere, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand All @@ -74,7 +74,7 @@ public NyeBrukereResponse sendBrukereTilArenaForvalter(

public void slettBrukerIArenaForvalteren(String ident, String miljoe) {
try {
var response = tokenExchange.exchange(serviceProperties)
var response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new SlettArenaBrukerCommand(ident, miljoe, accessToken.getTokenValue(), webClient).call())
.block();

Expand All @@ -92,7 +92,7 @@ public Map<String, List<NyttVedtakResponse>> opprettRettighet(List<RettighetRequ
for (var rettighet : rettigheter) {
NyttVedtakResponse response = null;
try {
response = tokenExchange.exchange(serviceProperties)
response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostRettighetCommand(rettighet, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand All @@ -117,7 +117,7 @@ public Map<String, List<NyttVedtakResponse>> opprettRettighet(List<RettighetRequ

public NyttVedtakResponse finnTiltak(FinnTiltakRequest rettighet) {
try {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostFinnTiltakCommand(rettighet, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand All @@ -129,7 +129,7 @@ public NyttVedtakResponse finnTiltak(FinnTiltakRequest rettighet) {
public void endreInnsatsbehovForBruker(EndreInnsatsbehovRequest endreRequest) {
EndreInnsatsbehovResponse response = null;
try {
response = tokenExchange.exchange(serviceProperties)
response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostEndreInnsatsbehovCommand(endreRequest, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand All @@ -150,7 +150,7 @@ public List<Arbeidsoeker> hentArbeidsoekere(
var queryParams = getQueryParams(personident, eier, miljoe, null);
NyeBrukereResponse response = null;
try {
response = tokenExchange.exchange(serviceProperties)
response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetArenaBrukereCommand(queryParams, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand Down Expand Up @@ -199,7 +199,7 @@ private List<Arbeidsoeker> gaaGjennomSider(
var queryParams = getQueryParams(personident, eier, miljoe, page + "");
NyeBrukereResponse response = null;
try {
response = tokenExchange.exchange(serviceProperties)
response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetArenaBrukereCommand(queryParams, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand Down Expand Up @@ -231,7 +231,7 @@ public DagpengerResponseDTO opprettDagpengerVedtak(DagpengerRequestDTO vedtak) {

private DagpengerResponseDTO opprettDagpenger(DagpengerRequestDTO request, String path) {
try {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostDagpengerCommand(
request, path, accessToken.getTokenValue(), webClient).call())
.block();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.nav.testnav.apps.syntvedtakshistorikkservice.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.syntvedtakshistorikkservice.config.Consumers;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.inntektstub.DeleteInntekterCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.inntektstub.PostInntekterCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.credential.InntektstubProperties;
import no.nav.testnav.apps.syntvedtakshistorikkservice.domain.inntektstub.Inntektsinformasjon;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
Expand All @@ -21,21 +21,24 @@ public class InntektstubConsumer {

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

public InntektstubConsumer(
InntektstubProperties serviceProperties,
Consumers consumers,
TokenExchange tokenExchange
) {
this.serviceProperties = serviceProperties;
this.webClient = WebClient.builder().baseUrl(serviceProperties.getUrl()).build();
serverProperties = consumers.getTestnavInntektstubProxy();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
this.tokenExchange = tokenExchange;
}

public List<Inntektsinformasjon> postInntekter(List<Inntektsinformasjon> inntektsinformasjon) {
try {
log.info("Oppretter inntekt i inntektstub for ident");
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostInntekterCommand(inntektsinformasjon, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand All @@ -47,7 +50,7 @@ public List<Inntektsinformasjon> postInntekter(List<Inntektsinformasjon> inntekt
public void deleteInntekter(List<String> identer) {
try {
log.info("Sletter ident(er) fra Inntektstub");
tokenExchange.exchange(serviceProperties)
tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new DeleteInntekterCommand(identer, accessToken.getTokenValue(), webClient).call())
.subscribe(response -> log.info("Slettet identer fra Inntektstub"));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.testnav.apps.syntvedtakshistorikkservice.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.syntvedtakshistorikkservice.config.Consumers;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.fastedata.GetOrganisasjonerCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.credential.OrgFasteDataServiceProperties;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.response.fastedata.Organisasjon;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
Expand All @@ -18,20 +18,23 @@ public class OrgFasteDataServiceConsumer {

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

public OrgFasteDataServiceConsumer(
OrgFasteDataServiceProperties serviceProperties,
Consumers consumers,
TokenExchange tokenExchange
) {
this.serviceProperties = serviceProperties;
this.webClient = WebClient.builder().baseUrl(serviceProperties.getUrl()).build();
serverProperties = consumers.getTestnavOrganisasjonFasteDataService();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
this.tokenExchange = tokenExchange;
}

public List<Organisasjon> getOrganisasjoner() {
try {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetOrganisasjonerCommand(accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.nav.testnav.apps.syntvedtakshistorikkservice.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.syntvedtakshistorikkservice.config.Consumers;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.pdl.GetPdlPersonCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.pdl.GetPdlPersonerCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.pdl.TagsOpprettingCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.pdl.TagsSlettingCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.credential.PdlProxyProperties;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.response.pdl.PdlPerson;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.response.pdl.PdlPersonBolk;
import no.nav.testnav.apps.syntvedtakshistorikkservice.domain.FilLaster;
Expand Down Expand Up @@ -33,18 +33,18 @@ public class PdlProxyConsumer {

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

private static final String SINGLE_PERSON_QUERY = "pdlperson/pdlquery.graphql";
private static final String BOLK_PERSON_QUERY = "pdlperson/pdlbolkquery.graphql";

public PdlProxyConsumer(
PdlProxyProperties serviceProperties,
Consumers consumers,
TokenExchange tokenExchange) {

this.serviceProperties = serviceProperties;
this.webClient = WebClient.builder()
.baseUrl(serviceProperties.getUrl())
serverProperties = consumers.getPdlApiProxy();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
this.tokenExchange = tokenExchange;
}
Expand All @@ -53,7 +53,7 @@ public PdlPerson getPdlPerson(String ident) {
if (isNullOrEmpty(ident)) return null;
try {
var query = getQueryFromFile(SINGLE_PERSON_QUERY);
var response = tokenExchange.exchange(serviceProperties)
var response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetPdlPersonCommand(ident, query, accessToken.getTokenValue(), webClient).call())
.block();
if (nonNull(response) && nonNull(response.getErrors()) && !response.getErrors().isEmpty()) {
Expand All @@ -72,7 +72,7 @@ public PdlPersonBolk getPdlPersoner(List<String> identer) {
if (isNull(identer) || identer.isEmpty()) return null;
try {
var query = getQueryFromFile(BOLK_PERSON_QUERY);
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new GetPdlPersonerCommand(identer, query, accessToken.getTokenValue(), webClient).call())
.block();
} catch (Exception e) {
Expand All @@ -95,7 +95,7 @@ private static String getQueryFromFile(String file) {
public boolean createTags(List<String> identer, List<Tags> tags) {
try {
if (isNull(identer) || identer.isEmpty()) return false;
var response = tokenExchange.exchange(serviceProperties)
var response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new TagsOpprettingCommand(webClient, identer, tags, accessToken.getTokenValue()).call())
.block();

Expand All @@ -114,7 +114,7 @@ public boolean createTags(List<String> identer, List<Tags> tags) {
public boolean deleteTags(List<String> identer, List<Tags> tags){
try {
if (isNull(identer) || identer.isEmpty()) return false;
var response = tokenExchange.exchange(serviceProperties)
var response = tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new TagsSlettingCommand(webClient, identer, tags, accessToken.getTokenValue()).call())
.block();
if (isNull(response) || !response.getStatusCode().is2xxSuccessful()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.nav.testnav.apps.syntvedtakshistorikkservice.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.syntvedtakshistorikkservice.config.Consumers;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.pensjon.PostPensjonTestdataInntektCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.command.pensjon.PostPensjonTestdataPersonCommand;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.credential.PensjonTestdataFacadeProxyProperties;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.request.pensjon.PensjonTestdataInntekt;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.request.pensjon.PensjonTestdataPerson;
import no.nav.testnav.apps.syntvedtakshistorikkservice.consumer.response.pensjon.PensjonTestdataResponse;
Expand All @@ -21,15 +21,15 @@ public class PensjonTestdataFacadeConsumer {

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

public PensjonTestdataFacadeConsumer(
PensjonTestdataFacadeProxyProperties serviceProperties,
Consumers consumers,
TokenExchange tokenExchange) {

this.serviceProperties = serviceProperties;
this.webClient = WebClient.builder()
.baseUrl(serviceProperties.getUrl())
serverProperties = consumers.getTestnavPensjonTestdataFacadeProxy();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.build();
this.tokenExchange = tokenExchange;
}
Expand All @@ -38,7 +38,7 @@ public PensjonTestdataResponse opprettPerson(
PensjonTestdataPerson person
) {
try {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostPensjonTestdataPersonCommand(webClient, person, accessToken.getTokenValue()).call())
.block();
} catch (Exception e) {
Expand All @@ -51,7 +51,7 @@ public PensjonTestdataResponse opprettInntekt(
PensjonTestdataInntekt inntekt
) {
try {
return tokenExchange.exchange(serviceProperties)
return tokenExchange.exchange(serverProperties)
.flatMap(accessToken -> new PostPensjonTestdataInntektCommand(webClient, inntekt, accessToken.getTokenValue()).call())
.block();
} catch (Exception e) {
Expand Down
Loading

0 comments on commit e84af9b

Please sign in to comment.