Example #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);
        }
Example #2
0
        public void TestUpdateTracks()
        {
            var unitOfWorkProvider = CreateMockUnitOfWorkProvider();
            var resourceRepository = new MockResourceRepository(unitOfWorkProvider);
            var bookData           = new BookData
            {
                Tracks = new List <TrackData>
                {
                    new TrackData // update on position 1
                    {
                        Name       = "track-8",
                        Position   = 1,
                        Recordings = new List <TrackRecordingData>
                        {
                            new TrackRecordingData // update resource to new version
                            {
                                FileName = "file-1.mp3"
                            }
                        }
                    },
                    new TrackData // no update on position 2
                    {
                        Name       = "track-2",
                        Position   = 2,
                        Recordings = null // update 2 recordings to have no parent
                    },
                    new TrackData         // create on position 3
                    {
                        Name       = "track-3",
                        Position   = 3,
                        Recordings = new List <TrackRecordingData>
                        {
                            new TrackRecordingData // create new recording
                            {
                                FileName = "file-3.mp3"
                            }
                        }
                    }
                },
                FileNameMapping = new Dictionary <string, FileResource>
                {
                    { "file-1.mp3", new FileResource {
                          NewNameInStorage = "guid-1"
                      } },
                    { "file-3.mp3", new FileResource {
                          NewNameInStorage = "guid-3"
                      } },
                }
            };

            var subtask = new UpdateTracksSubtask(resourceRepository);

            subtask.UpdateTracks(40, 1, bookData);

            var createdTracks     = resourceRepository.CreatedObjects.OfType <TrackResource>().ToList();
            var updatedTracks     = resourceRepository.UpdatedObjects.OfType <TrackResource>().ToList();
            var createdRecordings = resourceRepository.CreatedObjects.OfType <AudioResource>().ToList();
            var updatedRecordings = resourceRepository.UpdatedObjects.OfType <AudioResource>().ToList();
            var updatedResources  = resourceRepository.UpdatedObjects.OfType <Resource>().ToList();

            Assert.AreEqual(3, createdTracks.Count);
            Assert.AreEqual(0, updatedTracks.Count);
            Assert.AreEqual(3, updatedResources.Count);

            // Remove one Track and two Audio resources
            Assert.IsTrue(updatedResources[0].IsRemoved);
            Assert.IsTrue(updatedResources[1].IsRemoved);
            Assert.IsTrue(updatedResources[2].IsRemoved);

            Assert.AreEqual(0, updatedRecordings.Count);
            Assert.AreEqual(2, createdRecordings.Count);

            var recording1 = createdRecordings.FirstOrDefault(x => x.FileName == "file-1.mp3");
            var recording3 = createdRecordings.FirstOrDefault(x => x.FileName == "file-3.mp3");

            Assert.AreEqual(2, recording1?.VersionNumber);
            Assert.AreEqual(1, recording3?.VersionNumber);

            if (recording1 == null || recording3 == null)
            {
                Assert.Fail();
            }
            Assert.IsNotNull(recording1.FileId);
            Assert.IsNotNull(recording3.FileId);
        }