/// <summary>
        /// Create a RedListCategoryCache instance.
        /// </summary>
        public RedListCategoryCache()
        {
            mCategories        = new Dictionary <RedListCategory, TaxonIdList>();
            mTaxonIdCategories = new Dictionary <int, RedListCategory>();

            var categories = RedListedHelper.GetAllRedListCategories();

            foreach (var cat in categories)
            {
                this.mCategories[cat] = new TaxonIdList();
            }
        }
Example #2
0
 /// <summary>
 ///     Test if swedish occurence is specified in species fact.
 /// </summary>
 /// <param name="speciesFact">Species fact with swedish occurence information.</param>
 /// <returns>True if swedish occurence is specified.</returns>
 public static bool IsOldRedlistCategorySpecified(this ISpeciesFact speciesFact)
 {
     return(speciesFact.IsNotNull() && speciesFact.Field1.IsNotNull() && speciesFact.Field1.HasValue &&
            RedListedHelper.IsRedListedDdToNe(speciesFact.Field1.EnumValue.KeyInt) &&
            speciesFact.MainField.IsNotNull() && speciesFact.MainField.HasValue);
 }
Example #3
0
        /// <summary>
        /// Set species fact information about this taxon.
        /// </summary>
        /// <param name="speciesFact">Species fact with red list information.</param>
        public void SetSpeciesFact(ISpeciesFact speciesFact)
        {
            if (LandscapeTypeManager.LandscapeTypeFactors.IsNotNull() &&
                LandscapeTypeManager.LandscapeTypeFactors.Exists(speciesFact.Factor))
            {
                if (speciesFact.IsLandscapeTypeOccurrenceSpecified())
                {
                    string landscapeTypeOccurrence = speciesFact.Factor.Label;
                    landscapeTypeOccurrence = landscapeTypeOccurrence.Substring(landscapeTypeOccurrence.Length - 2, 1);
                    switch (speciesFact.MainField.EnumValue.KeyInt)
                    {
                    case (int)LandscapeTypeImportanceEnum.HasImportance:
                        LandscapeTypeOccurrence += landscapeTypeOccurrence.ToLower();
                        break;

                    case (int)LandscapeTypeImportanceEnum.VeryImportant:
                        LandscapeTypeOccurrence += landscapeTypeOccurrence.ToUpper();
                        break;
                    }
                }
            }
            else
            {
                switch (speciesFact.Factor.Id)
                {
                case (int)FactorId.RedlistCategory:
                    if (speciesFact.IsRedlistCategorySpecified())
                    {
                        RedListCategory = speciesFact.Field1.EnumValue.OriginalLabel.Substring(0, speciesFact.Field1.EnumValue.OriginalLabel.Length - 4) +
                                          "(" + speciesFact.MainField.StringValue + ")";
                        var category = (RedListCategory)Enum.Parse(typeof(RedListCategory), RedListCategory.Substring(RedListCategory.IndexOf("(", StringComparison.Ordinal) + 1, 2));
                        IsRedListed        = RedListedHelper.IsRedListedDdToNt((int)category);
                        IsRedListedEnsured = RedListedHelper.IsRedListedDdToNe((int)category);
                        RedListCategoryId  = Convert.ToInt32(speciesFact.Field1.EnumValue.KeyInt);
                    }

                    break;

                case (int)FactorId.RedlistCriteriaString:
                    if (speciesFact.IsRedlistCriteriaSpecified())
                    {
                        RedListCriteria = speciesFact.MainField.StringValue;
                    }

                    break;

                case (int)FactorId.Redlist_OrganismLabel1:
                    if (speciesFact.IsOrganismGroupSpecified())
                    {
                        if (OrganismGroup.IsEmpty())
                        {
                            OrganismGroup = speciesFact.MainField.EnumValue.OriginalLabel;
                        }
                        else
                        {
                            if (OrganismGroup != speciesFact.MainField.EnumValue.OriginalLabel)
                            {
                                OrganismGroup = speciesFact.MainField.EnumValue.OriginalLabel + ", " + OrganismGroup;
                            }
                        }
                    }

                    break;

                case (int)FactorId.SwedishOccurrence:
                    if (speciesFact.IsSwedishOccurrenceSpecified())
                    {
                        SwedishOccurrence   = speciesFact.MainField.EnumValue.OriginalLabel;
                        SwedishOccurrenceId = Convert.ToInt32(speciesFact.MainField.EnumValue.KeyInt);
                    }
                    break;
                }
            }
        }
        //public static void InitSwedishOccurrenceInformation(this SearchViewModel searchViewModel)
        //{
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.SwedishOccurrences.IsNotNull())
        //    {
        //        searchViewModel.IsSwedishOccurrenceEnabled = mSearchViewModelFromSession.IsSwedishOccurrenceEnabled;
        //        searchViewModel.SwedishOccurrenceTitle = mSearchViewModelFromSession.SwedishOccurrenceTitle;
        //        searchViewModel.SwedishOccurrences = mSearchViewModelFromSession.SwedishOccurrences;
        //    }
        //    else
        //    {
        //        searchViewModel.SwedishOccurrences = new List<RedListSwedishOccurrenceItemViewModel>();

        //        // Get swedish occurrence factor
        //        FactorList swedishOccurrenceFactors = SwedishOccurrenceCache.GetFactors(mUser);

        //        // Populate swedish occurrence
        //        foreach (var swedishOccurrenceFactor in swedishOccurrenceFactors)
        //        {
        //            foreach (var swedishOccurrenceItem in swedishOccurrenceFactor.DataType.Field1.Enum.Values)
        //            {
        //                // The level of swedish occurrence is defined in the appsettings
        //                if (swedishOccurrenceItem.KeyInt.HasValue && swedishOccurrenceItem.KeyInt.Value > AppSettings.Default.SwedishOccurrenceExist)
        //                {
        //                    var redListSwedishOccurrenceItemViewModel = new RedListSwedishOccurrenceItemViewModel
        //                    {
        //                        Id = swedishOccurrenceItem.KeyInt.Value,
        //                        Name = swedishOccurrenceItem.OriginalLabel,
        //                        Selected = true,
        //                    };
        //                    searchViewModel.SwedishOccurrences.Add(redListSwedishOccurrenceItemViewModel);
        //                }
        //            }
        //        }

        //        // Set swedish occurrences to true as default
        //        searchViewModel.IsSwedishOccurrenceEnabled = true;
        //    }
        //}

        ///// <summary>
        ///// Init Biotopes information.
        ///// </summary>
        ///// <param name="searchViewModel">Search criteria view model.</param>
        //public static void InitBiotopeInformation(this SearchViewModel searchViewModel)
        //{
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.Biotopes.IsNotNull())
        //    {
        //        searchViewModel.IsBiotopeEnabled = mSearchViewModelFromSession.IsBiotopeEnabled;
        //        searchViewModel.IsBiotopeImportant = mSearchViewModelFromSession.IsBiotopeImportant;
        //        searchViewModel.BiotopeOperator = mSearchViewModelFromSession.BiotopeOperator;
        //        searchViewModel.Biotopes = mSearchViewModelFromSession.Biotopes;
        //        searchViewModel.BiotopesTitle = mSearchViewModelFromSession.BiotopesTitle;
        //    }
        //    else
        //    {
        //        searchViewModel.Biotopes = new List<RedListBiotopeItemViewModel>();

        //        // Get superior factor for biotopes.
        //        IFactor superiorFactor = CoreData.FactorManager.GetFactor(mUser, FactorId.Biotopes);

        //        // Get biotope factors
        //        FactorList biotopeFactors = BiotopeCache.GetFactors(mUser);

        //        // Set title for biotopes, from factor.
        //        searchViewModel.BiotopesTitle = superiorFactor.Label;

        //        // Populate biotopes
        //        foreach (var biotopeFactor in biotopeFactors)
        //        {
        //            var redListBiotopeItemViewModel = new RedListBiotopeItemViewModel
        //            {
        //                Id = biotopeFactor.Id,
        //                Name = biotopeFactor.Name
        //            };

        //            searchViewModel.Biotopes.Add(redListBiotopeItemViewModel);
        //        }

        //        searchViewModel.BiotopeOperator = LogicalOperator.Or;
        //    }
        //}

        ///// <summary>
        ///// Init CountyOccurrences information.
        ///// </summary>
        ///// <param name="searchViewModel">Search criteria view model.</param>
        //public static void InitCountyOccurrencesInformation(this SearchViewModel searchViewModel)
        //{
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.CountyOccurrences.IsNotNull())
        //    {
        //        searchViewModel.IsCountyOccurrenceEnabled = mSearchViewModelFromSession.IsCountyOccurrenceEnabled;
        //        searchViewModel.CountyOccurrences = mSearchViewModelFromSession.CountyOccurrences;
        //        searchViewModel.CountyOccurrencesTitle = mSearchViewModelFromSession.CountyOccurrencesTitle;
        //    }
        //    else
        //    {
        //        searchViewModel.CountyOccurrences = new List<RedListCountyOccurrenceItemViewModel>();

        //        // Get superior factor, for county occurrence.
        //        IFactor superiorFactor = CoreData.FactorManager.GetFactor(mUser, FactorId.CountyOccurrence);

        //        // Get county occurrence factors
        //        FactorList countyOccurenceFactors = CountyOccurrenceCache.GetFactors(mUser);

        //        // Set title for county occurrence, from factor.
        //        searchViewModel.CountyOccurrencesTitle = superiorFactor.Label;

        //        // Populate county occurrence
        //        foreach (var countyOccurenceFactor in countyOccurenceFactors)
        //        {
        //            var redListCountyOccurrenceItemViewModel = new RedListCountyOccurrenceItemViewModel
        //            {
        //                Id = countyOccurenceFactor.Id,
        //                Name = countyOccurenceFactor.Name
        //            };

        //            searchViewModel.CountyOccurrences.Add(redListCountyOccurrenceItemViewModel);
        //        }
        //    }
        //}

        ///// <summary>
        ///// Init ThematicLists information.
        ///// </summary>
        ///// <param name="searchViewModel">Search criteria view model.</param>
        //public static void InitThematicListInformation(this SearchViewModel searchViewModel)
        //{
        //    searchViewModel.ThematicLists = new List<RedListThematicListItemViewModel>();
        //    if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.ThematicLists.IsNotNull())
        //    {
        //        searchViewModel.IsThematicListEnabled = mSearchViewModelFromSession.IsThematicListEnabled;
        //        searchViewModel.ThematicListOperator = mSearchViewModelFromSession.ThematicListOperator;
        //        searchViewModel.ThematicLists = mSearchViewModelFromSession.ThematicLists;
        //    }
        //    else
        //    {
        //        foreach (ThematicListEnum @enum in Enum.GetValues(typeof(ThematicListEnum)).Cast<ThematicListEnum>())
        //        {
        //            var redListThematicListItemViewModel = new RedListThematicListItemViewModel();
        //            switch (@enum)
        //            {
        //                case ThematicListEnum.ContinuousDecline:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListContinuousDecline;
        //                    break;
        //                case ThematicListEnum.ExtremeFluctuations:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListExtremeFluctuations;
        //                    break;
        //                case ThematicListEnum.SevereleyFragmented:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListSeverelyFragmented;
        //                    break;
        //                case ThematicListEnum.SmallPopulationOrDistribution:
        //                    redListThematicListItemViewModel.Id = (int)@enum;
        //                    redListThematicListItemViewModel.Name = RedListResource.TaxonSearchThematicListSmallPopulationOrDistribution;
        //                    break;
        //            }

        //            searchViewModel.ThematicLists.Add(redListThematicListItemViewModel);
        //        }

        //        searchViewModel.ThematicListOperator = LogicalOperator.Or;
        //    }
        //}

        /// <summary>
        /// Init RedListCategories information.
        /// </summary>
        /// <param name="searchViewModel">Search criteria view model.</param>
        public static void InitRedListCategories(this SearchViewModel searchViewModel)
        {
            if (mSearchViewModelFromSession.IsNotNull() && mSearchViewModelFromSession.RedListCategories.IsNotNull())
            {
                searchViewModel.IsRedListCategoriesEnabled = mSearchViewModelFromSession.IsRedListCategoriesEnabled;
                searchViewModel.RedListCategories          = mSearchViewModelFromSession.RedListCategories;
                searchViewModel.RedListCategoriesTitle     = mSearchViewModelFromSession.RedListCategoriesTitle;
            }
            else
            {
                var otherListedGroupCategoryIds = new List <int>();

                // Get red list category factor
                FactorList redListCategoryFactors = RedListCategoryCache.GetFactors(mUser);

                // Set red list categories title, from factor.
                searchViewModel.RedListCategoriesTitle = redListCategoryFactors[0].Label;

                // Group a limited list of red list categories; "red listed group"
                var        categories = RedListedHelper.GetRedListCategoriesDdToNt();
                List <int> redListedGroupCategoryIds = categories.Select(cat => (int)cat).ToList();

                // Group a limited list of red list categories; "other group"
                RedListCategory redListCategory;
                for (redListCategory = RedListCategory.LC; redListCategory <= RedListCategory.NE; redListCategory++)
                {
                    otherListedGroupCategoryIds.Add((int)redListCategory);
                }

                searchViewModel.RedListCategories = new List <RedListCategoryItemViewModel>();

                // Populate red list categories
                RedListCategoryItemViewModel redListCategoryItemViewModel;
                foreach (var redListCategoryFactor in redListCategoryFactors)
                {
                    foreach (var redListCategoryItem in redListCategoryFactor.DataType.Field1.Enum.Values)
                    {
                        if (redListCategoryItem.KeyInt.HasValue && redListedGroupCategoryIds.Contains(redListCategoryItem.KeyInt.Value))
                        {
                            redListCategoryItemViewModel = new RedListCategoryItemViewModel
                            {
                                Id               = redListCategoryItem.Id,
                                Name             = redListCategoryItem.OriginalLabel,
                                OrderNumber      = redListCategoryItem.KeyInt.Value,
                                Selected         = true,
                                InRedListedGroup = true,
                                InOtherGroup     = false
                            };
                            searchViewModel.RedListCategories.Add(redListCategoryItemViewModel);
                        }
                        if (redListCategoryItem.KeyInt.HasValue && otherListedGroupCategoryIds.Contains(redListCategoryItem.KeyInt.Value))
                        {
                            redListCategoryItemViewModel = new RedListCategoryItemViewModel
                            {
                                Id               = redListCategoryItem.Id,
                                Name             = redListCategoryItem.OriginalLabel,
                                OrderNumber      = redListCategoryItem.KeyInt.Value,
                                Selected         = false,
                                InRedListedGroup = false,
                                InOtherGroup     = true
                            };
                            searchViewModel.RedListCategories.Add(redListCategoryItemViewModel);
                        }
                    }
                }

                const bool ShowNonCategorizedTaxa = true;
                const int  NonCategorizedTaxaId   = 1000;

                // Add value for non categorized taxa. Ie taxa that dont have category 743
                if (ShowNonCategorizedTaxa)
                {
                    redListCategoryItemViewModel = new RedListCategoryItemViewModel
                    {
                        Id               = NonCategorizedTaxaId,
                        Name             = "Non categorized taxa -TEST", //RedListResource.TaxonSearchNonCategorizedTaxaLabel,
                        OrderNumber      = NonCategorizedTaxaId,
                        Selected         = false,
                        InRedListedGroup = false,
                        InOtherGroup     = true
                    };
                    searchViewModel.RedListCategories.Add(redListCategoryItemViewModel);
                }

                // Preselect red list category group as default
                searchViewModel.IsRedListCategoriesEnabled = true;
            }
        }