use of org.openforis.collect.manager.speciesimport.SpeciesImportStatus 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.manager.speciesimport.SpeciesImportStatus 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.manager.speciesimport.SpeciesImportStatus in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method testErrorHandling.
@Test
public void testErrorHandling() throws Exception {
SpeciesImportProcess process = importCSVFile(INVALID_TEST_CSV);
SpeciesImportStatus status = process.getStatus();
List<ParsingError> errors = status.getErrors();
assertEquals(7, errors.size());
assertTrue(status.isRowProcessed(1));
assertTrue(status.isRowProcessed(2));
assertTrue(status.isRowProcessed(4));
assertTrue(status.isRowProcessed(5));
assertFalse(status.isRowProcessed(3));
assertFalse(status.isRowProcessed(6));
assertFalse(status.isRowProcessed(7));
assertFalse(status.isRowProcessed(8));
assertFalse(status.isRowProcessed(9));
assertFalse(status.isRowProcessed(10));
assertFalse(status.isRowProcessed(11));
// unexisting row
assertFalse(status.isRowProcessed(12));
assertTrue(containsError(errors, 3, SpeciesFileColumn.CODE, ErrorType.EMPTY));
assertTrue(containsError(errors, 6, SpeciesFileColumn.CODE, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 7, SpeciesFileColumn.FAMILY, ErrorType.EMPTY));
assertTrue(containsError(errors, 8, SpeciesFileColumn.NO, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 9, SpeciesFileColumn.SCIENTIFIC_NAME, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 10, SpeciesFileColumn.SCIENTIFIC_NAME, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 11, "swh", ErrorType.INVALID_VALUE));
}
Aggregations