Search in sources :

Example 26 with Taxon

use of org.openforis.idm.model.species.Taxon 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"));
    }
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) Taxon(org.openforis.idm.model.species.Taxon) SpeciesImportProcess(org.openforis.collect.manager.speciesimport.SpeciesImportProcess) SpeciesImportStatus(org.openforis.collect.manager.speciesimport.SpeciesImportStatus) List(java.util.List) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 27 with Taxon

use of org.openforis.idm.model.species.Taxon 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());
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) SpeciesImportProcess(org.openforis.collect.manager.speciesimport.SpeciesImportProcess) SpeciesImportStatus(org.openforis.collect.manager.speciesimport.SpeciesImportStatus) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 28 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class TaxonTree method index.

protected void index(Node node) {
    Taxon taxon = node.getTaxon();
    scientificNameToNode.put(taxon.getScientificName(), node);
    String code = taxon.getCode();
    if (code != null) {
        codeToNode.put(code, node);
    }
    Integer taxonId = taxon.getTaxonId();
    if (taxonId != null) {
        taxonIdToNode.put(taxonId, node);
    }
    Integer systemId = taxon.getSystemId();
    if (systemId != null) {
        systemIdToNode.put(systemId, node);
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon)

Example 29 with Taxon

use of org.openforis.idm.model.species.Taxon in project collect by openforis.

the class SpeciesImportProcess method createTaxonSpecies.

protected Taxon createTaxonSpecies(SpeciesLine line) throws ParsingException {
    String speciesName;
    if (line.getRank() == SPECIES) {
        speciesName = line.getCanonicalScientificName();
    } else {
        speciesName = line.getSpeciesName();
    }
    if (speciesName == null) {
        ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName(), INVALID_SPECIES_NAME_ERROR_MESSAGE_KEY);
        throw new ParsingException(error);
    }
    Taxon taxonGenus = createTaxonGenus(line);
    return createTaxon(line, SPECIES, taxonGenus, speciesName);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException) Taxon(org.openforis.idm.model.species.Taxon)

Aggregations

Taxon (org.openforis.idm.model.species.Taxon)29 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)13 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)8 ArrayList (java.util.ArrayList)6 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)6 Test (org.junit.Test)4 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 TaxonTree (org.openforis.collect.model.TaxonTree)4 Node (org.openforis.collect.model.TaxonTree.Node)4 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)4 ParsingException (org.openforis.collect.io.exception.ParsingException)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)2 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)2 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)2 Attribute (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition.Attribute)2 TaxonRank (org.openforis.idm.model.species.Taxon.TaxonRank)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Stack (java.util.Stack)1