/// <summary> /// Get ids for taxa that matches search criteria. /// </summary> /// <param name="searchCriteria">Red list category search criteria.</param> /// <param name="taxonIds">If not null, limit search to these taxa.</param> /// <returns>Ids for taxa that matches search criteria.</returns> public TaxonIdList GetTaxonIds(List <int> searchCriteria, TaxonIdList taxonIds) { int index; TaxonIdList categoryTaxonIds; if (searchCriteria.IsEmpty() || (taxonIds.IsNotNull() && taxonIds.IsEmpty())) { // No taxa matches search critera and taxa limitations. return(new TaxonIdList()); } // Get all taxon ids that matches search criteria. categoryTaxonIds = this.mCategories[(RedListCategory)searchCriteria[0]].Clone(); for (index = 1; index < searchCriteria.Count; index++) { categoryTaxonIds.AddRange(this.mCategories[(RedListCategory)searchCriteria[index]]); } if (taxonIds.IsEmpty()) { taxonIds = categoryTaxonIds; } else { // Limit returned taxa. taxonIds.Subset(categoryTaxonIds); } return(taxonIds); }
/// <summary> /// Get ids for taxa that matches search criteria. /// </summary> /// <param name="analysisManager">Analysis manager.</param> /// <param name="searchCriteria">Analysis search critera.</param> /// <param name="taxonIds"> /// Limit search to these taxa. /// This parameter is ignored if value is null. /// </param> /// <returns>Ids for taxa that matches search criteria.</returns> public static TaxonIdList GetTaxonIds( this IAnalysisManager analysisManager, AnalysisSearchCriteria searchCriteria, TaxonIdList taxonIds) { return(mCache.GetTaxonIds(searchCriteria, taxonIds)); }
/// <summary> /// Get a copy of this taxon id list. /// </summary> /// <returns>A copy of this taxon id list.</returns> public TaxonIdList Clone() { TaxonIdList taxa; taxa = new TaxonIdList(); taxa.AddRange(this); return(taxa); }
/// <summary> /// Get ids for taxa that matches search criteria. /// </summary> /// <param name="analysisManager">Analysis manager.</param> /// <param name="searchCriteria">Analysis search critera.</param> /// <param name="taxa"> /// Limit search to these taxa. /// This parameter is ignored if value is null. /// </param> /// <returns>Ids for taxa that matches search criteria.</returns> public static TaxonIdList GetTaxonIds( this IAnalysisManager analysisManager, AnalysisSearchCriteria searchCriteria, TaxonList taxa) { TaxonIdList taxonIds = null; if (taxa.IsNotNull()) { taxonIds = new TaxonIdList(); taxonIds.Merge(taxa); } return(mCache.GetTaxonIds(searchCriteria, taxonIds)); }
/// <summary> /// Get taxon list information about specified taxa. /// Returned list has the same order as the input taxon list. /// </summary> /// <param name="taxonIds">Taxon ids.</param> /// <param name="useNonCategorizedTaxaIdOnly">Indicates if filtering on only data without category 743 is to be returned.</param> /// <param name="selectedCategories">Selected categories.</param> /// <returns>Taxon list information about specified taxa.</returns> public List <TaxonListInformation> GetTaxonListInformation( TaxonIdList taxonIds, bool useNonCategorizedTaxaIdOnly, IList <RedListCategoryItemViewModel> selectedCategories) { if (!mIsInitialized) { throw new Exception("TaxonListInformation cache is not initialized"); } var taxonListInformation = new List <TaxonListInformation>(); if (taxonIds.IsNotEmpty()) { CheckCachedInformation(taxonIds); foreach (ITaxonId taxonId in taxonIds) { TaxonListInformation taxonInfo = TaxonInformationCache.TaxonInformation[taxonId.Id]; // Check if only non categorized taxa are to be shown. if (useNonCategorizedTaxaIdOnly) { bool taxonFound = selectedCategories.Any(category => category.OrderNumber == taxonInfo.RedListCategoryId); // First we check if taxon is beloning to a selected category if so add this taxon. if (taxonFound) { taxonListInformation.Add(taxonInfo); } else if (!taxonInfo.IsRedListed && !taxonInfo.IsRedListedEnsured) { // Not add taxon since it is ensured or redlisted and selected catgories is not choosen // This option is needed to select taxon which is not redlisted or ensured. These taxa should not be added. // This selcetion is keept for debugging purposes. // Only non categorized species are used here taxonListInformation.Add(taxonInfo); } } else { taxonListInformation.Add(taxonInfo); } } } return(taxonListInformation); }
/// <summary> /// Check that taxon list information about specified taxa has been fetched in the cache. /// Cache the information if it is not cached. /// </summary> /// <param name="taxonIds">Taxon ids.</param> private void CheckCachedInformation(IEnumerable <ITaxonId> taxonIds) { var notCachedTaxa = new TaxonIdList(); foreach (ITaxonId taxonId in taxonIds) { if (!mTaxonInformationCache.TaxonInformation.ContainsKey(taxonId.Id)) { notCachedTaxa.Add(taxonId); } } if (notCachedTaxa.IsNotEmpty()) { LoadTaxonListInformation(notCachedTaxa); } }
///// <summary> ///// Get search criteria view model from database or cache. ///// </summary> ///// <returns>View model.</returns> //public SearchViewModel GetSearchViewModel() //{ // // If values are stored in session, update current values // SearchViewModel searchViewModelFromSession = GetSearchViewModelFromSession(); // if (searchViewModelFromSession.IsNull()) // { // searchViewModelFromSession = new SearchViewModel(); // } // var searchViewModel = new SearchViewModel(); // searchViewModel.InitSearchViewModel(mUserContext, searchViewModelFromSession); // searchViewModel.InitSwedishOccurrenceInformation(); // searchViewModel.InitBiotopeInformation(); // searchViewModel.InitCountyOccurrencesInformation(); // searchViewModel.InitThematicListInformation(); // searchViewModel.InitRedListCategories(); // searchViewModel.InitRedListTaxonCategories(); // searchViewModel.InitTaxonScope(); // searchViewModel.InitOrganismGroups(); // searchViewModel.InitLandscapeTypes(); // searchViewModel.InitSubstrate(); // searchViewModel.InitImpact(); // searchViewModel.InitLifeForms(); // searchViewModel.InitHost(); // return searchViewModel; //} /// <summary> /// Get list of taxon information by user selections. /// </summary> /// <param name="model">Search view model.</param> /// <param name="allTaxa"></param> /// <returns>List of taxon information.</returns> public List <TaxonListInformation> SearchTaxa(SearchViewModel model, List <int> allTaxa) { if (model == null) { return(null); } List <TaxonListInformation> taxonListInformations = null; if (allTaxa == null) { bool useNonCategorizedTaxaIdOnly; IList <RedListCategoryItemViewModel> selectedCategories; TaxonIdList taxonIds = GetTaxaBySearchCriteria( model, out useNonCategorizedTaxaIdOnly, out selectedCategories); taxonListInformations = TaxonListInformationManager.Instance.GetTaxonListInformation( taxonIds, useNonCategorizedTaxaIdOnly, selectedCategories); } else { var resList = new TaxonIdList(); foreach (var id in allTaxa) { resList.Add(new TaxonIdImplementation(id)); } taxonListInformations = TaxonListInformationManager.Instance.GetTaxonListInformation( resList, false, null); } return(taxonListInformations); }
/// <summary> /// Get ids for taxa that matches search criteria. /// </summary> /// <param name="searchCriteria">Analysis search criteria.</param> /// <param name="taxonIds"> /// Limit search to these taxon ids. /// This parameter is ignored if value is null. /// </param> /// <returns>Ids for taxa that matches search criteria.</returns> public TaxonIdList GetTaxonIds(AnalysisSearchCriteria searchCriteria, TaxonIdList taxonIds = null) { TaxonIdList tempTaxonIds; tempTaxonIds = null; if (taxonIds.IsNotNull()) { tempTaxonIds = new TaxonIdList(); tempTaxonIds.AddRange(taxonIds); } //if (searchCriteria.Biotopes.IsNotNull()) //{ // tempTaxonIds = Biotope.GetTaxonIds(searchCriteria.Biotopes, // tempTaxonIds); //} //if (searchCriteria.SwedishOccurrence.IsNotNull()) //{ // tempTaxonIds = SwedishOccurrence.GetTaxonIds(searchCriteria.SwedishOccurrence, // tempTaxonIds); //} //if (searchCriteria.CountyOccurrence.IsNotNull()) //{ // tempTaxonIds = CountyOccurrence.GetTaxonIds(searchCriteria.CountyOccurrence, // tempTaxonIds); //} //if (searchCriteria.Host.IsNotNull()) //{ // tempTaxonIds = Host.GetTaxonIds(searchCriteria.Host, // tempTaxonIds); //} //if (searchCriteria.Impact.IsNotNull()) //{ // tempTaxonIds = Impact.GetTaxonIds(searchCriteria.Impact, // tempTaxonIds); //} //if (searchCriteria.LandscapeTypes.IsNotNull()) //{ // tempTaxonIds = LandscapeType.GetTaxonIds(searchCriteria.LandscapeTypes, // tempTaxonIds); //} //if (searchCriteria.LifeForms.IsNotNull()) //{ // tempTaxonIds = LifeForm.GetTaxonIds(searchCriteria.LifeForms, // tempTaxonIds); //} //if (searchCriteria.OrganismGroups.IsNotNull()) //{ // tempTaxonIds = OrganismGroup.GetTaxonIds(searchCriteria.OrganismGroups, // tempTaxonIds); //} if (searchCriteria.RedListCategories.IsNotNull()) { tempTaxonIds = RedListCategory.GetTaxonIds(searchCriteria.RedListCategories, tempTaxonIds); } //if (searchCriteria.TaxonCategories.IsNotEmpty()) //{ // tempTaxonIds = TaxonScope.GetTaxonIds(searchCriteria.TaxonCategories, // tempTaxonIds); //} //else if (searchCriteria.TaxonScope.IsNotNull()) //{ // tempTaxonIds = TaxonScope.GetTaxonIds(searchCriteria.TaxonScope, // tempTaxonIds); //} //if (searchCriteria.Substrate.IsNotNull()) //{ // tempTaxonIds = Substrate.GetTaxonIds(searchCriteria.Substrate, // tempTaxonIds); //} //if (searchCriteria.ThematicLists.IsNotNull()) //{ // tempTaxonIds = ThematicLists.GetTaxonIds(searchCriteria.ThematicLists, // tempTaxonIds); //} return(tempTaxonIds); }
///// <summary> ///// Check dataselection and if only red listed is selected then check if taxa has factor 743/red listed. ///// Remove other taxa then from result depending on data selection LC/NE/NA taxa could be included or excluded. ///// </summary> ///// <param name="result"> ///// Result taxa list from taxa selection search. ///// </param> //private void RemoveTaxaNotRedlistedOrRedlistedEnsuredFromList(List<TaxonListInformation> result) //{ // // Make a copy of the list // var tempResult = new List<TaxonListInformation>(); // if (result.IsNotEmpty()) // { // tempResult.AddRange(result); // } // // Check dataselection and if only redlisted is selected then check if taxa has factor 743/redlisted and is not of type // // LC/NE/NA. Remove other taxa then from result. // if (SessionHandler.UseOnlyRedlistedData) // { // foreach (TaxonListInformation taxonListInformation in tempResult.Where(taxonListInformation => !taxonListInformation.IsRedListed)) // { // result.RemoveAll(x => x.Id == taxonListInformation.Id); // } // } //} /// <summary> /// Get taxa by user selections. /// </summary> /// <param name="model"> /// Search view model. /// </param> /// <param name="useNonCategorizedTaxaIdOnly"> /// Indicates if only taxa without category red listed (743) set. /// </param> /// <param name="selectedCategories"> returns selected categories to filter on if selection of non categorized data is choosen to be viewed.</param> /// <returns> /// List of taxon ids. /// </returns> private TaxonIdList GetTaxaBySearchCriteria(SearchViewModel model, out bool useNonCategorizedTaxaIdOnly, out IList <RedListCategoryItemViewModel> selectedCategories) { var searchCriteria = new AnalysisSearchCriteria(); bool onlyNonCategorizedTaxaIdUsed = false; useNonCategorizedTaxaIdOnly = false; selectedCategories = null; if (model.RedListCategories.IsNotEmpty()) { // Get number of selected selectedCategories = model.RedListCategories.Where(item => item.Selected).ToList(); const int NonCategorizedTaxaId = 1000; // Check if non categorizedtaxa is the selected then we have to get all taxa. if (model.RedListCategories.Any(redListCategory => (redListCategory.Id == NonCategorizedTaxaId) && redListCategory.Selected)) { onlyNonCategorizedTaxaIdUsed = true; useNonCategorizedTaxaIdOnly = true; } } if (!onlyNonCategorizedTaxaIdUsed) { searchCriteria.InitRedListCategories(model); } else { // Getting alla taxa for all categories; must filter below on data not categorized. searchCriteria.RedListCategories = null; } //// Red list taxon categories / (Arter/Småarter/Underarter) //searchCriteria.InitRedListTaxonCategories(model); //// Scope //searchCriteria.InitTaxonScope(model); //// Swedish occurrence //searchCriteria.InitSwedishOccurrenceInformation(model); //// Organism / Organismgrupp //searchCriteria.InitOrganismGroups(model); //// Landscape / Landskapstyp //searchCriteria.InitLandscapeTypes(model); //// County / Län //searchCriteria.InitCountyOccurrencesInformation(model); //// Biotope / Biotop //searchCriteria.InitBiotopeInformation(model); //// Substrate / Substrat //searchCriteria.InitSubstrate(model); //// Impact / Påverkan //searchCriteria.InitImpact(model); //// Lifeforms / Livsform //searchCriteria.InitLifeForms(model); //// Host / Värd //searchCriteria.InitHost(model); //// Thematic listing / Tematisk lista //searchCriteria.InitThematicListInformation(model); // Fetch the taxonids TaxonIdList taxonIds = CoreData.AnalysisManager.GetTaxonIds(searchCriteria); return(taxonIds); }