/// <summary> /// Method that returns a filtered version of this species fact /// list. The filtering is done on factors. /// </summary> /// <param name="factors">Factors for the requested species facts.</param> /// <returns>A filtered species fact list.</returns> public SpeciesFactList GetSpeciesFacts(FactorList factors) { if (factors == null) { throw new ArgumentException("FactorList is null", "factors"); } SpeciesFactList filteredList = new SpeciesFactList(); if (this.IsNotEmpty()) { foreach (ISpeciesFact fact in this) { foreach (IFactor factor in factors) { if (fact.Factor.Id == factor.Id) { filteredList.Add(fact); break; } } } } return(filteredList); }
/// <summary> /// Set factors for specified locale. /// </summary> /// <param name="factors">Factors.</param> /// <param name="locale">Locale.</param> /// <param name="getOnlyPublicFactors">Get only public factor trees or all from cache.</param> protected virtual void SetFactors(FactorList factors, ILocale locale, Boolean getOnlyPublicFactors) { String factorTreeType = getOnlyPublicFactors ? FactorTreesPermissionType.PublicFactorTrees.ToString() : FactorTreesPermissionType.AllFactorTrees.ToString(); Factors[locale.ISOCode + "#" + factorTreeType] = factors; }
/// <summary> /// Remove factors 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, FactorList selection) { ISpeciesFactDataSetSelection newSelection; newSelection = new SpeciesFactDataSetSelection(); newSelection.Factors.Merge(selection); RemoveSelection(userContext, newSelection); }
/// <summary> /// Create a species fact data set selection instance. /// </summary> public SpeciesFactDataSetSelection() { _factors = new FactorList(true); _hosts = new TaxonList(true); _individualCategories = new IndividualCategoryList(true); _periods = new PeriodList(true); _references = new ReferenceList(true); _taxa = new TaxonList(true); }
/// <summary> /// Add factor to search criteria. /// </summary> /// <param name="factor">The factor.</param> public void Add(IFactor factor) { if (Factors.IsNull()) { Factors = new FactorList(); } Factors.Add(factor); }
/// <summary> /// Default constructor /// </summary> public SpeciesFactSearchCriteria() { FactorDataTypes = new FactorDataTypeList(); Factors = new FactorList(); FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList(); Hosts = new TaxonList(); IndividualCategories = new IndividualCategoryList(); Periods = new PeriodList(); References = new ReferenceList(); Taxa = new TaxonList(); }
/// <summary> /// Create a species fact data set instance. /// </summary> public SpeciesFactDataSet() { Factors = new FactorList(true); Hosts = new TaxonList(true); IndividualCategories = new IndividualCategoryList(true); Periods = new PeriodList(true); References = new ReferenceList(true); _selection = new SpeciesFactDataSetSelection(); _selectionCopy = new SpeciesFactDataSetSelection(); SpeciesFacts = new SpeciesFactList(); Taxa = new TaxonList(true); }
/// <summary> /// Get a subset of this factor list by search string. /// </summary> /// <param name="searchString">Search string.</param> /// <param name="comparisonType">Type of string comparison.</param> /// <returns>A factor list.</returns> public FactorList GetFactorsBySearchString(String searchString, StringComparison comparisonType) { FactorList factors = new FactorList(); var subset = from IFactor factor in this where factor.Label.StartsWith(searchString, comparisonType) orderby factor.Label ascending select factor; factors.AddRange(subset.ToArray()); return(factors); }
/// <summary> /// Get factors with specified datatype. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="factorDataType">Factor datatype.</param> /// <returns>Factors with specified datatype.</returns> public virtual FactorList GetFactors(IUserContext userContext, IFactorDataType factorDataType) { FactorList allFactors, factors; // Check arguments. factorDataType.CheckNotNull("factorDataType"); allFactors = GetFactors(userContext); factors = new FactorList(); factors.AddRange(allFactors.FindAll(factor => factor.DataType.IsNotNull() && factor.DataType.Id == factorDataType.Id)); return(factors); }
/// <summary> /// Get factors for specified locale. /// </summary> /// <param name="locale">Locale.</param> /// <param name="getOnlyPublicFactors">Get only public factors or all from cache.</param> /// <returns>Factors for specified locale.</returns> protected virtual FactorList GetFactors(ILocale locale, Boolean getOnlyPublicFactors) { String factorTreeType = getOnlyPublicFactors ? FactorTreesPermissionType.PublicFactorTrees.ToString() : FactorTreesPermissionType.AllFactorTrees.ToString(); FactorList factors = null; if (Factors.ContainsKey(locale.ISOCode + "#" + factorTreeType)) { factors = (FactorList)(Factors[locale.ISOCode + "#" + factorTreeType]); } return(factors); }
/// <summary> /// Get all child factors that belongs to this factor tree node. /// The factor for this tree node is also included in the result. /// </summary> /// <returns>All child factors that belongs to this factor tree node.</returns> public FactorList GetAllChildFactors() { FactorList factors = new FactorList { Factor }; if (Children.IsNotEmpty()) { foreach (IFactorTreeNode child in Children) { factors.AddRange(child.GetAllChildFactors()); } } return(factors); }
/// <summary> /// Get factors with specified ids. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="factorIds">Factor ids.</param> /// <returns>Factors with specified ids.</returns> public virtual FactorList GetFactors(IUserContext userContext, List <Int32> factorIds) { FactorList allFactors, factors; // Check arguments. factorIds.CheckNotEmpty("factorIds"); factors = new FactorList(); allFactors = GetFactors(userContext); foreach (Int32 factorId in factorIds) { factors.Add(allFactors.Get(factorId)); } return(factors); }
/// <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 child factors that belongs to this factor tree node. /// The factor for this tree node may also /// be included in the result. /// </summary> /// <returns>All leaf factors that belongs to this factor tree node.</returns> public FactorList GetAllLeafFactors() { FactorList leaves = new FactorList(); if (Children.IsEmpty()) { leaves.Add(Factor); } else { foreach (IFactorTreeNode child in Children) { leaves.AddRange(child.GetAllLeafFactors()); } } return(leaves); }
/// <summary> /// Get factors that are manually editable. /// </summary> /// <returns>Factors that are manually editable.</returns> public FactorList GetEditableFactors() { FactorList editableFactors; editableFactors = null; if (this.IsNotEmpty()) { editableFactors = new FactorList(); foreach (IFactor factor in this) { if (factor.UpdateMode.AllowManualUpdate) { editableFactors.Add(factor); } } } return(editableFactors); }
/// <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> /// 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(); }
/// <summary> /// Get all factors that have an impact on this factors value. /// Only factors that are automatically calculated /// has dependent factors. /// </summary> /// <param name="userContext">Information about the user that makes this method call.</param> /// <returns>Dependent factors.</returns> public FactorList GetDependentFactors(IUserContext userContext) { FactorList factors; factors = new FactorList(); switch (Id) { case ((Int32)FactorId.RedListCategoryAutomatic): case ((Int32)FactorId.RedListCriteriaDocumentationAutomatic): case ((Int32)FactorId.RedListCriteriaAutomatic): factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.AreaOfOccupancy_B2Estimated)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ConservationDependent)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ContinuingDecline)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ContinuingDeclineBasedOn_Bbi)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ContinuingDeclineBasedOn_Bbii)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ContinuingDeclineBasedOn_Bbiii)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ContinuingDeclineBasedOn_Bbiv)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ContinuingDeclineBasedOn_Bbv)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ExtentOfOccurrence_B1Estimated)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ExtremeFluctuations)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ExtremeFluctuationsIn_Bci)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ExtremeFluctuationsIn_Bcii)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ExtremeFluctuationsIn_Bciii)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ExtremeFluctuationsIn_Bciv)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Grading)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.MaxProportionLocalPopulation)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.MaxSizeLocalPopulation)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.NumberOfLocations)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.PopulationSize_Total)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ProbabilityOfExtinction)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.RedlistEvaluationProgressionStatus)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Reduction_A1)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Reduction_A2)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Reduction_A3)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.Reduction_A4)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A1a)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A1b)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A1c)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A1d)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A1e)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A2a)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A2b)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A2c)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A2d)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A2e)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A3b)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A3c)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A3d)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A3e)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A4a)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A4b)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A4c)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A4d)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ReductionBasedOn_A4e)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.SeverelyFragmented)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.SwedishOccurrence)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.VeryRestrictedArea_D2VU)); if (Id == ((Int32)FactorId.RedListCriteriaDocumentationAutomatic)) { factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.RedListCriteriaDocumentationIntroduction)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.GlobalRedlistCategory)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.GenerationTime)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.LastEncounter)); factors.Add(CoreData.FactorManager.GetFactor(userContext, FactorId.ImmigrationOccurs)); } break; } return(factors); }
/// <summary> /// Method that returns a filtered version of this species fact list. The filtering is done on several parameters. /// </summary> /// <param name="individualCategories">Individual categories for the requested species facts.</param> /// <param name="periods">Periods for the requested species facts.</param> /// <param name="hosts">Hosts for the requested species facts.</param> /// <param name="taxa">Taxa for the requested species facts.</param> /// <param name="factors">Factors for the requested species facts.</param> /// <returns>A species fact list.</returns> public SpeciesFactList GetSpeciesFacts(IndividualCategoryList individualCategories, PeriodList periods, TaxonList hosts, TaxonList taxa, FactorList factors) { SpeciesFactList filteredList = new SpeciesFactList(); if (this.IsNotEmpty()) { foreach (ISpeciesFact fact in this) { bool go = true; if (fact.IndividualCategory != null) { if ((individualCategories != null) && (individualCategories.Count > 0)) { if (!individualCategories.Exists(fact.IndividualCategory)) { go = false; } } } if (go) { if (fact.Period != null) { if ((periods != null) && (periods.Count > 0)) { if (!periods.Exists(fact.Period)) { go = false; } } } } if (go) { if (fact.Host != null) { // For the time being we only accept species facts that dont have a host. go = false; //if ((hosts != null) && (hosts.Count > 0)) //{ // if (!hosts.Exists(fact.Host)) // go = false; //} } } if (go) { if (fact.Taxon != null) { if ((taxa != null) && (taxa.Count > 0)) { if (!taxa.Exists(fact.Taxon)) { go = false; } } } } if (go) { if (fact.Factor != null) { if ((factors != null) && (factors.Count > 0)) { if (!factors.Exists(fact.Factor)) { go = false; } } } } if (go) { filteredList.Add(fact); } } } return(filteredList); }