Пример #1
0
        /// <summary>
        /// Initializes the CTSManager and Parses the Query Params
        /// </summary>
        protected override void Init()
        {
            base.Init();

            ParsedReqUrlParams = new NciUrl(true, true, true);  //We need this to be lowercase and collapse duplicate params. (Or not use an NCI URL)
            ParsedReqUrlParams.SetUrl(this.Request.Url.Query);

            //////////////////////////////
            // Create an instance of a BasicCTSManager.
            ClinicalTrialsAPIClient apiClient = APIClientHelper.GetV1ClientInstance();

            CTSManager = new BasicCTSManager(apiClient);

            /////////////////////////////
            // Parse the Query to get the search params.
            try
            {
                // Get mapping file names from configuration
                TrialTermLookupConfig mappingConfig = new TrialTermLookupConfig();
                mappingConfig.MappingFiles.AddRange(Config.MappingFiles.Select(fp => HttpContext.Current.Server.MapPath(fp)));

                CTSSearchParamFactory factory = new CTSSearchParamFactory(new TrialTermLookupService(mappingConfig, apiClient), new ZipCodeGeoLookup());
                SearchParams = factory.Create(ParsedReqUrlParams);
            }
            catch (Exception ex)
            {
                log.Error("could not parse the CTS search parameters", ex);
                throw ex;
            }

            ///////////////////////////
            // Parse the page specific parameters
            if (IsInUrl(ParsedReqUrlParams, "pn"))
            {
                this._pageNum = ParsedReqUrlParams.CTSParamAsInt("pn", 1);
            }

            _itemsPerPage = Config.DefaultItemsPerPage;
            if (IsInUrl(ParsedReqUrlParams, "ni"))
            {
                this._itemsPerPage = ParsedReqUrlParams.CTSParamAsInt("ni", _itemsPerPage);
            }
        }
        protected sealed override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.LoadConfig();

            //This is referenced by the listing page templates.  Those templates
            //should be updated to reference the Page Number directly.
            this.SearchParams = new VelocitySearchParams(this);

            //Set our default items per page based on the config
            _itemsPerPage = this.GetItemsPerPage();

            //Using NciUrl for handling parameters instead of raw URL query
            //This is mainly for pagination
            ParsedReqUrlParams = new NciUrl(true, true, true);  //We need this to be lowercase and collapse duplicate params. (Or not use an NCI URL)
            ParsedReqUrlParams.SetUrl(this.Request.Url.Query);

            _basicCTSManager = new BasicCTSManager(APIClientHelper.GetV1ClientInstance());
        }
        /// <summary>
        /// CTSSearchParams -> filterCriterea mapping tests
        /// </summary>
        /// <param name="searchParams">An instance of a CTSSearchParams object</param>
        /// <param name="expectedCriteria">The expected criteria for the search</param>
        private void MappingTest(CTSSearchParams searchParams, Dictionary <string, object> expectedCriteria)
        {
            Dictionary <string, object> actualCriteria = null;

            //When search gets called trap the criteria and set the actualCriteria
            var mockClient = GetClientMock(
                (filterCriteria, size, from, include, exclude) => actualCriteria = filterCriteria,
                new ClinicalTrialsCollection()
            {
                TotalResults = 0, Trials = new ClinicalTrial[] { }
            }
                );

            //Create a new instance of the factory, passing in the Mock's version of an implementation
            //of our IClinicalTrialsAPIClient interface.
            BasicCTSManager manager = new BasicCTSManager(mockClient.Object);

            //Get the results of parsing the URL
            ClinicalTrialsCollection returnedCol = manager.Search(searchParams);

            //Test the actual result to the expected.  NOTE: If you add fields to the CTSSearchParams, you need
            //to also modify the comparer
            Assert.Equal(expectedCriteria, actualCriteria);
        }
        /// <summary>
        /// Create a collection of URL elements from a CSV file of dictionary entries
        /// </summary>
        /// <returns>SitemapUrlSet</returns>
        public override SitemapUrlSet GetSitemapUrls(string sitemapName)
        {
            List <SitemapUrl> sitemapUrls = new List <SitemapUrl>();

            _config = BasicCTSPageInfo.GetConfig();

            if (_config == null)
            {
                log.Error("Unable to read CTSPageInfo config file.");
                throw new Exception();
            }

            string path = _config.SitemapStore;

            if (path != null)
            {
                String file = HttpContext.Current.Server.MapPath(path);

                List <string> trialIDs    = new List <string>();
                List <string> validTrials = null;

                try
                {
                    using (StreamReader sr = new StreamReader(file))
                    {
                        string currentLine;
                        // currentLine will be null when the StreamReader reaches the end of file
                        while ((currentLine = sr.ReadLine()) != null)
                        {
                            if (currentLine.Length > 0)
                            {
                                trialIDs.Add(currentLine);
                            }
                            else
                            {
                                log.ErrorFormat("Error in clinical trials sitemap file {0} for line {1} : invalid syntax.", file, currentLine);
                                continue;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    log.ErrorFormat("Error in ClinicalTrialsSitemapUrlStore: unable to read dictionary sitemap file located at {0}.", file);
                    return(new SitemapUrlSet());
                }

                try
                {
                    BasicCTSManager _basicCTSManager = new BasicCTSManager(APIClientHelper.GetV1ClientInstance());

                    validTrials = _basicCTSManager.GetActiveTrialIDs(trialIDs).ToList();
                }
                catch
                {
                    log.ErrorFormat("Error in clinical trials sitemap file {0} : invalid clinical trial IDs", file);
                    return(new SitemapUrlSet());
                }

                if (validTrials != null)
                {
                    foreach (string ID in validTrials)
                    {
                        string entryUrl = GetSitemapUrl(ID);
                        double priority = 0.5;

                        sitemapUrls.Add(new SitemapUrl(entryUrl, sitemapChangeFreq.weekly, priority));
                    }
                }

                return(new SitemapUrlSet(sitemapUrls));
            }
            else
            {
                log.ErrorFormat("Could not load clinical trials provider file located at {0}.", path);
                return(new SitemapUrlSet());
            }
        }