Skip to content

Commit

Permalink
Adding consideration for GUID values in custom lists.
Browse files Browse the repository at this point in the history
I can't test this, since the List<LfOptionListItem> deserialization just decided to stop working, but I think this is a good general concept.

Assuming LF can't add list items on its own, any time a GUID is stored in MongoDB, it's from LCM. So if the value from MongoDB is a GUID, find the matching value from the LCM list.
  • Loading branch information
josephmyers authored and megahirt committed Jan 11, 2023
1 parent d197704 commit 3ce8afa
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/LfMerge.Core/DataConverters/ConvertMongoToLcmCustomField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public bool SetCustomFieldData(int hvo, int flid, BsonValue value, BsonValue gui
fieldWs = WritingSystemServices.ActualWs(cache, fieldWs, hvo, flid);
}
ICmPossibilityList parentList = GetParentListForField(flid);
ICmPossibility newPoss = parentList.FindOrCreatePossibility(nameHierarchy, fieldWs);
ICmPossibility newPoss = FindPossibility(value.AsString, parentList, fieldWs);

int oldHvo = data.get_ObjectProp(hvo, flid);
if (newPoss.Hvo == oldHvo)
Expand Down Expand Up @@ -308,7 +308,7 @@ public bool SetCustomFieldData(int hvo, int flid, BsonValue value, BsonValue gui
// So we assume they exist in FW, and just look them up.
foreach (string key in keysFromLF)
{
ICmPossibility poss = parentList.FindOrCreatePossibility(key, wsEn);
ICmPossibility poss = FindPossibility(key, parentList, wsEn);
// TODO: If this is a new possibility, then we need to populate it with ALL the corresponding data from LF,
// which we don't necessarily have at this point. Need to make that a separate step in the Send/Receive: converting option lists first.
fieldObjs.Add(poss);
Expand Down Expand Up @@ -420,5 +420,23 @@ public void SetCustomFieldsForThisCmObject(ICmObject cmObj, string objectType, B
logger.Warning("Custom field {0} from LF skipped, because we're not yet creating new custom fields in LCM", fieldName);
}
}

private ICmPossibility FindPossibility(string key, ICmPossibilityList parentList, int fieldWs)
{
ICmPossibility newPoss;
var guid = ParseGuidOrDefault(key);
if (guid != default(Guid))
{
// assuming LF doesn't have the ability to add list options,
// a GUID in the DB should have a match in LCM
newPoss = parentList.ReallyReallyAllPossibilities.First(p => p.Guid.Equals(guid));
}
else
{
newPoss = parentList.FindOrCreatePossibility(key, fieldWs);
}

return newPoss;
}
}
}

0 comments on commit 3ce8afa

Please sign in to comment.