use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesExportTask method initializeInternalVariables.
@Override
protected void initializeInternalVariables() throws Throwable {
super.initializeInternalVariables();
this.infoAttributeNames = extractInfoAttributeNames();
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
this.taxonomyName = taxonomy.getName();
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesExportTask method execute.
@Override
protected void execute() throws Throwable {
CsvWriter writer = new CsvWriter(outputStream);
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
List<String> vernacularNamesLangCodes = getNotEmptyValues(summaries.getVernacularNamesLanguageCodes());
// consider Latin vernacular name as synonym
vernacularNamesLangCodes.remove(LATIN_LANG_CODE);
// write headers
ArrayList<String> colNames = new ArrayList<String>();
colNames.add(SpeciesFileColumn.NO.getColumnName());
colNames.add(SpeciesFileColumn.CODE.getColumnName());
colNames.add(SpeciesFileColumn.FAMILY.getColumnName());
colNames.add(SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName());
colNames.add(SpeciesFileColumn.SYNONYMS.getColumnName());
colNames.addAll(vernacularNamesLangCodes);
colNames.addAll(infoAttributeNames);
writer.writeHeaders(colNames);
for (TaxonSummary item : summaries.getItems()) {
writeTaxonSummary(writer, vernacularNamesLangCodes, infoAttributeNames, item);
}
writer.flush();
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method testVernacularNamesImport.
@Test
public void testVernacularNamesImport() throws Exception {
SpeciesImportProcess process = importCSVFile(VALID_TEST_CSV);
SpeciesImportStatus status = process.getStatus();
assertTrue(status.isComplete());
CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName(survey, TEST_TAXONOMY_NAME);
TaxonSearchParameters taxonSearchParameters = new TaxonSearchParameters();
taxonSearchParameters.setHighestRank(FAMILY);
{
List<TaxonOccurrence> occurrences = speciesManager.findByVernacularName(taxonomy, null, "Mbamba", 10, taxonSearchParameters);
assertNotNull(occurrences);
assertEquals(1, occurrences.size());
TaxonOccurrence stored = occurrences.get(0);
TaxonOccurrence expected = new TaxonOccurrence(8, "AFZ/QUA", "Afzelia quanzensis", "Mbambakofi", "swh", null);
expected.setTaxonRank(SPECIES);
assertEquals(expected, stored);
}
{
List<TaxonOccurrence> occurrences = speciesManager.findByVernacularName(taxonomy, null, "Mshai-mamba", 10, taxonSearchParameters);
assertNotNull(occurrences);
assertEquals(1, occurrences.size());
TaxonOccurrence stored = occurrences.get(0);
TaxonOccurrence expected = new TaxonOccurrence(10, "ALB/ADI", "Albizia adianthifolia", "Mshai-mamba", "ksb", null);
expected.setTaxonRank(SPECIES);
assertEquals(expected, stored);
}
{
Taxon taxon = findTaxonByCode("ALB/ADI");
Integer taxonId = taxon.getSystemId();
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxonId);
assertTrue(contains(vernacularNames, "ksb", "Mchao"));
assertTrue(contains(vernacularNames, "ksb", "Mkengemshaa"));
assertTrue(contains(vernacularNames, "ksb", "Msai"));
assertTrue(contains(vernacularNames, "ksb", "Mshai"));
assertTrue(contains(vernacularNames, "ksb", "Mshai-mamba"));
assertFalse(contains(vernacularNames, "eng", "Mahogany"));
assertFalse(contains(vernacularNames, "ksb", "Mahogany"));
}
{
Taxon taxon = findTaxonByCode("BOU/PET");
assertEquals("Bourreria petiolaris", taxon.getScientificName());
Integer taxonId = taxon.getSystemId();
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxonId);
assertEquals(1, vernacularNames.size());
assertTrue(contains(vernacularNames, "swh", "Mpanda jongoo"));
}
{
Taxon taxon = findTaxonByCode("BOM/RHO");
assertEquals("Bombax rhodognaphalon", taxon.getScientificName());
Integer taxonId = taxon.getSystemId();
List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxonId);
assertEquals(1, vernacularNames.size());
assertTrue(contains(vernacularNames, "swh", "Msufi mwitu"));
}
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method testHierarchyImport.
@Test
public void testHierarchyImport() throws Exception {
SpeciesImportProcess process = importCSVFile(VALID_TEST_CSV);
SpeciesImportStatus status = process.getStatus();
assertTrue(status.isComplete());
CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
{
Taxon variety = findTaxonByCode("ALB/SCH/amaniensis");
assertNotNull(variety);
assertEquals(VARIETY, variety.getTaxonRank());
Integer speciesId = variety.getParentId();
assertNotNull(speciesId);
Taxon species = taxonDao.loadById(taxonomy, speciesId);
assertNotNull(species);
assertNull(species.getCode());
assertEquals(SPECIES, species.getTaxonRank());
assertEquals("Albizia schimperiana", species.getScientificName());
Integer genusId = species.getParentId();
assertNotNull(genusId);
Taxon genus = taxonDao.loadById(taxonomy, genusId);
assertNotNull(genus);
assertEquals("ALB", genus.getCode());
assertEquals(GENUS, genus.getTaxonRank());
assertEquals("Albizia sp.", genus.getScientificName());
Integer familyId = genus.getParentId();
assertNotNull(familyId);
Taxon family = taxonDao.loadById(taxonomy, familyId);
assertNotNull(family);
assertNull(family.getParentId());
assertEquals(FAMILY, family.getTaxonRank());
assertEquals("Fabaceae", family.getScientificName());
}
{
Taxon subspecies = findTaxonByCode("OLE/EUR/cuspidata");
assertNotNull(subspecies);
assertEquals(SUBSPECIES, subspecies.getTaxonRank());
Integer speciesId = subspecies.getParentId();
assertNotNull(speciesId);
Taxon species = taxonDao.loadById(taxonomy, speciesId);
assertNotNull(species);
assertEquals(SPECIES, species.getTaxonRank());
assertEquals("OLE/EUR", species.getCode());
assertEquals("Olea europaea", species.getScientificName());
}
}
use of org.openforis.collect.model.CollectTaxonomy in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method findByCode.
protected TaxonOccurrence findByCode(String code) {
CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
TaxonSearchParameters taxonSearchParameters = new TaxonSearchParameters();
List<TaxonOccurrence> occurrences = speciesManager.findByCode(taxonomy, code, 10, taxonSearchParameters);
assertNotNull(occurrences);
assertEquals(1, occurrences.size());
TaxonOccurrence occurrence = occurrences.get(0);
return occurrence;
}
Aggregations