public async Task <bool> Callback(CancellationToken cancellationToken) { _logger.LogInfo("Reporting callback invoked"); try { foreach (string taskItem in _reportServiceContext.Tasks) { _reports.TryGetValue(taskItem, out var report); if (cancellationToken.IsCancellationRequested) { break; } if (report == null) { if (taskItem.CaseInsensitiveEquals("TaskClearPeriodEndDASZip")) { await _reportZipService.RemoveZipAsync(_reportServiceContext, cancellationToken); } else { _logger.LogError($"Report with key {taskItem} not found"); } continue; } var fileName = await report.GenerateReport(_reportServiceContext, cancellationToken); if (report.IncludeInZip) { await _reportZipService.CreateOrUpdateZipWithReportAsync(fileName, _reportServiceContext, cancellationToken); } } } catch (Exception e) { _logger.LogError(e.Message, e); throw; } _logger.LogInfo("End of Reporting Entry Point"); return(true); }
public async Task <string> GenerateReport(IReportServiceContext reportServiceContext, CancellationToken cancellationToken) { var ukprn = reportServiceContext.Ukprn; var collectionYear = reportServiceContext.CollectionYear; var baseFileName = _fileNameService.GetFilename(reportServiceContext, BaseReportFileName, OutputTypes.Csv, true, true); var downloadFilename = _fileNameService.GetFilename(reportServiceContext, BaseReportFileName + " Download", OutputTypes.Csv, false, true); var summaryFilename = _fileNameService.GetFilename(reportServiceContext, BaseReportFileName + " Summary", OutputTypes.Json, false, true); _logger.LogInfo("UYP Summary Report Data Provider Start"); var dasPaymentsTask = _uypSummaryViewDataProvider.GetDASPaymentsAsync(ukprn, collectionYear, cancellationToken); var ilrLearnerInfoTask = _uypSummaryViewDataProvider.GetILRLearnerInfoAsync(ukprn, cancellationToken); var learnerDeliveryEarningsTask = _uypSummaryViewDataProvider.GetLearnerDeliveryEarningsAsync(ukprn, cancellationToken); var priceEpisodeEarningsTask = _uypSummaryViewDataProvider.GetPriceEpisodeEarningsAsync(ukprn, cancellationToken); var coInvestmentsTask = _uypSummaryViewDataProvider.GetCoinvestmentsAsync(ukprn, cancellationToken); var dataLockTask = _uypSummaryViewDataProvider.GetDASDataLockAsync(ukprn, collectionYear, cancellationToken); var hbcTask = _uypSummaryViewDataProvider.GetHBCPInfoAsync(ukprn, collectionYear, cancellationToken); await Task.WhenAll(dasPaymentsTask, ilrLearnerInfoTask, learnerDeliveryEarningsTask, priceEpisodeEarningsTask, coInvestmentsTask, dataLockTask, hbcTask); // Get the employer name information var apprenticeshipIds = dasPaymentsTask.Result.Select(p => p.ApprenticeshipId); var legalEntityNameDictionary = await _uypSummaryViewDataProvider.GetLegalEntityNameAsync(ukprn, apprenticeshipIds, cancellationToken); _logger.LogInfo("UYP Summary Report Data Provider End"); _logger.LogInfo("UYP Summary Report Model Build Start"); var uypSummaryViewRecords = _uypSummaryViewModelBuilder.Build( dasPaymentsTask.Result, ilrLearnerInfoTask.Result, learnerDeliveryEarningsTask.Result, priceEpisodeEarningsTask.Result, coInvestmentsTask.Result, dataLockTask.Result, hbcTask.Result, legalEntityNameDictionary, reportServiceContext.ReturnPeriod, ukprn).ToList(); _logger.LogInfo("UYP Summary Report Model Build End"); // Full data set used for summary and data persist await _csvFileService.WriteAsync <LearnerLevelViewModel, UYPSummaryViewClassMap>(uypSummaryViewRecords, baseFileName, reportServiceContext.Container, cancellationToken); var summaryViewData = CreateSummary(uypSummaryViewRecords, cancellationToken); string summaryFile = GetJson(summaryViewData, cancellationToken); await WriteAsync(summaryFilename, summaryFile, reportServiceContext.Container, cancellationToken); // Persist data for leaner level var persistModels = _uypSummaryViewPersistenceMapper.Map(reportServiceContext, uypSummaryViewRecords, cancellationToken); await _learnerLevelReportDataPersistanceService.PersistAsync(reportServiceContext, persistModels, cancellationToken); //persist data for summary view var summaryPersistModels = _uypSummaryViewPersistenceMapper.Map(reportServiceContext, summaryViewData); await _summaryReportDataPersistanceService.PersistAsync(reportServiceContext, summaryPersistModels, cancellationToken); // Only learners with issues are made available for the provider to download as a report var uypSummaryViewRecordsWithIssues = uypSummaryViewRecords.Where(p => p.IssuesAmount < 0); await _csvFileService.WriteAsync <LearnerLevelViewModel, UYPSummaryViewDownloadClassMap>(uypSummaryViewRecordsWithIssues, downloadFilename, reportServiceContext.Container, cancellationToken); if (SampleProviders.SampleReportProviderUkPrns.Contains(ukprn)) { var zipName = string.Format(ReportZipFileName, ukprn); await _reportZipService.CreateOrUpdateZipWithReportAsync(zipName, baseFileName, reportServiceContext, cancellationToken); await _reportZipService.CreateOrUpdateZipWithReportAsync(zipName, summaryFilename, reportServiceContext, cancellationToken); await _reportZipService.CreateOrUpdateZipWithReportAsync(zipName, downloadFilename, reportServiceContext, cancellationToken); } return(baseFileName); }