use of org.openforis.collect.io.data.csv.CSVDataExportParameters in project collect by openforis.
the class DataQueryController method startExport.
@RequestMapping(value = "start-export.json", method = RequestMethod.POST)
@ResponseBody
public Response startExport(@Validated DataQueryForm form, @RequestParam Step recordStep) throws Exception {
CollectSurvey survey = sessionManager.getActiveSurvey();
DataQuery query = new DataQuery(survey);
form.copyTo(query);
exportJob = collectJobManager.createJob(CSVDataExportJob.class);
exportJob.setOutputFile(File.createTempFile("data-query-export", ".csv"));
CSVDataExportParameters parameters = new CSVDataExportParameters();
RecordFilter recordFilter = new RecordFilter(survey);
recordFilter.setStepGreaterOrEqual(recordStep);
parameters.setRecordFilter(recordFilter);
parameters.setEntityId(query.getEntityDefinitionId());
parameters.setAlwaysGenerateZipFile(false);
parameters.setNodeFilter(new DescendantNodeFilter(query.getAttributeDefinition(), query.getConditions()));
exportJob.setParameters(parameters);
collectJobManager.start(exportJob);
/*
csvExportItemProcessor = new CSVWriterDataQueryResultItemProcessor(query);
csvExportItemProcessor.init();
exportJob = collectJobManager.createJob(DataQueryExecutorJob.class);
exportJob.setInput(new DataQueryExecutorJobInput(query, recordStep, csvExportItemProcessor));
collectJobManager.start(exportJob);
*/
Response response = new Response();
return response;
}
use of org.openforis.collect.io.data.csv.CSVDataExportParameters 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