예제 #1
0
        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
        }
예제 #2
0
 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);
 }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
 /// <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);
 }
예제 #6
0
        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);
        }
예제 #7
0
        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));
        }
예제 #8
0
        // 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);
        }
예제 #9
0
 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
         );
 }
예제 #10
0
        // 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;
                }
            }
        }
예제 #11
0
        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));
        }
예제 #12
0
        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));
        }
예제 #13
0
 public bool UpdateRecord(ILfProject project, LfOptionList data, string listCode)
 {
     _storedLfOptionLists[listCode ?? string.Empty] = DeepCopy(data);
     return(true);
 }
예제 #14
0
        public void UpdateMockOptionList(LfOptionList mockData)
        {
            string listCode = mockData.Code ?? string.Empty;

            _storedLfOptionLists[listCode] = DeepCopy(mockData);
        }
예제 #15
0
        public void UpdateMockOptionList(BsonDocument mockData)
        {
            LfOptionList data = BsonSerializer.Deserialize <LfOptionList>(mockData);

            UpdateMockOptionList(data);
        }
예제 #16
0
 public ConvertMongoToLcmOptionList(IRepository <ICmPossibility> possRepo, LfOptionList lfOptionList, ILogger logger, ICmPossibilityList parentList, int wsForKeys, CanonicalOptionListSource canonicalSource = null)