use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesDaoIntegrationTest method testCRUD.
// Disabled because SQLite does not provide Unicode case support by default
// TODO implement it
// @Test
// public void testFindUnicode() throws Exception {
// testFindVernacularName("Орех", 100, 1);
// }
//
// @Test
// public void testFindUnicodeCaseInsensitive() throws Exception {
// testFindVernacularName("орех", 100, 1);
// }
@Test
public void testCRUD() throws Exception {
// Create taxonomy
CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
// Create taxa
Stack<Taxon> taxa = new Stack<Taxon>();
taxa.push(testInsertAndLoadTaxon(taxonomy1, -1, "JUG", "Juglandaceaex", FAMILY, 9, null));
taxa.push(testInsertAndLoadTaxon(taxonomy1, -2, "JUG2", "sJuglans sp.", GENUS, 0, null));
taxa.push(testUpdateAndLoadTaxon(taxonomy1, taxa.pop(), "Juglans sp.", GENUS, 9, taxa.get(0)));
taxa.push(testInsertAndLoadTaxon(taxonomy1, -4, "JUG3", "Juglans regia", SPECIES, 9, taxa.get(1)));
// Create vernacular names
Stack<TaxonVernacularName> names = new Stack<TaxonVernacularName>();
names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnut family", "eng", "", 9));
names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnuts", "en", "Cockney", 0));
names.push(testUpdateAndLoadVernacularName(names.pop(), taxa.get(1), "Walnut", "eng", "", 9));
names.push(testInsertAndLoadVernacularName(taxa.get(1), "Noce", "ita", "", 9));
names.push(testInsertAndLoadVernacularName(taxa.get(2), "Persian walnut", "eng", "", 9));
names.push(testInsertAndLoadVernacularName(taxa.get(2), "English walnut", "eng", "", 9));
names.push(testInsertAndLoadVernacularName(taxa.get(2), "Noce bianco", "ita", "", 9));
names.push(testInsertAndLoadVernacularName(taxa.get(2), "Орех грецкий", "rus", "", 9));
// Remove names
while (!names.isEmpty()) {
testDeleteAndLoadVernacularName(names.pop());
}
// Remove taxa
while (!taxa.isEmpty()) {
testDeleteAndLoadTaxon(taxa.pop());
}
// Remove taxonomy
testDeleteAndLoadTaxonomy(taxonomy1);
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesDaoIntegrationTest method testFindScientificName.
private void testFindScientificName(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);
testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
List<Taxon> results = taxonDao.findByScientificName(taxonomy1, FAMILY, match, maxResults);
assertEquals(expectedResults, results.size());
match = match.toUpperCase();
for (Taxon taxon : results) {
String name = taxon.getScientificName();
name = name.toUpperCase();
assertTrue(name.startsWith(match));
}
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method fromVernacularNamesToTaxonOccurrences.
private List<TaxonOccurrence> fromVernacularNamesToTaxonOccurrences(CollectTaxonomy taxonomy, List<TaxonVernacularName> vernacularNames, TaxonSearchParameters parameters) {
List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
for (TaxonVernacularName vernacularName : vernacularNames) {
Taxon taxon = taxonDao.loadById(taxonomy, vernacularName.getTaxonSystemId());
TaxonRank highestRank = parameters.getHighestRank();
if (highestRank == null || highestRank == taxon.getTaxonRank() || highestRank.isHigherThan(taxon.getTaxonRank())) {
TaxonOccurrence o = new TaxonOccurrence(taxon, vernacularName);
if (parameters.isIncludeAncestorTaxons()) {
loadAncestorTaxons(taxon, o);
}
result.add(o);
}
}
return result;
}
use of org.openforis.idm.model.species.Taxon in project collect by openforis.
the class SpeciesManager method findByFamilyCode.
public List<TaxonOccurrence> findByFamilyCode(CollectTaxonomy taxonomy, String searchString, int maxResults, TaxonSearchParameters parameters) {
List<TaxonOccurrence> result = new ArrayList<TaxonOccurrence>();
TaxonTree taxonTree = loadTaxonTree(taxonomy);
List<Taxon> families = taxonTree.findTaxaByCodeStartingWith(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 SpeciesBackupImportTask method processLine.
protected void processLine(SpeciesBackupLine line) throws ParsingException {
Taxon taxon = new Taxon();
taxon.setSystemId(line.getId());
taxon.setParentId(line.getParentId());
taxon.setTaxonRank(line.getRank());
taxon.setTaxonId(line.getNo());
taxon.setCode(line.getCode());
taxon.setScientificName(line.getScientificName());
List<Attribute> taxonAttributes = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributes();
for (Attribute taxonAttribute : taxonAttributes) {
taxon.addInfoAttribute(line.getInfoAttribute(taxonAttribute.getName()));
}
Taxon parent = findParentTaxon(line);
taxonTree.addNode(parent, taxon);
processVernacularNames(line, taxon);
}
Aggregations