Skip to content

Commit

Permalink
LcmToMongo action now supports incomplete DB's.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
josephmyers authored and megahirt committed Jan 11, 2023
1 parent 3ce8afa commit 23a26f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,23 @@ private Dictionary<string, LfInputSystemRecord> LcmWsToLfWs()
return lfWsList;
}

private ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList LcmOptionList, bool updateMongoList = true)
private ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList lcmOptionList, bool updateMongoList = true)
{
LfOptionList lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode);
LfOptionList lfExistingOptionList = null;
try
{
lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode); //doesn't work unless the DB is fully populated
}
catch (Exception) { }

var converter = new ConvertLcmToMongoOptionList(lfExistingOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory);
LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(LcmOptionList);
LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(lcmOptionList);

if (lfExistingOptionList == null)
{
lfChangedOptionList.DateModified = lcmOptionList.DateModified; //if DB didn't have an entry, preserve LCM date
}

if (updateMongoList)
Connection.UpdateRecord(project, lfChangedOptionList, listCode);
return new ConvertLcmToMongoOptionList(lfChangedOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory);
Expand Down
4 changes: 2 additions & 2 deletions src/LfMerge.Core/MongoConnector/MongoConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -970,10 +970,10 @@ private bool UpdateRecordImpl<TDocument>(ILfProject project, TDocument data, Fil
mongoDb = GetMainDatabase();
UpdateDefinition<TDocument> update = BuildUpdate(data, false);
IMongoCollection<TDocument> collection = mongoDb.GetCollection<TDocument>(collectionName);
var updateOptions = new FindOneAndUpdateOptions<TDocument> {
var updateOptions = new UpdateOptions {
IsUpsert = true
};
collection.FindOneAndUpdate(filter, update, updateOptions);
collection.UpdateOne(filter, update, updateOptions);
return true;
}

Expand Down

0 comments on commit 23a26f1

Please sign in to comment.