Search in sources :

Example 6 with TaxonSummaries

use of org.openforis.collect.metamodel.TaxonSummaries in project collect by openforis.

the class SpeciesExportProcess method exportToCSV.

public void exportToCSV(OutputStream out, CollectSurvey survey, int taxonomyId) {
    CsvWriter writer = null;
    try {
        writer = new CsvWriter(out);
        CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
        taxonomyName = taxonomy.getName();
        TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
        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());
        List<String> vernacularNamesLangCodes = extractVernacularNameLanguageCodes(summaries);
        colNames.addAll(vernacularNamesLangCodes);
        List<String> infoAttributeNames = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributeNames();
        colNames.addAll(infoAttributeNames);
        writer.writeHeaders(colNames);
        List<TaxonSummary> items = summaries.getItems();
        for (TaxonSummary item : items) {
            writeTaxonSummary(writer, vernacularNamesLangCodes, infoAttributeNames, item);
        }
    } catch (Exception e) {
        log.error(e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
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 7 with TaxonSummaries

use of org.openforis.collect.metamodel.TaxonSummaries in project collect by openforis.

the class SurveyManagerIntegrationTest method publishSurveyTaxonomyTest.

@Test
public void publishSurveyTaxonomyTest() throws SurveyImportException {
    insertTestTaxonomy();
    CollectSurvey temporarySurvey = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
    {
        CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName(temporarySurvey, "tree");
        assertNotNull(taxonomy);
        TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
        assertEquals(1, summaries.getTotalCount());
        List<TaxonSummary> taxonSummaryList = summaries.getItems();
        {
            TaxonSummary taxonSummary = taxonSummaryList.get(0);
            assertEquals("Albizia glaberrima", taxonSummary.getScientificName());
            List<String> vernacularLanguages = taxonSummary.getVernacularLanguages();
            assertEquals(Arrays.asList("swh"), vernacularLanguages);
            List<String> vernacularNames = taxonSummary.getVernacularNames("swh");
            assertEquals(Arrays.asList("Mgerenge", "Mchani"), vernacularNames);
        }
    }
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with TaxonSummaries

use of org.openforis.collect.metamodel.TaxonSummaries in project collect by openforis.

the class SpeciesManager method loadFullTaxonSummariesOld.

public TaxonSummaries loadFullTaxonSummariesOld(CollectTaxonomy taxonomy) {
    TaxonTree tree = loadTaxonTree(taxonomy);
    List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.GENUS, false);
    List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
    Collections.sort(sortedVernacularNamesLanguageCodes);
    List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
    return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Example 9 with TaxonSummaries

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

Example 10 with TaxonSummaries

use of org.openforis.collect.metamodel.TaxonSummaries 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)

Aggregations

TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)10 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)7 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 CsvWriter (org.openforis.commons.io.csv.CsvWriter)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 TaxonTree (org.openforis.collect.model.TaxonTree)2 HashSet (java.util.HashSet)1 List (java.util.List)1 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)1 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)1 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)1 TaxonSummariesProxy (org.openforis.collect.metamodel.proxy.TaxonSummariesProxy)1 CodeList (org.openforis.idm.metamodel.CodeList)1 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)1 Taxon (org.openforis.idm.model.species.Taxon)1 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)1 Secured (org.springframework.security.access.annotation.Secured)1