/// <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);
        }
 /// <summary>
 /// Checs whether or not SpeciesFacts exist.
 /// </summary>
 /// <param name="speciesFactList">
 /// SpeciesFact lists.
 /// </param>
 public bool HasSpeciesFacts(SpeciesFactList speciesFactList)
 {
     return(speciesFactList.IsNotEmpty());
 }
Exemple #3
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;
            }
        }