-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/navikt/testnorge into fea…
…ture/tenor-soek-ny-funksjonalitet
- Loading branch information
Showing
48 changed files
with
431 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/PersonServiceConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...dl-forvalter/src/main/java/no/nav/pdl/forvalter/consumer/command/PdlMergeNpidCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.