use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class SurveyEditVM method exportCsvDataImportTemplate.
@Command
public void exportCsvDataImportTemplate() throws IOException {
CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
job.setOutputFile(File.createTempFile("data-import-template", ".zip"));
CSVDataExportParameters parameters = new CSVDataExportParameters();
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
RecordFilter recordFilter = new RecordFilter(survey, rootEntityDef.getId());
parameters.setRecordFilter(recordFilter);
parameters.setAlwaysGenerateZipFile(true);
parameters.setIncludeEnumeratedEntities(false);
job.setParameters(parameters);
jobManager.start(job, false);
if (job.isCompleted()) {
File outputFile = job.getOutputFile();
String dateStr = Dates.formatLocalDateTime(new Date());
String fileName = String.format(DATA_IMPORT_TEMPLATE_FILE_NAME_PATTERN, survey.getName(), dateStr, "zip");
String contentType = URLConnection.guessContentTypeFromName(fileName);
FileInputStream is = new FileInputStream(outputFile);
Filedownload.save(is, contentType, fileName);
} else {
throw new RuntimeException("Error generating the CSV data export template: " + job.getErrorMessage(), job.getLastException());
}
}
Aggregations