Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missed hierarchy delimiter for the replacing path prefix logic #26

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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