From 0d03f5c7f6b7749e2f46b57841665845c608804d Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Mon, 31 Mar 2025 16:16:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(X-Pack):=20OAuth2=20=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=94=AF=E6=8C=81=E5=A4=9A=E9=9B=86=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=98=A0=E5=B0=84=20#15523?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/dataease/utils/MappingUtils.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 sdk/common/src/main/java/io/dataease/utils/MappingUtils.java diff --git a/sdk/common/src/main/java/io/dataease/utils/MappingUtils.java b/sdk/common/src/main/java/io/dataease/utils/MappingUtils.java new file mode 100644 index 0000000000..28bb398232 --- /dev/null +++ b/sdk/common/src/main/java/io/dataease/utils/MappingUtils.java @@ -0,0 +1,41 @@ +package io.dataease.utils; + +import java.util.HashMap; +import java.util.Map; + +public class MappingUtils { + + public static Map mapNestedUserData(Map userMap, Map mappingMap) { + + Map resultMap = new HashMap<>(); + mappingMap.forEach((targetKey, sourcePath) -> { + Object value = getNestedValue(userMap, sourcePath); + if (value != null) { + resultMap.put(targetKey, value.toString()); + } + }); + + return resultMap; + } + + private static Object getNestedValue(Map sourceMap, String path) { + String[] keys = path.split("\\."); + Object current = sourceMap; + + for (String key : keys) { + if (!(current instanceof Map)) { + return null; + } + @SuppressWarnings("unchecked") + Map currentMap = (Map) current; + current = currentMap.get(key); + + if (current == null) { + return null; + } + } + + return current; + } + +}