Ejemplo n.º 1
0
        public async Task ExecuteAsync(IEasJobContext easJobContext, CancellationToken cancellationToken)
        {
            _logger.LogInfo("Storage Task is called.");

            try
            {
                var fileDataCache = await _fileDataCacheService.GetFileDataCacheAsync(easJobContext.Ukprn, cancellationToken);

                if (fileDataCache != null && !fileDataCache.FailedFileValidation)
                {
                    List <PaymentType> paymentTypes = await _easPaymentService.GetAllPaymentTypes(cancellationToken);

                    Guid submissionId = Guid.NewGuid();
                    List <EasSubmission>      submissionList       = BuildSubmissionList(easJobContext.Ukprn, fileDataCache.ValidEasCsvRecords, submissionId);
                    List <EasSubmissionValue> submissionValuesList = BuildEasSubmissionValues(fileDataCache.ValidEasCsvRecords, paymentTypes, submissionId);
                    await _easSubmissionService.PersistEasSubmissionAsync(submissionList, submissionValuesList, easJobContext.Ukprn, cancellationToken);

                    await _validationErrorLoggerService.LogValidationErrorsAsync(easJobContext, fileDataCache.ValidationErrors, cancellationToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Storage Task failed", ex);
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task ExecuteAsync(IEasJobContext easJobContext, CancellationToken cancellationToken)
        {
            _logger.LogInfo("Reporting Task is called.");
            try
            {
                IEnumerable <ValidationErrorModel> validationErrorModels;
                IEnumerable <EasCsvRecord>         easCsvRecords;

                IFileDataCache fileDataCache = await _fileDataCacheService.GetFileDataCacheAsync(easJobContext.Ukprn, cancellationToken);

                if (fileDataCache == null)
                {
                    List <PaymentType> allPaymentTypes = await _easPaymentService.GetAllPaymentTypes(cancellationToken);

                    List <EasSubmissionValue> easSubmissionValues = await _easSubmissionService.GetEasSubmissionValuesAsync(easJobContext.Ukprn, cancellationToken);

                    var validationErrors = await _validationErrorService.GetValidationErrorsAsync(easJobContext.Ukprn, cancellationToken);

                    easCsvRecords         = BuildEasCsvRecords(allPaymentTypes, easSubmissionValues);
                    validationErrorModels = BuildValidationErrorModels(validationErrors);
                    if (easCsvRecords.Any() || validationErrorModels.Any())
                    {
                        await _reportingController.ProduceReportsAsync(easJobContext, easCsvRecords, validationErrorModels, cancellationToken);
                    }
                }

                if (fileDataCache != null && !fileDataCache.FailedFileValidation)
                {
                    easCsvRecords         = fileDataCache.AllEasCsvRecords;
                    validationErrorModels = fileDataCache.ValidationErrors;
                    await _reportingController.ProduceReportsAsync(easJobContext, easCsvRecords, validationErrorModels, cancellationToken);
                }

                if (fileDataCache != null && fileDataCache.FailedFileValidation)
                {
                    _logger.LogError($"Reports are not generated as File- {easJobContext.FileReference} failed file Validation");
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError("Reporting Task failed", ex);
                throw;
            }
        }