/// <summary>
        /// Convert a list of WebSpeciesFact instances
        /// to a SpeciesFactList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFacts">List of WebSpeciesFact instances.</param>
        /// <returns>List of SpeciesFact instances.</returns>
        protected override SpeciesFactList GetSpeciesFacts(
            IUserContext userContext,
            List <WebSpeciesFact> webSpeciesFacts)
        {
            SpeciesFactList        speciesFacts;
            FactorList             factors = CoreData.FactorManager.GetFactors(userContext);
            IndividualCategoryList individualCategories = CoreData.FactorManager.GetIndividualCategories(userContext);
            PeriodList             periods = CoreData.FactorManager.GetPeriods(userContext);

            speciesFacts = null;
            if (webSpeciesFacts.IsNotEmpty())
            {
                speciesFacts = new SpeciesFactList();
                foreach (WebSpeciesFact webSpeciesFact in webSpeciesFacts)
                {
                    if (webSpeciesFact.QualityId <= (int)SpeciesFactQualityId.Acceptable)
                    {
                        speciesFacts.Add(GetSpeciesFact(webSpeciesFact, factors, individualCategories, periods));
                    }
                    // else: Bad quality, do not use this species fact.
                }
            }

            return(speciesFacts);
        }
Exemple #2
0
        /// <summary>
        /// Convert a list of WebSpeciesFact instances
        /// to a SpeciesFactList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webSpeciesFacts">List of WebSpeciesFact instances.</param>
        /// <returns>List of SpeciesFact instances.</returns>
        protected virtual SpeciesFactList GetSpeciesFacts(IUserContext userContext, List <WebSpeciesFact> webSpeciesFacts)
        {
            SpeciesFactList        speciesFacts;
            FactorList             factors = CoreData.FactorManager.GetFactors(userContext);
            IndividualCategoryList individualCategories = CoreData.FactorManager.GetIndividualCategories(userContext);
            PeriodList             periods = CoreData.FactorManager.GetPeriods(userContext);
            ReferenceList          references;
            SpeciesFactQualityList speciesFactQualities = CoreData.SpeciesFactManager.GetSpeciesFactQualities(userContext);
            List <Int32>           referenceIds, taxonIds;
            TaxonList taxa;

            speciesFacts = null;
            if (webSpeciesFacts.IsNotEmpty())
            {
                referenceIds = GetReferenceIds(webSpeciesFacts);
                references   = CoreData.ReferenceManager.GetReferences(userContext, referenceIds);
                taxonIds     = GetTaxonIds(webSpeciesFacts);
                taxa         = CoreData.TaxonManager.GetTaxa(userContext, taxonIds);
                speciesFacts = new SpeciesFactList();
                foreach (WebSpeciesFact webSpeciesFact in webSpeciesFacts)
                {
                    speciesFacts.Add(GetSpeciesFact(userContext, webSpeciesFact, factors, individualCategories, periods, references, speciesFactQualities, taxa));
                }
            }

            return(speciesFacts);
        }
 /// <summary>
 /// Expands a Species Fact List with empty species facts so that every combination from the user parameter selection is represented.
 /// Factor Headers are excluded.
 /// Periodic factors are not expanded to individual categories other than the default.
 /// </summary>
 /// <param name="userContext">The user context.</param>
 /// <param name="taxon">Taxon object of the species fact.</param>
 /// <param name="individualCategory">Individual category object of the species fact.</param>
 /// <param name="factor">Factor object of the species fact.</param>
 /// <param name="host">Host taxon object of the species fact.</param>
 /// <param name="period">Period object of the species fact.</param>
 /// <param name="speciesFacts">Species fact list to be expanded.</param>
 private static void ExpandSpeciesFactListWithEmptySpeciesFact(
     IUserContext userContext,
     ITaxon taxon,
     IIndividualCategory individualCategory,
     IFactor factor,
     ITaxon host,
     IPeriod period,
     SpeciesFactList speciesFacts)
 {
     if (!speciesFacts.Exists(CoreData.SpeciesFactManager.GetSpeciesFactIdentifier(
                                  taxon,
                                  individualCategory,
                                  factor,
                                  host,
                                  period)))
     {
         speciesFacts.Add(CoreData.SpeciesFactManager.GetSpeciesFact(
                              userContext,
                              taxon,
                              individualCategory,
                              factor,
                              host,
                              period));
     }
 }
        /// <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);
        }
Exemple #5
0
        /// <summary>
        /// Bind species fact to related member.
        /// </summary>
        private void SetParagraphSpeciesFacts()
        {
            SpeciesFactList speciesFacts;

            if (_speciesFacts.IsNotEmpty())
            {
                speciesFacts = new SpeciesFactList();
                foreach (ISpeciesFact speciesFact in _speciesFacts)
                {
                    switch (speciesFact.Factor.Id)
                    {
                    case (Int32)FactorId.SpeciesInformationDocumentTaxonomicInformation:
                        speciesFacts.Add(speciesFact);
                        _taxonomicParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentDescription:
                        speciesFacts.Add(speciesFact);
                        _descriptionParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentDistribution:
                        speciesFacts.Add(speciesFact);
                        _distributionParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentEcology:
                        speciesFacts.Add(speciesFact);
                        _ecologyParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentThreats:
                        speciesFacts.Add(speciesFact);
                        _threatsParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentMeasures:
                        speciesFacts.Add(speciesFact);
                        _measuresParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentExtra:
                        speciesFacts.Add(speciesFact);
                        _extraParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentPreamble:
                        speciesFacts.Add(speciesFact);
                        _preambleParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentReferences:
                        speciesFacts.Add(speciesFact);
                        _referencesParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentAuthorAndYear:
                        speciesFacts.Add(speciesFact);
                        _authorParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentItalicsInReferences:
                        speciesFacts.Add(speciesFact);
                        _italicsInReferencesParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentItalicsInText:
                        speciesFacts.Add(speciesFact);
                        _italicsInTextParagraphSpeciesFact = speciesFact;
                        break;

                    case (Int32)FactorId.SpeciesInformationDocumentIsPublishable:
                        speciesFacts.Add(speciesFact);
                        _isPublishable = speciesFact;
                        break;
                    }
                }

                // Make sure that only species facts that belong
                // to this SpeciesInformationDocument is handled.
                _speciesFacts = speciesFacts;
            }
        }