Skip to content

Commit 8e5d78a

Browse files
committed
LcmToMongo action now supports incomplete DB's.
This fixes an exception thrown when trying to deserialize OptionListItem's with partial DB entries. For initial clones, the DB is somewhat filled out (why?), so this adds a try/catch to allow the DB request to fail, in which case an empty LF list will be used. Also had to change slightly the UpdateRecord call of MongoConnection from using FindOneAndUpdate to UpdateOne. It appeared the only difference was the return type, which was unused, and the former was deserializing its target type before serializing it, causing the same DB exception.
1 parent 5ad3381 commit 8e5d78a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,23 @@ private Dictionary<string, LfInputSystemRecord> LcmWsToLfWs()
624624
return lfWsList;
625625
}
626626

627-
private ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList LcmOptionList, bool updateMongoList = true)
627+
private ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList lcmOptionList, bool updateMongoList = true)
628628
{
629-
LfOptionList lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode);
629+
LfOptionList lfExistingOptionList = null;
630+
try
631+
{
632+
lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode); //doesn't work unless the DB is fully populated
633+
}
634+
catch (Exception) { }
635+
630636
var converter = new ConvertLcmToMongoOptionList(lfExistingOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory);
631-
LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(LcmOptionList);
637+
LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(lcmOptionList);
638+
639+
if (lfExistingOptionList == null)
640+
{
641+
lfChangedOptionList.DateModified = lcmOptionList.DateModified; //if DB didn't have an entry, preserve LCM date
642+
}
643+
632644
if (updateMongoList)
633645
Connection.UpdateRecord(project, lfChangedOptionList, listCode);
634646
return new ConvertLcmToMongoOptionList(lfChangedOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory);

src/LfMerge.Core/MongoConnector/MongoConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,10 @@ private bool UpdateRecordImpl<TDocument>(ILfProject project, TDocument data, Fil
970970
mongoDb = GetMainDatabase();
971971
UpdateDefinition<TDocument> update = BuildUpdate(data, false);
972972
IMongoCollection<TDocument> collection = mongoDb.GetCollection<TDocument>(collectionName);
973-
var updateOptions = new FindOneAndUpdateOptions<TDocument> {
973+
var updateOptions = new UpdateOptions {
974974
IsUpsert = true
975975
};
976-
collection.FindOneAndUpdate(filter, update, updateOptions);
976+
collection.UpdateOne(filter, update, updateOptions);
977977
return true;
978978
}
979979

0 commit comments

Comments
 (0)