From fc4392663d367877ec363ea25db8fd5614864695 Mon Sep 17 00:00:00 2001 From: Sergei Skuratovich <900852+SSNikolaevich@users.noreply.github.com> Date: Thu, 6 Feb 2025 16:13:45 +0300 Subject: [PATCH] Fixed missed hierarchy delimiter for the replacing path prefix logic --- .../mapper/atlasmap/ComplexMappingAtlasModule.java | 9 +++++---- .../platform/engine/mapper/atlasmap/FieldUtils.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/ComplexMappingAtlasModule.java b/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/ComplexMappingAtlasModule.java index f9c7dab..91dfeb2 100644 --- a/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/ComplexMappingAtlasModule.java +++ b/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/ComplexMappingAtlasModule.java @@ -38,6 +38,7 @@ import static org.qubership.integration.platform.engine.mapper.atlasmap.FieldUtils.hasNotIndexedCollection; import static org.qubership.integration.platform.engine.mapper.atlasmap.FieldUtils.replacePathPrefix; +import static org.qubership.integration.platform.engine.mapper.atlasmap.FieldUtils.replacePathPrefixIndex; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; @@ -160,7 +161,7 @@ public void populateTargetField(AtlasInternalSession session) throws AtlasExcept && nonNull(lastSegment.getCollectionIndex()) ) { targetPath.setCollectionIndex(targetPath.getSegments(true).size() - 1, null); - replacePathPrefix(t, targetPath.toString(), t.getPath()); + replacePathPrefixIndex(t, targetPath.toString(), t.getPath()); } String prefix = Optional.ofNullable(s.getPath()).map(p -> p.endsWith("/") ? p.substring(0, p.length() - 1) : p).orElse(""); Field result = t.isEmpty() @@ -195,9 +196,9 @@ && nonNull(lastSegment.getCollectionIndex()) Field previousTargetSubField = null; for (Field sourceSubField : group.getField()) { Field targetSubField = cloneField(targetField); - getCollectionHelper().copyCollectionIndexes( - sourceField, sourceSubField, targetSubField, previousTargetSubField); - replacePathPrefix(targetSubField, targetField.getPath(), targetSubField.getPath()); + getCollectionHelper() + .copyCollectionIndexes(sourceField, sourceSubField, targetSubField, previousTargetSubField); + replacePathPrefixIndex(targetSubField, targetField.getPath(), targetSubField.getPath()); previousTargetSubField = targetSubField; session.head().setSourceField(sourceSubField); session.head().setTargetField(targetSubField); diff --git a/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/FieldUtils.java b/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/FieldUtils.java index d3cc37f..d835c6d 100644 --- a/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/FieldUtils.java +++ b/src/main/java/org/qubership/integration/platform/engine/mapper/atlasmap/FieldUtils.java @@ -61,6 +61,19 @@ public static List getCollectionElements(Field field) { } } + public static String replacePrefixIndex(String s, String from, String to) { + return isNull(s) ? null : s.startsWith(from) ? to + s.substring(from.length() - 1) : s; + } + + public static void replacePathPrefixIndex(Field field, String from, String to) { + field.setPath(replacePrefixIndex(field.getPath(), from, to)); + if (field instanceof FieldGroup group) { + group.getField().forEach(f -> replacePathPrefixIndex(f, from, to)); + } else if (field instanceof ComplexField complexField) { + complexField.getChildFields().forEach(f -> replacePathPrefixIndex(f, from, to)); + } + } + public static String replacePrefix(String s, String from, String to) { return isNull(s) ? null : s.startsWith(from) ? to + s.substring(from.length()) : s; }