use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesDaoIntegrationTest method testFindVernacularName.
private void testFindVernacularName(String match, int maxResults, int expectedResults) {
// Create taxonomy
CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
Taxon family1 = testInsertAndLoadTaxon(taxonomy1, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
Taxon genus1 = testInsertAndLoadTaxon(taxonomy1, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
Taxon species1 = testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
testInsertAndLoadVernacularName(family1, "Walnut family", "eng", "", 9);
testInsertAndLoadVernacularName(genus1, "Walnut", "eng", "", 0);
testInsertAndLoadVernacularName(genus1, "Noce", "ita", "", 9);
testInsertAndLoadVernacularName(species1, "Noce bianco", "ita", "", 9);
testInsertAndLoadVernacularName(species1, "Persian walnut", "eng", "", 9);
testInsertAndLoadVernacularName(species1, "Орех грецкий", "rus", "", 9);
List<TaxonVernacularName> results = taxonVernacularNameDao.findByVernacularName(taxonomy1.getId(), match, maxResults);
assertEquals(expectedResults, results.size());
match = match.toUpperCase();
for (TaxonVernacularName tvn : results) {
String name = tvn.getVernacularName();
name = name.toUpperCase();
assertTrue(name.contains(match));
}
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesBackupImportTask method findParentTaxon.
private Taxon findParentTaxon(SpeciesBackupLine line) throws ParsingException {
Node parentNode = line.getParentId() == null ? null : taxonTree.getNodeBySystemId(line.getParentId());
Taxon parent = parentNode == null ? null : parentNode.getTaxon();
return parent;
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method loadTaxonSummaries.
public TaxonSummaries loadTaxonSummaries(CollectSurvey survey, int taxonomyId, int offset, int maxRecords) {
CollectTaxonomy taxonomy = loadTaxonomyById(survey, taxonomyId);
String taxonomyName = taxonomy.getName();
int totalCount = taxonDao.countTaxons(taxonomy);
Set<String> vernacularNamesLanguageCodes = new HashSet<String>();
List<TaxonSummary> items = new ArrayList<TaxonSummary>();
TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
if (totalCount > 0) {
List<Taxon> taxons = taxonDao.loadTaxons(taxonomy, offset, maxRecords);
for (Taxon taxon : taxons) {
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxon.getSystemId());
TaxonSummary summary = new TaxonSummary(taxonDefinition, taxon, vernacularNames, null);
List<String> itemVernLangCodes = summary.getVernacularLanguages();
vernacularNamesLanguageCodes.addAll(itemVernLangCodes);
items.add(summary);
}
}
List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(vernacularNamesLanguageCodes);
Collections.sort(sortedVernacularNamesLanguageCodes);
List<String> infoAttributeNames = taxonDefinition.getAttributeNames();
return new TaxonSummaries(totalCount, items, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method persistTaxonTreeNode.
protected void persistTaxonTreeNode(List<Taxon> taxonInsertBuffer, List<TaxonVernacularName> taxonVernacularNameInsertBuffer, CollectTaxonomy taxonomy, Node node) {
Taxon taxon = node.getTaxon();
taxon.setTaxonomyId(taxonomy.getId());
taxon.setStep(CONFIRMED_TAXON_STEP_NUMBER);
taxonInsertBuffer.add(taxon);
if (taxonInsertBuffer.size() > TAXON_INSERT_BUFFER_SIZE) {
flushTaxonInsertBuffer(taxonomy, taxonInsertBuffer);
}
List<TaxonVernacularName> vernacularNames = node.getVernacularNames();
for (TaxonVernacularName vernacularName : vernacularNames) {
taxonVernacularNameInsertBuffer.add(vernacularName);
if (taxonInsertBuffer.size() > TAXON_VERNACULAR_NAME_INSERT_BUFFER_SIZE) {
flushTaxonVernacularNameInsertBuffer(taxonVernacularNameInsertBuffer);
}
}
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method fromTaxonomiesToTaxonOccurrences.
private List<TaxonOccurrence> fromTaxonomiesToTaxonOccurrences(List<Taxon> list, TaxonSearchParameters parameters) {
List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>(list.size());
for (Taxon taxon : list) {
TaxonOccurrence o = new TaxonOccurrence(taxon);
o.setTaxonRank(taxon.getTaxonRank());
if (parameters.isIncludeUniqueVernacularName()) {
includeUniqueVernacularNameIfAny(taxon.getSystemId(), o);
}
if (parameters.isIncludeAncestorTaxons()) {
loadAncestorTaxons(taxon, o);
}
result.add(o);
}
return result;
}
Aggregations