From 84a4cf89381a774866bdd2aba555a04699cd5fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn-Andre=20Skaar?= <31540110+bjornandre@users.noreply.github.com> Date: Fri, 10 May 2024 20:53:11 +0200 Subject: [PATCH] Paths in datadoc should not contain the array indices. (#113) * Paths in datadoc should not contain the array indices. * Code cleanup --- .../service/pseudo/RecordMapProcessorFactory.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 fb7e50e..52e52be 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 @@ -147,7 +147,7 @@ private String process(PseudoOperation operation, } metadataProcessor.addMetadata(FieldMetadata.builder() .shortName(field.getName()) - .dataElementPath(field.getPath().substring(1).replace('/', '.')) // Skip leading slash and use dot as separator + .dataElementPath(normalizePath(field.getPath())) // Skip leading slash and use dot as separator .dataElementPattern(match.getRule().getPattern()) .encryptionKeyReference(funcDeclaration.getArgs().getOrDefault(KEY_REFERENCE, null)) .encryptionAlgorithm(match.getFunc().getAlgorithm()) @@ -179,6 +179,13 @@ private String process(PseudoOperation operation, } } + private static String normalizePath(String path) { + // Normalize the path by skipping leading '/' and use dot as separator + return path.substring(1).replace('/', '.') + // Also replace the [] separator in nested structs + .replaceAll("\\[\\d*]", ""); + } + // TODO: This should not be needed protected static List pseudoKeysetsOf(List encryptedKeysets) { @@ -192,5 +199,4 @@ private MapFailureStrategy getMapFailureStrategy(Map config) { config.getOrDefault(MapFuncConfig.Param.MAP_FAILURE_STRATEGY, null) ).map(String::valueOf).map(MapFailureStrategy::valueOf).orElse(MapFailureStrategy.RETURN_ORIGINAL); } - }