public CreateImportedRecordMetadataWork(ImportedRecordMetadataRepository importedRecordMetadataRepository, ProjectRepository projectRepository, ImportedRecord data, int importHistoryId) : base(importedRecordMetadataRepository)
 {
     m_importedRecordMetadataRepository = importedRecordMetadataRepository;
     m_projectRepository = projectRepository;
     m_data            = data;
     m_importHistoryId = importHistoryId;
 }
Exemplo n.º 2
0
        public void Init()
        {
            var mockFactory = new MockRepository(MockBehavior.Loose)
            {
                CallBase = true
            };

            m_importedProjectMetadataManagerMock = mockFactory.Create <ImportedProjectMetadataManager>(new object[1]);
            m_importHistoryManagerMock           = mockFactory.Create <ImportHistoryManager>(new object[1]);

            m_importedProjectMetadataManagerMock.Setup(x => x.GetImportedProjectMetadataByExternalId(It.IsAny <string>())).
            Returns(new ImportedProjectMetadata {
                ExternalId = "1", Project = new Project {
                    Id = 1
                }
            });

            m_filteringManager = new FilteringManager(m_importedProjectMetadataManagerMock.Object, m_importHistoryManagerMock.Object);

            var parserMock = new Mock <IProjectParser>();

            parserMock.Setup(x => x.GetPairKeyValueList(It.IsAny <ImportedRecord>())).Returns(new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("100a", "Èapek, Karel"),
                new KeyValuePair <string, string>("100a", "Hus, Jan,")
            });
            m_parser         = parserMock.Object;
            m_importedRecord = new ImportedRecord();
        }
Exemplo n.º 3
0
        public IList <KeyValuePair <string, string> > GetPairKeyValueList(ImportedRecord importedRecord)
        {
            var record = ((string)importedRecord.RawData).XmlDeserializeFromString <MARC21record>();

            return(record.datafield
                   .SelectMany(p => p.subfield,
                               (dataField, subfield) => new KeyValuePair <string, string>(dataField.tag + subfield.code, subfield.Value)).ToList());
        }
Exemplo n.º 4
0
        public void Init()
        {
            var serviceProvider = MockIocFactory.CreateMockIocContainer();
            var parsers         = serviceProvider.GetServices <IProjectParser>();

            m_parser         = (Marc21ProjectParser)parsers.First(x => x.BibliographicFormatName == BibliographicFormatNameConstant.Marc21);
            m_importedRecord = new ImportedRecord {
                RawData = GetRecord("OaiPmh_Marc21_JanHus.xml")
            };
        }
Exemplo n.º 5
0
        public ImportedRecord SetFilterData(ImportedRecord importedRecord, IDictionary <string, List <string> > filteringExpressions,
                                            IProjectParser parser)
        {
            if (importedRecord.IsDeleted.HasValue && importedRecord.IsDeleted.Value)
            {
                importedRecord.IsSuitable = false;
                return(importedRecord);
            }

            var importedRecordDb = m_importedProjectMetadataManager.GetImportedProjectMetadataByExternalId(importedRecord.ExternalId);

            importedRecord.IsNew = importedRecordDb?.Project == null;

            if (importedRecord.IsNew)
            {
                foreach (var item in parser.GetPairKeyValueList(importedRecord))
                {
                    filteringExpressions.TryGetValue(item.Key, out var filterExpressions);
                    if (filterExpressions == null)
                    {
                        continue;
                    }

                    if (filterExpressions.Select(Regex.Escape).Select(expr => expr.Replace("%", ".*"))
                        .Any(expr => Regex.IsMatch(item.Value, expr)))
                    {
                        importedRecord.IsSuitable = true;
                        return(importedRecord);
                    }
                }

                importedRecord.IsSuitable = false;
            }
            else
            {
                var importHistory = m_importHistoryManager.GetLastImportHistoryForImportedProjectMetadata(importedRecordDb.Id);

                if (!importedRecord.TimeStamp.HasValue ||
                    importHistory == null ||
                    importHistory.Date < importedRecord.TimeStamp.Value ||
                    !string.IsNullOrEmpty(importedRecord.FaultedMessage))
                {
                    importedRecord.ProjectId = importedRecordDb.Project.Id;
                    importedRecord.ImportedProjectMetadataId = importedRecordDb.Id;
                    importedRecord.IsSuitable = true;
                }
                else
                {
                    importedRecord.IsSuitable = false;
                }
            }

            return(importedRecord);
        }
Exemplo n.º 6
0
        public void SaveImportedProject(ImportedRecord importedRecord, int userId, int externalRepositoryId, int bookTypeId,
                                        IList <int> roleIds, int importHistoryId, RepositoryImportProgressInfo progressInfo)
        {
            try
            {
                if (importedRecord.IsFailed)
                {
                    progressInfo.IncrementFailedProjectsCount();
                }
                else
                {
                    new SaveImportedDataWork(m_projectRepository, m_metadataRepository, m_catalogValueRepository,
                                             m_personRepository, m_permissionRepository, importedRecord, userId, externalRepositoryId, bookTypeId,
                                             roleIds).Execute();
                }
            }
            catch (DataException e)
            {
                importedRecord.IsFailed       = true;
                importedRecord.FaultedMessage = e.Message;
                progressInfo.IncrementFailedProjectsCount();

                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError(e, e.Message);
                }
            }


            try
            {
                progressInfo.IncrementProcessedProjectsCount();
                m_importedRecordMetadataManager.CreateImportedRecordMetadata(importedRecord, importHistoryId);
            }
            catch (DataException e)
            {
                if (!importedRecord.IsFailed)
                {
                    importedRecord.IsFailed       = true;
                    importedRecord.FaultedMessage = e.Message;
                    progressInfo.IncrementFailedProjectsCount();
                }

                if (m_logger.IsErrorEnabled())
                {
                    m_logger.LogError(e, e.Message);
                }
            }
        }
Exemplo n.º 7
0
 public SaveImportedDataWork(ProjectRepository projectRepository, MetadataRepository metadataRepository,
                             CatalogValueRepository catalogValueRepository, PersonRepository personRepository, PermissionRepository permissionRepository,
                             ImportedRecord importedRecord, int userId, int externalRepositoryId, int bookTypeId, IList <int> roleIds) : base(projectRepository)
 {
     m_projectRepository      = projectRepository;
     m_metadataRepository     = metadataRepository;
     m_catalogValueRepository = catalogValueRepository;
     m_personRepository       = personRepository;
     m_permissionRepository   = permissionRepository;
     m_importedRecord         = importedRecord;
     m_userId = userId;
     m_externalRepositoryId = externalRepositoryId;
     m_bookTypeId           = bookTypeId;
     m_roleIds = roleIds;
 }
Exemplo n.º 8
0
        public void Init()
        {
            var mockIoc         = new MockIocContainer(true);
            var serviceProvider = mockIoc.CreateServiceProvider();

            m_mockDataManager                = serviceProvider.GetRequiredService <MockDataManager>();
            m_projectRepository              = serviceProvider.GetRequiredService <ProjectRepository>();
            m_metadataRepository             = serviceProvider.GetRequiredService <MetadataRepository>();
            m_personRepository               = serviceProvider.GetRequiredService <PersonRepository>();
            m_permissionRepository           = serviceProvider.GetRequiredService <PermissionRepository>();
            m_catalogValueRepository         = serviceProvider.GetRequiredService <CatalogValueRepository>();
            m_externalRepositoryRepository   = serviceProvider.GetRequiredService <ExternalRepositoryRepository>();
            m_importedProjectMetadataManager = serviceProvider.GetRequiredService <ImportedProjectMetadataManager>();

            m_importedRecord = new ImportedRecord
            {
                IsNew           = true,
                IsFailed        = false,
                IsDeleted       = false,
                ImportedProject = new ImportedProject
                {
                    Id = "1",
                    ProjectMetadata = new ProjectMetadata
                    {
                        Title         = "Title",
                        PublisherText = "PublisherText",
                        PublishDate   = "PublishDate",
                        PublishPlace  = "PublishPlace",
                    },
                    Authors = new HashSet <Author> {
                        new Author("Jan", "Hus")
                    },
                    Keywords = new List <string> {
                        "Keyword"
                    },
                    LiteraryGenres = new List <string> {
                        "LiteraryGenre"
                    }
                },
                ExternalId = "Ext1"
            };
        }
Exemplo n.º 9
0
        public ImportedRecord AddParsedProject(ImportedRecord importedRecord)
        {
            var record  = ((string)importedRecord.RawData).XmlDeserializeFromString <MARC21record>();
            var project = new ImportedProject();

            foreach (var dataField in record.datafield)
            {
                m_dataFieldProcessors.TryGetValue(dataField.tag, out var dataFieldProcessor);
                dataFieldProcessor?.Process(dataField, project);
            }

            foreach (var controlField in record.controlfield)
            {
                m_controlFieldProcessors.TryGetValue(controlField.tag, out var controlFieldProcessor);
                controlFieldProcessor?.Process(controlField, project);
            }

            importedRecord.ImportedProject = project;
            return(importedRecord);
        }
Exemplo n.º 10
0
        public ImportedRecord ParseResponse(object response)
        {
            var projectImportMetadata = new ImportedRecord();

            var record = (recordType)response;

            projectImportMetadata.ExternalId = record.header.identifier;
            projectImportMetadata.RawData    = record.metadata.OuterXml;
            projectImportMetadata.IsDeleted  = record.header.statusSpecified;

            if (!string.IsNullOrEmpty(record.header.datestamp))
            {
                try
                {
                    projectImportMetadata.TimeStamp = DateTime.Parse(record.header.datestamp);
                }
                catch (ArgumentOutOfRangeException)
                {
                    //The date is set to zero - we are omitting this information
                }
            }

            return(projectImportMetadata);
        }
Exemplo n.º 11
0
        public int CreateImportedRecordMetadata(ImportedRecord importedRecord, int importHistoryId)
        {
            var result = new CreateImportedRecordMetadataWork(m_importedRecordMetadataRepository, m_projectRepository, importedRecord, importHistoryId).Execute();

            return(result);
        }