TaxonLabel taxonLabel,
List<String> ubioResultErrors) {
String tvId = request.getParameter("taxonvariantid");
String manualIdString = request.getParameter("manualid");
Long manualId = null;
TaxonVariant variant = null;
if ( ! manualIdString.equals("") ) {
try {
manualId = Long.parseLong(manualIdString);
} catch ( NumberFormatException e ) {
ubioResultErrors.add("Not a valid ID: "+manualIdString);
return variant;
}
}
if ( manualId == null ) {
// 1a or 1b depending whether findTaxonVariantByID returns a variant or null
try {
variant = getTaxonLabelService().findTaxonVariantByID(Long.parseLong(tvId));
} catch ( NumberFormatException e ) {
LOGGER.info("NumberFormatException, user supplied taxon variant id was probably null: "+tvId);
}
}
else {
Taxon taxon = null;
taxon = getTaxonHome().findByUBIOTaxId(manualId);
if ( taxon != null ) {
// 2a
Collection<TaxonVariant> variants = getTaxonHome().findVariantsByTaxon(taxon);
variant = variants.iterator().next();
}
else {
// 2b
TaxonLabelService taxonLabelService = getTaxonLabelService();
Integer ncbiId = taxonLabelService.findNcbiTaxIdByUBIOTaxId(manualId);
Taxon newTaxon = null;
TaxonVariant newVariant = null;
if ( null != ncbiId ) {
String ncbiPreferredName = taxonLabelService.getNCBIPreferredName(ncbiId.toString());
newTaxon = new Taxon(ncbiPreferredName,manualId,ncbiId);
newVariant = new TaxonVariant(manualId,taxonLabel.getTaxonLabel(),ncbiPreferredName,"canonical form");
}
else {
newTaxon = new Taxon();
newTaxon.setName(taxonLabel.getTaxonLabel());
newTaxon.setUBioNamebankId(manualId);
newVariant = new TaxonVariant(manualId,taxonLabel.getTaxonLabel(),taxonLabel.getTaxonLabel(),"canonical form");
}
newVariant.setTaxon(newTaxon);
getTaxonHome().store(newTaxon);
getTaxonHome().store(newVariant);
variant = newVariant;
}
}