public void ProcessJob(UploadJob job, IWorksheetNameValidator nameValidator, ISimpleWorksheetDataProcessor processor, IExcelFileReader excelFileReader) { try { _jobRepository = new UploadJobRepository(); _jobErrorRepository = new UploadJobErrorRepository(); // Create SimpleUpload object from job var simpleUpload = ToSimpleUpload(job); jobStatus = new StatusHelper(_jobRepository, _logger); _logger.Info("Job# {0} current status is {1} ", job.Guid, job.Status); if (job.Status == UploadJobStatus.ConfirmationGiven) { jobStatus.InProgress(job); // Get indicator details worksheet as data table var indicatorDetails = excelFileReader.GetIndicatorDetails(); // Get pholio data worksheet as data table var pholioData = excelFileReader.GetPholioData(); // Save the total number of rows in file WorkerHelper.UpdateNumberOfRowsInFile(job, pholioData, _jobRepository, true); // Validate the Data processor.Validate(indicatorDetails, pholioData, simpleUpload); // Remove duplicate rows CheckDuplicateRowsInWorksheet(job, simpleUpload, ref pholioData); // Archive rows processor.ArchiveDuplicates(simpleUpload.DuplicateRowInDatabaseErrors, job); // Upload data to core data set UploadDataToCoreDataSet(job, processor, indicatorDetails, pholioData); } else { // Update the job status to in progress jobStatus.InProgress(job); // Get worksheets from file var worksheets = excelFileReader.GetWorksheets(); // Check worksheet names are correct var worksheetsOk = CheckWorksheets(job, worksheets, nameValidator); if (!worksheetsOk) return; // Get indicator details worksheet as data table var indicatorDetails = excelFileReader.GetIndicatorDetails(); // Get pholio data worksheet as data table var pholioData = excelFileReader.GetPholioData(); // Save the total number of rows in file WorkerHelper.UpdateNumberOfRowsInFile(job, pholioData, _jobRepository, true); // Validate the Data processor.Validate(indicatorDetails, pholioData, simpleUpload); // Check user permission for indicator var indicatorIds = new List<int> { simpleUpload.IndicatorId }; var permissionsOk = CheckPermission(indicatorIds, job); if (!permissionsOk) return; // Check for duplications in file, if there will be any duplicate rows // we will remove them. CheckDuplicateRowsInWorksheet(job, simpleUpload, ref pholioData); // Check validation errors var validationOk = CheckValidationFailures(job, simpleUpload); if (!validationOk) return; // Check for duplications database rows var haveDuplicates = CheckDuplicateRowsInDatabase(job, simpleUpload); if (haveDuplicates) return; // Upload to DB UploadDataToCoreDataSet(job, processor, indicatorDetails, pholioData); } } catch (Exception ex) { jobStatus.UnexpectedError(job); _logger.Error(ex); } }
private void UploadDataToCoreDataSet(UploadJob job, ISimpleWorksheetDataProcessor processor, DataTable indicatorDetails, DataTable pholioData) { // Upload to DB var rowsUploaded = processor.UploadData(indicatorDetails, pholioData, job).DataToUpload.Count; // All good job done jobStatus.SuccessfulUpload(job, rowsUploaded); }