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;
            }
        }
        private async Task <List <ValidationErrorModel> > ValidateAsync(IEasJobContext easJobContext, IReadOnlyDictionary <string, ValidationErrorRule> validationErrorReferenceData, IEnumerable <EasCsvRecord> easCsvRecords, CancellationToken cancellationToken)
        {
            List <ValidationResult> validationResults = new List <ValidationResult>();
            List <ValidationResult> businessRulesValidationResults = new List <ValidationResult>();

            cancellationToken.ThrowIfCancellationRequested();

            List <PaymentType> paymentTypes = await _easPaymentService.GetAllPaymentTypes(cancellationToken);

            List <ContractAllocation> contractsForProvider = await _fcsDataService.GetContractsForProviderAsync(easJobContext.Ukprn, cancellationToken);

            List <FundingLineContractTypeMapping> fundingLineContractTypeMappings = await _fundingLineContractTypeMappingDataService.GetAllFundingLineContractTypeMappings(cancellationToken);

            var devolvedContracts = await _fcsDataService.GetDevolvedContractsForProviderAsync(easJobContext.Ukprn, cancellationToken);

            var sofCodeMcaShortCodeDictionary = await _postcodesDataService.GetMcaShortCodesForSofCodesAsync(DataServiceConstants.ValidDevolvedSourceOfFundingCodes, cancellationToken);

            BusinessRulesValidator validator = new BusinessRulesValidator(contractsForProvider, fundingLineContractTypeMappings, paymentTypes, devolvedContracts, sofCodeMcaShortCodeDictionary, _dateTimeProvider, easJobContext.ReturnPeriod);

            // Business Rule validators
            foreach (EasCsvRecord easRecord in easCsvRecords)
            {
                ValidationResult validate = validator.Validate(easRecord);
                if (!validate.IsValid)
                {
                    businessRulesValidationResults.Add(validate);
                }
            }

            // Cross Record Validation
            var crossRecordValidationResult = new CrossRecordValidator().Validate(easCsvRecords);

            validationResults.AddRange(businessRulesValidationResults);
            if (!crossRecordValidationResult.IsValid)
            {
                validationResults.Add(crossRecordValidationResult);
            }

            var validationErrorList = _validationErrorBuilder.BuildValidationErrors(validationResults, validationErrorReferenceData).ToList();

            return(validationErrorList);
        }