Ejemplo n.º 1
0
 protected async Task <bool> WhenTheCsvIsGenerated(FundingLineCsvGeneratorJobType jobType,
                                                   string specificationId,
                                                   string fundingPeriodId,
                                                   string path,
                                                   string fundingLineCode,
                                                   string fundingStreamId)
 {
     return(await BatchProcessor.GenerateCsv(jobType, specificationId, fundingPeriodId, path, _transformation.Object, fundingLineCode, fundingStreamId));
 }
        public override async Task Process(Message message)
        {
            JobParameters parameters = message;

            string specificationId = parameters.SpecificationId;
            string fundingLineCode = parameters.FundingLineCode;
            string fundingStreamId = parameters.FundingStreamId;
            string fundingPeriodId = parameters.FundingPeriodId;
            FundingLineCsvGeneratorJobType jobType = parameters.JobType;

            CsvFileInfo fileInfo = new CsvFileInfo(_fileSystemCacheSettings.Path,
                                                   jobType,
                                                   specificationId,
                                                   fundingLineCode,
                                                   fundingStreamId,
                                                   fundingPeriodId);

            string temporaryPath = fileInfo.TemporaryPath;

            EnsureFileIsNew(temporaryPath);

            IFundingLineCsvTransform      fundingLineCsvTransform      = _transformServiceLocator.GetService(jobType);
            IFundingLineCsvBatchProcessor fundingLineCsvBatchProcessor = _batchProcessorServiceLocator.GetService(jobType);

            fundingLineCsvTransform.FundingLineCode = fundingLineCode;

            bool processedResults = await fundingLineCsvBatchProcessor.GenerateCsv(jobType,
                                                                                   specificationId,
                                                                                   fundingPeriodId,
                                                                                   temporaryPath,
                                                                                   fundingLineCsvTransform,
                                                                                   fundingLineCode,
                                                                                   fundingStreamId);

            if (!processedResults)
            {
                _logger.Information(
                    $"Did not create a new csv report as no providers matched for the job type {jobType} in the specification {specificationId}" +
                    $" and funding line code {fundingLineCode} and funding stream id {fundingStreamId}");

                return;
            }

            ICloudBlob blob = _blobClient.GetBlockBlobReference(fileInfo.FileName, PublishedFundingReportContainerName);

            blob.Properties.ContentDisposition = fileInfo.ContentDisposition;

            await using (Stream csvFileStream = _fileSystemAccess.OpenRead(temporaryPath))
            {
                await _blobClientPolicy.ExecuteAsync(() => UploadBlob(blob, csvFileStream, parameters.ToDictionary()));
            }
        }