Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/navikt/testnorge into fea…
Browse files Browse the repository at this point in the history
…ture/tenor-soek-ny-funksjonalitet
  • Loading branch information
betsytraran committed May 23, 2024
2 parents c975640 + ccc446d commit e8d02a6
Show file tree
Hide file tree
Showing 48 changed files with 431 additions and 427 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public static void main(String[] args) {

SpringApplication.run(DollyBackendApplicationStarter.class, args);
}
}
}
9 changes: 7 additions & 2 deletions apps/dolly-backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ management:
path-mapping:
prometheus: metrics
endpoint:
prometheus.enabled: true
heapdump.enabled: true
health:
show-components: always
show-details: always
heapdump:
enabled: true
prometheus:
enabled: true
prometheus:
metrics:
export:
Expand Down
1 change: 1 addition & 0 deletions apps/pdl-forvalter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
implementation 'no.nav.testnav.libs:reactive-core'
implementation 'no.nav.testnav.libs:security-core'
implementation 'no.nav.testnav.libs:servlet-security'
implementation 'no.nav.testnav.libs:servlet-insecure-security'

implementation 'org.springframework.cloud:spring-cloud-starter-vault-config'
implementation 'org.springframework.cloud:spring-cloud-vault-config-databases'
Expand Down
1 change: 1 addition & 0 deletions apps/pdl-forvalter/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
- application: testnav-ident-pool
- application: testnav-kodeverk-service
- application: testnav-organisasjon-forvalter
- application: testnav-person-service
- application: testnav-tps-messaging-service
external:
- host: testnav-pdl-proxy.dev-fss-pub.nais.io
Expand Down
1 change: 1 addition & 0 deletions apps/pdl-forvalter/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ spec:
- application: testnav-ident-pool
- application: testnav-kodeverk-service
- application: testnav-organisasjon-forvalter
- application: testnav-person-service
- application: testnav-tps-messaging-service
external:
- host: testnav-pdl-proxy.dev-fss-pub.nais.io
Expand Down
1 change: 1 addition & 0 deletions apps/pdl-forvalter/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ includeBuild '../../libs/data-transfer-search-objects'
includeBuild '../../libs/servlet-core'
includeBuild '../../libs/reactive-core'
includeBuild '../../libs/servlet-security'
includeBuild '../../libs/servlet-insecure-security'
includeBuild '../../libs/testing'

gradleEnterprise {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package no.nav.pdl.forvalter.config;

import no.nav.testnav.libs.reactivecore.config.CoreConfig;
import no.nav.testnav.libs.servletcore.config.ApplicationCoreConfig;
import no.nav.testnav.libs.servletsecurity.config.SecureOAuth2ServerToServerConfiguration;
import no.nav.testnav.libs.standalone.servletsecurity.config.InsecureJwtServerToServerConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -10,6 +12,8 @@

@Configuration
@Import({ApplicationCoreConfig.class,
CoreConfig.class,
InsecureJwtServerToServerConfiguration.class,
SecureOAuth2ServerToServerConfiguration.class})
public class ApplicationConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@

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)
Expand All @@ -29,6 +21,6 @@ public class Consumers {
private ServerProperties kodeverkService;
private ServerProperties identPool;
private ServerProperties orgForvalter;
private ServerProperties pdlService;

private ServerProperties pdlProxy;
private ServerProperties personService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import no.nav.pdl.forvalter.config.Consumers;
import no.nav.pdl.forvalter.consumer.command.PdlAktoerNpidCommand;
import no.nav.pdl.forvalter.consumer.command.PdlDeleteCommandPdl;
import no.nav.pdl.forvalter.consumer.command.PdlDeleteHendelseIdCommandPdl;
import no.nav.pdl.forvalter.consumer.command.PdlMergeNpidCommand;
import no.nav.pdl.forvalter.consumer.command.PdlOpprettArtifactCommandPdl;
import no.nav.pdl.forvalter.consumer.command.PdlOpprettNpidCommand;
import no.nav.pdl.forvalter.consumer.command.PdlOpprettPersonCommandPdl;
import no.nav.pdl.forvalter.dto.ArtifactValue;
import no.nav.pdl.forvalter.dto.MergeIdent;
import no.nav.pdl.forvalter.dto.OpprettIdent;
import no.nav.pdl.forvalter.dto.OrdreRequest;
import no.nav.testnav.libs.data.pdlforvalter.v1.DbVersjonDTO.Master;
Expand All @@ -30,7 +32,7 @@
import java.util.Set;

import static java.util.Objects.isNull;
import static no.nav.pdl.forvalter.utils.IdenttypeFraIdentUtility.getIdenttype;
import static no.nav.pdl.forvalter.utils.IdenttypeUtility.getIdenttype;
import static no.nav.pdl.forvalter.utils.PdlTestDataUrls.getBestillingUrl;
import static no.nav.pdl.forvalter.utils.TestnorgeIdentUtility.isTestnorgeIdent;
import static no.nav.testnav.libs.data.pdlforvalter.v1.PdlArtifact.PDL_SLETTING;
Expand All @@ -44,19 +46,22 @@ public class PdlTestdataConsumer {
private final TokenExchange tokenExchange;
private final ServerProperties serverProperties;
private final ObjectMapper objectMapper;
private final PersonServiceConsumer personServiceConsumer;

public PdlTestdataConsumer(
TokenExchange tokenExchange,
Consumers consumers,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
PersonServiceConsumer personServiceConsumer) {
this.tokenExchange = tokenExchange;
serverProperties = consumers.getPdlService();
serverProperties = consumers.getPdlProxy();
this.webClient = WebClient
.builder()
.baseUrl(serverProperties.getUrl())
.filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(logRequest()))
.build();
this.objectMapper = objectMapper;
this.personServiceConsumer = personServiceConsumer;
}

private ExchangeFilterFunction logRequest() {
Expand Down Expand Up @@ -86,21 +91,18 @@ public Flux<OrdreResponseDTO.PdlStatusDTO> send(OrdreRequest orders) {
return tokenExchange
.exchange(serverProperties)
.flatMapMany(accessToken -> Flux.concat(
Flux.fromIterable(orders.getSletting())
.parallel()
.flatMap(order -> Flux.fromIterable(order)
.flatMap(entry -> entry.apply(accessToken))
.collectList()),
Flux.fromIterable(orders.getOppretting())
.flatMap(order -> Flux.fromIterable(order)
.flatMap(entry -> entry.apply(accessToken))
.collectList()),
Flux.fromIterable(orders.getOpplysninger())
.parallel()
.flatMap(order -> Flux.fromIterable(order)
.flatMap(entry -> entry.apply(accessToken))
.collectList()))
.flatMap(Flux::fromIterable));
Flux.fromIterable(orders.getSletting())
.parallel()
.map(order -> order.apply(accessToken)),
Flux.fromIterable(orders.getOppretting())
.map(order -> order.apply(accessToken)),
Flux.fromIterable(orders.getMerge())
.map(order -> order.apply(accessToken)),
Flux.fromIterable(orders.getOpplysninger())
.parallel()
.map(order -> order.apply(accessToken))
))
.flatMap(Flux::from);
}

public Mono<List<OrdreResponseDTO.HendelseDTO>> delete(Set<String> identer) {
Expand Down Expand Up @@ -131,7 +133,6 @@ public Flux<OrdreResponseDTO.HendelseDTO> send(ArtifactValue value, AccessToken
if (isNull(artifact.getFolkeregistermetadata())) {
artifact.setFolkeregistermetadata(new FolkeregistermetadataDTO());
}
artifact.getFolkeregistermetadata().setGjeldende(artifact.getGjeldende());
body = objectMapper.writeValueAsString(artifact);
} catch (JsonProcessingException e) {
return Flux.just(
Expand Down Expand Up @@ -159,7 +160,7 @@ public Flux<OrdreResponseDTO.HendelseDTO> send(ArtifactValue value, AccessToken

case PDL_OPPRETT_PERSON -> Identtype.NPID == getIdenttype(value.getIdent()) ?

new PdlAktoerNpidCommand(webClient,
new PdlOpprettNpidCommand(webClient,
value.getIdent(),
accessToken.getTokenValue()
).call() :
Expand All @@ -171,6 +172,15 @@ public Flux<OrdreResponseDTO.HendelseDTO> send(ArtifactValue value, AccessToken
accessToken.getTokenValue()
).call();

case PDL_PERSON_MERGE -> personServiceConsumer.syncIdent(value.getIdent())
.flatMap(syncIdent ->
new PdlMergeNpidCommand(webClient,
getBestillingUrl().get(value.getArtifact()),
((MergeIdent) value.getBody()).getNpid(),
value.getIdent(),
accessToken.getTokenValue()
).call());

default -> !isTestnorgeIdent(value.getIdent()) || value.getBody().getMaster() == Master.PDL ?
new PdlOpprettArtifactCommandPdl(
webClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package no.nav.pdl.forvalter.consumer;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import no.nav.pdl.forvalter.config.Consumers;
import no.nav.pdl.forvalter.consumer.command.PersonExistsGetCommand;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;

import static org.apache.commons.lang3.BooleanUtils.isTrue;

@Slf4j
@Service
public class PersonServiceConsumer {

private static final long DELAY = 100; // milliseconds
private static final int MAX_REPETITIONS = 100;
private final WebClient webClient;
private final ServerProperties serverProperties;
private final TokenExchange tokenExchange;

public PersonServiceConsumer(Consumers consumers, TokenExchange tokenExchange) {

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

@SneakyThrows
public Flux<Boolean> syncIdent(String ident) {

return getPersonService(ident, new AtomicLong(0), false);
}

private Flux<Boolean> getPersonService(String ident, AtomicLong counter, Boolean response) {

if (isTrue(response) || counter.get() == MAX_REPETITIONS) {
log.info("Synkronisering av ident {} tok {} repetisjoner", ident, counter.get());
return Flux.just(response);

} else {
counter.incrementAndGet();
return Flux.just(1)
.delayElements(Duration.ofMillis(DELAY))
.flatMap(delayed -> tokenExchange.exchange(serverProperties)
.flatMapMany(token -> new PersonExistsGetCommand(webClient, ident, token.getTokenValue()).call())
.flatMap(resultat -> getPersonService(ident, counter, resultat)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package no.nav.pdl.forvalter.consumer.command;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.libs.data.pdlforvalter.v1.OrdreResponseDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.PdlStatus;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.boot.web.server.WebServerException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

import java.time.Duration;

@Slf4j
@RequiredArgsConstructor
public class PdlMergeNpidCommand extends PdlTestdataCommand {

private static final String NPID = "npid";
private static final String OTHER_IDENT = "otherIdent";

private final WebClient webClient;
private final String url;
private final String npid;
private final String otherIdent;
private final String token;

@Override
public Flux<OrdreResponseDTO.HendelseDTO> call() {

return webClient
.post()
.uri(builder -> builder.path(url)
.queryParam(NPID, npid)
.queryParam(OTHER_IDENT, otherIdent)
.build())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.contentType(MediaType.APPLICATION_JSON)
.exchangeToFlux(response ->
Flux.just(OrdreResponseDTO.HendelseDTO.builder()
.status(PdlStatus.OK)
.build()))
.doOnError(WebServerException.class, error -> log.error(error.getMessage(), error))
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5))
.filter(WebClientFilter::is5xxException))
.onErrorResume(error -> Mono.just(errorHandling(error, null)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.boot.web.server.WebServerException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -18,10 +17,11 @@

@Slf4j
@RequiredArgsConstructor
public class PdlAktoerNpidCommand extends PdlTestdataCommand {
public class PdlOpprettNpidCommand extends PdlTestdataCommand {

private static final String PDL_AKTOER_ADMIN_PREFIX = "/pdl-npid";
private static final String PDL_PERSON_AKTOER_URL = PDL_AKTOER_ADMIN_PREFIX + "/api/npid";
private static final String PDL_AKTOER_ADMIN_PREFIX = "/pdl-testdata";
private static final String PDL_PERSON_AKTOER_URL = PDL_AKTOER_ADMIN_PREFIX + "/api/v1/npid/create";
private static final String NPID = "npid";

private final WebClient webClient;
private final String npid;
Expand All @@ -32,10 +32,11 @@ public Flux<OrdreResponseDTO.HendelseDTO> call() {

return webClient
.post()
.uri(PDL_PERSON_AKTOER_URL)
.uri(builder -> builder.path(PDL_PERSON_AKTOER_URL)
.queryParam(NPID, npid)
.build())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(npid))
.exchangeToFlux(response ->
Flux.just(OrdreResponseDTO.HendelseDTO.builder()
.status(PdlStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import reactor.util.retry.Retry;

import java.time.Duration;
import java.util.Optional;

import static no.nav.pdl.forvalter.utils.PdlTestDataUrls.TemaGrunnlag.GEN;

Expand All @@ -39,7 +40,7 @@ public Flux<OrdreResponseDTO.HendelseDTO> call() {
.post()
.uri(builder -> builder.path(url)
.queryParam("kilde", "Dolly")
.queryParam(IDENTHISTORIKK, opprettIdent.getHistoriskeIdenter())
.queryParamIfPresent(IDENTHISTORIKK, Optional.ofNullable(opprettIdent.getHistoriskeIdenter()))
.queryParam(OPPHOERT, opprettIdent.isOpphoert())
.build())
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
Expand Down
Loading

0 comments on commit e8d02a6

Please sign in to comment.