use of org.openforis.collect.io.data.csv.ModelCsvWriter in project collect by openforis.
the class CSVDataExportProcess method exportData.
// private String calculateOutputFileName() {
// return "data.zip";
// /*
// StringBuilder sb = new StringBuilder();
// sb.append(survey.getName());
// sb.append("_");
// sb.append(rootEntityName);
// sb.append("_");
// sb.append("csv_data");
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// String today = formatter.format(new Date());
// sb.append(today);
// sb.append(".zip");
// return sb.toString();
// */
// }
private void exportData(OutputStream outputStream, int entityDefId) throws InvalidExpressionException, IOException, RecordPersistenceException {
Writer outputWriter = new OutputStreamWriter(outputStream, OpenForisIOUtils.UTF_8);
CSVDataExportColumnProviderGenerator csvDataExportColumnProviderGenerator = new CSVDataExportColumnProviderGenerator(recordFilter.getSurvey(), configuration);
DataTransformation transform = csvDataExportColumnProviderGenerator.generateDataTransformation(entityDefId);
@SuppressWarnings("resource") ModelCsvWriter // closing modelWriter will close referenced output stream
modelWriter = new ModelCsvWriter(outputWriter, transform);
modelWriter.printColumnHeadings();
CollectSurvey survey = recordFilter.getSurvey();
Step step = recordFilter.getStepGreaterOrEqual();
List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
for (CollectRecordSummary s : summaries) {
if (status.isRunning()) {
try {
CollectRecord record = recordManager.load(survey, s.getId(), step, false);
modelWriter.printData(record);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
status.incrementProcessed();
} else {
break;
}
}
modelWriter.flush();
}
Aggregations