Esempio n. 1
0
        public void Run_CustomMultiListRefTest(int whichSense, params string[] desiredKeys)
        {
            // Setup
            var lfProj = _lfProj;

            sutFdoToMongo.Run(lfProj);

            Guid       entryGuid = Guid.Parse(TestEntryGuidStr);
            LfLexEntry entry     = _conn.GetLfLexEntryByGuid(entryGuid);
            LfSense    sense     = entry.Senses[whichSense];

            SetCustomMultiOptionList(sense, "customField_senses_Cust_Multi_ListRef", desiredKeys);
            entry.AuthorInfo = new LfAuthorInfo();
            entry.AuthorInfo.ModifiedDate = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(entry);

            // Exercise
            sutMongoToFdo.Run(lfProj);

            // Verify
            FdoCache cache = _cache;

            var fdoEntry = cache.ServiceLocator.GetObject(entryGuid) as ILexEntry;

            Assert.IsNotNull(fdoEntry);
            Assert.That(cache.ServiceLocator.MetaDataCache.FieldExists(LexSenseTags.kClassName, "Cust Multi ListRef", false), "LexSense should have the Cust Multi ListRef field in our test data.");
            int                  fieldId    = cache.ServiceLocator.MetaDataCache.GetFieldId(LexSenseTags.kClassName, "Cust Multi ListRef", false);
            ILexSense            fdoSense   = fdoEntry.SensesOS[whichSense];
            IEnumerable <string> fdoAbbrevs = GetFdoAbbrevsForField(fdoSense, fieldId);

            Assert.That(fdoAbbrevs, Is.EquivalentTo(desiredKeys));
        }
Esempio n. 2
0
 // TODO: Move custom field tests to their own test class, and move these helper functions with them
 public void AddCustomFieldToSense(LfSense sense, string fieldName, BsonValue fieldValue)
 {
     if (sense.CustomFields == null)
     {
         sense.CustomFields = new BsonDocument();
     }
     if (sense.CustomFieldGuids == null)
     {
         sense.CustomFieldGuids = new BsonDocument();
     }
     sense.CustomFields[fieldName] = fieldValue;
     // Clear out the GUIDs: since LF doesn't add them, we want to test what happens if they're missing
     sense.CustomFieldGuids[fieldName] = new BsonArray();
 }
Esempio n. 3
0
        /// <summary>
        /// Convert FDO sense to LF sense.
        /// </summary>
        /// <returns>LF sense
        /// <param name="fdoSense">Fdo sense.</param>
        private LfSense FdoSenseToLfSense(ILexSense fdoSense)
        {
            var lfSense = new LfSense();

            ILgWritingSystem VernacularWritingSystem = ServiceLocator.LanguageProject.DefaultVernacularWritingSystem;
            ILgWritingSystem AnalysisWritingSystem   = ServiceLocator.LanguageProject.DefaultAnalysisWritingSystem;

            lfSense.Guid       = fdoSense.Guid;
            lfSense.Gloss      = ToMultiText(fdoSense.Gloss);
            lfSense.Definition = ToMultiText(fdoSense.Definition);

            // Fields below in alphabetical order by ILexSense property, except for Guid, Gloss and Definition
            lfSense.AcademicDomains        = ToStringArrayField(AcademicDomainListCode, fdoSense.DomainTypesRC);
            lfSense.AnthropologyCategories = ToStringArrayField(AnthroCodeListCode, fdoSense.AnthroCodesRC);
            lfSense.AnthropologyNote       = ToMultiText(fdoSense.AnthroNote);
            lfSense.DiscourseNote          = ToMultiText(fdoSense.DiscourseNote);
            lfSense.EncyclopedicNote       = ToMultiText(fdoSense.EncyclopedicInfo);
            if (fdoSense.ExamplesOS != null)
            {
                lfSense.Examples = new List <LfExample>(fdoSense.ExamplesOS.Select(FdoExampleToLfExample));
            }

            lfSense.GeneralNote = ToMultiText(fdoSense.GeneralNote);
            lfSense.GrammarNote = ToMultiText(fdoSense.GrammarNote);
            if (fdoSense.LIFTid == null)
            {
                lfSense.LiftId = null;
            }
            else
            {
                lfSense.LiftId = fdoSense.LIFTid.Normalize(System.Text.NormalizationForm.FormC);                  // Because LIFT files on disk are NFC and we need to make sure LiftIDs match those on disk
            }
            if (fdoSense.MorphoSyntaxAnalysisRA != null)
            {
                IPartOfSpeech secondaryPos = null;                 // Only used in derivational affixes
                IPartOfSpeech pos          = ConvertFdoToMongoPartsOfSpeech.FromMSA(fdoSense.MorphoSyntaxAnalysisRA, out secondaryPos);
                // Sometimes the part of speech can be null for legitimate reasons, so check the known class IDs before warning of an unknown MSA type
                if (pos == null && !ConvertFdoToMongoPartsOfSpeech.KnownMsaClassIds.Contains(fdoSense.MorphoSyntaxAnalysisRA.ClassID))
                {
                    Logger.Warning("Got MSA of unknown type {0} in sense {1} in project {2}",
                                   fdoSense.MorphoSyntaxAnalysisRA.GetType().Name,
                                   fdoSense.Guid,
                                   LfProject.ProjectCode);
                }
                else
                {
                    lfSense.PartOfSpeech          = ToStringField(GrammarListCode, pos);
                    lfSense.SecondaryPartOfSpeech = ToStringField(GrammarListCode, secondaryPos);                     // It's fine if secondaryPos is still null here
                }
            }
            lfSense.PhonologyNote = ToMultiText(fdoSense.PhonologyNote);
            if (fdoSense.PicturesOS != null)
            {
                lfSense.Pictures = new List <LfPicture>(fdoSense.PicturesOS.Select(FdoPictureToLfPicture));
                //Use the commented code for debugging into FdoPictureToLfPicture
                //
                //lfSense.Pictures = new List<LfPicture>();
                //foreach (var fdoPic in fdoSense.PicturesOS)
                //	lfSense.Pictures.Add(FdoPictureToLfPicture(fdoPic));
            }
            lfSense.SenseBibliography = ToMultiText(fdoSense.Bibliography);
            lfSense.SenseRestrictions = ToMultiText(fdoSense.Restrictions);

            if (fdoSense.ReversalEntriesRC != null)
            {
                IEnumerable <string> reversalEntries = fdoSense.ReversalEntriesRC.Select(fdoReversalEntry => fdoReversalEntry.LongName);
                lfSense.ReversalEntries = LfStringArrayField.FromStrings(reversalEntries);
            }
            lfSense.ScientificName = LfMultiText.FromSingleITsString(fdoSense.ScientificName, ServiceLocator.WritingSystemFactory);
            lfSense.SemanticDomain = ToStringArrayField(SemDomListCode, fdoSense.SemanticDomainsRC);
            lfSense.SemanticsNote  = ToMultiText(fdoSense.SemanticsNote);
            // fdoSense.SensesOS; // Not mapped because LF doesn't handle subsenses. TODO: When LF handles subsenses, map this one.
            lfSense.SenseType            = ToStringField(SenseTypeListCode, fdoSense.SenseTypeRA);
            lfSense.SociolinguisticsNote = ToMultiText(fdoSense.SocioLinguisticsNote);
            if (fdoSense.Source != null)
            {
                lfSense.Source = LfMultiText.FromSingleITsString(fdoSense.Source, ServiceLocator.WritingSystemFactory);
            }
            lfSense.Status = ToStringArrayField(StatusListCode, fdoSense.StatusRA);
            lfSense.Usages = ToStringArrayField(UsageTypeListCode, fdoSense.UsageTypesRC);


            /* Fields not mapped because it doesn't make sense to map them (e.g., Hvo, backreferences, etc):
             * fdoSense.AllOwnedObjects;
             * fdoSense.AllSenses;
             * fdoSense.Cache;
             * fdoSense.CanDelete;
             * fdoSense.ChooserNameTS;
             * fdoSense.ClassID;
             * fdoSense.ClassName;
             * fdoSense.Entry;
             * fdoSense.EntryID;
             * fdoSense.FullReferenceName;
             * fdoSense.GetDesiredMsaType();
             * fdoSense.Hvo;
             * fdoSense.ImportResidue;
             * fdoSense.IndexInOwner;
             * fdoSense.IsValidObject;
             * fdoSense.LexSenseReferences;
             * fdoSense.LongNameTSS;
             * fdoSense.ObjectIdName;
             * fdoSense.OwnedObjects;
             * fdoSense.Owner;
             * fdoSense.OwningFlid;
             * fdoSense.OwnOrd;
             * fdoSense.ReferringObjects;
             * fdoSense.ReversalNameForWs(wsVern);
             * fdoSense.SandboxMSA; // Set-only property
             * fdoSense.Self;
             * fdoSense.Services;
             * fdoSense.ShortName;
             * fdoSense.ShortNameTSS;
             * fdoSense.SortKey;
             * fdoSense.SortKey2;
             * fdoSense.SortKey2Alpha;
             * fdoSense.SortKeyWs;
             * fdoSense.VariantFormEntryBackRefs;
             * fdoSense.VisibleComplexFormBackRefs;
             */

            /* Fields not mapped because LanguageForge doesn't handle that data:
             * fdoSense.AppendixesRC;
             * fdoSense.ComplexFormEntries;
             * fdoSense.ComplexFormsNotSubentries;
             * fdoSense.DoNotPublishInRC;
             * fdoSense.Subentries;
             * fdoSense.ThesaurusItemsRC;
             * fdoSense.LiftResidue;
             * fdoSense.LexSenseOutline;
             * fdoSense.PublishIn;
             */

            BsonDocument customFieldsAndGuids = _convertCustomField.GetCustomFieldsForThisCmObject(fdoSense, "senses", ListConverters);
            BsonDocument customFieldsBson     = customFieldsAndGuids["customFields"].AsBsonDocument;
            BsonDocument customFieldGuids     = customFieldsAndGuids["customFieldGuids"].AsBsonDocument;

            // TODO: Role Views only set on initial clone
            if (LfProject.IsInitialClone)
            {
                ;
            }

            // If custom field was deleted in Flex, delete config here


            lfSense.CustomFields     = customFieldsBson;
            lfSense.CustomFieldGuids = customFieldGuids;

            return(lfSense);
        }
Esempio n. 4
0
        public void SetCustomMultiOptionList(LfSense sense, string fieldName, string[] keys)
        {
            BsonValue value = new BsonArray(keys);

            AddCustomFieldToSense(sense, fieldName, new BsonDocument("values", value));
        }