Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/SIL.LCModel/Application/ApplicationServices/XmlImportData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ internal string XmlState
private ReferenceTracker m_rglinks = new ReferenceTracker();
private TextWriter m_wrtrLog;
private bool m_createLinks;
private DateTime m_importDate = DateTime.Now;


/// ------------------------------------------------------------------------------------
Expand Down Expand Up @@ -470,6 +471,7 @@ private void MergeRedundantEntries(ILexEntry leOld, ILexEntry leNew)
ILexSense[] rgls = leOld.SensesOS.ToArray();
for (int i = 0; i < rgls.Length; ++i)
leNew.SensesOS.Add(rgls[i]);
MergeDates(leOld, leNew);
MergeEntryRefs(leOld, leNew);
CopyCustomFieldData(leOld, leNew);

Expand All @@ -479,6 +481,23 @@ private void MergeRedundantEntries(ILexEntry leOld, ILexEntry leNew)
m_mapIdGuid[id] = leNew.Guid;
}

/// Use the newest date between the two dates, as long as it is different from the importDate
private void MergeDates(ILexEntry leOld, ILexEntry leNew)
{
if (leOld.DateCreated == m_importDate)
{
return;
}
if (leNew.DateCreated == m_importDate)
{
leNew.DateCreated = leOld.DateCreated;
}
else if (leOld.DateCreated > leNew.DateCreated)
{
leNew.DateCreated = leOld.DateCreated;
}
}

private void MergeEntryRefs(ILexEntry leOld, ILexEntry leNew)
{
if (leOld.EntryRefsOS.Count == 0)
Expand Down Expand Up @@ -1089,6 +1108,7 @@ private void ReadXmlObject(XmlReader xrdr, FieldInfo fi, ICmObject objToUse)
if (m_factLexEntry == null)
m_factLexEntry = m_cache.ServiceLocator.GetInstance<ILexEntryFactory>();
cmo = m_factLexEntry.Create();
((LexEntry)cmo).DateCreated = m_importDate;
m_nHomograph = 0;
break;
case TextTags.kClassId:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ public void ImportData2()
/// </summary>
///--------------------------------------------------------------------------------------
[Test]
//[Ignore("This needs to be rewritten so that imported files are in resources.")]
public void ImportData3()
{
XmlImportData xid = new XmlImportData(m_cache, true);
Expand Down Expand Up @@ -1380,6 +1379,38 @@ public void ImportData4()
}
}

///
[Test]
public void MergeCreatedDateWorks()
{
var xid = new XmlImportData(m_cache, false);
var createdDate = "2011-09-14 12:00:00.000";
using (var reader = new StringReader("<LexDb xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" xmlns:user=\"urn:my-scripts\">" +
"<Entries><LexEntry><LexemeForm><MoStemAllomorph><MorphType><Link ws=\"en\" name=\"stem\" /></MorphType>" +
"<Form><AUni ws=\"cub\">ãcʉriojomecacʉ</AUni></Form></MoStemAllomorph></LexemeForm><DateCreated>" +
$"<Time val=\"{createdDate}\" /></DateCreated><DialectLabels><Link ws=\"en\" abbr=\"C\" name=\"C\" />" +
"</DialectLabels><EntryRefs><LexEntryRef><ComponentLexemes><Link ws=\"cub\" entry=\"ãcʉriojʉmecacʉ\" />" +
"</ComponentLexemes></LexEntryRef></EntryRefs></LexEntry><LexEntry id=\"IID0E3\"><LexemeForm><MoStemAllomorph>" +
"<MorphType><Link ws=\"en\" name=\"stem\" /></MorphType><Form><AUni ws=\"cub\">ãcʉriojʉmecacʉ</AUni></Form>" +
"</MoStemAllomorph></LexemeForm><DateCreated><Time val=\"2011-09-14 12:00:00.000\" /></DateCreated><DialectLabels>" +
"<Link ws=\"en\" abbr=\"Q\" name=\"Q\" /><Link ws=\"en\" abbr=\"V\" name=\"V\" /></DialectLabels>" +
"<MorphoSyntaxAnalyses><MoStemMsa id=\"MSA1000\"><PartOfSpeech><Link ws=\"en\" abbr=\"s.\" /></PartOfSpeech>" +
"</MoStemMsa></MorphoSyntaxAnalyses><Senses><LexSense><Definition><AStr ws=\"en\">" +
"<Run ws=\"en\">tree species cf jocʉcʉ</Run></AStr></Definition><MorphoSyntaxAnalysis><Link target=\"MSA1000\" />" +
"</MorphoSyntaxAnalysis></LexSense></Senses></LexEntry><LexEntry><LexemeForm><MoStemAllomorph><MorphType>" +
"<Link ws=\"en\" name=\"stem\" /></MorphType><Form><AUni ws=\"cub\">ãcʉriojomecacʉ</AUni></Form></MoStemAllomorph>" +
"</LexemeForm><EntryRefs><LexEntryRef><VariantEntryTypes><Link ws=\"es\" name=\"Variante\" /></VariantEntryTypes>" +
"<ComponentLexemes><Link target=\"IID0E3\" /></ComponentLexemes></LexEntryRef></EntryRefs></LexEntry></Entries></LexDb>"))
{
StringBuilder sbLog = new StringBuilder();
xid.ImportData(reader, new StringWriter(sbLog), 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].DateCreated, Is.EqualTo(entries[1].DateCreated));
Assert.That(entries[0].DateCreated, Is.EqualTo(DateTime.Parse(createdDate)),
"The DateCreated of the entries should match the import data.");
}
}
///--------------------------------------------------------------------------------------
/// <summary>
/// Tests the method ImportData() on sequence lexical relations.
Expand Down
Loading