/// <summary> /// A method that obtains red list information. /// </summary> /// <param name="userContext">User context.</param> private void LoadRedListInformation(IUserContext userContext) { ISpeciesFactSearchCriteria searchCriteria; SpeciesFactList speciesFacts; if (_organismGroupName.IsNull()) { _organismGroupName = String.Empty; _redlistCategoryName = String.Empty; _redlistCategoryShortString = String.Empty; _redlistCriteria = String.Empty; searchCriteria = new SpeciesFactSearchCriteria(); searchCriteria.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.RedlistCategory)); searchCriteria.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.RedlistCriteriaString)); searchCriteria.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Redlist_OrganismLabel1)); searchCriteria.Add(_period); searchCriteria.AddTaxon(_taxon); searchCriteria.IncludeNotValidHosts = true; searchCriteria.IncludeNotValidTaxa = true; speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, searchCriteria); if (speciesFacts.IsNotEmpty()) { foreach (ISpeciesFact speciesFact in speciesFacts) { switch (speciesFact.Factor.Id) { case (Int32)FactorId.RedlistCategory: if (speciesFact.HasField1) { _redlistCategoryName = speciesFact.Field1.EnumValue.OriginalLabel; _redlistCategoryName = _redlistCategoryName.Remove(_redlistCategoryName.Length - 5); } if (speciesFact.HasField4) { _redlistCategoryShortString = speciesFact.Field4.StringValue; } break; case (Int32)FactorId.RedlistCriteriaString: if (speciesFact.HasField4 && speciesFact.Field4.StringValue.IsNotEmpty()) { _redlistCriteria = speciesFact.Field4.StringValue.Trim(); } break; case (Int32)FactorId.Redlist_OrganismLabel1: if (speciesFact.MainField.HasValue) { _organismGroupName = speciesFact.MainField.EnumValue.OriginalLabel; } break; } } } } }
/// <summary> /// The get species facts. /// </summary> /// <param name="userContext"> /// The user context. /// </param> /// <param name="taxa"> /// The taxa. /// </param> /// <param name="factorIds"> /// The factor ids. /// </param> /// <param name="speciesFactList"> /// The species fact list. /// </param> /// <returns> /// The <see cref="Dictionary"/>. /// </returns> public static Dictionary <int, Dictionary <FactorId, SpeciesFact> > GetSpeciesFacts( IUserContext userContext, IEnumerable <ITaxon> taxa, IEnumerable <FactorId> factorIds, out SpeciesFactList speciesFactList) { var intFactorIds = new List <int>(factorIds.Select(factorId => (int)factorId)); FactorList factors = CoreData.FactorManager.GetFactors(userContext, intFactorIds); ISpeciesFactSearchCriteria speciesFactSearchCriteria = new SpeciesFactSearchCriteria(); IPeriod period = CoreData.FactorManager.GetCurrentPublicPeriod(userContext); speciesFactSearchCriteria.EnsureNoListsAreNull(); speciesFactSearchCriteria.IncludeNotValidHosts = true; speciesFactSearchCriteria.IncludeNotValidTaxa = true; speciesFactSearchCriteria.Add(period); speciesFactSearchCriteria.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext)); speciesFactSearchCriteria.Taxa = new TaxonList(); foreach (ITaxon taxon in taxa) { speciesFactSearchCriteria.Taxa.Add(taxon); } speciesFactSearchCriteria.Factors = new FactorList(); foreach (IFactor factor in factors) { speciesFactSearchCriteria.Factors.Add(factor); } speciesFactList = CoreData.SpeciesFactManager.GetSpeciesFacts(userContext, speciesFactSearchCriteria); //speciesFactList = CoreData.SpeciesFactManager.GetDyntaxaSpeciesFacts(userContext, speciesFactSearchCriteria); var dic = new Dictionary <int, Dictionary <FactorId, SpeciesFact> >(); foreach (SpeciesFact speciesFact in speciesFactList) { var factorId = (FactorId)speciesFact.Factor.Id; if (!dic.ContainsKey(speciesFact.Taxon.Id)) { dic.Add(speciesFact.Taxon.Id, new Dictionary <FactorId, SpeciesFact>()); } if (!dic[speciesFact.Taxon.Id].ContainsKey(factorId)) { dic[speciesFact.Taxon.Id].Add(factorId, speciesFact); } } return(dic); }
public void Merge() { Int32 count; ISpeciesFactSearchCriteria searchCriteria; SpeciesFactList speciesFacts; // Get species fact list with species facts. searchCriteria = new SpeciesFactSearchCriteria(); searchCriteria.IncludeNotValidHosts = true; searchCriteria.IncludeNotValidTaxa = true; searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.ActionPlan)); speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(GetUserContext(), searchCriteria); Assert.IsTrue(speciesFacts.IsNotEmpty()); // Merge species fact that already are in the list. count = speciesFacts.Count; speciesFacts.Merge(GetUserContext(), speciesFacts[0].Taxon, speciesFacts[0].IndividualCategory, speciesFacts[0].Factor, speciesFacts[0].Host, speciesFacts[0].Period); Assert.AreEqual(count, speciesFacts.Count); // Merge species fact that is not in the list. count = speciesFacts.Count; speciesFacts.Merge(GetUserContext(), speciesFacts[0].Taxon, speciesFacts[0].IndividualCategory, CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.SwedishHistory), speciesFacts[0].Host, speciesFacts[0].Period); Assert.AreEqual(count, speciesFacts.Count - 1); }
public void GetSpeciesFactsBySearchCriteriaForestAgency() { SpeciesFactList speciesFacts; ISpeciesFactSearchCriteria searchCriteria; String text; // This test currently only works in production. searchCriteria = new SpeciesFactSearchCriteria(); searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2682)); // Ekologi searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2683)); // Naturvård searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 2684)); // Trädslag searchCriteria.Add(CoreData.FactorManager.GetDefaultIndividualCategory(GetUserContext())); searchCriteria.AddTaxon(CoreData.TaxonManager.GetTaxon(GetUserContext(), 256840)); speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(GetUserContext(), searchCriteria); RemoveSpeciesFactsWithBadQuality(speciesFacts); Assert.IsTrue(speciesFacts.IsNotEmpty()); text = speciesFacts[0].MainField.GetString(); Assert.IsTrue(text.IsNotEmpty()); }
public void RemoveSpeciesFactsWithBadQuality() { Int32 countWithBadQuality, countWithoutBadQuality; SpeciesFactList speciesFacts; ISpeciesFactSearchCriteria searchCriteria; searchCriteria = new SpeciesFactSearchCriteria(); searchCriteria.Add(CoreData.FactorManager.GetFactor(GetUserContext(), 779)); speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(GetUserContext(), searchCriteria); Assert.IsTrue(speciesFacts.IsNotEmpty()); countWithBadQuality = speciesFacts.Count; speciesFacts.RemoveSpeciesFactsWithBadQuality(); Assert.IsTrue(speciesFacts.IsNotEmpty()); countWithoutBadQuality = speciesFacts.Count; Assert.IsTrue(countWithoutBadQuality < countWithBadQuality); }
/// <summary> /// Retrieves information about the specified taxon. /// </summary> /// <param name="taxonId">Id of the taxon.</param> /// <returns>Information about the specified taxon.</returns> public TaxonSpeciesFactViewModel GetTaxonSpeciesFact(int taxonId) { mTaxon = CoreData.TaxonManager.GetTaxon(mUserContext, taxonId); mTaxonSpeciesFact = new TaxonSpeciesFactViewModel(mUserContext, mTaxon); IIndividualCategory individualCategory = CoreData.FactorManager.GetDefaultIndividualCategory(mUserContext); IPeriod period = CoreData.FactorManager.GetCurrentRedListPeriod(mUserContext); PeriodList periods = CoreData.FactorManager.GetPublicPeriods(mUserContext); IFactor categoryFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.RedlistCategory); IFactor criteriaDocumentationFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.RedlistCriteriaDocumentation); IFactor criteriaFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.RedlistCriteriaString); IFactor globalCategoryFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.GlobalRedlistCategory); //FactorList landscapeTypesFactors = LandscapeTypeCache.GetFactors(mUserContext); //FactorList lifeFormFactors = LifeFormCache.GetFactors(mUserContext); FactorList conventionFactors = CoreData.FactorManager.GetFactorTree(mUserContext, FactorId.Conventions).GetAllLeafFactors(); IFactor organismGroup1Factor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.Redlist_OrganismLabel1); IFactor organismGroup2Factor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.Redlist_OrganismLabel2); //FactorList countyOccurrenceFactors = CountyOccurrenceCache.GetFactors(mUserContext); //FactorList biotopeFactors = BiotopeCache.GetFactors(mUserContext); //FactorList substrateFactors = SubstrateCache.GetFactors(mUserContext); //FactorList impactFactors = ImpactCache.GetFactors(mUserContext); IFactor actionPlanFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.ActionPlan); IFactor protectedByLawFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.ProtectedByLaw); IFactor swedishOccurrenceFactor = CoreData.FactorManager.GetFactor(mUserContext, FactorId.SwedishOccurrence); //FactorList hostFactors = HostCache.GetFactors(mUserContext); // Get species facts. var countyOccurrenceSpeciesFacts = new SpeciesFactList(); var landscapeTypeSpeciesFacts = new SpeciesFactList(); var biotopeSpeciesFacts = new SpeciesFactList(); var lifeFormSpeciesFacts = new SpeciesFactList(); var conventionSpeciesFacts = new SpeciesFactList(); var previouslyCategorySpeciesFact = new SpeciesFactList(); ISpeciesFact categorySpeciesFact = null; ISpeciesFact criteriaDocumentationSpeciesFact = null; ISpeciesFact criteriaSpeciesFact = null; ISpeciesFact globalCategorySpeciesFact = null; ISpeciesFact organismGroup1SpeciesFact = null; ISpeciesFact organismGroup2SpeciesFact = null; var substrateSpeciesFacts = new SpeciesFactList(); var impactSpeciesFacts = new SpeciesFactList(); ISpeciesFact actionPlanSpeciesFact = null; ISpeciesFact protectedByLawSpeciesFact = null; ISpeciesFact swedishOccurrenceSpeciesFact = null; var hostSpeciesFacts = new SpeciesFactList(); ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria { Factors = new FactorList() }; searchCriteria.AddTaxon(mTaxon); searchCriteria.Add(individualCategory); foreach (IPeriod tempPeriod in periods) { searchCriteria.Add(tempPeriod); } // Add current period if not exist. bool currentPeriodExist = periods.Any(tempPeriod => tempPeriod.Id == period.Id); if (!currentPeriodExist) { searchCriteria.Add(period); } searchCriteria.Add(categoryFactor); searchCriteria.Add(criteriaDocumentationFactor); searchCriteria.Add(criteriaFactor); searchCriteria.Add(globalCategoryFactor); //searchCriteria.Factors.AddRange(landscapeTypesFactors); //searchCriteria.Factors.AddRange(lifeFormFactors); searchCriteria.Factors.AddRange(conventionFactors); searchCriteria.Add(organismGroup1Factor); searchCriteria.Add(organismGroup2Factor); //searchCriteria.Factors.AddRange(countyOccurrenceFactors); //searchCriteria.Factors.AddRange(biotopeFactors); //searchCriteria.Factors.AddRange(substrateFactors); //searchCriteria.Factors.AddRange(impactFactors); searchCriteria.Add(actionPlanFactor); searchCriteria.Add(protectedByLawFactor); searchCriteria.Add(swedishOccurrenceFactor); //searchCriteria.Factors.AddRange(hostFactors); SpeciesFactList speciesFacts = CoreData.SpeciesFactManager.GetSpeciesFacts(mUserContext, searchCriteria); // Split species facts into information groups. if (speciesFacts.IsNotEmpty()) { foreach (ISpeciesFact speciesFact in speciesFacts) { //if (countyOccurrenceFactors.Exists(speciesFact.Factor)) //{ // countyOccurrenceSpeciesFacts.Add(speciesFact); //} //else if (landscapeTypesFactors.Exists(speciesFact.Factor)) //{ // landscapeTypeSpeciesFacts.Add(speciesFact); //} //else if (biotopeFactors.Exists(speciesFact.Factor)) //{ // biotopeSpeciesFacts.Add(speciesFact); //} //else if (substrateFactors.Exists(speciesFact.Factor)) //{ // substrateSpeciesFacts.Add(speciesFact); // if (hostFactors.Exists(speciesFact.Factor)) // { // hostSpeciesFacts.Add(speciesFact); // } //} //else if (impactFactors.Exists(speciesFact.Factor)) //{ // impactSpeciesFacts.Add(speciesFact); //} //else if (lifeFormFactors.Exists(speciesFact.Factor)) //{ // lifeFormSpeciesFacts.Add(speciesFact); //} if (conventionFactors.Exists(speciesFact.Factor)) { conventionSpeciesFacts.Add(speciesFact); } else if (speciesFact.Factor.Id == (int)FactorId.RedlistCategory && speciesFact.Period.Id != period.Id) { previouslyCategorySpeciesFact.Add(speciesFact); } else { switch (speciesFact.Factor.Id) { case (int)FactorId.ActionPlan: actionPlanSpeciesFact = speciesFact; break; case (int)FactorId.GlobalRedlistCategory: globalCategorySpeciesFact = speciesFact; break; case (int)FactorId.ProtectedByLaw: protectedByLawSpeciesFact = speciesFact; break; case (int)FactorId.RedlistCategory: categorySpeciesFact = speciesFact; break; case (int)FactorId.RedlistCriteriaDocumentation: criteriaDocumentationSpeciesFact = speciesFact; break; case (int)FactorId.RedlistCriteriaString: criteriaSpeciesFact = speciesFact; break; case (int)FactorId.Redlist_OrganismLabel1: organismGroup1SpeciesFact = speciesFact; break; case (int)FactorId.Redlist_OrganismLabel2: organismGroup2SpeciesFact = speciesFact; break; case (int)FactorId.SwedishOccurrence: swedishOccurrenceSpeciesFact = speciesFact; break; } } } } //mTaxonSpeciesFact.InitCountyOccurrenceInformation(countyOccurrenceSpeciesFacts); //mTaxonSpeciesFact.InitLandscapeTypeInformation(landscapeTypeSpeciesFacts); //mTaxonSpeciesFact.InitBiotopeInformation(biotopeSpeciesFacts); //mTaxonSpeciesFact.InitLifeFormInformation(lifeFormSpeciesFacts); //mTaxonSpeciesFact.InitConventionInformation(conventionSpeciesFacts); InitRedListInformation( mTaxonSpeciesFact, categorySpeciesFact, criteriaSpeciesFact, criteriaDocumentationSpeciesFact, globalCategorySpeciesFact, period); //mTaxonSpeciesFact.InitOrganismGroupInformation(organismGroup1SpeciesFact, // organismGroup2SpeciesFact); //mTaxonSpeciesFact.InitSubstrateInformation(substrateSpeciesFacts); //mTaxonSpeciesFact.InitImpactInformation(impactSpeciesFacts); //mTaxonSpeciesFact.InitActionPlanInformation(actionPlanSpeciesFact); //mTaxonSpeciesFact.InitProtectedByLawInformation(protectedByLawSpeciesFact); //mTaxonSpeciesFact.InitHostInformation(hostSpeciesFacts, mUserContext); //mTaxonSpeciesFact.InitSwedishOccurrenceInformation(swedishOccurrenceSpeciesFact); //mTaxonSpeciesFact.InitPreviouslyRedListedCategories(previouslyCategorySpeciesFact); //GetSpeciesInformationDocument(); //long pictureId; //mTaxonSpeciesFact.HasImage = !string.IsNullOrWhiteSpace(GetPictureByTaxon(mTaxon, // AppSettings.Default.PictureXtraLargeHeight, // AppSettings.Default.PictureXtraLargeWidth, // AppSettings.Default.PictureLargeSize, // true, // string.Empty, // out pictureId)); //mTaxonSpeciesFact.ImageMetaData = GetPictureMetadataByPictureId(pictureId); //mTaxonSpeciesFact.HasCountyMap = GetCountyMap(mTaxon) != null; //mTaxonSpeciesFact.HasObservationMap = SpeciesFilter.IsTaxaSpeciesOrBelow(mTaxon) && // SpeciesFactCacheManager.Instance.GetObservationMap(mTaxon.Id.ToString(CultureInfo.InvariantCulture)) != null; mTaxonSpeciesFact.HasSpeciesFacts = HasSpeciesFacts(speciesFacts); mTaxonSpeciesFact.IsValid = CheckIfTaxonValid(); //mTaxonSpeciesFact.Synonyms = mTaxon.GetSynonymsViewModel(mUserContext); // Identify higher level taxa //mTaxonSpeciesFact.CategoryNameHighLevel = SpeciesFilter.IsTaxaSpeciesOrBelow(mTaxon) ? "" : mTaxon.Category.Name + " - "; //// Ignore if not higher taxa //if ((mTaxonSpeciesFact.IsHigherTaxa = !SpeciesFilter.IsTaxaSpeciesOrBelow(mTaxon)) == false) //{ // return mTaxonSpeciesFact; //} // Count all occurences for each category in underlying taxa //var taxonNameSearchInformation = TaxonNameSearchManager.Instance.GetInformation(this.mTaxon.Id); //foreach (var category in RedListedHelper.GetAllRedListCategories()) //{ // mTaxonSpeciesFact.RedListCategoryTaxa[category] = new List<int>(); //} //foreach (var taxonInfoType in taxonNameSearchInformation.AllChildTaxaIdsInScope) //{ // if (SpeciesFilter.IsTaxaSpeciesOrBelow(taxonInfoType.CategoryId, taxonInfoType.ParentCategoryId) && taxonInfoType.HasValidRedListCategory) // { // mTaxonSpeciesFact.RedListCategoryTaxa[taxonInfoType.RedListCategoryId].Add(taxonInfoType.TaxonId); // } //} return(mTaxonSpeciesFact); }