예제 #1
0
        protected override void ExecuteWorkImplementation()
        {
            m_projectId = m_nullableProjectId ?? throw new InvalidOperationException("Required ProjectId wasn't set in ResourceSessionDirector");
            // Updating Project data is not required, because data has been already updated

            m_importedResourceVersionIds = new List <long>();

            m_bookVersionId = new UpdateBookVersionSubtask(m_resourceRepository).UpdateBookVersion(m_projectId, m_userId, m_bookData);

            var updateEditionNoteSubtask = new UpdateEditionNoteSubtask(m_resourceRepository);
            var editionNoteVersionId     = updateEditionNoteSubtask.UpdateEditionNote(m_projectId, m_bookVersionId, m_userId, m_bookData);

            if (editionNoteVersionId != null)
            {
                m_importedResourceVersionIds.Add(editionNoteVersionId.Value);
            }

            //TODO update: transformations

            new UpdateAuthorsSubtask(m_projectRepository, m_personRepository).UpdateAuthors(m_projectId, m_bookData);
            new UpdateResponsiblePersonSubtask(m_projectRepository, m_personRepository).UpdateResponsiblePersonList(m_projectId, m_bookData);

            var updateMetadataSubtask = new UpdateMetadataSubtask(m_metadataRepository);

            updateMetadataSubtask.UpdateMetadata(m_projectId, m_userId, m_bookData);

            // Categories are not updated from import (XMD doesn't contain detailed categorization)
            //new UpdateCategoriesSubtask(m_categoryRepository).UpdateCategoryList(m_projectId, m_bookData);

            new UpdateLiteraryKindsSubtask(m_catalogValueRepository, m_metadataRepository).UpdateLiteraryKinds(m_projectId, m_bookData);
            new UpdateLiteraryGenresSubtask(m_catalogValueRepository, m_metadataRepository).UpdateLiteraryGenres(m_projectId, m_bookData);
            new UpdateLiteraryOriginalsSubtask(m_catalogValueRepository, m_metadataRepository).UpdateLiteraryOriginals(m_projectId, m_bookData);
            new UpdateKeywordsSubtask(m_projectRepository, m_catalogValueRepository).UpdateKeywords(m_projectId, m_bookData);

            var updateTermsSubtask = new UpdateTermsSubtask(m_resourceRepository);

            updateTermsSubtask.UpdateTerms(m_projectId, m_bookData);

            var updatePagesSubtask = new UpdatePagesSubtask(m_resourceRepository);

            updatePagesSubtask.UpdatePages(m_projectId, m_bookVersionId, m_userId, m_bookData, updateTermsSubtask.ResultTermCache);
            m_importedResourceVersionIds.AddRange(updatePagesSubtask.ImportedResourceVersionIds);

            var updateChaptersSubtask = new UpdateChaptersSubtask(m_resourceRepository);

            updateChaptersSubtask.UpdateChapters(m_projectId, m_userId, m_bookData, updatePagesSubtask.ResultPageResourceList);
            m_importedResourceVersionIds.AddRange(updateChaptersSubtask.ImportedResourceVersionIds);

            var updateHeadwordsSubtask = new UpdateHeadwordsSubtask(m_resourceRepository);

            updateHeadwordsSubtask.UpdateHeadwords(m_projectId, m_bookVersionId, m_userId, m_bookData, updatePagesSubtask.ResultPageResourceList);
            m_importedResourceVersionIds.AddRange(updateHeadwordsSubtask.ImportedResourceVersionIds);

            var updateTracksSubtask = new UpdateTracksSubtask(m_resourceRepository);

            updateTracksSubtask.UpdateTracks(m_projectId, m_userId, m_bookData);
            updateTracksSubtask.UpdateFullBookTracks(m_projectId, m_userId, m_bookData);
            m_importedResourceVersionIds.AddRange(updateTracksSubtask.ImportedResourceVersionIds);

            new UpdateHistoryLogSubtask(m_projectRepository).UpdateHistoryLog(m_projectId, m_userId, m_message, m_bookData);
        }
예제 #2
0
        public void TestUpdateChapters()
        {
            var unitOfWorkProvider = CreateMockUnitOfWorkProvider();
            var resourceRepository = new MockResourceRepository(unitOfWorkProvider);

            var contentItem1 = new BookContentItemData
            {
                Text      = "Chapter 40",
                ItemOrder = 2,
                Page      = new BookPageData
                {
                    Text     = "40r",
                    Position = 1,
                    XmlId    = "new-xml-40-r"
                },
                SubContentItems = new List <BookContentItemData>()
            };
            var contentItem2 = new BookContentItemData
            {
                Text      = "Chapter 41",
                ItemOrder = 1,
                Page      = new BookPageData
                {
                    Text     = "40v",
                    Position = 2,
                    XmlId    = "new-xml-40-v"
                },
                SubContentItems = new List <BookContentItemData>()
            };

            contentItem2.SubContentItems.Add(contentItem1);
            var bookData = new BookData
            {
                BookContentItems = new List <BookContentItemData>
                {
                    contentItem2
                }
            };

            var subtask       = new UpdateChaptersSubtask(resourceRepository);
            var pageResources = resourceRepository.GetProjectLatestPages(0).ToList();

            subtask.UpdateChapters(41, 2, bookData, pageResources);

            var createdChapters  = resourceRepository.CreatedObjects.OfType <ChapterResource>().ToList();
            var updatedResources = resourceRepository.UpdatedObjects.OfType <Resource>().ToList();

            Assert.AreEqual(2, createdChapters.Count);
            Assert.AreEqual(1, updatedResources.Count);

            var firstChapter   = createdChapters.First(x => x.Name == "Chapter 40");
            var secondChapter  = createdChapters.First(x => x.Name == "Chapter 41");
            var deletedChapter = updatedResources.First();

            Assert.AreEqual(2, firstChapter.Position);
            Assert.AreEqual(1, secondChapter.Position);
            Assert.IsTrue(deletedChapter.IsRemoved);

            Assert.IsNotNull(firstChapter.ParentResource);
            Assert.IsNull(secondChapter.ParentResource);

            Assert.AreEqual(90, firstChapter.ResourceBeginningPage.Id);
            Assert.AreEqual(80, secondChapter.ResourceBeginningPage.Id);
        }