private ArtDatabanken.Data.ArtDatabankenService.TaxonSearchCriteria GetSearchCriteria(Boolean refresh)
 {
     if (_searchCriteria.IsNull() || refresh)
     {
         _searchCriteria = new ArtDatabanken.Data.ArtDatabankenService.TaxonSearchCriteria();
     }
     return(_searchCriteria);
 }
예제 #2
0
        /// <summary>
        /// Get information about taxa that matches the search criteria.
        /// </summary>
        /// <param name="searchCriteria">The taxon search criteria.</param>
        /// <returns>Taxa information.</returns>
        /// <exception cref="ArgumentException">Thrown if searchCriteria is null.</exception>
        public static TaxonList GetTaxaBySearchCriteria(TaxonSearchCriteria searchCriteria)
        {
            List <WebTaxon>        webTaxa;
            WebTaxonSearchCriteria webSearchCriteria;

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

            // Get data from web service.
            webSearchCriteria = GetTaxonSearchCriteria(searchCriteria);
            webTaxa           = WebServiceClient.GetTaxaBySearchCriteria(webSearchCriteria);
            return(GetTaxa(webTaxa));
        }
예제 #3
0
        /// <summary>
        /// Convert TaxonSearchCriteria to WebTaxonSearchCriteria.
        /// </summary>
        /// <param name="searchCriteria">A TaxonSearchCriteria instance.</param>
        /// <returns>A WebTaxonSearchCriteria instance.</returns>
        private static WebTaxonSearchCriteria GetTaxonSearchCriteria(TaxonSearchCriteria searchCriteria)
        {
            WebTaxonSearchCriteria webSearchCriteria;

            webSearchCriteria = new WebTaxonSearchCriteria();
            webSearchCriteria.RestrictReturnToScope = searchCriteria.RestrictReturnToScope;
#if DATA_SPECIFIED_EXISTS
            webSearchCriteria.RestrictReturnToScopeSpecified = true;
#endif
            webSearchCriteria.RestrictReturnToSwedishSpecies = searchCriteria.RestrictReturnToSwedishSpecies;
#if DATA_SPECIFIED_EXISTS
            webSearchCriteria.RestrictReturnToSwedishSpeciesSpecified = true;
#endif
            if (searchCriteria.RestrictReturnToTaxonTypeIds.IsNotNull())
            {
                webSearchCriteria.RestrictReturnToTaxonTypeIds = searchCriteria.RestrictReturnToTaxonTypeIds;
            }
            webSearchCriteria.RestrictSearchToSwedishSpecies = searchCriteria.RestrictSearchToSwedishSpecies;
#if DATA_SPECIFIED_EXISTS
            webSearchCriteria.RestrictSearchToSwedishSpeciesSpecified = true;
#endif
            if (searchCriteria.RestrictSearchToTaxonIds.IsNotNull())
            {
                webSearchCriteria.RestrictSearchToTaxonIds = searchCriteria.RestrictSearchToTaxonIds;
            }
            if (searchCriteria.RestrictSearchToTaxonTypeIds.IsNotNull())
            {
                webSearchCriteria.RestrictSearchToTaxonTypeIds = searchCriteria.RestrictSearchToTaxonTypeIds;
            }
            webSearchCriteria.TaxonInformationType = searchCriteria.TaxonInformationType;
#if DATA_SPECIFIED_EXISTS
            webSearchCriteria.TaxonInformationTypeSpecified = true;
#endif
            webSearchCriteria.TaxonNameSearchString = searchCriteria.TaxonNameSearchString;
            return(webSearchCriteria);
        }
 public TaxonSearchCriteriaTest()
 {
     _searchCriteria = null;
 }
        public void GetTaxaBySearchCriteria()
        {
            Data.ArtDatabankenService.TaxonList           taxa;
            Data.ArtDatabankenService.TaxonSearchCriteria searchCriteria;

            foreach (TaxonInformationType taxonInformationType in Enum.GetValues(typeof(TaxonInformationType)))
            {
                for (WebService.TaxonSearchScope taxonReturnScope = WebService.TaxonSearchScope.NoScope; taxonReturnScope <= WebService.TaxonSearchScope.AllChildTaxa; taxonReturnScope++)
                {
                    searchCriteria = new Data.ArtDatabankenService.TaxonSearchCriteria();
                    searchCriteria.TaxonInformationType  = taxonInformationType;
                    searchCriteria.RestrictReturnToScope = taxonReturnScope;

                    searchCriteria.RestrictSearchToTaxonIds       = null;
                    searchCriteria.RestrictSearchToTaxonTypeIds   = null;
                    searchCriteria.TaxonNameSearchString          = null;
                    searchCriteria.RestrictSearchToSwedishSpecies = false;
                    taxa = Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    if (taxonReturnScope == WebService.TaxonSearchScope.NoScope)
                    {
                        Assert.IsTrue(taxa.IsNotEmpty());
                    }
                    else
                    {
                        Assert.IsTrue(taxa.IsEmpty());
                    }

                    searchCriteria.RestrictSearchToTaxonIds       = null;
                    searchCriteria.RestrictSearchToTaxonTypeIds   = null;
                    searchCriteria.TaxonNameSearchString          = "björn";
                    searchCriteria.RestrictSearchToSwedishSpecies = true;
                    taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    Assert.IsNotNull(taxa);
                    Assert.IsTrue(taxa.IsNotEmpty());
                    Assert.AreEqual(taxa.Count, 1);

                    searchCriteria.RestrictSearchToTaxonIds       = null;
                    searchCriteria.RestrictSearchToTaxonTypeIds   = null;
                    searchCriteria.TaxonNameSearchString          = "björn%";
                    searchCriteria.RestrictSearchToSwedishSpecies = false;
                    taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    Assert.IsNotNull(taxa);
                    Assert.IsTrue(taxa.IsNotEmpty());
                    Assert.IsTrue(taxa.Count > 1);

                    searchCriteria.RestrictSearchToTaxonIds       = GetTaxaIds();
                    searchCriteria.RestrictSearchToTaxonTypeIds   = null;
                    searchCriteria.TaxonNameSearchString          = "björn%";
                    searchCriteria.RestrictSearchToSwedishSpecies = true;
                    taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    Assert.IsNotNull(taxa);
                    Assert.IsTrue(taxa.IsNotEmpty());
                    Assert.AreEqual(taxa.Count, 1);

                    searchCriteria.RestrictSearchToTaxonIds       = GetTaxaIds();
                    searchCriteria.RestrictSearchToTaxonTypeIds   = GetTaxonTypeIds();
                    searchCriteria.TaxonNameSearchString          = "björn%";
                    searchCriteria.RestrictSearchToSwedishSpecies = false;
                    taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    Assert.IsNotNull(taxa);
                    Assert.IsTrue(taxa.IsNotEmpty());
                    Assert.AreEqual(taxa.Count, 1);

                    searchCriteria.RestrictSearchToTaxonIds       = null;
                    searchCriteria.RestrictSearchToTaxonTypeIds   = GetTaxonTypeIds();
                    searchCriteria.TaxonNameSearchString          = "%björn%";
                    searchCriteria.RestrictSearchToSwedishSpecies = true;
                    taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    Assert.IsNotNull(taxa);
                    Assert.IsTrue(taxa.IsNotEmpty());
                    Assert.IsTrue(taxa.Count > 1);

                    searchCriteria.RestrictSearchToTaxonIds       = null;
                    searchCriteria.RestrictSearchToTaxonTypeIds   = null;
                    searchCriteria.TaxonNameSearchString          = "blåvingad sandgräshoppa";
                    searchCriteria.RestrictReturnToSwedishSpecies = true;
                    taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
                    Assert.IsTrue(taxa.IsEmpty());
                }
            }

            // Test getting parent taxa.
            searchCriteria = new ArtDatabanken.Data.ArtDatabankenService.TaxonSearchCriteria();
            searchCriteria.TaxonInformationType  = TaxonInformationType.Basic;
            searchCriteria.RestrictReturnToScope = WebService.TaxonSearchScope.AllParentTaxa;
            searchCriteria.TaxonNameSearchString = "björn";
            taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxaBySearchCriteria(searchCriteria);
            Assert.IsTrue(taxa.IsNotEmpty());
        }
예제 #6
0
        /// <summary>
        /// Get string with taxonomic information.
        /// </summary>
        /// <returns>String with taxonomic information.</returns>
        private String GetAutomaticTaxonomicString()
        {
            StringBuilder text;

            if (_taxonomicParagraphSpeciesFact.IsNotNull() &&
                (_taxonomicParagraphSpeciesFact.Quality.Id == (Int32)SpeciesFactQualityId.VerryGood) &&
                _taxonomicParagraphSpeciesFact.Field5.HasValue)
            {
                return(_taxonomicParagraphSpeciesFact.Field5.StringValue);
            }

            text = new StringBuilder();
            if (_taxon.IsNotNull())
            {
                _italicStringsInAutomaticTaxonomicParagraph.Clear();

                TaxonSearchCriteria criteria = new TaxonSearchCriteria();
                List <Int32>        taxonIds = new List <Int32>();
                taxonIds.Add(_taxon.Id);
                criteria.RestrictSearchToTaxonIds = taxonIds;
                criteria.RestrictReturnToScope    = WebService.TaxonSearchScope.AllParentTaxa;
                TaxonList parentTaxa      = TaxonManager.GetTaxaBySearchCriteria(criteria);
                TaxonList suitableParents = new TaxonList();
                foreach (Taxon parent in parentTaxa)
                {
                    if ((parent.TaxonType.Id == (Int32)(TaxonTypeId.Kingdom)) ||
                        (parent.TaxonType.Id == (Int32)(TaxonTypeId.Phylum)) ||
                        (parent.TaxonType.Id == (Int32)(TaxonTypeId.Class)) ||
                        (parent.TaxonType.Id == (Int32)(TaxonTypeId.Order)) ||
                        (parent.TaxonType.Id == (Int32)(TaxonTypeId.Family)))
                    {
                        if (!(parent.Id == (Int32)TaxonId.Dummy))
                        {
                            suitableParents.Add(parent);
                        }
                    }
                }
                Int32 startFromIndex = suitableParents.Count - 3;
                if (startFromIndex < 0)
                {
                    startFromIndex = 0;
                }
                for (Int32 index = startFromIndex; index < suitableParents.Count; index++)
                {
                    if (text.ToString() != String.Empty)
                    {
                        text.Append(", ");
                    }
                    text.Append(suitableParents[index].TaxonType.Label + " ");
                    text.Append(suitableParents[index].ScientificName);

                    //Eventuellt ska denna kodrad tas bort (förslag från Tomas Hallingbäck): Överordnade taxa bör ej vara kursiverade
                    //Enligt artexperternas diskussion 2010-03-04 ska överordnade vetenskapliga taxonnamn ej kursiveras!
                    //_italicStringsInAutomaticTaxonomicParagraph.Add(suitableParents[index].ScientificName);

                    if (suitableParents[index].CommonName.IsNotEmpty())
                    {
                        text.Append(" (" + suitableParents[index].CommonName + ")");
                    }
                }

                if (text.ToString() != String.Empty)
                {
                    text.Append(", ");
                }

                text.Append(_taxon.ScientificNameAndAuthor);
                _italicStringsInAutomaticTaxonomicParagraph.Add(_taxon.ScientificName);

                TaxonNameList Synonyms = new TaxonNameList();
                foreach (TaxonName name in _taxon.TaxonNames)
                {
                    if ((name.TaxonNameType.Id == 0) &&
                        (name.TaxonNameUseType.Id == 0) &&
                        (!name.IsRecommended) &&
                        (name.Name != _taxon.ScientificName))
                    {
                        _italicStringsInAutomaticTaxonomicParagraph.Add(name.Name);
                        Synonyms.Add(name);
                    }
                }

                if (Synonyms.Count > 0)
                {
                    text.Append(". Syn. ");
                    for (Int32 itemIndex = 0; itemIndex < Synonyms.Count; itemIndex++)
                    {
                        if (itemIndex > 0)
                        {
                            if (itemIndex == Synonyms.Count - 1)
                            {
                                text.Append(" och ");
                            }
                            else
                            {
                                text.Append(", ");
                            }
                        }

                        text.Append(Synonyms[itemIndex].Name);
                        if (Synonyms[itemIndex].Author.IsNotEmpty())
                        {
                            text.Append(" " + Synonyms[itemIndex].Author);
                        }
                    }
                }
                if (text.ToString() != String.Empty)
                {
                    text.Append(". ");
                }
            }
            String cleanText = text.ToString().Replace("..", ".");

            return(cleanText);
        }