use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method loadAncestorTaxons.
private void loadAncestorTaxons(Taxon taxon, TaxonOccurrence o) {
Taxon currentTaxon = taxon;
while (currentTaxon.getParentId() != null) {
Taxon parentTaxon = taxonDao.loadById((CollectTaxonomy) currentTaxon.getTaxonomy(), currentTaxon.getParentId());
TaxonOccurrence parentTaxonOccurrence = new TaxonOccurrence(parentTaxon);
o.addAncestorTaxon(parentTaxonOccurrence);
currentTaxon = parentTaxon;
}
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method findByFamilyScientificName.
public List<TaxonOccurrence> findByFamilyScientificName(CollectTaxonomy taxonomy, String searchString, int maxResults, TaxonSearchParameters parameters) {
List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
TaxonTree taxonTree = loadTaxonTree(taxonomy);
List<Taxon> families = taxonTree.findTaxaByScientificNameStartingWith(searchString, parameters.getHighestRank());
result.addAll(fromTaxonomiesToTaxonOccurrences(families, parameters));
for (Taxon familyTaxon : families) {
List<TaxonOccurrence> descendants = taxonTree.getDescendantOccurrences(familyTaxon, parameters);
result.addAll(descendants);
}
return result;
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method loadTaxonTree.
public TaxonTree loadTaxonTree(CollectTaxonomy taxonomy) {
TaxonTree tree = taxonTreeByTaxonomyIdCache.get(taxonomy.getId());
if (tree == null) {
String taxonomyName = taxonomy.getName();
TaxonomyDefinition taxonDefinition = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
List<Taxon> taxons = taxonDao.loadTaxonsForTreeBuilding(taxonomy);
tree = new TaxonTree(taxonDefinition);
Map<Integer, Taxon> idToTaxon = new HashMap<Integer, Taxon>();
for (Taxon taxon : taxons) {
Integer systemId = taxon.getSystemId();
Integer parentId = taxon.getParentId();
Taxon parent = parentId == null ? null : idToTaxon.get(parentId);
Node newNode = tree.addNode(parent, taxon);
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(systemId);
tree.addVernacularNames(newNode, vernacularNames);
idToTaxon.put(systemId, taxon);
}
taxonTreeByTaxonomyIdCache.put(taxonomy.getId(), tree);
}
return tree;
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesImportProcess method findParentTaxon.
private Taxon findParentTaxon(SpeciesLine line) throws ParsingException {
TaxonRank rank = line.getRank();
TaxonRank parentRank = rank.getParent();
String scientificName;
switch(parentRank) {
case FAMILY:
scientificName = line.getFamilyName();
break;
case GENUS:
scientificName = line.getGenus();
break;
case SPECIES:
scientificName = line.getSpeciesName();
break;
default:
throw new RuntimeException("Unsupported rank");
}
Taxon result = taxonTree.findTaxonByScientificName(scientificName);
return result;
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesImportProcess method createTaxon.
protected Taxon createTaxon(SpeciesLine line, TaxonRank rank, Taxon parent, String normalizedScientificName) throws ParsingException {
boolean mostSpecificRank = line.getRank() == rank;
Taxon taxon = taxonTree.findTaxonByScientificName(normalizedScientificName);
boolean newTaxon = taxon == null;
if (newTaxon) {
taxon = new Taxon();
taxon.setTaxonRank(rank);
taxon.setScientificName(normalizedScientificName);
Node node = taxonTree.addNode(parent, taxon);
node.addMetadata(LINE_NUMBER_TREE_NODE_METADATA, line.getLineNumber());
node.addMetadata(RAW_SCIENTIFIC_NAME_TREE_NODE_METADATA, line.getRawScientificName());
} else if (mostSpecificRank) {
checkDuplicateScientificName(line, parent, normalizedScientificName);
}
if (mostSpecificRank) {
String code = line.getCode();
Integer taxonId = line.getTaxonId();
checkDuplicates(line, code, taxonId);
taxon.setCode(code);
taxon.setTaxonId(taxonId);
TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
List<Attribute> taxonAttributes = taxonDefinition.getAttributes();
for (Attribute attribute : taxonAttributes) {
String value = line.getInfoAttribute(attribute.getName());
taxon.addInfoAttribute(value);
}
taxonTree.updateNodeInfo(taxon);
processVernacularNames(line, taxon);
}
return taxon;
}
Aggregations