Search in sources :

Example 31 with CollectTaxonomy

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();
}
Also used : CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 32 with CollectTaxonomy

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();
}
Also used : CsvWriter(org.openforis.commons.io.csv.CsvWriter) TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Example 33 with CollectTaxonomy

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"));
    }
}
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 34 with CollectTaxonomy

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());
    }
}
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 35 with CollectTaxonomy

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;
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Aggregations

CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)43 Taxon (org.openforis.idm.model.species.Taxon)13 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)8 Secured (org.springframework.security.access.annotation.Secured)8 Test (org.junit.Test)7 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)7 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 ArrayList (java.util.ArrayList)5 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)5 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)5 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)4 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)3 CsvWriter (org.openforis.commons.io.csv.CsvWriter)3 File (java.io.File)2 List (java.util.List)2 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)2 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1