/// <summary> /// Get dyntaxa taxon id as a string. /// </summary> /// <param name="speciesObservationFields">Dictionary of web data fields.</param> /// <param name="context">Web service context.</param> /// <returns>Returns dyntaxa taxon id as a string.</returns> protected override string GetDyntaxaTaxonId(Dictionary <string, WebDataField> speciesObservationFields, WebServiceContext context) { Dictionary <Int32, TaxonInformation> taxonInformationDictionary; TaxonInformation taxonInformation = null; TaxonNameDictionaries taxonNameDictionaries; taxonNameDictionaries = TaxonManager.GetTaxonNameDictionaries(context); // Try to get dyntaxaTaxonId through scientific name. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("scientificname")) { taxonInformation = taxonNameDictionaries.ScientificNames.Get(speciesObservationFields["scientificname"].Value.ToLower()); } // Try to get dyntaxaTaxonId through scientific name and author. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("scientificname")) { taxonInformation = taxonNameDictionaries.ScientificNameAndAuthor.Get(speciesObservationFields["scientificname"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through scientific name of species. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("species")) { taxonInformation = taxonNameDictionaries.ScientificNames.Get(speciesObservationFields["species"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through scientific name of genus. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("genus")) { taxonInformation = taxonNameDictionaries.ScientificNames.Get(speciesObservationFields["genus"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through scientificName of generic name. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("genericname")) { taxonInformation = taxonNameDictionaries.ScientificNames.Get(speciesObservationFields["genericname"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through scientific name as synonyms. // No synonyms in the species observation database. // Try to get the dyntaxaTaxonId through genus. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("genus")) { taxonInformation = taxonNameDictionaries.Genus.Get(speciesObservationFields["genus"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through scientific name of genus and taxon rank. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("genus") && speciesObservationFields.ContainsKey("taxonrank")) { taxonInformation = taxonNameDictionaries.ScientificNames.GetByTaxonRank(speciesObservationFields["genus"].Value.ToLower(), speciesObservationFields["taxonrank"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through genus and kingdom. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("genus") && speciesObservationFields.ContainsKey("kingdom")) { taxonInformation = taxonNameDictionaries.Genus.GetByKingdom(speciesObservationFields["genus"].Value.ToLower(), speciesObservationFields["kingdom"].Value.ToLower()); } // Try to get the dyntaxaTaxonId through scientificname by combining genericname and specificepithet. if (taxonInformation.IsNull() && speciesObservationFields.ContainsKey("genericname") && speciesObservationFields.ContainsKey("specificepithet")) { taxonInformation = taxonNameDictionaries.ScientificNames.Get(speciesObservationFields["genericname"].Value.ToLower() + " " + speciesObservationFields["specificepithet"].Value.ToLower()); } // Loop through all invalid taxons until a valid taxon is found. if (taxonInformation.IsNotNull()) { taxonInformationDictionary = WebSpeciesObservationServiceData.TaxonManager.GetTaxonInformation(context); int previousTaxonId = -1; while (!(taxonInformation.IsValid) && (taxonInformation.DyntaxaTaxonId != previousTaxonId) && (0 <= taxonInformation.CurrentDyntaxaTaxonId)) { previousTaxonId = taxonInformation.DyntaxaTaxonId; taxonInformation = taxonInformationDictionary[taxonInformation.CurrentDyntaxaTaxonId]; } if (taxonInformation.IsValid) { return(taxonInformation.DyntaxaTaxonId.ToString()); } } return(string.Empty); }
/// <summary> /// Update taxon information in database. /// New information is read from web service TaxonService. /// </summary> /// <param name="context"> /// User context. /// </param> /// <param name="taxons"> /// The taxon. /// </param> /// <param name="taxonTrees"> /// Contains information about all valid taxon trees. /// </param> /// <param name="taxonRemarks"> /// The taxon remarks. /// </param> private static void UpdateTempTaxonInformation( WebServiceContext context, List <WebTaxon> taxons, IEnumerable <WebTaxonTreeNode> taxonTrees, Dictionary <Int32, String> taxonRemarks) { Dictionary <Int32, TaxonInformation> taxonInformations; TaxonInformation taxonInformation; ResetTaxaCache(); foreach (var taxonTreeNode in taxonTrees) { AddTaxaToCache(taxonTreeNode); } //load taxon tree with only main parents var mainParentsTaxonTree = WebServiceData.TaxonManager.GetTaxonTreesBySearchCriteria(context, new WebTaxonTreeSearchCriteria { IsMainRelationRequired = true, IsValidRequired = true }); var dictionaryTaxonTreeNode = ConvertTreeNodeStructure(mainParentsTaxonTree); taxonInformations = GetSpeciesFactInformation(context); // Create worktable. using (var taxaTable = CreateTaxaTable()) { // Add information into table (only once per taxonId) var taxonIds = new DataIdInt32List(true); foreach (var taxon in taxons) { if (taxonIds.Contains(taxon.Id)) { continue; } else { taxonIds.Add(taxon.Id); } if (taxonInformations.ContainsKey(taxon.Id)) { taxonInformation = taxonInformations[taxon.Id]; } else { taxonInformation = new TaxonInformation(); taxonInformation.ActionPlanId = 0; taxonInformation.ConservationRelevant = false; taxonInformation.DisturbanceRadius = 0; taxonInformation.DyntaxaTaxonId = taxon.Id; taxonInformation.Natura2000 = false; taxonInformation.ProtectedByLaw = false; taxonInformation.ProtectionLevel = 0; taxonInformation.RedlistCategory = String.Empty; taxonInformation.SwedishImmigrationHistory = String.Empty; taxonInformation.SwedishOccurrence = String.Empty; } var row = taxaTable.NewRow(); row[0] = taxon.Id; // dyntaxaTaxonId if (!taxon.CategoryId.Equals(CATEGORY_HYBRID)) { try { // infraspecificEpithet row[1] = GetPartOfScientificName(taxon.ScientificName, INFRA_SPECIFIC_EPITHET); } catch (Exception) { WebServiceData.LogManager.Log( context, "Problems with taxon id = " + taxon.Id, LogType.Error, null); throw; } } else { row[1] = null; } row[2] = String.Empty; // nameAccordingTo isplanned=0 row[3] = String.Empty; // nameAccordingToId isplanned=0 row[4] = String.Empty; // namePublishedIn isplanned=0 row[5] = String.Empty; // namePublishedInId isplanned=0 row[6] = String.Empty; // namePublishedInYear isplanned=0 row[7] = String.Empty; // nomenclaturalCode isplanned=0 row[8] = String.Empty; // nomenclaturalStatus - Metod som hämtar namn från taxonobjektet row[9] = GetTaxaOriginalNameFromCache(taxon.Id); // originalNameUsage row[10] = String.Empty; // originalNameUsageId row[11] = taxon.ScientificName; // scientificName row[12] = taxon.Author; // scientificNameAuthorship row[13] = GetTaxonNameGuidFromCache(taxon.Id); // scientificNameId if (!taxon.CategoryId.Equals(CATEGORY_HYBRID)) { // specificEpithet row[14] = GetPartOfScientificName(taxon.ScientificName, SPECIFIC_EPITHET); } else { row[14] = null; } row[15] = taxon.Guid; // taxonConceptId row[16] = String.Empty; // taxonConceptStatus row[17] = String.Empty; // taxonomicStatus row[18] = GetTaxonCategoryFromCache(taxon.CategoryId); // taxonRank row[19] = taxon.SortOrder; // taxonSortOrder row[20] = TAXON_URL_PREFIX + taxon.Id.WebToString(); // taxonURL row[21] = taxon.CommonName; // vernacularName row[22] = taxon.CategoryId; //row[23] = 0; // actionplan //row[24] = 0; // conservationRelevant //row[25] = 0; // natura2000 //row[26] = 0; // protectedByLaw //row[27] = 0; // protectionLevel //row[28] = String.Empty; // redlistCategory //row[29] = String.Empty; // swedishImmigrationHistory //row[30] = String.Empty; // swedishOccurrence //row[31] = String.Empty; // organismGroup //row[32] = 0; // disturbanceRadius row[23] = taxonInformation.ActionPlanId; // actionplan row[24] = taxonInformation.ConservationRelevant ? 1 : 0; // conservationRelevant row[25] = taxonInformation.Natura2000 ? 1 : 0; // natura2000 row[26] = taxonInformation.ProtectedByLaw ? 1 : 0; // protectedByLaw row[27] = taxonInformation.ProtectionLevel; // protectionLevel row[28] = taxonInformation.RedlistCategory; // redlistCategory row[29] = taxonInformation.SwedishImmigrationHistory; // swedishImmigrationHistory row[30] = taxonInformation.SwedishOccurrence; // swedishOccurrence row[31] = taxonInformation.OrganismGroup; // organismGroup row[32] = taxonInformation.DisturbanceRadius; // disturbanceRadius row[33] = String.Empty; row[34] = String.Empty; row[35] = String.Empty; row[36] = String.Empty; row[37] = String.Empty; row[38] = String.Empty; row[39] = String.Empty; row[40] = String.Empty; if (taxon.IsValid) { // Load TempTaxonTreeNodes into dictionary. // Dictionary<Int32, MyTaxonTreeNode> dictionaryTaxonTreeNode = GetTaxonTreeNodes(context); Int32 currentTaxonId = taxon.Id; String higherClassificationList = String.Empty; String sign = String.Empty; //loop through the tree structure and set the corresponding values if (dictionaryTaxonTreeNode.ContainsKey(currentTaxonId)) { while (dictionaryTaxonTreeNode[currentTaxonId].Parents.IsNotEmpty()) { currentTaxonId = dictionaryTaxonTreeNode[currentTaxonId].Parents[0].TaxonId; if (dictionaryTaxonTreeNode[currentTaxonId].Parents.IsNotEmpty()) { higherClassificationList = dictionaryTaxonTreeNode[currentTaxonId].Parents[0].Information .ScientificName + sign + higherClassificationList; sign = ";"; } switch (dictionaryTaxonTreeNode[currentTaxonId].Information.TaxonCategoryId) { case (Int32)TaxonCategoryId.Class: // row[34] = String.Empty; //class row[34] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; case (Int32)TaxonCategoryId.Family: // row[35] = String.Empty; //family row[35] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; case (Int32)TaxonCategoryId.Genus: // row[36] = String.Empty; //genus row[36] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; case (Int32)TaxonCategoryId.Kingdom: // row[37] = String.Empty; //kingdom row[37] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; case (Int32)TaxonCategoryId.Order: // row[38] = String.Empty; //order row[38] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; case (Int32)TaxonCategoryId.Phylum: // row[39] = String.Empty; //phylum row[39] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; case (Int32)TaxonCategoryId.Subgenus: // row[40] = String.Empty; //subgenus row[40] = dictionaryTaxonTreeNode[currentTaxonId].Information.ScientificName; break; } } row[33] = higherClassificationList; } } row[41] = taxon.IsValid; // isValid if (taxon.IsValid) { row[42] = DBNull.Value; } else { row[42] = TaxonManager.GetNewTaxonId(context, taxon.Id); // newDyntaxaTaxonId } if (taxonRemarks.ContainsKey(taxon.Id)) { row[43] = taxonRemarks[taxon.Id]; } else { row[43] = "-"; } if (taxon.IsValid) { row[44] = taxon.Id; } else { row[44] = TaxonManager.GetCurrentTaxonId(context, taxon.Id); // currentDyntaxaTaxonId } taxaTable.Rows.Add(row); } // Copy data into database. context.GetSpeciesObservationDatabase().AddTableData(context, taxaTable); } }