Skip to content

Commit

Permalink
Refactor and streamline Dolly services codebase
Browse files Browse the repository at this point in the history
The Dolly services' codebase has undergone significant revisions to increase code clarity and efficiency. We have simplified chained method calls by removing unnecessary conditions and extraneous parameter passing in function calls. Additionally, functions have been moved around to more appropriate service classes to better reflect their scopes of responsibility. These changes are expected to enhance code maintainability and readability without affecting functionality.
  • Loading branch information
krharum committed Apr 24, 2024
1 parent d1b9e97 commit 7c5adbc
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import no.nav.dolly.service.BestillingService;
import no.nav.dolly.service.IdentService;
import no.nav.dolly.util.TransactionHelperService;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonUpdateRequestDTO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -145,16 +146,26 @@ protected Flux<BestillingProgress> gjenopprettKlienter(DollyPerson dollyPerson,
.map(ClientFuture::get);
}

protected void leggIdentTilGruppe(BestillingProgress progress, String beskrivelse) {

leggIdentTilGruppe(null, progress, beskrivelse);
}

protected void leggIdentTilGruppe(String ident, BestillingProgress progress, String beskrivelse) {

identService.saveIdentTilGruppe(ident, progress.getBestilling().getGruppe(), progress.getMaster(), beskrivelse);
log.info("Ident {} lagt til gruppe {}", ident, progress.getBestilling().getGruppe().getId());
identService.saveIdentTilGruppe(isNotBlank(ident) ? ident : progress.getIdent(), progress.getBestilling().getGruppe(), progress.getMaster(), beskrivelse);
log.info("Ident {} lagt til gruppe {}", progress.getIdent(), progress.getBestilling().getGruppe().getId());
}

protected Flux<DollyPerson> opprettDollyPerson(BestillingProgress progress, Bruker bruker) {

return opprettDollyPerson(null, progress, bruker);
}

protected Flux<DollyPerson> opprettDollyPerson(String ident, BestillingProgress progress, Bruker bruker) {

return Flux.just(DollyPerson.builder()
.ident(ident)
.ident(isNotBlank(ident) ? ident : progress.getIdent())
.master(progress.getMaster())
.tags(Stream.concat(progress.getBestilling().getGruppe().getTags().stream(),
Stream.of(Tags.DOLLY)
Expand Down Expand Up @@ -282,4 +293,23 @@ protected Flux<RsDollyBestillingRequest> createBestilling(Bestilling bestilling,
coBestilling.getMiljoer())
.build()));
}

protected Flux<PdlResponse> oppdaterPdlPerson(OriginatorUtility.Originator originator, BestillingProgress progress) {

if (nonNull(originator.getPdlBestilling()) && nonNull(originator.getPdlBestilling().getPerson())) {

transactionHelperService.persister(progress, BestillingProgress::setPdlForvalterStatus,
"Info: Oppdatering av person startet ...");
return pdlDataConsumer.oppdaterPdl(originator.getIdent(),
PersonUpdateRequestDTO.builder()
.person(originator.getPdlBestilling().getPerson())
.build())
.doOnNext(response -> log.info("Oppdatert person til PDL-forvalter med response {}", response));

} else {
return Flux.just(PdlResponse.builder()
.ident(originator.getIdent())
.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,28 @@ public void executeAsync(Bestilling bestilling) {
if (nonNull(bestKriterier)) {

Flux.fromArray(bestilling.getPdlImport().split(","))
.flatMap(testnorgeIdent -> opprettProgress(bestilling, PDL, testnorgeIdent)
.flatMap(progress -> opprettDollyPerson(testnorgeIdent, progress, bestilling.getBruker())
.doOnNext(dollyPerson -> leggIdentTilGruppe(testnorgeIdent,
progress, bestKriterier.getBeskrivelse()))
.doOnNext(dollyPerson -> counterCustomRegistry.invoke(bestKriterier))
.flatMap(dollyPerson -> Flux.concat(
gjenopprettKlienter(dollyPerson, bestKriterier,
fase1Klienter(),
progress, true),
personServiceClient.syncPerson(dollyPerson, progress)
.map(ClientFuture::get)
.filter(BestillingProgress::isPdlSync)
.flatMap(pdlSync ->
Flux.concat(
gjenopprettKlienter(dollyPerson, bestKriterier,
fase2Klienter(),
progress, true),
gjenopprettKlienter(dollyPerson, bestKriterier,
fase3Klienter(),
progress, true)))))
.flatMap(testnorgeIdent -> Flux.just(OriginatorUtility.prepOriginator(bestKriterier, testnorgeIdent, mapperFacade)))
.flatMap(originator -> opprettProgress(bestilling, PDL, originator.getIdent())
.flatMap(progress -> opprettPerson(originator, progress)
.flatMap(pdlResponse -> sendOrdrePerson(progress, pdlResponse)
.flatMap(testnorgeIdent -> opprettDollyPerson(progress, bestilling.getBruker())
.doOnNext(dollyPerson -> leggIdentTilGruppe(progress, bestKriterier.getBeskrivelse()))
.doOnNext(dollyPerson -> counterCustomRegistry.invoke(bestKriterier))
.flatMap(dollyPerson -> Flux.concat(
gjenopprettKlienter(dollyPerson, bestKriterier,
fase1Klienter(),
progress, true),
personServiceClient.syncPerson(dollyPerson, progress)
.map(ClientFuture::get)
.filter(BestillingProgress::isPdlSync)
.flatMap(pdlSync ->
Flux.concat(
gjenopprettKlienter(dollyPerson, bestKriterier,
fase2Klienter(),
progress, true),
gjenopprettKlienter(dollyPerson, bestKriterier,
fase3Klienter(),
progress, true)))))))
.doOnError(throwable -> {
var error = errorStatusDecoder.getErrorText(
WebClientFilter.getStatus(throwable), WebClientFilter.getMessage(throwable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ public void executeAsync(Bestilling bestilling) {
Flux.fromIterable(testidenter)
.flatMap(testident -> Flux.just(OriginatorUtility.prepOriginator(bestKriterier, testident, mapperFacade))
.flatMap(originator -> opprettProgress(bestilling, originator.getMaster(), testident.getIdent())
.flatMap(progress -> (originator.isPdlf() ?
.flatMap(progress ->
oppdaterPdlPerson(originator, progress, testident.getIdent())
.flatMap(pdlResponse -> sendOrdrePerson(progress, pdlResponse)) :
Flux.just(testident.getIdent()))
.flatMap(pdlResponse -> sendOrdrePerson(progress, pdlResponse))
.filter(StringUtils::isNotBlank)
.flatMap(ident -> opprettDollyPerson(ident, progress, bestilling.getBruker())
.flatMap(dollyPerson -> (!dollyPerson.getIdent().equals(bestilling.getIdent()) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.pdldata.PdlDataConsumer;
import no.nav.dolly.bestilling.pdldata.dto.PdlResponse;
import no.nav.dolly.bestilling.personservice.PersonServiceClient;
import no.nav.dolly.domain.jpa.Bestilling;
import no.nav.dolly.domain.jpa.BestillingProgress;
Expand All @@ -19,7 +18,6 @@
import no.nav.dolly.service.BestillingService;
import no.nav.dolly.service.IdentService;
import no.nav.dolly.util.TransactionHelperService;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonUpdateRequestDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
Expand All @@ -29,7 +27,6 @@

import java.util.List;

import static java.util.Objects.nonNull;
import static no.nav.dolly.util.MdcUtil.MDC_KEY_BESTILLING;

@Slf4j
Expand Down Expand Up @@ -119,24 +116,7 @@ public void oppdaterPersonAsync(RsDollyUpdateRequest request, Bestilling bestill
.subscribe();
}

private Flux<PdlResponse> oppdaterPdlPerson(OriginatorUtility.Originator originator, BestillingProgress progress) {

if (nonNull(originator.getPdlBestilling()) && nonNull(originator.getPdlBestilling().getPerson())) {

transactionHelperService.persister(progress, BestillingProgress::setPdlForvalterStatus,
"Info: Oppdatering av person startet ...");
return pdlDataConsumer.oppdaterPdl(originator.getIdent(),
PersonUpdateRequestDTO.builder()
.person(originator.getPdlBestilling().getPerson())
.build())
.doOnNext(response -> log.info("Oppdatert person til PDL-forvalter med response {}", response));

} else {
return Flux.just(PdlResponse.builder()
.ident(originator.getIdent())
.build());
}
}

private Flux<String> updateIdent(DollyPerson dollyPerson, BestillingProgress progress) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void executeAsync(Bestilling bestilling) {
.flatMap(pdlResponse -> sendOrdrePerson(progress, pdlResponse)
.filter(StringUtils::isNotBlank)
.flatMap(ident -> opprettDollyPerson(ident, progress, bestilling.getBruker())
.doOnNext(dollyPerson -> leggIdentTilGruppe(ident, progress,
.doOnNext(dollyPerson -> leggIdentTilGruppe(progress,
bestKriterier.getBeskrivelse()))
.doOnNext(dollyPerson -> counterCustomRegistry.invoke(bestKriterier))
.flatMap(dollyPerson -> Flux.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ public static Originator prepOriginator(RsDollyUtvidetBestilling bestillingReque

} else {

PdlMasterCleanerUtility.clean(bestillingRequest.getPdldata().getPerson());
var persondata = mapperFacade.map(bestillingRequest, PdlPersondata.class);
PdlMasterCleanerUtility.clean(persondata.getPerson());
return Originator.builder()
.pdlBestilling(mapperFacade.map(bestillingRequest.getPdldata(), BestillingRequestDTO.class))
.pdlBestilling(mapperFacade.map(persondata, BestillingRequestDTO.class))
.ident(nonNull(testident) ? testident.getIdent() : ident)
.master(Master.PDL)
.build();
Expand Down

0 comments on commit 7c5adbc

Please sign in to comment.