Skip to content

Commit

Permalink
Fixed missed hierarchy delimiter for the replacing (#26)
Browse files Browse the repository at this point in the history
path prefix logic
  • Loading branch information
SSNikolaevich authored Feb 7, 2025
1 parent 5046d1d commit 3993916
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public static List<Field> 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;
}
Expand Down

0 comments on commit 3993916

Please sign in to comment.