/// <summary>
        /// Get species fact (Swedish history or Swedish occurrence)
        /// for specified taxon.
        /// </summary>
        /// <param name="factor">Get species fact for this factor.</param>
        /// <param name="taxon">Get species fact for this taxon.</param>
        /// <returns>Species fact (Swedish history and Swedish occurrence) for specified taxon.</returns>
        public ArtDatabanken.Data.SpeciesFact GetSpeciesFact(IUserContext userContext, ArtDatabanken.Data.FactorId factor, ITaxon taxon)
        {
            Dictionary <ArtDatabanken.Data.FactorId, ArtDatabanken.Data.SpeciesFact> speciesFacts;
            List <ArtDatabanken.Data.FactorId> factorIds;
            List <ITaxon> allTaxa;

            ArtDatabanken.Data.SpeciesFact speciesFact;

            speciesFact = null;
            if (_allSpeciesFacts.IsNull())
            {
                // Get species facts.
                factorIds = new List <ArtDatabanken.Data.FactorId>();
                factorIds.Add(ArtDatabanken.Data.FactorId.SwedishHistory);
                factorIds.Add(ArtDatabanken.Data.FactorId.SwedishOccurrence);
                allTaxa = new List <ITaxon>();
                allTaxa.AddRange(TaxonTree.GetTaxa().GetGenericList());
                _allSpeciesFacts = SpeciesFactHelper.GetSpeciesFacts(userContext, allTaxa, factorIds);
            }
            if (_allSpeciesFacts.ContainsKey(taxon.Id))
            {
                speciesFacts = _allSpeciesFacts[taxon.Id];
                if (speciesFacts.ContainsKey(factor))
                {
                    speciesFact = speciesFacts[factor];
                }
            }

            return(speciesFact);
        }
 /// <summary>
 /// Get taxon tree node for specified taxon.
 /// </summary>
 /// <param name="taxon">Taxon.</param>
 /// <returns>Taxon tree node for specified taxon.</returns>
 public ITaxonTreeNode GetTaxonTreeNode(ITaxon taxon)
 {
     // Get taxon tree nodes.
     if (_taxonTrees.IsNull())
     {
         _taxonTrees = new Hashtable();
         foreach (ITaxonTreeNode taxonTreeNode in TaxonTree.GetTaxonTreeNodes())
         {
             _taxonTrees[taxonTreeNode.Taxon.Id] = taxonTreeNode;
         }
     }
     return((ITaxonTreeNode)_taxonTrees[taxon.Id]);
 }
Exemplo n.º 3
0
            private AnnualFinancialReportMonthEntry BuildReportEntry(TaxonTree currentTaxon)
            {
                var financialJournalEntries = _dispatcher.Fetch(new FinancialJournalQuery(_thatMonth)
                {
                    Taxon = new TaxonTreeQuery
                    {
                        TaxonKey = currentTaxon.Key,
                        Deep     = currentTaxon.GetElements().Any() ? 0 : -1
                    }
                });

                var subEntries = currentTaxon.GetElements()
                                 .Select(BuildReportEntry);

                return(AnnualFinancialReportMonthEntry.Create(currentTaxon, financialJournalEntries, subEntries));
            }
Exemplo n.º 4
0
 public MonthReportBuilder(IQueryDispatcher dispatcher, TaxonTree taxon)
 {
     _dispatcher = dispatcher;
     _taxon      = taxon;
 }
        /// <summary>
        /// Init selection of taxon categories.
        /// Taxon categories are always based on valid taxa and taxon relations.
        /// The code must be changed if this assumption is not correct.
        /// </summary>
        /// <param name="userContext">User context.</param>
        /// <param name="taxon">Taxon.</param>
        private void InitTaxonCategories(IUserContext userContext, ITaxon taxon)
        {
            ExportTaxonCategory taxonCategory;

            TaxonCategories          = CoreData.TaxonManager.GetTaxonCategories(userContext);
            FilterAllTaxonCategories = new List <ExportTaxonCategory>();

            // Add all parent taxon categories.
            FilterParentTaxonCategories = new List <ExportTaxonCategory>();
            foreach (ITaxonCategory parentTaxonCategory in TaxonTree.GetParentTaxonCategories())
            {
                taxonCategory = ExportTaxonCategory.Create(parentTaxonCategory, false);
                FilterParentTaxonCategories.Add(taxonCategory);
                if (!FilterAllTaxonCategories.Exists(x => x.CategoryId == taxonCategory.CategoryId))
                {
                    FilterAllTaxonCategories.Add(taxonCategory);
                }
            }

            // Add the current taxon category.
            FilterCurrentTaxonCategory = ExportTaxonCategory.Create(taxon.Category, true);
            if (!FilterAllTaxonCategories.Exists(x => x.CategoryId == FilterCurrentTaxonCategory.CategoryId))
            {
                FilterAllTaxonCategories.Add(FilterCurrentTaxonCategory);
            }

            // Add all child taxon categories.
            FilterChildrenTaxonCategories = new List <ExportTaxonCategory>();
            foreach (ITaxonCategory childTaxonCategory in TaxonTree.GetChildTaxonCategories())
            {
                taxonCategory = ExportTaxonCategory.Create(childTaxonCategory, childTaxonCategory.IsMainCategory);
                FilterChildrenTaxonCategories.Add(taxonCategory);
                if (!FilterAllTaxonCategories.Exists(x => x.CategoryId == taxonCategory.CategoryId))
                {
                    FilterAllTaxonCategories.Add(taxonCategory);
                }
            }

            // Create output categories by cloning from filter categories.
            OutputAllTaxonCategories    = new List <ExportTaxonCategory>();
            OutputParentTaxonCategories = new List <ExportTaxonCategory>();
            foreach (ExportTaxonCategory filterParentTaxonCategory in FilterParentTaxonCategories)
            {
                taxonCategory           = (ExportTaxonCategory)filterParentTaxonCategory.Clone();
                taxonCategory.IsChecked = false;
                OutputParentTaxonCategories.Add(taxonCategory);
                OutputAllTaxonCategories.Add(taxonCategory);
            }

            OutputCurrentTaxonCategory           = (ExportTaxonCategory)FilterCurrentTaxonCategory.Clone();
            OutputCurrentTaxonCategory.IsChecked = false;
            OutputAllTaxonCategories.Add(OutputCurrentTaxonCategory);

            OutputChildTaxonCategories = new List <ExportTaxonCategory>();
            foreach (ExportTaxonCategory filterChildTaxonCategory in FilterChildrenTaxonCategories)
            {
                taxonCategory           = (ExportTaxonCategory)filterChildTaxonCategory.Clone();
                taxonCategory.IsChecked = false;
                OutputChildTaxonCategories.Add(taxonCategory);
                OutputAllTaxonCategories.Add(taxonCategory);
            }
        }
        /// <summary>
        /// Get all taxa that fulfills filter criteria.
        /// </summary>
        /// <returns>All taxa that fulfills filter criteria.</returns>
        public TaxonList GetFilteredTaxa(IUserContext userContext)
        {
            Boolean      isConditionFulfilled;
            Int32        index;
            List <Int32> filteredSwedishHistoryValues, filteredSwedishOccurrenceValues;

            ArtDatabanken.Data.SpeciesFact speciesFact;
            TaxonCategoryList filteredTaxonCategories;
            TaxonList         filteredTaxa;
            ITaxonTreeNode    taxonTreeNode;

            // Get all taxa.
            filteredTaxa = TaxonTree.GetTaxa();

            // Filter on taxon categories.
            if (!IsAllFilterTaxonCategoriesChecked())
            {
                filteredTaxonCategories = GetFilteredTaxonCategories();
                if (FilterParentTaxonCategories.IsNotEmpty())
                {
                    for (index = filteredTaxa.Count - 1; index >= 0; index--)
                    {
                        if (!filteredTaxonCategories.Contains(filteredTaxa[index].Category))
                        {
                            // Remove taxon from filtered list.
                            filteredTaxa.RemoveAt(index);
                        }
                    }
                }
            }

            // Filter on is-valid-taxon is "yes" or "no"
            if (FilterIsValidTaxon.HasValue)
            {
                for (index = filteredTaxa.Count - 1; index >= 0; index--)
                {
                    // Filter is "Valid = no"
                    if (!FilterIsValidTaxon.Value)
                    {
                        // taxon is valid
                        if (filteredTaxa[index].IsValid)
                        {
                            // Remove taxon from filtered list.
                            filteredTaxa.RemoveAt(index);
                        }
                    }
                    // Filter is "Valid = yes"
                    else if (FilterIsValidTaxon.Value)
                    {
                        // taxon is NOT valid
                        if (!filteredTaxa[index].IsValid)
                        {
                            // Remove taxon from filtered list.
                            filteredTaxa.RemoveAt(index);
                        }
                    }
                }
            }

            // Filter on species facts.
            filteredSwedishHistoryValues    = GetFilteredSwedishHistoryValues(userContext);
            filteredSwedishOccurrenceValues = GetFilteredSwedishOccurrenceValues();

            /*
             * // GuNy 2013-02-04
             * ITaxon tempTaxon;
             *
             * if (filteredSwedishHistoryValues.IsNotEmpty() || filteredSwedishOccurrenceValues.IsNotEmpty())
             * {
             *  for (index = filteredTaxa.Count - 1; index >= 0; index--)
             *  {
             *      // GuNy 2013-02-04
             *      tempTaxon = filteredTaxa[index];
             *      isConditionFulfilled = false;
             *
             *      if (filteredSwedishHistoryValues.IsNotEmpty())
             *      {
             *          // Filter on swedish history.
             *          speciesFact = GetSpeciesFact(FactorId.SwedishHistory, tempTaxon);
             *          if (speciesFact.IsNotNull() && speciesFact.Field1.IsNotNull()
             *              && speciesFact.Field1.EnumValue.IsNotNull()
             *              && filteredSwedishHistoryValues.Contains(speciesFact.Field1.EnumValue.KeyInt))
             *          {
             *              isConditionFulfilled = true;
             *          }
             *          if (!isConditionFulfilled)
             *          {
             *              // Remove taxon from filtered list.
             *              filteredTaxa.RemoveAt(index);
             *              continue;
             *          }
             *      }
             *
             *      if (filteredSwedishOccurrenceValues.IsNotEmpty())
             *      {
             *          // Filter on swedish occurrence
             *          isConditionFulfilled = false;
             *          speciesFact = GetSpeciesFact(FactorId.SwedishOccurence, tempTaxon);
             *          if (speciesFact.IsNotNull() && speciesFact.Field1.IsNotNull()
             *              && speciesFact.Field1.EnumValue.IsNotNull()
             *              && filteredSwedishOccurrenceValues.Contains(speciesFact.Field1.EnumValue.KeyInt))
             *          {
             *              isConditionFulfilled = true;
             *          }
             *
             *          if (!isConditionFulfilled)
             *          {
             *              // Remove taxon from filtered list.
             *              filteredTaxa.RemoveAt(index);
             *          }
             *      }
             *  }
             * }
             * return filteredTaxa;
             * }
             *
             */

            if (filteredSwedishHistoryValues.IsNotEmpty() ||
                filteredSwedishOccurrenceValues.IsNotEmpty())
            {
                for (index = filteredTaxa.Count - 1; index >= 0; index--)
                {
                    taxonTreeNode = GetTaxonTreeNode(filteredTaxa[index]);

                    if (filteredSwedishHistoryValues.IsNotEmpty())
                    {
                        // Filter on swedish history
                        isConditionFulfilled = false;
                        bool checkOwnFails = false;

                        // First check current taxon
                        speciesFact = GetSpeciesFact(userContext, ArtDatabanken.Data.FactorId.SwedishHistory, taxonTreeNode.Taxon);
                        if (speciesFact.IsNotNull() &&
                            speciesFact.Field1.IsNotNull() &&
                            speciesFact.Field1.EnumValue.IsNotNull() &&
                            speciesFact.Field1.EnumValue.KeyInt.HasValue)
                        {
                            if (filteredSwedishHistoryValues.Contains(speciesFact.Field1.EnumValue.KeyInt.Value))
                            {
                                isConditionFulfilled = true;
                            }
                            else
                            {
                                checkOwnFails = true;
                            }
                        }

                        if (!isConditionFulfilled && !checkOwnFails)
                        {
                            foreach (ITaxon tempTaxon in taxonTreeNode.GetTaxa())
                            {
                                speciesFact = GetSpeciesFact(userContext, ArtDatabanken.Data.FactorId.SwedishHistory, tempTaxon);
                                if (tempTaxon.Id == taxonTreeNode.Taxon.Id)
                                {
                                    continue;
                                }

                                if (speciesFact.IsNotNull() &&
                                    speciesFact.Field1.IsNotNull() &&
                                    speciesFact.Field1.EnumValue.IsNotNull() &&
                                    speciesFact.Field1.EnumValue.KeyInt.HasValue &&
                                    filteredSwedishHistoryValues.Contains(speciesFact.Field1.EnumValue.KeyInt.Value))
                                {
                                    isConditionFulfilled = true;
                                    break;
                                }
                            }
                        }

                        if (!isConditionFulfilled)
                        {
                            // Remove taxon from filtered list.
                            filteredTaxa.RemoveAt(index);
                            continue;
                        }
                    }

                    if (filteredSwedishOccurrenceValues.IsNotEmpty())
                    {
                        // Filter on swedish occurrence
                        isConditionFulfilled = false;
                        bool checkOwnFails = false;

                        // First check current taxon
                        speciesFact = GetSpeciesFact(userContext, ArtDatabanken.Data.FactorId.SwedishOccurrence, taxonTreeNode.Taxon);
                        if (speciesFact.IsNotNull() &&
                            speciesFact.Field1.IsNotNull() &&
                            speciesFact.Field1.EnumValue.IsNotNull() &&
                            speciesFact.Field1.EnumValue.KeyInt.HasValue)
                        {
                            if (filteredSwedishOccurrenceValues.Contains(speciesFact.Field1.EnumValue.KeyInt.Value))
                            {
                                isConditionFulfilled = true;
                            }
                            else
                            {
                                checkOwnFails = true;
                            }
                        }

                        if (!isConditionFulfilled && !checkOwnFails)
                        {
                            foreach (ITaxon tempTaxon in taxonTreeNode.GetTaxa())
                            {
                                speciesFact = GetSpeciesFact(userContext, ArtDatabanken.Data.FactorId.SwedishOccurrence, tempTaxon);
                                if (tempTaxon.Id == taxonTreeNode.Taxon.Id)
                                {
                                    continue;
                                }

                                if (speciesFact.IsNotNull() &&
                                    speciesFact.Field1.IsNotNull() &&
                                    speciesFact.Field1.EnumValue.IsNotNull() &&
                                    speciesFact.Field1.EnumValue.KeyInt.HasValue &&
                                    filteredSwedishOccurrenceValues.Contains(speciesFact.Field1.EnumValue.KeyInt.Value))
                                {
                                    isConditionFulfilled = true;
                                    break;
                                }
                            }
                        }

                        if (!isConditionFulfilled)
                        {
                            // Remove taxon from filtered list.
                            filteredTaxa.RemoveAt(index);
                        }
                    }
                }
            }

            return(filteredTaxa);
        }