use of org.openforis.collect.model.TaxonTree in project collect by openforis.
the class CollectSpeciesListService method loadSpeciesListData.
@Override
public Object loadSpeciesListData(Survey survey, String taxonomyName, String attribute, String speciesCode) {
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName((CollectSurvey) survey, taxonomyName);
TaxonTree taxonTree = speciesManager.loadTaxonTree(taxonomy);
Taxon taxon = taxonTree.findTaxonByCode(speciesCode);
if (taxon == null) {
return null;
}
Node taxonNode = taxonTree.getNodeBySystemId(taxon.getSystemId());
if (FAMILY_ATTRIBUTE.equals(attribute) || FAMILY_NAME_ATTRIBUTE.equals(attribute) || FAMILY_SCIENTIFIC_NAME_ATTRIBUTE.equals(attribute)) {
// family name
Node familyNode = taxonNode.getAncestor(TaxonRank.FAMILY);
return familyNode == null ? null : familyNode.getTaxon().getScientificName();
} else if (GENUS_ATTRIBUTE.equals(attribute)) {
Node genusNode = taxonNode.getAncestor(TaxonRank.GENUS);
return genusNode == null ? null : genusNode.getTaxon().getScientificName();
} else if (SCIENTIFIC_NAME_ATTRIBUTE.equals(attribute)) {
return taxon.getScientificName();
} else if (CODE_ATTRIBUTE.equals(attribute)) {
return taxon.getCode();
} else if (Languages.exists(Standard.ISO_639_3, attribute)) {
TaxonVernacularName vernacularName = taxonNode.getVernacularName(attribute);
return vernacularName == null ? null : vernacularName.getVernacularName();
} else {
// info (extra) attribute
TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
if (taxonDefinition == null) {
throw new IllegalArgumentException("No reference data schema found for taxonomy: " + taxonomyName);
} else {
int attributeIndex = taxonDefinition.getAttributeNames().indexOf(attribute);
if (attributeIndex < 0) {
throw new IllegalArgumentException("Unsupported attribute: " + attribute);
} else {
return taxon.getInfoAttribute(attributeIndex);
}
}
}
}
use of org.openforis.collect.model.TaxonTree 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.collect.model.TaxonTree in project collect by openforis.
the class SpeciesManager method loadFullTaxonSummaries.
public TaxonSummaries loadFullTaxonSummaries(CollectTaxonomy taxonomy) {
TaxonTree tree = loadTaxonTree(taxonomy);
List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.FAMILY, true);
List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
Collections.sort(sortedVernacularNamesLanguageCodes);
List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
use of org.openforis.collect.model.TaxonTree 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.collect.model.TaxonTree in project collect by openforis.
the class SpeciesManager method loadFullTaxonSummariesOld.
public TaxonSummaries loadFullTaxonSummariesOld(CollectTaxonomy taxonomy) {
TaxonTree tree = loadTaxonTree(taxonomy);
List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.GENUS, false);
List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
Collections.sort(sortedVernacularNamesLanguageCodes);
List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Aggregations