Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into change/from_vault_to_secretmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc3092 committed Nov 26, 2024
2 parents 6ab5be6 + ea6439f commit 44cf309
Show file tree
Hide file tree
Showing 37 changed files with 1,253 additions and 1,100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.aareg.amelding.AmeldingService;
import no.nav.dolly.bestilling.aareg.domain.ArbeidsforholdRespons;
import no.nav.dolly.config.ApplicationConfig;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.jpa.Bruker;
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
Expand All @@ -16,11 +17,13 @@
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.util.TransactionHelperService;
import no.nav.testnav.libs.dto.aareg.v1.Arbeidsforhold;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import no.nav.testnav.libs.securitycore.domain.AccessToken;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.YearMonth;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -49,9 +52,10 @@ public class AaregClient implements ClientRegister {
private static final String SYSTEM = "AAREG";

private final AaregConsumer aaregConsumer;
private final AmeldingService ameldingService;
private final ApplicationConfig applicationConfig;
private final ErrorStatusDecoder errorStatusDecoder;
private final MapperFacade mapperFacade;
private final AmeldingService ameldingService;
private final TransactionHelperService transactionHelperService;

@Override
Expand All @@ -66,7 +70,7 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
var miljoerTrygg = new AtomicReference<>(miljoer);

var initStatus = miljoer.stream()
.map(miljo -> String.format("%s:%s", miljo, getInfoVenter(SYSTEM)))
.map(miljo -> "%s:%s".formatted(miljo, getInfoVenter(SYSTEM)))
.collect(Collectors.joining(","));

transactionHelperService.persister(progress, BestillingProgress::getAaregStatus,
Expand All @@ -83,11 +87,20 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
return ameldingService.sendAmelding(bestilling, dollyPerson, miljoerTrygg.get());
}
})
.timeout(Duration.ofSeconds(applicationConfig.getClientTimeout()))
.onErrorResume(error -> getErrors(error, miljoerTrygg.get()))
.map(status -> futurePersist(progress, status));
}
return Flux.empty();
}

private Flux<String> getErrors(Throwable error, Set<String> miljoer) {

return Flux.just(miljoer.stream()
.map(miljoe -> "%s:Feil= %s".formatted(miljoe, ErrorStatusDecoder.encodeStatus(WebClientFilter.getMessage(error))))
.collect(Collectors.joining(",")));
}

@Override
public void release(List<String> identer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@
import no.nav.dolly.bestilling.arenaforvalter.service.ArenaDagpengerService;
import no.nav.dolly.bestilling.arenaforvalter.service.ArenaStansYtelseService;
import no.nav.dolly.bestilling.arenaforvalter.utils.ArenaEksisterendeVedtakUtil;
import no.nav.dolly.config.ApplicationConfig;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata;
import no.nav.dolly.domain.resultset.dolly.DollyPerson;
import no.nav.dolly.util.IdentTypeUtil;
import no.nav.dolly.util.TransactionHelperService;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.Objects.nonNull;
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.AAP;
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.AAP115;
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.ANDREFEIL;
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.BRUKER;
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.DAGPENGER;
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.fmtResponse;
Expand All @@ -41,13 +45,14 @@ public class ArenaForvalterClient implements ClientRegister {
private static final String MILJOE_FMT = "%s$BRUKER= %s";
private static final String SYSTEM = "Arena";

private final ArenaForvalterConsumer arenaForvalterConsumer;
private final TransactionHelperService transactionHelperService;
private final ArenaBrukerService arenaBrukerService;
private final ApplicationConfig applicationConfig;
private final ArenaAap115Service arenaAap115Service;
private final ArenaAapService arenaAapService;
private final ArenaBrukerService arenaBrukerService;
private final ArenaDagpengerService arenaDagpengerService;
private final ArenaForvalterConsumer arenaForvalterConsumer;
private final ArenaStansYtelseService arenaStansYtelseService;
private final TransactionHelperService transactionHelperService;

@Override
public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, DollyPerson dollyPerson, BestillingProgress progress, boolean isOpprettEndre) {
Expand All @@ -66,6 +71,9 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
BestillingProgress::setArenaforvalterStatus, initStatus);
})
.flatMap(miljoer -> doArenaOpprett(ordre, dollyPerson.getIdent(), miljoer)
.timeout(Duration.ofSeconds(applicationConfig.getClientTimeout()))
.onErrorResume(error ->
Mono.just(fmtResponse(miljoer, ANDREFEIL, WebClientFilter.getMessage(error))))
.map(status -> futurePersist(progress, status))));
}

Expand Down Expand Up @@ -94,7 +102,7 @@ private Mono<String> doArenaOpprett(Arenadata arenadata, String ident, List<Stri
arenaDagpengerService.sendDagpenger(arenadata, arenaOperasjoner, ident, miljoe)
.map(dagpengerStatus -> fmtResponse(miljoe, DAGPENGER, dagpengerStatus))
));
} else {
} else {
return Flux.just(fmtResponse(miljoe, BRUKER, NOT_SUPPORTED));
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;

Expand All @@ -29,6 +30,7 @@ public class ArenaStatusUtil {
public static final String AAP115 = "AAP115";
public static final String AAP = "AAP";
public static final String DAGPENGER = "DAGP";
public static final String ANDREFEIL = "ARENA Oppretting Feil=";

public static Mono<String> getDagpengerStatus(ArenaNyeDagpengerResponse response, ErrorStatusDecoder errorStatusDecoder) {

Expand All @@ -37,7 +39,7 @@ public static Mono<String> getDagpengerStatus(ArenaNyeDagpengerResponse response
.map(status -> errorStatusDecoder.getErrorText(response.getStatus(), getMessage(response.getFeilmelding()))),
Flux.fromIterable(response.getNyeDagp())
.filter(nyDagP -> nonNull(nyDagP.getNyeDagpResponse()))
.map(nyDagP -> "JA".equals(nyDagP.getNyeDagpResponse().getUtfall()) ?
.map(nyDagP -> "JA".equals(nyDagP.getNyeDagpResponse().getUtfall()) ?
"OK" :
encodeStatus(ArenaUtils.AVSLAG + nyDagP.getNyeDagpResponse().getBegrunnelse()))
.collect(Collectors.joining()),
Expand Down Expand Up @@ -78,9 +80,16 @@ public static Mono<String> getAapStatus(AapResponse response, ErrorStatusDecoder
}
}

public static String fmtResponse(Collection<String> miljoer, String system, String status) {

return miljoer.stream()
.map(miljo -> fmtResponse(miljo, system, status))
.collect(Collectors.joining(","));
}

public static String fmtResponse(String miljoe, String system, String status) {

return String.format(MILJOE_FMT, miljoe, system, encodeStatus(status));
return MILJOE_FMT.formatted(miljoe, system, encodeStatus(status));
}

public static String getMessage(String jsonFeilmelding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import no.nav.dolly.bestilling.dokarkiv.domain.DokarkivResponse;
import no.nav.dolly.bestilling.dokarkiv.domain.JoarkTransaksjon;
import no.nav.dolly.bestilling.personservice.PersonServiceConsumer;
import no.nav.dolly.config.ApplicationConfig;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.jpa.TransaksjonMapping;
Expand All @@ -21,17 +22,21 @@
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.service.TransaksjonMappingService;
import no.nav.dolly.util.TransactionHelperService;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static no.nav.dolly.domain.resultset.SystemTyper.DOKARKIV;
import static no.nav.dolly.errorhandling.ErrorStatusDecoder.encodeStatus;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

Expand All @@ -40,40 +45,47 @@
@RequiredArgsConstructor
public class DokarkivClient implements ClientRegister {

private final ApplicationConfig applicationConfig;
private final DokarkivConsumer dokarkivConsumer;
private final ErrorStatusDecoder errorStatusDecoder;
private final MapperFacade mapperFacade;
private final TransaksjonMappingService transaksjonMappingService;
private final ObjectMapper objectMapper;
private final TransactionHelperService transactionHelperService;
private final PersonServiceConsumer personServiceConsumer;
private final ErrorStatusDecoder errorStatusDecoder;
private final TransactionHelperService transactionHelperService;
private final TransaksjonMappingService transaksjonMappingService;

@Override
public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, DollyPerson dollyPerson, BestillingProgress progress, boolean isOpprettEndre) {

return Flux.just(bestilling)
.filter(bestilling1 -> nonNull(bestilling1.getDokarkiv()))
.map(RsDollyUtvidetBestilling::getDokarkiv)
.flatMap(dokarkiv -> Flux.from(getPersonData(List.of(dollyPerson.getIdent()))
.map(person -> buildRequest(dokarkiv, person))
.flatMap(request -> dokarkivConsumer.getEnvironments()
.flatMapIterable(env -> env)
.filter(env -> bestilling.getEnvironments().contains(env))
.flatMap(env ->
!transaksjonMappingService.existAlready(DOKARKIV,
dollyPerson.getIdent(), env, bestilling.getId()) || isOpprettEndre ?

dokarkivConsumer.postDokarkiv(env, request)
.map(status ->
getStatus(dollyPerson.getIdent(),
bestilling.getId(), status)) :

Mono.just(env + ":OK")
))
.collect(Collectors.joining(",")))
.flatMap(dokarkiv -> Flux.from(getPersonData(dollyPerson.getIdent())
.flatMap(person -> getFilteredMiljoer(bestilling.getEnvironments())
.flatMapMany(miljoer -> Flux.fromIterable(miljoer)
.flatMap(env -> buildRequest(dokarkiv, person)
.flatMap(request ->
!transaksjonMappingService.existAlready(DOKARKIV,
dollyPerson.getIdent(), env, bestilling.getId()) || isOpprettEndre ?
dokarkivConsumer.postDokarkiv(env, request)
.map(status ->
getStatus(dollyPerson.getIdent(),
bestilling.getId(), status)) :
Mono.just(env + ":OK")
))
.timeout(Duration.ofSeconds(applicationConfig.getClientTimeout()))
.onErrorResume(error -> getErrors(error, miljoer))
)))
.collect(Collectors.joining(","))
.map(status -> futurePersist(progress, status)));
}

private Flux<String> getErrors(Throwable error, List<String> miljoer) {

return Flux.fromIterable(miljoer)
.map(miljoe -> "%s:%s".formatted(miljoe, encodeStatus(WebClientFilter.getMessage(error))));
}

private ClientFuture futurePersist(BestillingProgress progress, String status) {

return () -> {
Expand All @@ -84,12 +96,20 @@ private ClientFuture futurePersist(BestillingProgress progress, String status) {
};
}

private Mono<List<String>> getFilteredMiljoer(Set<String> miljoer) {

return dokarkivConsumer.getEnvironments()
.flatMapMany(Flux::fromIterable)
.filter(miljoer::contains)
.collectList();
}

private String getStatus(String ident, Long bestillingId, DokarkivResponse response) {

log.info("Dokarkiv response {} for ident {}", response, ident);

if (isNull(response)) {
return null;
return "UKJENT:Intet svar";
}

if (isBlank(response.getFeilmelding())) {
Expand All @@ -101,7 +121,7 @@ private String getStatus(String ident, Long bestillingId, DokarkivResponse respo

return String.format("%s:FEIL=Teknisk feil se logg! %s", response.getMiljoe(),
isNotBlank(response.getFeilmelding()) ?
ErrorStatusDecoder.encodeStatus(errorStatusDecoder.getStatusMessage(response.getFeilmelding())) :
encodeStatus(errorStatusDecoder.getStatusMessage(response.getFeilmelding())) :
"UKJENT");
}
}
Expand All @@ -112,22 +132,22 @@ public void release(List<String> identer) {
// Sletting er ikke støttet
}

private Flux<PdlPersonBolk.PersonBolk> getPersonData(List<String> identer) {
private Flux<PdlPersonBolk.PersonBolk> getPersonData(String ident) {

return personServiceConsumer.getPdlPersoner(identer)
return personServiceConsumer.getPdlPersoner(List.of(ident))
.filter(pdlPersonBolk -> nonNull(pdlPersonBolk.getData()))
.map(PdlPersonBolk::getData)
.map(PdlPersonBolk.Data::getHentPersonBolk)
.flatMap(Flux::fromIterable)
.filter(personBolk -> nonNull(personBolk.getPerson()));
}

private DokarkivRequest buildRequest(RsDokarkiv rsDokarkiv, PdlPersonBolk.PersonBolk personBolk) {
private Mono<DokarkivRequest> buildRequest(RsDokarkiv rsDokarkiv, PdlPersonBolk.PersonBolk personBolk) {

var context = new MappingContext.Factory().getContext();
context.setProperty("personBolk", personBolk);

return mapperFacade.map(rsDokarkiv, DokarkivRequest.class, context);
return Mono.just(mapperFacade.map(rsDokarkiv, DokarkivRequest.class, context));
}

private void saveTransaksjonId(DokarkivResponse response, String ident, Long bestillingId, String miljoe) {
Expand All @@ -140,7 +160,7 @@ private void saveTransaksjonId(DokarkivResponse response, String ident, Long bes
.bestillingId(bestillingId)
.transaksjonId(toJson(JoarkTransaksjon.builder()
.journalpostId(response.getJournalpostId())
.dokumentInfoId(response.getDokumenter().get(0).getDokumentInfoId())
.dokumentInfoId(response.getDokumenter().getFirst().getDokumentInfoId())
.build()))
.datoEndret(LocalDateTime.now())
.miljoe(miljoe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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 reactor.core.publisher.Mono;

import java.util.List;
Expand Down Expand Up @@ -41,18 +40,18 @@ public DokarkivConsumer(
.build();
}

@Timed(name = "providers", tags = { "operation", "dokarkiv-opprett" })
public Flux<DokarkivResponse> postDokarkiv(String environment, DokarkivRequest dokarkivRequest) {
@Timed(name = "providers", tags = {"operation", "dokarkiv-opprett"})
public Mono<DokarkivResponse> postDokarkiv(String environment, DokarkivRequest dokarkivRequest) {

log.info("Dokarkiv sender melding for ident {} miljoe {} request {}",
dokarkivRequest.getBruker().getId(), environment, dokarkivRequest);

return tokenService.exchange(serverProperties)
.flatMapMany(token -> new DokarkivPostCommand(webClient, environment, dokarkivRequest,
.flatMap(token -> new DokarkivPostCommand(webClient, environment, dokarkivRequest,
token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "dokarkiv_getEnvironments" })
@Timed(name = "providers", tags = {"operation", "dokarkiv_getEnvironments"})
public Mono<List<String>> getEnvironments() {

return tokenService.exchange(serverProperties)
Expand Down
Loading

0 comments on commit 44cf309

Please sign in to comment.