Skip to content

Commit 5ad3381

Browse files
committed
Adding consideration for GUID values in custom lists.
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.
1 parent 69a4ee6 commit 5ad3381

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/LfMerge.Core/DataConverters/ConvertMongoToLcmCustomField.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public bool SetCustomFieldData(int hvo, int flid, BsonValue value, BsonValue gui
215215
fieldWs = WritingSystemServices.ActualWs(cache, fieldWs, hvo, flid);
216216
}
217217
ICmPossibilityList parentList = GetParentListForField(flid);
218-
ICmPossibility newPoss = parentList.FindOrCreatePossibility(nameHierarchy, fieldWs);
218+
ICmPossibility newPoss = FindPossibility(value.AsString, parentList, fieldWs);
219219

220220
int oldHvo = data.get_ObjectProp(hvo, flid);
221221
if (newPoss.Hvo == oldHvo)
@@ -308,7 +308,7 @@ public bool SetCustomFieldData(int hvo, int flid, BsonValue value, BsonValue gui
308308
// So we assume they exist in FW, and just look them up.
309309
foreach (string key in keysFromLF)
310310
{
311-
ICmPossibility poss = parentList.FindOrCreatePossibility(key, wsEn);
311+
ICmPossibility poss = FindPossibility(key, parentList, wsEn);
312312
// TODO: If this is a new possibility, then we need to populate it with ALL the corresponding data from LF,
313313
// which we don't necessarily have at this point. Need to make that a separate step in the Send/Receive: converting option lists first.
314314
fieldObjs.Add(poss);
@@ -420,5 +420,23 @@ public void SetCustomFieldsForThisCmObject(ICmObject cmObj, string objectType, B
420420
logger.Warning("Custom field {0} from LF skipped, because we're not yet creating new custom fields in LCM", fieldName);
421421
}
422422
}
423+
424+
private ICmPossibility FindPossibility(string key, ICmPossibilityList parentList, int fieldWs)
425+
{
426+
ICmPossibility newPoss;
427+
var guid = ParseGuidOrDefault(key);
428+
if (guid != default(Guid))
429+
{
430+
// assuming LF doesn't have the ability to add list options,
431+
// a GUID in the DB should have a match in LCM
432+
newPoss = parentList.ReallyReallyAllPossibilities.First(p => p.Guid.Equals(guid));
433+
}
434+
else
435+
{
436+
newPoss = parentList.FindOrCreatePossibility(key, fieldWs);
437+
}
438+
439+
return newPoss;
440+
}
423441
}
424442
}

0 commit comments

Comments
 (0)