public async Task RunOnce(ILogger logger)
        {
            logger.LogInformation("Begin poll for JobCategories");
            var data = await GetData(_appSettings.SiteFinityJobCategoriesTaxonomyId);

            logger.LogInformation($"Have {data?.Count} job Categorys to save");

            foreach (var jobCategory in data)
            {
                var code = JobCategoryHelper.GetCode(jobCategory.Title);
                // Remove any old job categories that have this title but will have a different code
                var category = await _jobCategoryRepository.GetJobCategory(code);

                if (category == null)
                {
                    category = new JobCategory()
                    {
                        Name  = jobCategory.Title,
                        Texts = new[]
                        {
                            new JobCategoryText()
                            {
                                LanguageCode = "en",
                                Text         = jobCategory.Description,
                                Url          = $"{jobCategory.UrlName}"
                            }
                        },
                        Traits       = jobCategory.Traits.Select(x => x.ToUpper()).ToArray(),
                        PartitionKey = partitionKey
                    };
                }
                else
                {
                    category.Name  = jobCategory.Title;
                    category.Texts = new[]
                    {
                        new JobCategoryText()
                        {
                            LanguageCode = "en",
                            Text         = jobCategory.Description,
                            Url          = $"{jobCategory.UrlName}"
                        }
                    };
                    category.Traits       = jobCategory.Traits.Select(x => x.ToUpper()).ToArray();
                    category.PartitionKey = partitionKey;
                }

                await _jobCategoryRepository.CreateOrUpdateJobCategory(category);
            }

            logger.LogInformation("End poll for JobCategories");
        }
        private async Task CreateJobCategoryQuestionSet(JobCategorySkillMappingResult skillsMapping)
        {
            // Remove any old job categories that have this title but will have a different code
            var category = await _jobCategoryRepository.GetJobCategory(JobCategoryHelper.GetCode(skillsMapping.JobCategory));

            if (category != null)
            {
                category.Skills.Clear();
                category.Skills.AddRange(skillsMapping.SkillMappings);
            }
            else
            {
                _logger.LogError($"Unable to add skills to category {skillsMapping.JobCategory} - the category does not exist");
            }

            await _jobCategoryRepository.CreateOrUpdateJobCategory(category);
        }
Beispiel #3
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "result/{sessionId}/{jobCategory}")] HttpRequest req,
            string sessionId,
            string jobCategory,
            ILogger log,
            [Inject] IHttpRequestHelper httpRequestHelper,
            [Inject] IHttpResponseMessageHelper httpResponseMessageHelper,
            [Inject] IUserSessionRepository userSessionRepository,
            [Inject] IJobProfileRepository jobProfileRepository)
        {
            try
            {
                var correlationId = httpRequestHelper.GetDssCorrelationId(req);
                if (string.IsNullOrEmpty(correlationId))
                {
                    log.LogInformation("Unable to locate 'DssCorrelationId' in request header");
                }

                if (!Guid.TryParse(correlationId, out var correlationGuid))
                {
                    log.LogInformation("Unable to parse 'DssCorrelationId' to a Guid");
                    correlationGuid = Guid.NewGuid();
                }

                if (string.IsNullOrEmpty(sessionId))
                {
                    log.LogInformation($"Correlation Id: {correlationId} - Session Id not supplied");
                    return(httpResponseMessageHelper.BadRequest());
                }

                var userSession = await userSessionRepository.GetUserSession(sessionId);

                if (userSession == null)
                {
                    log.LogInformation($"Correlation Id: {correlationId} - Session Id does not exist {sessionId}");
                    return(httpResponseMessageHelper.NoContent());
                }

                if (userSession.ResultData == null)
                {
                    log.LogInformation($"Correlation Id: {correlationId} - Result data does not yet exist for session {userSession.PrimaryKey}");
                    return(httpResponseMessageHelper.BadRequest());
                }

                var traits      = userSession.ResultData.Traits;
                int traitsTake  = (traits.Length > 3 && traits[2].TotalScore == traits[3].TotalScore) ? 4 : 3;
                var jobFamilies = userSession.ResultData.JobCategories;

                if (!jobCategory.EqualsIgnoreCase("short"))
                {
                    jobCategory = JobCategoryHelper.GetCode(jobCategory);
                }

                var suggestedJobProfiles = new List <JobProfileResult>();
                foreach (var category in jobFamilies)
                {
                    if (category.FilterAssessmentResult == null)
                    {
                        continue;
                    }

                    var categoryProfiles = new List <JobProfileResult>();
                    if (category.TotalQuestions == 0)
                    {
                        // Build the list of job profiles
                        var jobProfiles =
                            await jobProfileRepository.JobProfilesForJobFamily(category.JobCategoryName);

                        var profilesSet = category.FilterAssessmentResult.SuggestedJobProfiles.ToHashSet(StringComparer.InvariantCultureIgnoreCase);

                        foreach (var jobProfile in jobProfiles.Where(p =>
                                                                     (p.JobProfileCategories == null || p.JobProfileCategories.Contains(category.JobCategoryName, StringComparer.InvariantCultureIgnoreCase)) &&
                                                                     profilesSet.Contains(p.Title))
                                 )
                        {
                            categoryProfiles.Add(new JobProfileResult()
                            {
                                CareerPathAndProgression = jobProfile.CareerPathAndProgression,
                                Overview           = jobProfile.Overview,
                                SalaryExperienced  = jobProfile.SalaryExperienced,
                                SalaryStarter      = jobProfile.SalaryStarter,
                                JobCategory        = category.JobCategoryName,
                                SocCode            = jobProfile.SocCode,
                                Title              = jobProfile.Title,
                                UrlName            = jobProfile.UrlName,
                                TypicalHours       = jobProfile.TypicalHours,
                                TypicalHoursPeriod = String.Join("/", jobProfile.WorkingHoursDetails),
                                ShiftPattern       = String.Join("/", jobProfile.WorkingPattern),
                                ShiftPatternPeriod = String.Join("/", jobProfile.WorkingPatternDetails),
                                WYDDayToDayTasks   = jobProfile.WYDDayToDayTasks
                            });
                        }
                    }

                    category.ResultsShown =
                        category.ResultsShown ||
                        category.JobCategoryCode.EqualsIgnoreCase(jobCategory) ||
                        (category.TotalQuestions == 0 && (categoryProfiles.Count == 0));

                    suggestedJobProfiles.AddRange(categoryProfiles);
                }

                var model = new ResultsResponse()
                {
                    AssessmentType     = userSession.AssessmentType,
                    SessionId          = userSession.UserSessionId,
                    JobFamilyCount     = userSession.ResultData.JobCategories.Length,
                    JobFamilyMoreCount = userSession.ResultData.JobCategories.Length - 3,
                    Traits             = traits.Take(traitsTake).Select(x => x.TraitText).ToArray(),
                    JobCategories      = jobFamilies,
                    JobProfiles        = suggestedJobProfiles.ToArray(),
                    WhatYouToldUs      = userSession.ResultData?.JobCategories.SelectMany(r => r.FilterAssessmentResult?.WhatYouToldUs ?? new string[] { }).Distinct().ToArray() ?? new string[] { }
                };

                await userSessionRepository.UpdateUserSession(userSession);

                return(httpResponseMessageHelper.Ok(JsonConvert.SerializeObject(model)));
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Fatal exception {message}", ex.ToString());
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.InternalServerError
                });
            }
        }
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "assessment/{sessionId}/{assessment}/q/{questionNumber}")] HttpRequest req,
            string sessionId,
            string assessment,
            int questionNumber,
            ILogger log,
            [Inject] IHttpRequestHelper httpRequestHelper,
            [Inject] IHttpResponseMessageHelper httpResponseMessageHelper,
            [Inject] IUserSessionRepository userSessionRepository,
            [Inject] IQuestionRepository questionRepository,
            [Inject] IOptions <AppSettings> appSettings)
        {
            try
            {
                var correlationId = httpRequestHelper.GetDssCorrelationId(req);
                if (string.IsNullOrEmpty(correlationId))
                {
                    log.LogInformation("Unable to locate 'DssCorrelationId' in request header");
                }

                if (!Guid.TryParse(correlationId, out var correlationGuid))
                {
                    log.LogInformation("Unable to parse 'DssCorrelationId' to a Guid");
                    correlationGuid = Guid.NewGuid();
                }

                if (string.IsNullOrEmpty(sessionId))
                {
                    log.LogInformation($"CorrelationId: {correlationGuid} - Session Id not supplied");
                    return(httpResponseMessageHelper.BadRequest());
                }

                if (string.IsNullOrEmpty(assessment))
                {
                    log.LogInformation($"CorrelationId: {correlationGuid} - Assessment not supplied");
                    return(httpResponseMessageHelper.BadRequest());
                }

                if (string.IsNullOrEmpty(appSettings?.Value.SessionSalt))
                {
                    log.LogInformation($"CorrelationId: {correlationGuid} -Session salt not missing from configuration");
                    return(httpResponseMessageHelper.BadRequest());
                }

                if (!sessionId.Contains("-"))
                {
                    var datetimeStamp = SessionIdHelper.Decode(appSettings?.Value.SessionSalt, sessionId);
                    if (datetimeStamp == null)
                    {
                        log.LogError($"CorrelationId: {correlationGuid} - Could not decode session id correctly: {sessionId}");
                        return(httpResponseMessageHelper.BadRequest());
                    }
                    string partitionKey = SessionIdHelper.GetYearMonth(datetimeStamp);
                    sessionId = $"{partitionKey}-{sessionId}";
                }

                var userSession = await userSessionRepository.GetUserSession(sessionId);

                if (userSession == null)
                {
                    log.LogError($"CorrelationId: {correlationGuid} - Session Id does not exist {sessionId}");
                    return(httpResponseMessageHelper.NoContent());
                }

                Question question = null;

                if (assessment.EqualsIgnoreCase("short"))
                {
                    if (userSession.AssessmentState.IsComplete && questionNumber == 1)
                    {
                        userSession.AssessmentState.RecordedAnswers = new Answer[] {};
                        await userSessionRepository.UpdateUserSession(userSession);
                    }

                    question = await questionRepository.GetQuestion(questionNumber, userSession.CurrentQuestionSetVersion);

                    userSession.AssessmentState.CurrentQuestion = questionNumber;
                }
                else
                {
                    userSession.FilteredAssessmentState.CurrentFilterAssessmentCode = JobCategoryHelper.GetCode(assessment);
                    userSession.FilteredAssessmentState.CurrentQuestion             = questionNumber;

                    question = await questionRepository.GetQuestion(userSession.FilteredAssessmentState.CurrentQuestionId);
                }

                if (question == null)
                {
                    log.LogInformation($"CorrelationId: {correlationGuid} - Question number {userSession.CurrentQuestion} could not be found on session {userSession.PrimaryKey}");
                    return(httpResponseMessageHelper.NoContent());
                }

                var percentageComplete = userSession.AssessmentState.PercentageComplete;

                var nextQuestion = question.IsFilterQuestion ? userSession.FilteredAssessmentState.MoveToNextQuestion() : userSession.AssessmentState.MoveToNextQuestion();
                await userSessionRepository.UpdateUserSession(userSession);

                var response = new AssessmentQuestionResponse()
                {
                    CurrentFilterAssessmentCode = userSession.FilteredAssessmentState?.CurrentFilterAssessmentCode,
                    IsComplete           = question.IsFilterQuestion ? (userSession.FilteredAssessmentState?.IsComplete ?? false) : userSession.AssessmentState.IsComplete,
                    NextQuestionNumber   = nextQuestion,
                    QuestionId           = question.QuestionId,
                    QuestionText         = question.Texts.FirstOrDefault(x => x.LanguageCode.ToLower() == "en")?.Text,
                    TraitCode            = question.TraitCode,
                    QuestionNumber       = questionNumber,
                    SessionId            = userSession.PrimaryKey,
                    PercentComplete      = percentageComplete,
                    ReloadCode           = userSession.UserSessionId,
                    MaxQuestionsCount    = userSession.MaxQuestions,
                    RecordedAnswersCount = userSession.RecordedAnswers.Length,
                    RecordedAnswer       = userSession.RecordedAnswers.SingleOrDefault(r => r?.QuestionId == question.QuestionId)?.SelectedOption,
                    StartedDt            = userSession.StartedDt,
                    IsFilterAssessment   = !assessment.EqualsIgnoreCase("short"),
                    JobCategorySafeUrl   = userSession.FilteredAssessmentState?.JobFamilyNameUrlSafe
                };

                return(httpResponseMessageHelper.Ok(JsonConvert.SerializeObject(response)));
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Fatal exception {message}", ex.ToString());
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #5
0
        public void CanGenerateJobCategoryCode(string category, string expected)
        {
            var processor = JobCategoryHelper.GetCode(category);

            Assert.Equal(expected, processor);
        }
Beispiel #6
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "assessment/filtered/{sessionId}/{jobCategory}")] HttpRequest req,
            string sessionId,
            string jobCategory,
            ILogger log,
            [Inject] IHttpRequestHelper httpRequestHelper,
            [Inject] IHttpResponseMessageHelper httpResponseMessageHelper,
            [Inject] IUserSessionRepository userSessionRepository)
        {
            try
            {
                var correlationId = httpRequestHelper.GetDssCorrelationId(req);
                if (string.IsNullOrEmpty(correlationId))
                {
                    log.LogInformation("Unable to locate 'DssCorrelationId' in request header");
                }

                if (!Guid.TryParse(correlationId, out var correlationGuid))
                {
                    log.LogInformation("Unable to parse 'DssCorrelationId' to a Guid");
                    correlationGuid = Guid.NewGuid();
                }

                if (string.IsNullOrEmpty(sessionId))
                {
                    log.LogInformation($"CorrelationId: {correlationGuid} - Session Id not supplied");
                    return(httpResponseMessageHelper.BadRequest());
                }

                var userSession = await userSessionRepository.GetUserSession(sessionId);

                if (userSession == null)
                {
                    log.LogInformation($"CorrelationId: {correlationGuid} - Session Id does not exist {sessionId}");
                    return(httpResponseMessageHelper.NoContent());
                }

                if (userSession.ResultData == null)
                {
                    log.LogInformation(
                        $"CorrelationId: {correlationGuid} - Session Id {sessionId} has not completed the short assessment");
                    return(httpResponseMessageHelper.BadRequest());
                }

                var code = JobCategoryHelper.GetCode(jobCategory);

                if (!userSession.FilteredAssessmentState.JobCategoryStates.Any(j => j.JobCategoryCode.EqualsIgnoreCase(code)))
                {
                    return(httpResponseMessageHelper.BadRequest());
                }

                userSession.FilteredAssessmentState.CurrentFilterAssessmentCode = code;

                if (userSession.FilteredAssessmentState.IsComplete)
                {
                    userSession.FilteredAssessmentState.RemoveAnswersForCategory(code);
                }

                var questionNumber = userSession.FilteredAssessmentState.MoveToNextQuestion();

                await userSessionRepository.UpdateUserSession(userSession);

                return(httpResponseMessageHelper.Ok(JsonConvert.SerializeObject(new FilterSessionResponse()
                {
                    SessionId = userSession.PrimaryKey,
                    QuestionNumber = questionNumber
                })));
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Fatal exception {message}", ex.ToString());
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.InternalServerError
                });
            }
        }