Esempio n. 1
0
        public void SaveImportedRecord()
        {
            var userId = m_mockDataManager.GetOrCreateUser();
            var externalRepositoryId = m_mockDataManager.CreateExternalRepository("", new List <FilteringExpressionContract>());
            var historyId            = m_mockDataManager.CreateImportHistory();
            var info = new RepositoryImportProgressInfo(externalRepositoryId, "Test");

            m_importedProjectManager.SaveImportedProject(m_importedRecord, userId, externalRepositoryId, m_mockDataManager.GetOrCreateBookType(),
                                                         new List <int>(), historyId, info);

            Assert.AreEqual(false, info.IsCompleted);
            Assert.AreEqual(0, info.FailedProjectsCount);
            Assert.AreEqual(1, info.ProcessedProjectsCount);
            Assert.AreEqual(null, info.FaultedMessage);

            Assert.AreNotEqual(null, m_importedRecord.ProjectId);

            var project = m_metadataRepository.GetAdditionalProjectMetadata(m_importedRecord.ProjectId, true, true, false, true, true, true,
                                                                            false);

            var snapshot = m_projectRepository.GetLatestSnapshot(m_importedRecord.ProjectId);
            var importedRecordMetadata  = m_importedRecordMetadataRepository.InvokeUnitOfWork(x => x.GetImportedRecordMetadataBySnapshot(snapshot.Id));
            var importedProjectMetadata = m_importedProjectMetadataRepository.InvokeUnitOfWork(x => x.GetImportedProjectMetadata(m_importedRecord.ExternalId));

            Assert.AreNotEqual(null, importedProjectMetadata.Id);
            Assert.AreEqual(m_importedRecord.ExternalId, importedProjectMetadata.ExternalId);
            Assert.AreEqual(project.Id, importedProjectMetadata.Project.Id);

            Assert.AreEqual(historyId, importedRecordMetadata.LastUpdate.Id);
            Assert.AreEqual(null, importedRecordMetadata.LastUpdateMessage);
            Assert.AreEqual(importedProjectMetadata.Id, importedRecordMetadata.ImportedProjectMetadata.Id);
        }
Esempio n. 2
0
        public void UpdateLiteraryKinds(long projectId, BookData bookData)
        {
            if (bookData.LiteraryKinds == null)
            {
                return;
            }

            var dbKindList = m_catalogValueRepository.GetLiteraryKindList();
            var project    = m_metadataRepository.GetAdditionalProjectMetadata(projectId, false, false, true, false, false, false, false);

            foreach (var newKindName in bookData.LiteraryKinds)
            {
                var dbKind = dbKindList.FirstOrDefault(x => x.Name == newKindName);

                // Create new Literary Kind
                if (dbKind == null)
                {
                    dbKind = new LiteraryKind
                    {
                        Name = newKindName
                    };
                    m_catalogValueRepository.Create(dbKind);
                    dbKindList.Add(dbKind);
                }

                // Assign Literary Kind to project
                if (project.LiteraryKinds.All(x => x.Id != dbKind.Id))
                {
                    project.LiteraryKinds.Add(dbKind);
                }
            }
            m_catalogValueRepository.Update(project);
        }
Esempio n. 3
0
        public void SaveFullRecord()
        {
            var userId = m_mockDataManager.GetOrCreateUser();
            var externalRepositoryId = m_mockDataManager.CreateExternalRepository("", new List <FilteringExpressionContract>());

            new SaveImportedDataWork(m_projectRepository, m_metadataRepository, m_catalogValueRepository,
                                     m_personRepository, m_permissionRepository, m_importedRecord, userId, externalRepositoryId,
                                     m_mockDataManager.GetOrCreateBookType(),
                                     new List <int>()).Execute();

            Assert.AreNotEqual(null, m_importedRecord.ProjectId);

            var project = m_metadataRepository.GetAdditionalProjectMetadata(m_importedRecord.ProjectId, true, true, false, true, true, true,
                                                                            false);

            var externalRepository = m_externalRepositoryRepository.GetExternalRepository(externalRepositoryId);

            Assert.AreEqual(m_importedRecord.ImportedProject.ProjectMetadata.Title, project.Name);
            Assert.AreEqual(string.Format(externalRepository.UrlTemplate, m_importedRecord.ImportedProject.Id), project.OriginalUrl);
            Assert.AreEqual(userId, project.CreatedByUser.Id);
            Assert.AreEqual(1, project.Snapshots.Count);

            CollectionAssert.AreEquivalent(m_importedRecord.ImportedProject.Keywords.ToList(), project.Keywords.Select(x => x.Text).ToList());
            CollectionAssert.AreEquivalent(m_importedRecord.ImportedProject.LiteraryGenres.ToList(),
                                           project.LiteraryGenres.Select(x => x.Name).ToList());

            Assert.AreEqual(m_importedRecord.ImportedProject.Authors.Count, project.Authors.Count);
            Assert.AreEqual(m_importedRecord.ImportedProject.Authors.First().FirstName, project.Authors.First().OriginalAuthor.FirstName);
            Assert.AreEqual(m_importedRecord.ImportedProject.Authors.First().LastName, project.Authors.First().OriginalAuthor.LastName);

            var metadataResource = m_metadataRepository.GetLatestMetadataResource(m_importedRecord.ProjectId);

            Assert.AreEqual(m_importedRecord.ImportedProject.ProjectMetadata.Title, metadataResource.Title);
            Assert.AreEqual(m_importedRecord.ImportedProject.ProjectMetadata.PublisherText, metadataResource.PublisherText);
            Assert.AreEqual(m_importedRecord.ImportedProject.ProjectMetadata.PublishDate, metadataResource.PublishDate);
            Assert.AreEqual(m_importedRecord.ImportedProject.ProjectMetadata.PublishPlace, metadataResource.PublishPlace);

            var importedProjectMetadata = m_importedProjectMetadataManager.GetImportedProjectMetadataByExternalId(m_importedRecord.ExternalId);

            Assert.AreNotEqual(null, importedProjectMetadata.Id);
            Assert.AreEqual(m_importedRecord.ExternalId, importedProjectMetadata.ExternalId);
            Assert.AreEqual(project.Id, importedProjectMetadata.Project.Id);
        }
Esempio n. 4
0
        protected override MetadataResource ExecuteWorkImplementation()
        {
            var result = m_metadataRepository.GetLatestMetadataResource(m_projectId, true);

            if (m_parameters.IsAnyAdditionalParameter())
            {
                m_metadataRepository.GetAdditionalProjectMetadata(m_projectId, m_parameters.IncludeAuthor, m_parameters.IncludeResponsiblePerson,
                                                                  m_parameters.IncludeKind, m_parameters.IncludeGenre);
            }

            return(result);
        }
Esempio n. 5
0
        protected override void ExecuteWorkImplementation()
        {
            if (m_importedRecord.IsNew)
            {
                m_importedRecord.ProjectId = CreateProject();
                m_importedRecord.ImportedProjectMetadataId = CreateImportedProjectMetadata();
            }

            m_projectId = m_importedRecord.ProjectId;
            var project = m_metadataRepository.GetAdditionalProjectMetadata(m_projectId, true, false, false, true, true, true, false);

            UpdateLiteraryGenres(project);
            UpdateLiteraryOriginals(project);
            UpdateKeywords(project);
            UpdateAuthors(project);
            UpdateMetadata(project);

            m_catalogValueRepository.Update(project);

            CreateSnapshot();
            ProcessExternalImportPermission();
            m_projectRepository.UnitOfWork.CurrentSession.Flush();
            m_projectRepository.UnitOfWork.CurrentSession.Evict(project); //because of unit tests - unit test is running in one session
        }