public void Action_WithPreviousMongoGrammarWithMatchingGuids_ShouldBeUpdatedFromLcmGrammar() { // Setup var lfProject = _lfProj; LcmCache cache = lfProject.FieldWorksProject.Cache; int wsEn = cache.WritingSystemFactory.GetWsFromStr("en"); var converter = new ConvertLcmToMongoOptionList(null, wsEn, MagicStrings.LfOptionListCodeForGrammaticalInfo, new LfMerge.Core.Logging.NullLogger(), _cache.WritingSystemFactory); LfOptionList lfGrammar = converter.PrepareOptionListUpdate(cache.LanguageProject.PartsOfSpeechOA); LfOptionListItem itemForTest = lfGrammar.Items.First(); Guid g = itemForTest.Guid.Value; itemForTest.Abbreviation = "Different abbreviation"; itemForTest.Value = "Different name"; itemForTest.Key = "Different key"; _conn.UpdateMockOptionList(lfGrammar); // Exercise SutLcmToMongo.Run(lfProject); // Verify lfGrammar = _conn.GetLfOptionLists() .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo); Assert.That(lfGrammar, Is.Not.Null); Assert.That(lfGrammar.Items, Is.Not.Empty); Assert.That(lfGrammar.Items.Count, Is.EqualTo(lfProject.FieldWorksProject.Cache.LanguageProject.AllPartsOfSpeech.Count)); itemForTest = lfGrammar.Items.FirstOrDefault(x => x.Guid == g); Assert.That(itemForTest, Is.Not.Null); Assert.That(itemForTest.Abbreviation, Is.Not.EqualTo("Different abbreviation")); Assert.That(itemForTest.Value, Is.Not.EqualTo("Different name")); Assert.That(itemForTest.Key, Is.EqualTo("Different key")); // NOTE: Is.EqualTo, because keys shouldn't be updated }
public ConvertMongoToLcmOptionList(IRepository <ICmPossibility> possRepo, LfOptionList lfOptionList, ILogger logger, CanonicalOptionListSource canonicalSource = null) { _possRepo = possRepo; _logger = logger; #if false // Once we allow LanguageForge to create optionlist items with "canonical" values (parts of speech, semantic domains, etc.), uncomment this block _parentList = parentList; _wsForKeys = wsForKeys; #endif _canonicalSource = canonicalSource; RebuildLookupTables(lfOptionList); }
private LfOptionList CreateLfGrammarWith(IEnumerable <LfOptionListItem> grammarItems) { var result = new LfOptionList(); result.Code = MagicStrings.LfOptionListCodeForGrammaticalInfo; result.Name = MagicStrings.LcmOptionlistNames[MagicStrings.LfOptionListCodeForGrammaticalInfo]; result.DateCreated = result.DateModified = System.DateTime.Now; result.CanDelete = false; result.DefaultItemKey = null; result.Items = grammarItems.ToList(); return(result); }
private ConvertFdoToMongoOptionList ConvertOptionListFromFdo(ILfProject project, string listCode, ICmPossibilityList fdoOptionList, bool updateMongoList = true) { LfOptionList lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode); var converter = new ConvertFdoToMongoOptionList(lfExistingOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory); LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(fdoOptionList); if (updateMongoList) { Connection.UpdateRecord(project, lfChangedOptionList, listCode); } return(new ConvertFdoToMongoOptionList(lfChangedOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory)); }
/// <summary> /// Initializes a new instance of the <see cref="LfMerge.DataConverters.ConvertFdoToMongoOptionList"/> class. /// </summary> /// <param name="lfOptionList">Lf option list.</param> /// <param name="wsForKeys">Ws for keys.</param> /// <param name="listCode">List code.</param> /// <param name="logger">Logger.</param> public ConvertFdoToMongoOptionList(LfOptionList lfOptionList, int wsForKeys, string listCode, ILogger logger, ILgWritingSystemFactory wsf) { _logger = logger; _wsf = wsf; _wsForKeys = wsForKeys; if (lfOptionList == null) { lfOptionList = MakeEmptyOptionList(listCode); } _lfOptionList = lfOptionList; UpdateOptionListItemDictionaries(_lfOptionList); }
protected LfOptionList MakeEmptyOptionList(string listCode) { var result = new LfOptionList(); result.Items = new List <LfOptionListItem>(); result.DateCreated = result.DateModified = DateTime.Now; // TODO: Investigate why this was changed from UtcNow result.Code = listCode; result.Name = FdoOptionListName(listCode); result.CanDelete = false; result.DefaultItemKey = null; return(result); }
public ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList lcmOptionList, bool updateMongoList = true) { LfOptionList lfExistingOptionList = _conn.GetLfOptionListByCode(project, listCode); var converter = new ConvertLcmToMongoOptionList(lfExistingOptionList, _wsEn, listCode, _env.Logger, _cache.WritingSystemFactory); LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(lcmOptionList); if (updateMongoList) { _conn.UpdateRecord(project, lfChangedOptionList, listCode); } return(new ConvertLcmToMongoOptionList(lfChangedOptionList, _wsEn, listCode, _env.Logger, _cache.WritingSystemFactory)); }
// Clone old option list into new list, changing only the items // ... We could use a MongoDB update query for this, but that would // require new code in MongoConnection and MongoConnectionDouble. // TODO: We pretty much have that code by now. See if we can get rid of this function by now. protected LfOptionList CloneOptionListWithEmptyItems(LfOptionList original) { var newList = new LfOptionList(); newList.CanDelete = original.CanDelete; newList.Code = original.Code; newList.DateCreated = original.DateCreated; newList.DateModified = original.DateModified; newList.DefaultItemKey = original.DefaultItemKey; newList.Name = original.Name; // lfNewOptionList.Items is set to an empty list by its constructor; no need to set it here. return(newList); }
protected void UpdateOptionListItemDictionaries(LfOptionList lfOptionList) { _lfOptionListItemByGuid = lfOptionList.Items .Where(item => item.Guid != null) .ToDictionary(item => item.Guid.Value, item => item); _lfOptionListItemByStrKey = lfOptionList.Items .ToDictionary(item => item.Key, item => item); _lfOptionListItemKeyByGuid = _lfOptionList.Items .Where(item => item.Guid != null) .ToDictionary( item => item.Guid.GetValueOrDefault(), item => item.Key ); }
// This method is public just in case, although I don't anticipate its being needed in user code public virtual void RebuildLookupTables(LfOptionList lfOptionList) { _lfOptionList = lfOptionList; PossibilitiesByKey = new Dictionary <string, ICmPossibility>(); if (lfOptionList == null || lfOptionList.Items == null) { return; } foreach (LfOptionListItem item in lfOptionList.Items) { ICmPossibility poss = LookupByItem(item); if (poss != null) { PossibilitiesByKey[item.Key] = poss; } } }
public void Action_WithPreviousMongoGrammarWithGuids_ShouldReplaceItemsFromLfGrammarWithItemsFromLcmGrammar() { // Setup var lfProject = _lfProj; int initialGrammarItemCount = 10; LfOptionList lfGrammar = CreateLfGrammarWith(DefaultGrammarItems(initialGrammarItemCount)); _conn.UpdateMockOptionList(lfGrammar); // Exercise SutLcmToMongo.Run(lfProject); // Verify lfGrammar = _conn.GetLfOptionLists() .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo); Assert.That(lfGrammar, Is.Not.Null); Assert.That(lfGrammar.Items, Is.Not.Empty); Assert.That(lfGrammar.Items.Count, Is.EqualTo(lfProject.FieldWorksProject.Cache.LanguageProject.AllPartsOfSpeech.Count)); }
public void Action_WithEmptyMongoGrammar_ShouldPopulateMongoGrammarFromLcmGrammar() { // Setup var lfProject = _lfProj; LfOptionList lfGrammar = _conn.GetLfOptionLists() .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo); Assert.That(lfGrammar, Is.Null); // Exercise SutLcmToMongo.Run(lfProject); // Verify lfGrammar = _conn.GetLfOptionLists() .FirstOrDefault(optionList => optionList.Code == MagicStrings.LfOptionListCodeForGrammaticalInfo); Assert.That(lfGrammar, Is.Not.Null); Assert.That(lfGrammar.Items, Is.Not.Empty); Assert.That(lfGrammar.Items.Count, Is.EqualTo(lfProject.FieldWorksProject.Cache.LanguageProject.AllPartsOfSpeech.Count)); }
public bool UpdateRecord(ILfProject project, LfOptionList data, string listCode) { _storedLfOptionLists[listCode ?? string.Empty] = DeepCopy(data); return(true); }
public void UpdateMockOptionList(LfOptionList mockData) { string listCode = mockData.Code ?? string.Empty; _storedLfOptionLists[listCode] = DeepCopy(mockData); }
public void UpdateMockOptionList(BsonDocument mockData) { LfOptionList data = BsonSerializer.Deserialize <LfOptionList>(mockData); UpdateMockOptionList(data); }
public ConvertMongoToLcmOptionList(IRepository <ICmPossibility> possRepo, LfOptionList lfOptionList, ILogger logger, ICmPossibilityList parentList, int wsForKeys, CanonicalOptionListSource canonicalSource = null)