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);
}
}
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();
}
}
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();
}
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();
}
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);
}
}
Aggregations