/// <summary>
        /// Get all unique child taxa.
        /// This method operates on current taxon tree in contrast to
        /// the full taxon tree with all taxon tree nodes.
        /// </summary>
        /// <param name="taxonTreeNode">Current child taxon tree node.</param>
        /// <param name="childTaxa">Accumulated child taxa so far.</param>
        private void GetChildTaxa(ITaxonTreeNode taxonTreeNode,
                                  TaxonList childTaxa)
        {
            // Add the taxon for this taxon tree node.
            childTaxa.Merge(taxonTreeNode.Taxon);

            if (taxonTreeNode.Children.IsNotEmpty())
            {
                // Add taxa for child taxon tree node.
                foreach (ITaxonTreeNode childTaxonTreeNode in taxonTreeNode.Children)
                {
                    GetChildTaxa(childTaxonTreeNode, childTaxa);
                }
            }
        }
        /// <summary>
        /// Get all unique parent taxa.
        /// This method operates on current taxon tree in contrast to
        /// the full taxon tree with all taxon tree nodes.
        /// </summary>
        /// <param name="taxonTreeNode">Current parent taxon tree node.</param>
        /// <param name="parentTaxa">Accumulated parent taxa so far.</param>
        private void GetParentTaxa(ITaxonTreeNode taxonTreeNode,
                                   TaxonList parentTaxa)
        {
            // Add the taxon for this taxon tree node.
            parentTaxa.Merge(taxonTreeNode.Taxon);

            if (taxonTreeNode.Parents.IsNotEmpty())
            {
                // Add taxa for parent taxon tree node.
                foreach (ITaxonTreeNode parentTaxonTreeNode in taxonTreeNode.Parents)
                {
                    GetParentTaxa(parentTaxonTreeNode, parentTaxa);
                }
            }
        }
        /// <summary>
        /// Remove factors, hosts, individual categories, periods or
        /// taxa from current species fact data set scope.
        /// The species facts in the data set are updated
        /// to the new species fact data set scope.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="selection">Changed scope of the data set.</param>
        public virtual void RemoveSelection(IUserContext userContext,
                                            ISpeciesFactDataSetSelection selection)
        {
            FactorList             factors;
            IndividualCategoryList individualCategories;
            PeriodList             periods;
            ReferenceList          references;
            TaxonList hosts, taxa;

            // Check arguments.
            selection.CheckNotNull("selection");

            // Update selection with existing scope.
            factors = new FactorList();
            factors.Merge(_selection.Factors);
            factors.Remove(selection.Factors);
            selection.Factors = factors;

            hosts = new TaxonList();
            hosts.Merge(_selection.Hosts);
            hosts.Remove(selection.Hosts);
            selection.Hosts = hosts;

            individualCategories = new IndividualCategoryList();
            individualCategories.Merge(_selection.IndividualCategories);
            individualCategories.Remove(selection.IndividualCategories);
            selection.IndividualCategories = individualCategories;

            periods = new PeriodList();
            periods.Merge(_selection.Periods);
            periods.Remove(selection.Periods);
            selection.Periods = periods;

            references = new ReferenceList();
            references.Merge(_selection.References);
            references.Remove(selection.References);
            selection.References = references;

            taxa = new TaxonList();
            taxa.Merge(_selection.Taxa);
            taxa.Remove(selection.Taxa);
            selection.Taxa = taxa;

            // Update species fact data set.
            UpdateSelection(userContext, selection);
        }
        /// <summary>
        /// Get all unique taxa in this species fact list.
        /// </summary>
        /// <returns>All unique taxa in this species fact list.</returns>
        public TaxonList GetTaxa()
        {
            TaxonList taxa;

            taxa = new TaxonList();
            if (this.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in this)
                {
                    if (speciesFact.Taxon.IsNotNull())
                    {
                        taxa.Merge(speciesFact.Taxon);
                    }
                }

                taxa.Sort();
            }

            return(taxa);
        }
        /// <summary>
        /// Reset species fact data set to no species facts.
        /// This method is used when species fact data set selection
        /// does not contain both factors and taxa.
        /// </summary>
        /// <param name="selection">
        /// Scope of the data set is defined by this
        /// species fact data set selection.
        /// </param>
        private void Reset(ISpeciesFactDataSetSelection selection)
        {
            Factors = new FactorList(true);
            Factors.Merge(selection.Factors);
            Hosts = new TaxonList(true);
            Hosts.Merge(selection.Hosts);
            IndividualCategories = new IndividualCategoryList(true);
            IndividualCategories.Merge(selection.IndividualCategories);
            Periods = new PeriodList(true);
            Periods.Merge(selection.Periods);
            References = new ReferenceList(true);
            References.Merge(selection.References);
            SpeciesFacts = new SpeciesFactList(true);
            Taxa         = new TaxonList();
            Taxa.Merge(selection.Taxa);

            // Save selection information.
            _selection     = (ISpeciesFactDataSetSelection)(selection.Clone());
            _selectionCopy = (ISpeciesFactDataSetSelection)(selection.Clone());
        }
        /// <summary>
        /// Get all unique hosts in this species fact list.
        /// </summary>
        /// <returns>All unique hosts in this species fact list.</returns>
        public TaxonList GetHosts()
        {
            TaxonList hosts;

            hosts = new TaxonList();
            if (this.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in this)
                {
                    if (speciesFact.Host.IsNotNull() &&
                        speciesFact.Host.Id != (Int32)(TaxonId.Life))
                    {
                        hosts.Merge(speciesFact.Host);
                    }
                }

                hosts.Sort();
            }

            return(hosts);
        }
Beispiel #7
0
        /// <summary>
        /// Get taxa with specified ids.
        /// </summary>
        /// <param name="userContext">User context.</param>
        /// <param name="taxonIds">Taxon ids</param>
        /// <returns>Taxa with specified ids.</returns>
        public override TaxonList GetTaxa(IUserContext userContext,
                                          List <Int32> taxonIds)
        {
            ITaxon       taxon;
            List <Int32> notFoundTaxonIds;
            TaxonList    foundTaxa, notFoundTaxa, taxa;

            if (userContext.CurrentRole.IsNotNull() &&
                userContext.CurrentRole.Identifier.IsNotEmpty() &&
                userContext.CurrentRole.Identifier.StartsWith(Settings.Default.DyntaxaRevisionRoleIdentifier))
            {
                // Do not cache taxa if user is in a revision.
                taxa = base.GetTaxa(userContext, taxonIds);
            }
            else
            {
                // Get cached taxa.
                foundTaxa        = new TaxonList(true);
                notFoundTaxa     = null;
                notFoundTaxonIds = new List <Int32>();
                foreach (Int32 taxonId in taxonIds)
                {
                    taxon = GetTaxon(taxonId, userContext.Locale);
                    if (taxon.IsNull())
                    {
                        notFoundTaxonIds.Add(taxonId);
                    }
                    else
                    {
                        foundTaxa.Add(taxon);
                    }
                }

                // Get taxa from data source.
                if (notFoundTaxonIds.IsNotEmpty())
                {
                    notFoundTaxa = base.GetTaxa(userContext, notFoundTaxonIds);
                    foundTaxa.Merge(notFoundTaxa);
                    taxa = new TaxonList(true);
                    foreach (Int32 taxonId in taxonIds)
                    {
                        taxa.Add(foundTaxa.Get(taxonId));
                    }
                }
                else
                {
                    taxa = foundTaxa;
                }

                // Save taxa in cache.
                if (notFoundTaxa.IsNotEmpty())
                {
                    foreach (ITaxon tempTaxon in notFoundTaxa)
                    {
                        SetTaxon(tempTaxon, userContext.Locale);
                    }
                }
            }

            return(taxa);
        }
        /// <summary>
        /// Update information about which factors, hosts,
        /// individual categories, periods, references and taxa
        /// that are used in the species facts.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="selection">
        /// Scope of the data set is defined by this
        /// species fact data set selection.
        /// </param>
        /// <param name="speciesFacts">Species facts.</param>
        private void UpdateScope(IUserContext userContext,
                                 ISpeciesFactDataSetSelection selection,
                                 SpeciesFactList speciesFacts)
        {
            Factors = new FactorList(true);
            Factors.AddRange(selection.Factors);
            Hosts = new TaxonList(true);
            Hosts.AddRange(selection.Hosts);
            IndividualCategories = new IndividualCategoryList(true);
            IndividualCategories.AddRange(selection.IndividualCategories);
            Periods = new PeriodList(true);
            Periods.AddRange(selection.Periods);
            References = new ReferenceList(true);
            Taxa       = new TaxonList(true);
            Taxa.AddRange(selection.Taxa);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    Factors.Merge(speciesFact.Factor);
                    if (speciesFact.HasHost)
                    {
                        Hosts.Merge(speciesFact.Host);
                    }

                    IndividualCategories.Merge(speciesFact.IndividualCategory);
                    if (speciesFact.HasPeriod)
                    {
                        Periods.Merge(speciesFact.Period);
                    }

                    if (speciesFact.HasReference)
                    {
                        References.Merge(speciesFact.Reference);
                    }

                    Taxa.Merge(speciesFact.Taxon);
                }
            }

            // Set default values if no values are entered.
            if (Hosts.IsEmpty())
            {
                Hosts.Add(CoreData.TaxonManager.GetTaxon(userContext, TaxonId.Life));
            }

            if (IndividualCategories.IsEmpty())
            {
                IndividualCategories.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext));
            }

            if (Periods.IsEmpty())
            {
                Periods.AddRange(CoreData.FactorManager.GetPeriods(userContext));
            }

            // Sort all lists.
            Factors.Sort();
            Hosts.Sort();
            IndividualCategories.Sort();
            Periods.Sort();
            References.Sort();
            Taxa.Sort();
        }