protected override void DoRun(ILfProject project) { // TODO: These checks might be overkill; consider removing some of them if (project == null) { Logger.Error("Project was null in TransferLcmToMongoAction.DoRun"); return; } Logger.Debug("TransferLcmToMongoAction: locating FieldWorks project"); FwProject fwProject = project.FieldWorksProject; if (fwProject == null) { Logger.Error("Can't find FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("TransferLcmToMongoAction: locating FieldWorks project cache"); _cache = fwProject.Cache; if (_cache == null) { Logger.Error("Can't find cache for FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("TransferLcmToMongoAction: connecting to FieldWorks service locator"); _servLoc = _cache.ServiceLocator; if (_servLoc == null) { Logger.Error("Can't find service locator for FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("TransferLcmToMongoAction: setting up lexicon converter"); _lexiconConverter = new ConvertLcmToMongoLexicon(project, Logger, _connection, Progress, _projectRecordFactory); Logger.Debug("TransferLcmToMongoAction: about to run lexicon conversion"); _lexiconConverter.RunConversion(); Logger.Debug("TransferLcmToMongoAction: successful transfer; setting last-synced date"); _connection.SetLastSyncedDate(project, DateTime.UtcNow); }
public void Action_ChangedWithSampleData_ShouldUpdatePictures() { // Setup initial Mongo project has 1 picture and 2 captions var lfProj = _lfProj; var data = new SampleData(); _conn.UpdateMockLfLexEntry(data.bsonTestData); string expectedInternalFileName = Path.Combine("Pictures", data.bsonTestData["senses"][0]["pictures"][0]["fileName"].ToString()); string expectedExternalFileName = data.bsonTestData["senses"][0]["pictures"][1]["fileName"].ToString(); int newMongoPictureCount = data.bsonTestData["senses"][0]["pictures"].AsBsonArray.Count; int newMongoCaptionCount = data.bsonTestData["senses"][0]["pictures"][0]["caption"].AsBsonDocument.Count(); Assert.That(newMongoPictureCount, Is.EqualTo(2)); Assert.That(newMongoCaptionCount, Is.EqualTo(2)); // Initial LCM project has 63 entries, 3 internal pictures, and 1 externally linked picture LcmCache cache = _cache; ILexEntryRepository entryRepo = _servLoc.GetInstance <ILexEntryRepository>(); int originalNumOfLcmPictures = entryRepo.AllInstances(). Count(e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0)); Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfLcmEntries)); Assert.That(originalNumOfLcmPictures, Is.EqualTo(3 + 1)); string expectedGuidStr = data.bsonTestData["guid"].AsString; Guid expectedGuid = Guid.Parse(expectedGuidStr); var entryBefore = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry; Assert.That(entryBefore.SensesOS.Count, Is.GreaterThan(0)); Assert.That(entryBefore.SensesOS.First().PicturesOS.Count, Is.EqualTo(1)); // Exercise adding 1 picture with 2 captions. Note that the picture that was previously attached // to this LCM entry will end up being deleted, because it does not have a corresponding picture in LF. data.bsonTestData["authorInfo"]["modifiedDate"] = DateTime.UtcNow; _conn.UpdateMockLfLexEntry(data.bsonTestData); SutMongoToLcm.Run(lfProj); // Verify "Added" picture is now the only picture on the sense (because the "old" picture was deleted), // and that it has 2 captions with the expected values. entryRepo = _servLoc.GetInstance <ILexEntryRepository>(); int numOfLcmPictures = entryRepo.AllInstances(). Count(e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0)); Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfLcmEntries)); Assert.That(numOfLcmPictures, Is.EqualTo(originalNumOfLcmPictures)); var entry = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry; Assert.IsNotNull(entry); Assert.That(entry.Guid, Is.EqualTo(expectedGuid)); Assert.That(entry.SensesOS.Count, Is.GreaterThan(0)); Assert.That(entry.SensesOS.First().PicturesOS.Count, Is.EqualTo(2)); Assert.That(entry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(), Is.EqualTo(expectedInternalFileName)); Assert.That(entry.SensesOS[0].PicturesOS[1].PictureFileRA.InternalPath.ToString(), Is.EqualTo(expectedExternalFileName)); LfMultiText expectedNewCaption = ConvertLcmToMongoLexicon. ToMultiText(entry.SensesOS[0].PicturesOS[0].Caption, cache.ServiceLocator.WritingSystemManager); int expectedNumOfNewCaptions = expectedNewCaption.Count(); Assert.That(expectedNumOfNewCaptions, Is.EqualTo(2)); string expectedNewVernacularCaption = expectedNewCaption["qaa-x-kal"].Value; string expectedNewAnalysisCaption = expectedNewCaption["en"].Value; Assert.That(expectedNewVernacularCaption.Equals("First Vernacular caption")); Assert.That(expectedNewAnalysisCaption.Equals("Internal path reference")); var testSubEntry = cache.ServiceLocator.GetObject(Guid.Parse(TestSubEntryGuidStr)) as ILexEntry; Assert.That(testSubEntry, Is.Not.Null); Assert.That(testSubEntry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath, Is.EqualTo($"Pictures{Path.DirectorySeparatorChar}TestImage.tif")); var kenEntry = cache.ServiceLocator.GetObject(Guid.Parse(KenEntryGuidStr)) as ILexEntry; Assert.That(kenEntry, Is.Not.Null); Assert.That(kenEntry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath, Is.EqualTo(string.Format("F:{0}src{0}xForge{0}web-languageforge{0}test{0}php{0}common{0}TestImage.jpg", Path.DirectorySeparatorChar))); }