Skip to content

Commit

Permalink
Merge pull request #100 from statisticsnorway/fix-mapTo-for-snr-batch
Browse files Browse the repository at this point in the history
Fixed check for null object returned from lookup service.
  • Loading branch information
RupinderKaurSSB authored Mar 14, 2024
2 parents a41cef0 + 650acbe commit 546e633
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import no.ssb.dapla.dlp.pseudo.func.PseudoFuncInput;
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.MapFunc;
import no.ssb.dapla.dlp.pseudo.func.map.MapFuncConfig;
Expand Down Expand Up @@ -44,7 +45,7 @@ public RecordMapProcessor<PseudoMetadataProcessor> newPseudonymizeRecordProcesso
for (PseudoConfig config : pseudoConfigs) {
final PseudoFuncs fieldPseudonymizer = newPseudoFuncs(config.getRules(),
pseudoKeysetsOf(config.getKeysets()));
chain.preprocessor((f, v) -> init(fieldPseudonymizer, f, v));
chain.preprocessor((f, v) -> init(fieldPseudonymizer,TransformDirection.APPLY, f, v));
chain.register((f, v) -> process(PSEUDONYMIZE, fieldPseudonymizer, f, v, metadataProcessor));
}
return new RecordMapProcessor<>(chain, metadataProcessor);
Expand All @@ -57,7 +58,7 @@ public RecordMapProcessor<PseudoMetadataProcessor> newDepseudonymizeRecordProces
for (PseudoConfig config : pseudoConfigs) {
final PseudoFuncs fieldDepseudonymizer = newPseudoFuncs(config.getRules(),
pseudoKeysetsOf(config.getKeysets()));
chain.preprocessor((f, v) -> init(fieldDepseudonymizer, f, v));
chain.preprocessor((f, v) -> init(fieldDepseudonymizer, TransformDirection.RESTORE, f, v));
chain.register((f, v) -> process(DEPSEUDONYMIZE, fieldDepseudonymizer, f, v, metadataProcessor));
}

Expand All @@ -83,10 +84,10 @@ protected PseudoFuncs newPseudoFuncs(Collection<PseudoFuncRule> rules,
return new PseudoFuncs(rules, pseudoSecrets.resolve(), keysets);
}

private String init(PseudoFuncs pseudoFuncs, FieldDescriptor field, String varValue) {
private String init(PseudoFuncs pseudoFuncs, TransformDirection direction, FieldDescriptor field, String varValue) {
if (varValue != null) {
pseudoFuncs.findPseudoFunc(field).ifPresent(pseudoFunc ->
pseudoFunc.getFunc().init(PseudoFuncInput.of(varValue)));
pseudoFunc.getFunc().init(PseudoFuncInput.of(varValue), direction));
}
return varValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ public class MultiSidResponse {
@Jacksonized
@Introspected
@Serdeable
public record Mapping (List<String> fnrList, List<String> snr, List<String> fnr) { }
public record Mapping (List<String> fnrList, List<String> snrList, List<String> snr, List<String> fnr) { }

public Map<String, SidInfo> toMap() {
Map<String, SidInfo> result = new HashMap<>();
for (ListIterator<String> it = getMapping().fnrList().listIterator(); it.hasNext(); ) {

ListIterator<String> identifierIterator = getMapping().fnrList != null ?
getMapping().fnrList().listIterator() : getMapping().snrList().listIterator();

for (ListIterator<String> it = identifierIterator; it.hasNext(); ) {
int index = it.nextIndex();
result.put(it.next(), new SidInfo.SidInfoBuilder()
.snr(getMapping().snr().get(index))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void testInvokeMultiFnr() {
// sidService should call our sidClient mock
when(sidClient.lookup(any(MultiSidRequest.class))).thenReturn(Publishers.just(
MultiSidResponse.builder().mapping(MultiSidResponse.Mapping.builder()
.fnrList(Arrays.asList("11854898347"))
.fnr(Arrays.asList("11854898347"))
.snr(Arrays.asList("0001ha3"))
.fnrList(Arrays.asList("01839899544","11854898347"))
.fnr(Arrays.asList("01839899544","11854898347"))
.snr(Arrays.asList("0006kh2","0001ha3"))
.build()).build())
);
sidService.lookupFnr(List.of("11854898347"), Optional.empty());
Expand All @@ -62,8 +62,9 @@ public void testInvokeMultiSnr() {
// sidService should call our sidClient mock
when(sidClient.lookup(any(MultiSidRequest.class))).thenReturn(Publishers.just(
MultiSidResponse.builder().mapping(MultiSidResponse.Mapping.builder()
.snr(List.of("0001ha3", "0006kh2"))
.fnr(List.of("11854898347"))
.snrList(Arrays.asList("0006kh2", "0001ha3"))
.snr(List.of("0006kh2", "0001ha3"))
.fnr(List.of("01839899544","11854898347"))
.build()).build())
);
sidService.lookupSnr(List.of("0001ha3"),Optional.empty());
Expand Down

0 comments on commit 546e633

Please sign in to comment.