use of org.openforis.collect.model.CollectTaxonomy 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.collect.model.CollectTaxonomy 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.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesManager method moveTaxonomies.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void moveTaxonomies(CollectSurvey fromSurvey, CollectSurvey toSurvey) {
deleteTaxonomiesBySurvey(toSurvey);
List<CollectTaxonomy> taxonomies = taxonomyDao.loadAllBySurvey(fromSurvey);
for (CollectTaxonomy taxonomy : taxonomies) {
taxonomy.setSurvey(toSurvey);
taxonomyDao.update(taxonomy);
}
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesBackupExportTask method initializeInternalVariables.
@Override
protected void initializeInternalVariables() throws Throwable {
super.initializeInternalVariables();
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
this.taxonomyName = taxonomy.getName();
this.infoAttributeNames = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributeNames();
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesBackupExportTask method execute.
@Override
protected void execute() throws Throwable {
CsvWriter writer = new CsvWriter(outputStream);
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
TaxonSummaries summaries = speciesManager.loadFullTaxonSummaries(taxonomy);
List<String> vernacularNamesLangCodes = getNotEmptyValues(summaries.getVernacularNamesLanguageCodes());
// consider Latin vernacular name as synonym
vernacularNamesLangCodes.remove(LATIN_LANG_CODE);
this.vernacularNamesLangCodes = vernacularNamesLangCodes;
// write headers
writeHeaders(writer);
for (TaxonSummary item : summaries.getItems()) {
writeTaxonSummary(writer, item);
}
writer.flush();
}
Aggregations