Skip to content

Commit c2762f9

Browse files
committed
fix: Accented notes aren't well sorted in tree view - MEED-10328 - Meeds-io/meeds#4136 (#1648)
Before this change, when create some notes starting with different letters then create a note that starts with an accent char sample and check notes order in tree view, accented notes are listed at the end of the tree view. To fix this issue, locale-aware sorting using Collator has been applied in TreeUtils.tranformToJson() with PRIMARY strength, ensuring accents and case are ignored during comparison. After this change, notes are correctly ordered alphabetically regardless of accented characters.
1 parent bae90a7 commit c2762f9

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

notes-service/src/main/java/org/exoplatform/wiki/tree/utils/TreeUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.exoplatform.wiki.tree.utils;
2020

21+
import java.text.Collator;
2122
import java.util.*;
2223
import java.util.stream.Collectors;
2324

@@ -130,6 +131,7 @@ public static List<JsonNodeData> tranformToJson(TreeNode treeNode,
130131
children.add(jsonNodeData);
131132
counter++;
132133
}
134+
sortNodes(children, locale);
133135
return children;
134136
}
135137

@@ -312,4 +314,18 @@ private static ResourceBundleService getResourceBundleService() {
312314
}
313315
return resourceBundleService;
314316
}
317+
318+
private static void sortNodes(List<JsonNodeData> nodes, Locale locale) {
319+
if (nodes == null || nodes.isEmpty()) {
320+
return;
321+
}
322+
Collator collator = Collator.getInstance(locale);
323+
collator.setStrength(Collator.PRIMARY);
324+
325+
nodes.sort((a, b) -> {
326+
String nameA = a.getName() != null ? a.getName() : "";
327+
String nameB = b.getName() != null ? b.getName() : "";
328+
return collator.compare(nameA, nameB);
329+
});
330+
}
315331
}

notes-service/src/test/java/org/exoplatform/wiki/service/rest/NotesRestServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public void testGetFullTreeData() throws Exception {
366366
assertEquals(5, jsonNodeData.getChildren().size());
367367
assertEquals("testPage", jsonNodeData.getChildren().get(0).getName());
368368
assertEquals("testPage 1", jsonNodeData.getChildren().get(1).getName());
369-
assertEquals("testPage 2", jsonNodeData.getChildren().get(2).getName());
370-
assertEquals("testPage 10", jsonNodeData.getChildren().get(3).getName());
369+
assertEquals("testPage 10", jsonNodeData.getChildren().get(2).getName());
370+
assertEquals("testPage 2", jsonNodeData.getChildren().get(3).getName());
371371
assertEquals("testPage 22", jsonNodeData.getChildren().get(4).getName());
372372

373373
doThrow(new IllegalAccessException()).when(noteService)

0 commit comments

Comments
 (0)