Search in sources :

Example 6 with CsvWriter

use of org.openforis.commons.io.csv.CsvWriter 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 CsvWriter

use of org.openforis.commons.io.csv.CsvWriter in project collect by openforis.

the class SamplingDesignExportTask method execute.

@Override
protected void execute() throws Throwable {
    if (getTotalItems() > 0) {
        Integer surveyId = survey.getId();
        CsvWriter writer = new CsvWriter(outputStream, OpenForisIOUtils.UTF_8, ',', '"');
        SamplingDesignSummaries summaries = samplingDesignManager.loadBySurvey(surveyId);
        ArrayList<String> colNames = getHeaders();
        writer.writeHeaders(colNames);
        List<SamplingDesignItem> items = summaries.getRecords();
        for (SamplingDesignItem item : items) {
            writeSummary(writer, item);
            incrementProcessedItems();
        }
        writer.flush();
    }
}
Also used : CsvWriter(org.openforis.commons.io.csv.CsvWriter) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 8 with CsvWriter

use of org.openforis.commons.io.csv.CsvWriter 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 9 with CsvWriter

use of org.openforis.commons.io.csv.CsvWriter 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 10 with CsvWriter

use of org.openforis.commons.io.csv.CsvWriter in project collect by openforis.

the class SamplingDesignExportProcess method exportToCSV.

public void exportToCSV(OutputStream out, CollectSurvey survey) {
    CsvWriter writer = null;
    try {
        writer = new CsvWriter(out);
        SamplingDesignSummaries summaries = samplingDesignManager.loadBySurvey(survey.getId());
        ArrayList<String> colNames = new ArrayList<String>();
        colNames.addAll(Arrays.asList(SamplingDesignFileColumn.LEVEL_COLUMN_NAMES));
        colNames.add(SamplingDesignFileColumn.X.getColumnName());
        colNames.add(SamplingDesignFileColumn.Y.getColumnName());
        colNames.add(SamplingDesignFileColumn.SRS_ID.getColumnName());
        // info columns
        List<ReferenceDataDefinition.Attribute> infoAttributes = getInfoAttributes(survey);
        for (ReferenceDataDefinition.Attribute attribute : infoAttributes) {
            colNames.add(attribute.getName());
        }
        writer.writeHeaders(colNames);
        List<SamplingDesignItem> items = summaries.getRecords();
        for (SamplingDesignItem item : items) {
            writeSummary(writer, survey, item);
        }
    } catch (Exception e) {
        log.error(e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : CsvWriter(org.openforis.commons.io.csv.CsvWriter) ArrayList(java.util.ArrayList) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) ReferenceDataDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Aggregations

CsvWriter (org.openforis.commons.io.csv.CsvWriter)11 FileOutputStream (java.io.FileOutputStream)4 ArrayList (java.util.ArrayList)4 OutputStreamWriter (java.io.OutputStreamWriter)3 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)3 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)3 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)3 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)2 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)2 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Task (org.openforis.concurrency.Task)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)1 ReferenceDataDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1