-
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.
Improve PDL handling and add PdlMasterCleanerUtility
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
Showing
4 changed files
with
53 additions
and
6 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
46 changes: 46 additions & 0 deletions
46
.../dolly-backend/src/main/java/no/nav/dolly/bestilling/service/PdlMasterCleanerUtility.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,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); | ||
} | ||
} |