Search in sources :

Example 1 with CollectEarthSurveyExportJob

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);
    }
}
Also used : CollectEarthSurveyExportJob(org.openforis.collect.manager.CollectEarthSurveyExportJob) SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CollectEarthSurveyExportJob

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);
    }
}
Also used : CollectEarthSurveyExportJob(org.openforis.collect.manager.CollectEarthSurveyExportJob) SurveySummary(org.openforis.collect.model.SurveySummary) JobView(org.openforis.collect.web.controller.CollectJobController.JobView) SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)2 CollectEarthSurveyExportJob (org.openforis.collect.manager.CollectEarthSurveyExportJob)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 File (java.io.File)1 SurveySummary (org.openforis.collect.model.SurveySummary)1 JobView (org.openforis.collect.web.controller.CollectJobController.JobView)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1