Skip to content

Commit

Permalink
Improve PDL handling and add PdlMasterCleanerUtility
Browse files Browse the repository at this point in the history
This commit adds the PdlMasterCleanerUtility class to clean data related to PDL persons. Improvements have also been made in the OriginatorUtility, OppdaterPersonService, and DollyBestillingService for better handling of PDL persons' data. Furthermore, the conditional handling in DollyBestillingService is refactored for simplification.
  • Loading branch information
krharum committed Apr 18, 2024
1 parent 80da00b commit a762c4a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ protected Flux<String> sendOrdrePerson(BestillingProgress progress, PdlResponse
if (progress.getMaster() == PDL) {

transactionHelperService.persister(progress, BestillingProgress::setPdlImportStatus, "OK");
return Flux.just(progress.getIdent());
}

} else if (isNull(forvalterStatus.getStatus()) || forvalterStatus.getStatus().is2xxSuccessful()) {
if (isNull(forvalterStatus.getStatus()) || forvalterStatus.getStatus().is2xxSuccessful()) {

transactionHelperService.persister(progress, BestillingProgress::setPdlOrdreStatus,
"Info: Ordre til PDL startet ...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ public void oppdaterPersonAsync(RsDollyUpdateRequest request, Bestilling bestill
var testident = identService.getTestIdent(bestilling.getIdent());
Flux.just(OriginatorUtility.prepOriginator(request, testident, mapperFacade))
.flatMap(originator -> opprettProgress(bestilling, originator.getMaster(), testident.getIdent())
.flatMap(progress -> (progress.isPdlf() ?
.flatMap(progress ->
oppdaterPdlPerson(originator, progress)
.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 @@ -66,9 +66,11 @@ public static Originator prepOriginator(RsDollyUtvidetBestilling bestillingReque

} else {

PdlMasterCleanerUtility.clean(bestillingRequest.getPdldata().getPerson());
return Originator.builder()
.master(Master.PDL)
.pdlBestilling(mapperFacade.map(bestillingRequest.getPdldata(), BestillingRequestDTO.class))
.ident(nonNull(testident) ? testident.getIdent() : ident)
.master(Master.PDL)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package no.nav.dolly.bestilling.service;

import lombok.experimental.UtilityClass;
import no.nav.dolly.exceptions.DollyFunctionalException;
import no.nav.testnav.libs.data.pdlforvalter.v1.DbVersjonDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static java.util.Objects.nonNull;
import static no.nav.testnav.libs.data.pdlforvalter.v1.DbVersjonDTO.Master.FREG;

@UtilityClass
public class PdlMasterCleanerUtility {

public PersonDTO clean(PersonDTO person) {

if (nonNull(person)) {
Arrays.stream(person.getClass().getMethods())
.filter(method -> method.getName().contains("get"))
.map(method -> {
try {
return method.invoke(person);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new DollyFunctionalException("Feilet å filtrere bestilling på master = PDL");
}
})
.filter(Objects::nonNull)
.filter(data -> data instanceof List)
.map(data -> (List<? extends DbVersjonDTO>) data)
.forEach(PdlMasterCleanerUtility::filterOpplysning);

person.setNyident(null);
}

return person;
}

public void filterOpplysning(List<? extends DbVersjonDTO> opplysninger) {

opplysninger.removeIf(opplysning -> opplysning.getMaster() == FREG);
}
}

0 comments on commit a762c4a

Please sign in to comment.