public async Task <RuleOutcome> EvaluateAsync(Vacancy subject) { RuleOutcome outcomeResult; var outcomeBuilder = RuleOutcomeDetailsBuilder.Create(RuleId.TitlePopularity); var popularityScore = await _popularityService.GetTitlePopularityAsync(subject.ProgrammeId, subject.Title); var trainingProgramme = await _apprenticeshipProgrammeProvider.GetApprenticeshipProgrammeAsync(subject.ProgrammeId); var data = JsonConvert.SerializeObject(new TitlePopularityData { TrainingCode = trainingProgramme.Id, TrainingTitle = trainingProgramme.Title, TrainingType = trainingProgramme.ApprenticeshipType.ToString().ToLower() }); if (popularityScore < _qaRulesConfig.TitlePopularityPercentageThreshold) { outcomeResult = new RuleOutcome(RuleId.TitlePopularity, 100, $"Title is not common for the training specified.", nameof(Vacancy.Title), null, data); } else { outcomeResult = new RuleOutcome(RuleId.TitlePopularity, 0, $"Title is common for the training specified.", nameof(Vacancy.Title), null, data); } var outcome = outcomeBuilder.Add(new RuleOutcome[] { outcomeResult }) .ComputeSum(); return(outcome); }
private async Task SetProgrammeAsync(BsonDocument result) { var programmeId = result[Column.ProgrammeId].AsString; var programme = await _programmeProvider.GetApprenticeshipProgrammeAsync(programmeId); var programmeValue = $"{programme.Id} {programme.Title}"; result.InsertAt(result.IndexOfName(Column.ProgrammeId), new BsonElement(Column.StandardOrFramework, (BsonValue)programmeValue)); result.Remove(Column.ProgrammeId); }
private async Task SetTrainingProgrammeAsync(Vacancy vacancy, DatesViewModel vm) { if (string.IsNullOrEmpty(vacancy.ProgrammeId)) { return; } var programme = await _apprenticeshipProgrammeProvider.GetApprenticeshipProgrammeAsync(vacancy.ProgrammeId); if (programme?.EffectiveTo.HasValue == true) { vm.TrainingDescription = $"{programme.Title}, Level:{(int) programme.ApprenticeshipLevel}"; vm.TrainingEffectiveToDate = programme.EffectiveTo.Value.AsGdsDate(); } }
private async Task UpdateWithTrainingProgrammeInfo(VacancySummary summary) { if (summary.ProgrammeId != null) { var programme = await _apprenticeshipProgrammeProvider.GetApprenticeshipProgrammeAsync(summary.ProgrammeId); if (programme == null) { _logger.LogWarning($"No training programme found for ProgrammeId: {summary.ProgrammeId}"); } else { summary.TrainingTitle = programme.Title; summary.TrainingType = programme.ApprenticeshipType; summary.TrainingLevel = programme.Level; } } }
private async Task SetProgrammeAsync(BsonDocument result) { var programmeId = result[ColumnProgramme].AsString; var programme = await _programmeProvider.GetApprenticeshipProgrammeAsync(programmeId); var programmeValue = $"{programme.Id} {programme.Title}"; var programmeStatus = programme.IsActive ? "Active" : "Inactive"; string framework = null; string frameworkStatus = null; string standard = null; string standardStatus = null; if (programme.ApprenticeshipType == TrainingType.Framework) { framework = programmeValue; frameworkStatus = programmeStatus; } if (programme.ApprenticeshipType == TrainingType.Standard) { standard = programmeValue; standardStatus = programmeStatus; } result.InsertAt(result.IndexOfName(ColumnProgramme), new BsonElement(ColumnFramework, (BsonValue)framework ?? BsonNull.Value)); result.InsertAt(result.IndexOfName(ColumnProgramme), new BsonElement(ColumnFrameworkStatus, (BsonValue)frameworkStatus ?? BsonNull.Value)); result.InsertAt(result.IndexOfName(ColumnProgramme), new BsonElement(ColumnStandard, (BsonValue)standard ?? BsonNull.Value)); result.InsertAt(result.IndexOfName(ColumnProgramme), new BsonElement(ColumnStandardStatus, (BsonValue)standardStatus ?? BsonNull.Value)); result.Remove(ColumnProgramme); }
internal static IRuleBuilderInitial <Vacancy, Vacancy> TrainingMustExist( this IRuleBuilder <Vacancy, Vacancy> ruleBuilder, IApprenticeshipProgrammeProvider apprenticeshipProgrammeProvider) { return(ruleBuilder.CustomAsync(async(vacancy, context, cancellationToken) => { var programme = await apprenticeshipProgrammeProvider.GetApprenticeshipProgrammeAsync(vacancy.ProgrammeId); if (programme == null) { var message = $"Training programme {vacancy.ProgrammeId} does not exist."; var failure = new ValidationFailure(string.Empty, message) { ErrorCode = ErrorCodes.TrainingNotExist, CustomState = VacancyRuleSet.TrainingProgramme, PropertyName = nameof(Vacancy.ProgrammeId) }; context.AddFailure(failure); } })); }
public Task <IApprenticeshipProgramme> GetApprenticeshipProgrammeAsync(string programmeId) { return(_apprenticeshipProgrammesProvider.GetApprenticeshipProgrammeAsync(programmeId)); }