use of org.openforis.collect.manager.CollectEarthSurveyExportJob in project collect by openforis.
the class SurveyController method downloadCsvExportResult.
@RequestMapping(value = "export/{surveyId}/result", method = GET)
public void downloadCsvExportResult(HttpServletResponse response) throws FileNotFoundException, IOException {
if (surveyBackupJob != null) {
File outputFile;
String outputFileExtension;
CollectSurvey survey;
String projectName;
if (surveyBackupJob instanceof CollectEarthSurveyExportJob) {
CollectEarthSurveyExportJob backupJob = (CollectEarthSurveyExportJob) surveyBackupJob;
outputFile = backupJob.getOutputFile();
outputFileExtension = COLLECT_EARTH_PROJECT_FILE_EXTENSION;
survey = backupJob.getSurvey();
projectName = survey.getName();
} else {
SurveyBackupJob backupJob = (SurveyBackupJob) surveyBackupJob;
outputFile = backupJob.getOutputFile();
outputFileExtension = backupJob.getOutputFormat().getOutputFileExtension();
survey = backupJob.getSurvey();
projectName = survey.getName();
if (backupJob.getOutputFormat() == SurveyBackupJob.OutputFormat.MOBILE) {
projectName += "_" + backupJob.getOutputSurveyDefaultLanguage();
}
}
String fileName = String.format("%s_%s.%s", projectName, Dates.formatCompactDateTime(survey.getModifiedDate()), outputFileExtension);
Controllers.writeFileToResponse(response, outputFile, fileName, Controllers.ZIP_CONTENT_TYPE);
}
}
use of org.openforis.collect.manager.CollectEarthSurveyExportJob in project collect by openforis.
the class SurveyController method startExport.
@RequestMapping(value = "export/{id}", method = POST)
@ResponseBody
public JobView startExport(@Valid SurveyExportParameters params, BindingResult result) {
this.surveyBackupJob = null;
String uri = params.getSurveyUri();
// boolean skipValidation = params.isSkipValidation();
SurveySummary surveySummary = surveyManager.loadSummaryByUri(uri);
final CollectSurvey loadedSurvey;
if (surveySummary.isTemporary() && params.getSurveyType() == SurveyType.TEMPORARY) {
loadedSurvey = surveyManager.loadSurvey(surveySummary.getId());
} else {
loadedSurvey = surveyManager.getByUri(uri);
}
switch(params.getOutputFormat()) {
case EARTH:
{
// if (skipValidation || collectEarthSurveyValidator.validate(loadedSurvey).isOk()) {
CollectEarthSurveyExportJob job = jobManager.createJob(CollectEarthSurveyExportJob.class);
job.setSurvey(loadedSurvey);
job.setLanguageCode(params.getLanguageCode());
jobManager.start(job, String.valueOf(loadedSurvey.getId()));
this.surveyBackupJob = job;
return new JobView(job);
}
// break;
case MOBILE:
default:
SurveyBackupJob job = jobManager.createJob(SurveyBackupJob.class);
job.setSurvey(loadedSurvey);
// surveyBackupJob.setIncludeData(parameters.isIncludeData());
// surveyBackupJob.setIncludeRecordFiles(parameters.isIncludeUploadedFiles());
job.setOutputFormat(org.openforis.collect.io.SurveyBackupJob.OutputFormat.valueOf(params.getOutputFormat().name()));
job.setOutputSurveyDefaultLanguage(ObjectUtils.defaultIfNull(params.getLanguageCode(), loadedSurvey.getDefaultLanguage()));
jobManager.start(job, String.valueOf(loadedSurvey.getId()));
this.surveyBackupJob = job;
return new JobView(job);
}
}
Aggregations