From 77f93b9cf8ec3ae14c7afd6a67d8fb3caff58921 Mon Sep 17 00:00:00 2001 From: Jason Naylor Date: Mon, 22 Sep 2025 15:43:27 -0700 Subject: [PATCH 1/2] Fix LT-21976: Merge dialect labels on duplicated entries in import --- .../ApplicationServices/XmlImportData.cs | 11 ++++++ .../ApplicationServices/XmlImportDataTests.cs | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/SIL.LCModel/Application/ApplicationServices/XmlImportData.cs b/src/SIL.LCModel/Application/ApplicationServices/XmlImportData.cs index edd1ef7e..7ceb957a 100644 --- a/src/SIL.LCModel/Application/ApplicationServices/XmlImportData.cs +++ b/src/SIL.LCModel/Application/ApplicationServices/XmlImportData.cs @@ -473,6 +473,7 @@ private void MergeRedundantEntries(ILexEntry leOld, ILexEntry leNew) leNew.SensesOS.Add(rgls[i]); MergeDates(leOld, leNew); MergeEntryRefs(leOld, leNew); + MergeDialectLabels(leOld, leNew); CopyCustomFieldData(leOld, leNew); // Clean up our internal Id map before deleting anything. @@ -481,6 +482,16 @@ private void MergeRedundantEntries(ILexEntry leOld, ILexEntry leNew) m_mapIdGuid[id] = leNew.Guid; } + private void MergeDialectLabels(ILexEntry leOld, ILexEntry leNew) + { + // We don't want duplicates, so we have to check each reference. + foreach (var dlOld in leOld.DialectLabelsRS) + { + if (!leNew.DialectLabelsRS.Contains(dlOld)) + leNew.DialectLabelsRS.Add(dlOld); + } + } + /// Use the newest date between the two dates, as long as it is different from the importDate private void MergeDates(ILexEntry leOld, ILexEntry leNew) { diff --git a/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs b/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs index d92faf1b..28a822ae 100644 --- a/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs +++ b/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs @@ -1415,6 +1415,40 @@ public void MergeCreatedDateWorks() "The DateCreated of the entries should match the import data."); } } + + [Test] + public void DialectLableMergeWorks() + { + var xid = new XmlImportData(m_cache, false); + using(var reader = new StringReader("" + + "" + + "
ãcʉriojomecacʉ
" + + "" + + "" + + "" + + "
" + + "" + + "
ãcʉriojʉmecacʉ
" + + "" + + "" + + "" + + "" + + "tree species cf jocʉcʉ" + + "
" + + "" + + "
ãcʉriojomecacʉ
" + + "" + + "
" + + "
")) + using(var writer = new StringWriter(new StringBuilder())) + { + xid.ImportData(reader, writer, null); + var entries = m_cache.LangProject.LexDbOA.Entries.ToArray(); + Assert.That(entries.Length, Is.EqualTo(2), "The lexicon should have 2 entries."); + Assert.That(entries[0].DialectLabelsRS.Count, Is.EqualTo(2)); + Assert.That(entries[1].DialectLabelsRS.Count, Is.EqualTo(1)); + } + } ///-------------------------------------------------------------------------------------- /// /// Tests the method ImportData() on sequence lexical relations. From 25fec71f3268935d0c943f543748b68542a31fbd Mon Sep 17 00:00:00 2001 From: Jason Naylor Date: Mon, 22 Sep 2025 15:46:02 -0700 Subject: [PATCH 2/2] Update tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Application/ApplicationServices/XmlImportDataTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs b/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs index 28a822ae..27176e91 100644 --- a/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs +++ b/tests/SIL.LCModel.Tests/Application/ApplicationServices/XmlImportDataTests.cs @@ -1417,7 +1417,7 @@ public void MergeCreatedDateWorks() } [Test] - public void DialectLableMergeWorks() + public void DialectLabelMergeWorks() { var xid = new XmlImportData(m_cache, false); using(var reader = new StringReader("" +