Example #1
0
        public async Task <IEnumerable <ApprenticeshipOverlapValidationResult> > ValidateOverlappingApprenticeships(
            IEnumerable <ApprenticeshipOverlapValidationRequest> apprenticeshipOverlapValidationRequests)
        {
            var requests = apprenticeshipOverlapValidationRequests.ToList();

            _logger.Trace($"Validating {requests.Count} overlapping validation requests");

            var command = new Application.Queries.GetOverlappingApprenticeships.GetOverlappingApprenticeshipsRequest
            {
                OverlappingApprenticeshipRequests = requests.Select(Map).ToList()
            };

            var response = await _mediator.SendAsync(command);

            var result = new List <ApprenticeshipOverlapValidationResult>();

            var requestGroups = response.Data.GroupBy(x => x.RequestApprenticeshipId).ToList();

            foreach (var group in requestGroups)
            {
                result.Add(new ApprenticeshipOverlapValidationResult
                {
                    Self = requests.Single(x => x.ApprenticeshipId == group.Key),
                    OverlappingApprenticeships =
                        response.Data
                        .Select(MapFrom)
                        .Where(x => x.RequestApprenticeshipId == group.Key)
                });
            }

            _logger.Info($"Validated {requests.Count} overlapping validation requests");

            return(result);
        }
        public async Task <ConsistencyStatistics> GetStatistics()
        {
            _logger.Trace("Getting Statistics for consistency checks");

            var response = await _mediator.SendAsync(new GetStatisticsRequest());

            return(_statisticsMapper.MapFrom(response.Data));
        }
        private async Task ValidateOverlaps(List <Apprenticeship> apprenticeships)
        {
            _logger.Info("Performing overlap validation for bulk upload");
            var watch = Stopwatch.StartNew();
            var overlapValidationRequest = new GetOverlappingApprenticeshipsRequest
            {
                OverlappingApprenticeshipRequests = new List <ApprenticeshipOverlapValidationRequest>()
            };

            var i = 0;

            foreach (var apprenticeship in apprenticeships.Where(x => x.StartDate.HasValue && x.EndDate.HasValue && !string.IsNullOrEmpty(x.ULN)))
            {
                overlapValidationRequest.OverlappingApprenticeshipRequests.Add(new ApprenticeshipOverlapValidationRequest
                {
                    ApprenticeshipId = i, //assign a row id, as this value will be zero for files
                    Uln       = apprenticeship.ULN,
                    StartDate = apprenticeship.StartDate.Value,
                    EndDate   = apprenticeship.EndDate.Value
                });
                i++;
            }
            _logger.Trace($"Building Overlap validation command took {watch.ElapsedMilliseconds} milliseconds");

            watch = Stopwatch.StartNew();

            if (overlapValidationRequest.OverlappingApprenticeshipRequests.Any())
            {
                var overlapResponse = await _mediator.SendAsync(overlapValidationRequest);

                watch.Stop();
                _logger.Trace($"Overlap validation took {watch.ElapsedMilliseconds} milliseconds");

                if (overlapResponse.Data.Any())
                {
                    _logger.Info($"Found {overlapResponse.Data.Count} overlapping errors");
                    var errors = overlapResponse.Data.Select(overlap => new ValidationFailure(string.Empty, overlap.ValidationFailReason.ToString())).ToList();
                    throw new ValidationException(errors);
                }
            }
        }
Example #4
0
        public Task <long> Handle(CreateBulkUploadCommand command)
        {
            var validation = _validator.Validate(command);

            if (!validation.IsValid)
            {
                throw new ValidationException(validation.Errors);
            }

            _logger.Trace($"Inserting file for provider: {command.ProviderId}");

            return(_repository.InsertBulkUploadFile(command.BulkUploadFile, command.FileName, command.CommitmentId));
        }
        public async Task <Types.DataLock.DataLockStatus> GetDataLock(long apprenticeshipId, long dataLockEventId)
        {
            _logger.Trace($"Getting data lock: {dataLockEventId} for apprenticeship: {apprenticeshipId}", apprenticeshipId: apprenticeshipId);

            var response = await _mediator.SendAsync(new GetDataLockRequest
            {
                ApprenticeshipId = apprenticeshipId,
                DataLockEventId  = dataLockEventId
            });

            _logger.Info($"Retrieved data lock: {dataLockEventId} for apprenticeship: {apprenticeshipId}", apprenticeshipId: apprenticeshipId);

            return(_dataLockMapper.Map(response.Data));
        }
Example #6
0
        public async Task <IEnumerable <CommitmentListItem> > GetCommitments(long providerId)
        {
            _logger.Trace($"Getting commitments for provider {providerId}", providerId: providerId);

            var response = await _mediator.SendAsync(new GetCommitmentsRequest
            {
                Caller = new Caller
                {
                    CallerType = CallerType.Provider,
                    Id         = providerId
                }
            });

            _logger.Info($"Retrieved commitments for provider {providerId}. {response.Data?.Count} commitments found", providerId: providerId, recordCount: response.Data?.Count);

            return(_commitmentMapper.MapFrom(response.Data, CallerType.Provider));
        }
        public async Task <IEnumerable <Commitment.CommitmentListItem> > GetCommitments(long accountId)
        {
            _logger.Trace($"Getting commitments for employer account {accountId}", accountId: accountId);

            var response = await _mediator.SendAsync(new GetCommitmentsRequest
            {
                Caller = new Caller
                {
                    CallerType = CallerType.Employer,
                    Id         = accountId
                }
            });

            _logger.Info($"Retrieved commitments for employer account {accountId}. {response.Data?.Count} commitments found", accountId: accountId);

            return(_commitmentMapper.MapFrom(response.Data, CallerType.Employer));
        }