Beispiel #1
0
        public CourseListInput GetCourseSearchInput(string courseName, CourseSearchProperties courseSearchProperties)
        {
            if (courseSearchProperties == null)
            {
                throw new ArgumentNullException(nameof(courseSearchProperties));
            }

            var apiRequest = new CourseListInput
            {
                CourseListRequest = new CourseListRequestStructure
                {
                    CourseSearchCriteria = new SearchCriteriaStructure
                    {
                        APIKey             = configuration.GetConfig <string>(Constants.CourseSearchApiKey),
                        SubjectKeyword     = courseName,
                        EarliestStartDate  = null,
                        AttendanceModes    = convertTribalCodesService.GetTribalAttendanceModes(string.Join(",", courseSearchProperties.Filters.Attendance ?? new List <string>())),
                        StudyModes         = convertTribalCodesService.GetTribalStudyModes(string.Join(",", courseSearchProperties.Filters.StudyMode ?? new List <string>())),
                        DFE1619Funded      = courseSearchProperties.Filters.Only1619Courses ? "Y" : null,
                        AttendancePatterns = convertTribalCodesService.GetTribalAttendancePatterns(string.Join(",", courseSearchProperties.Filters.AttendancePattern ?? new List <string>())),
                        ProviderKeyword    = courseSearchProperties.Filters.Provider,
                        Distance           = courseSearchProperties.Filters.Distance,
                        DistanceSpecified  = courseSearchProperties.Filters.DistanceSpecified,
                        Location           = courseSearchProperties.Filters.Location
                    },
                    RecordsPerPage  = courseSearchProperties.Count.ToString(),
                    PageNo          = courseSearchProperties.Page.ToString(),
                    SortBy          = GetSortType(courseSearchProperties.OrderedBy),
                    SortBySpecified = true
                }
            };

            return(apiRequest);
        }
Beispiel #2
0
        public CourseListInput GetCourseSearchInput(CourseSearchProperties courseSearchProperties)
        {
            if (courseSearchProperties == null)
            {
                throw new ArgumentNullException(nameof(courseSearchProperties));
            }

            var apiRequest = new CourseListInput
            {
                CourseListRequest = new CourseListRequestStructure
                {
                    CourseSearchCriteria = new SearchCriteriaStructure
                    {
                        APIKey            = configuration.GetConfig <string>(Constants.CourseSearchApiKey),
                        SubjectKeyword    = courseSearchProperties.Filters.SearchTerm,
                        EarliestStartDate = courseBusinessRules.GetEarliestStartDate(courseSearchProperties.Filters.StartDate, courseSearchProperties.Filters.StartDateFrom),
                        AttendanceModes   = convertTribalCodes.GetTribalAttendanceModes(courseSearchProperties.Filters.CourseType),
                        StudyModes        = convertTribalCodes.GetTribalStudyModes(courseSearchProperties.Filters.CourseHours),
                        ProviderKeyword   = courseSearchProperties.Filters.Provider,
                        Distance          = courseSearchProperties.Filters.DistanceSpecified ? courseSearchProperties.Filters.Distance : default(float),
                        DistanceSpecified = courseSearchProperties.Filters.DistanceSpecified,
                        Location          = courseSearchProperties.Filters.Location
                    },
                    RecordsPerPage  = courseSearchProperties.Count.ToString(),
                    PageNo          = courseSearchProperties.Page.ToString(),
                    SortBy          = GetSortType(courseSearchProperties.OrderedBy),
                    SortBySpecified = true
                }
            };

            return(apiRequest);
        }
        /// <summary>
        /// Gets the results from the web service.
        /// </summary>
        /// <param name="criteria">The course search criteria.</param>
        /// <param name="sortBy">The column on which to sort the results.</param>
        /// <param name="recordsPerPage">The number of records to return per page.</param>
        /// <param name="pageNo">The number of the page of data to get.</param>
        /// <returns>A list of found courses.</returns>
        private CourseListOutput GetResults(SearchCriteriaStructure criteria, string sortBy, string recordsPerPage, string pageNo)
        {
            CourseListOutput output = new CourseListOutput();
            ServiceInterface client = new ServiceInterfaceClient("CourseSearchService");

            CourseListRequestStructure listRequestStructure = new CourseListRequestStructure
            {
                CourseSearchCriteria = criteria,
                RecordsPerPage       = recordsPerPage,
                PageNo = pageNo
            };

            if (!string.IsNullOrEmpty(sortBy))
            {
                SortType tempSortType;
                Enum.TryParse(sortBy, out tempSortType);
                listRequestStructure.SortBy          = tempSortType;
                listRequestStructure.SortBySpecified = true;
            }

            CourseListInput request = new CourseListInput(listRequestStructure);

            try
            {
                output = client.CourseList(request);
            }
            catch (Exception ex)
            {
                ResultsOverviewLabel.Text = ex.Message + "\n" + ex.StackTrace;
            }

            return(output);
        }
        /// <summary>
        /// Retrieves Courses matching the search criteria in the CourseListInput request.
        /// </summary>
        /// <param name="request">CourseListInput request object containing search criteria.</param>
        /// <exception cref="CourseSearchServiceException">The exception details of the error that has occurred.</exception>
        /// <returns>CourseListOutput object containing matching Course details.</returns>
        public CourseListOutput CourseList(CourseListInput request)
        {
            CourseListOutput clo;

            try
            {
                clo = _courseService.GetCourseList(request);
            }
            catch (Exception ex)
            {
                CourseSearchServiceException exc = new CourseSearchServiceException("An error has occured in the CourseSearchService", ex);
                throw exc;
            }

            return(clo);
        }
        /// <summary>
        /// Gets a list of courses matching the search criteria in CourseListRequestStructure
        /// and logs the duration of the search.
        /// </summary>
        /// <param name="courseListInput">Search criteria.</param>
        /// <returns>Populated CourseLisOutput containing matching courses.</returns>
        public CourseListOutput GetCourseList(CourseListInput courseListInput)
        {
            CourseListOutput courseListOutput = new CourseListOutput(new CourseListResponseStructure());

            CourseListRequest request = BuildCourseListRequest(courseListInput.CourseListRequest);

            CourseListResponse response = _courseQuery.GetCourseList(request);

            courseListOutput.CourseListResponse =
                BuildCourseListResponseStructure(response, courseListInput.CourseListRequest);

            // Record search time
            _courseQuery.RecordSearchTime(Constants.SEARCH_TIME_COLUMN_FLAG, response.SearchHeaderId);

            return(courseListOutput);
        }
Beispiel #6
0
        /// <summary>
        /// Gets the results from the web service.
        /// </summary>
        /// <param name="criteria">The course search criteria.</param>
        /// <returns>A list of found courses.</returns>
        private static CourseListOutput GetResults(SearchCriteriaStructure criteria)
        {
            ServiceInterface client = new ServiceInterfaceClient("CourseSearchService");

            CourseListRequestStructure listRequestStructure = new CourseListRequestStructure
            {
                CourseSearchCriteria = criteria,
                RecordsPerPage       = "10",
                PageNo          = "1",
                SortBy          = SortType.D,
                SortBySpecified = true
            };

            CourseListInput  request = new CourseListInput(listRequestStructure);
            CourseListOutput output  = client.CourseList(request);

            return(output);
        }
Beispiel #7
0
        protected Int32 ProcessRequest(String searchTerm, String location, Int32 pageNumber)
        {
            //while (lastRequest.AddTicks(100000000 * 2) <= DateTime.Now)
            //{
            //    // Wait at least 2/10th of a second
            //}
            //lastRequest = DateTime.Now;

            ServiceInterface client = new ServiceInterfaceClient("CourseSearchService");

            CourseListRequestStructure listRequestStructure = new CourseListRequestStructure
            {
                CourseSearchCriteria = new SearchCriteriaStructure
                {
                    //APIKey
                    APIKey = ConfigurationManager.AppSettings["APIKey"],
                    // SUBJECT
                    SubjectKeyword = searchTerm,
                    Location       = location
                },
                RecordsPerPage  = "10",
                PageNo          = pageNumber.ToString(),
                SortBy          = SortType.D,
                SortBySpecified = true
            };

            CourseListInput request = new CourseListInput(listRequestStructure);

            try
            {
                CourseListOutput output = client.CourseList(request);
                WriteLog(String.Format("Term:{0} Location:{1} PageNum:{2} Results:{3}", searchTerm, location, pageNumber, output.CourseListResponse.ResultInfo.NoOfRecords));
                return(String.IsNullOrEmpty(output.CourseListResponse.ResultInfo.NoOfPages) ? 0 : Convert.ToInt32(output.CourseListResponse.ResultInfo.NoOfPages));
            }
            catch (Exception ex)
            {
                WriteLog(String.Format("Term:{0} Location:{1} PageNum:{2} Error:{3}", searchTerm, location, pageNumber, ex.Message));
            }

            return(0);
        }
Beispiel #8
0
        internal static CourseListInput GetCourseListInput(string request)
        {
            var apiRequest = new CourseListInput
            {
                CourseListRequest = new CourseListRequestStructure
                {
                    CourseSearchCriteria = new SearchCriteriaStructure
                    {
                        APIKey            = ConfigurationManager.AppSettings[Constants.CourseSearchApiKey],
                        SubjectKeyword    = request,
                        EarliestStartDate = DateTime.Now.ToString("yyyy-MM-dd"),
                        AttendanceModes   = Convert.ToString(ConfigurationManager.AppSettings[Constants.CourseSearchAttendanceModes])?.Split(',')
                    },
                    RecordsPerPage  = ConfigurationManager.AppSettings[Constants.CourseSearchPageSize],
                    PageNo          = "1",
                    SortBy          = SortType.A,
                    SortBySpecified = true
                }
            };

            return(apiRequest);
        }
        public void GetCourseSearchInputTest(CourseSearchProperties courseSearchProperties, CourseListInput expectedCourseListInput)
        {
            // Assign
            var buildTribalMessageService = new TribalMessageBuilder(fakeConvertTribalCodesService, fakeConfiguration, fakeCourseBusinessRules);

            //Act
            var result = buildTribalMessageService.GetCourseSearchInput(courseSearchProperties);

            //Assert
            result.Should().BeEquivalentTo(expectedCourseListInput);
            A.CallTo(() => fakeConvertTribalCodesService.GetTribalAttendanceModes(A <CourseType> ._)).MustHaveHappened();
            A.CallTo(() => fakeCourseBusinessRules.GetEarliestStartDate(A <StartDate> ._, A <DateTime> ._)).MustHaveHappened();
            A.CallTo(() => fakeConvertTribalCodesService.GetTribalStudyModes(A <CourseHours> ._)).MustHaveHappened();
            A.CallTo(() => fakeConfiguration.GetConfig <string>(A <string> ._)).MustHaveHappened(1, Times.Exactly);
        }
        /// <summary>
        /// On clicking CourseList button, calls CourseSearchService ClientList() method wtih test data.
        /// </summary>
        private void btnCourseList_Click(object sender, EventArgs e)
        {
            txtResult.Text = "Processing ...";

            ServiceInterface client = new ServiceInterfaceClient("CourseSearch");

            CourseListRequestStructure listRequestStructure = new CourseListRequestStructure();

            listRequestStructure.CourseSearchCriteria = new SearchCriteriaStructure();
            listRequestStructure.CourseSearchCriteria.SubjectKeyword = "chemistry";
//            listRequestStructure.CourseSearchCriteria.ProviderID = "4517";  // 4517 University of Bristol
            listRequestStructure.CourseSearchCriteria.Location = "grantham";
//            listRequestStructure.CourseSearchCriteria.Distance = 30.0f;
//            listRequestStructure.CourseSearchCriteria.DistanceSpecified = true;

            CourseListInput request = new CourseListInput(listRequestStructure);

            try
            {
                CourseListOutput response = client.CourseList(request);

                StringBuilder sb = new StringBuilder();
                sb.Append("Request details:");
                sb.Append("\nCourse Search Criteria:");
                sb.Append("\n A10 codes: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.A10Codes);
                sb.Append("\n Adult LR status: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.AdultLRStatus);
                sb.Append("\n Attendance Modes: " +
                          ((response.CourseListResponse.RequestDetails.CourseSearchCriteria.AttendanceModes != null) ?
                           response.CourseListResponse.RequestDetails.CourseSearchCriteria.AttendanceModes.ToString() : "null"));
                sb.Append("\n Attendance Patterns: " +
                          ((response.CourseListResponse.RequestDetails.CourseSearchCriteria.AttendancePatterns != null) ?
                           response.CourseListResponse.RequestDetails.CourseSearchCriteria.AttendancePatterns.ToString() : "null"));
                sb.Append("\n Distance: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.Distance.ToString());
                sb.Append("\n Distance specified: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.DistanceSpecified.ToString());
                sb.Append("\n Earliest Start date: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.EarliestStartDate);
                sb.Append("\n ER app status: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.ERAppStatus);
                sb.Append("\n ER TTG status: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.ERTtgStatus);
                sb.Append("\n Flex start date: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.FlexStartFlag);
                sb.Append("\n IES flag: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.IESFlag);
                sb.Append("\n ILS flag: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.ILSFlag);
                sb.Append("\n LDCS Category code: " +
                          ((response.CourseListResponse.RequestDetails.CourseSearchCriteria.LDCS != null) ?
                           response.CourseListResponse.RequestDetails.CourseSearchCriteria.LDCS.CategoryCode.ToString() : ""));
                sb.Append("\n Location: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.Location);
                sb.Append("\n Opps App closed flag: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.OppsAppClosedFlag);
                sb.Append("\n Other funding status: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.OtherFundingStatus);
                sb.Append("\n Provider ID: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.ProviderID);
                sb.Append("\n Provider Keyword: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.ProviderKeyword);
                sb.Append("\n Qualification levels: " +
                          ((response.CourseListResponse.RequestDetails.CourseSearchCriteria.QualificationLevels != null) ?
                           response.CourseListResponse.RequestDetails.CourseSearchCriteria.QualificationLevels.ToString() : "null"));
                sb.Append("\n Qualification types: " +
                          ((response.CourseListResponse.RequestDetails.CourseSearchCriteria.QualificationTypes != null) ?
                           response.CourseListResponse.RequestDetails.CourseSearchCriteria.QualificationTypes.ToString() : "null"));
                sb.Append("\n SFL flag: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.SFLFlag);
                sb.Append("\n Study modes: " +
                          ((response.CourseListResponse.RequestDetails.CourseSearchCriteria.StudyModes != null) ?
                           response.CourseListResponse.RequestDetails.CourseSearchCriteria.StudyModes.ToString() : "null"));
                sb.Append("\n Subject keyword: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.SubjectKeyword);
                sb.Append("\n TQS flag: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.TQSFlag);
                sb.Append("\n TTG flag: " + response.CourseListResponse.RequestDetails.CourseSearchCriteria.TTGFlag);
                sb.Append("\n\n");

                sb.Append("Course Details:");

                if (response.CourseListResponse.CourseDetails != null)
                {
                    foreach (CourseStructure courseStructure in response.CourseListResponse.CourseDetails)
                    {
                        sb.Append("\n" + courseStructure.Course.CourseID);
                        sb.Append("\n" + courseStructure.Provider);
                        sb.Append("\n" + courseStructure.Course.CourseTitle);
                        sb.Append("\n" + courseStructure.Course.QualificationType);
                        sb.Append("\n" + courseStructure.Course.QualificationLevel);
                        sb.Append("\n" + courseStructure.Course.CourseSummary);
                        sb.Append("\n" + courseStructure.Course.NoOfOpps);

                        sb.Append("\n" + courseStructure.Opportunity.OpportunityId);
                        sb.Append("\n" + courseStructure.Opportunity.StudyMode);
                        sb.Append("\n" + courseStructure.Opportunity.AttendanceMode);
                        sb.Append("\n" + courseStructure.Opportunity.AttendancePattern);
                        sb.Append("\n" + courseStructure.Opportunity.StartDate.Item);
                        sb.Append("\n" + courseStructure.Opportunity.Duration.DurationValue);
                        sb.Append("\n" + courseStructure.Opportunity.Duration.DurationUnit);
                        sb.Append("\n" + courseStructure.Opportunity.Duration.DurationDescription);

                        if (courseStructure.Opportunity.Item.GetType() == typeof(VenueInfo))
                        {
                            VenueInfo venue = (VenueInfo)courseStructure.Opportunity.Item;
                            sb.Append("\n" + venue.VenueName);
                            sb.Append("\n" + venue.Distance);
                            sb.Append("\n" + venue.VenueAddress.Address_line_1);
                            sb.Append("\n" + venue.VenueAddress.Address_line_2);
                            sb.Append("\n" + venue.VenueAddress.Town);
                            sb.Append("\n" + venue.VenueAddress.County);
                            sb.Append("\n" + venue.VenueAddress.PostCode);
                            sb.Append("\n" + venue.VenueAddress.Latitude);
                            sb.Append("\n" + venue.VenueAddress.Longitude);
                        }
                        else
                        {
                            sb.Append("\n" + (string)courseStructure.Opportunity.Item);
                        }

                        sb.Append("\n");
                    }
                }
                sb.Append("\n\n");

                sb.Append("Matching LDCS Details:");

                if (response.CourseListResponse.MatchingLDCS != null)
                {
                    foreach (CourseListResponseStructureMatchingLDCS mathcingLDCS in response.CourseListResponse.MatchingLDCS)
                    {
                        sb.Append("\n" + mathcingLDCS.LDCS.LDCSCode);
                        sb.Append("\n" + mathcingLDCS.LDCS.LDCSDesc);
                        sb.Append("\n" + mathcingLDCS.Counts);
                    }
                }
                sb.Append("\n\n");

                txtResult.Text = sb.ToString();
            }
            catch (Exception ex)
            {
                txtResult.Text = ex.Message;
            }
        }
        public void GetCourseSearchInputTest(string courseName, CourseSearchProperties courseSearchProperties, CourseListInput expectedCourseListInput)
        {
            // Assign
            var buildTribalMessageService = new BuildTribalMessageService(fakeConvertTribalCodesService, fakeConfiguration);

            //Act
            var result = buildTribalMessageService.GetCourseSearchInput(courseName, courseSearchProperties);

            //Assert
            result.Should().BeEquivalentTo(expectedCourseListInput);
            A.CallTo(() => fakeConvertTribalCodesService.GetTribalAttendanceModes(A <string> ._)).MustHaveHappened();
            A.CallTo(() => fakeConvertTribalCodesService.GetTribalAttendancePatterns(A <string> ._)).MustHaveHappened();
            A.CallTo(() => fakeConvertTribalCodesService.GetTribalStudyModes(A <string> ._)).MustHaveHappened();
            A.CallTo(() => fakeConfiguration.GetConfig <string>(A <string> ._)).MustHaveHappened(1, Times.Exactly);
        }