From f7635fb3309a772981b3c5d635b35efe13dde57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn-Andre=20Skaar?= <31540110+bjornandre@users.noreply.github.com> Date: Wed, 10 Apr 2024 13:48:10 +0200 Subject: [PATCH] Fix return value when hitting FPE limitation (#109) * Fixed bug in setting metrics and metadata * When hitting FPE limitation return either null or the original value according to MapFailureStrategy --- .../service/pseudo/RecordMapProcessorFactory.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/no/ssb/dlp/pseudo/service/pseudo/RecordMapProcessorFactory.java b/src/main/java/no/ssb/dlp/pseudo/service/pseudo/RecordMapProcessorFactory.java index 2a18343..fb7e50e 100644 --- a/src/main/java/no/ssb/dlp/pseudo/service/pseudo/RecordMapProcessorFactory.java +++ b/src/main/java/no/ssb/dlp/pseudo/service/pseudo/RecordMapProcessorFactory.java @@ -7,6 +7,7 @@ import no.ssb.dapla.dlp.pseudo.func.PseudoFuncOutput; import no.ssb.dapla.dlp.pseudo.func.TransformDirection; import no.ssb.dapla.dlp.pseudo.func.fpe.FpeFunc; +import no.ssb.dapla.dlp.pseudo.func.map.MapFailureStrategy; import no.ssb.dapla.dlp.pseudo.func.map.MapFunc; import no.ssb.dapla.dlp.pseudo.func.map.MapFuncConfig; import no.ssb.dapla.dlp.pseudo.func.tink.fpe.TinkFpeFunc; @@ -28,6 +29,8 @@ import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.Optional; import static no.ssb.dlp.pseudo.core.PseudoOperation.DEPSEUDONYMIZE; import static no.ssb.dlp.pseudo.core.PseudoOperation.PSEUDONYMIZE; @@ -123,7 +126,7 @@ private String process(PseudoOperation operation, funcDeclaration.getFuncName().equals(PseudoFuncNames.MAP_SID_FF31) )) { metadataProcessor.addMetric(FieldMetric.FPE_LIMITATION); - return varValue; + return getMapFailureStrategy(funcDeclaration.getArgs()) == MapFailureStrategy.RETURN_ORIGINAL ? varValue : null; } final boolean isSidMapping = funcDeclaration.getFuncName().equals(PseudoFuncNames.MAP_SID) @@ -184,4 +187,10 @@ protected static List pseudoKeysetsOf(List .toList(); } + private MapFailureStrategy getMapFailureStrategy(Map config) { + return Optional.ofNullable( + config.getOrDefault(MapFuncConfig.Param.MAP_FAILURE_STRATEGY, null) + ).map(String::valueOf).map(MapFailureStrategy::valueOf).orElse(MapFailureStrategy.RETURN_ORIGINAL); + } + }