Search in sources :

Example 1 with SurveyBackupJob

use of org.openforis.collect.io.SurveyBackupJob in project collect by openforis.

the class DataExportService method fullExport.

@Transactional
public Proxy fullExport(CollectSurvey survey, boolean includeRecordFiles, boolean onlyOwnedRecords, String[] rootEntityKeyValues, boolean full) {
    if (backupJob == null || !backupJob.isRunning()) {
        resetJobs();
        RecordFilter filter = createRecordFilter(survey, null, onlyOwnedRecords, rootEntityKeyValues);
        SurveyBackupJob job = jobManager.createJob(SurveyBackupJob.class);
        job.setFull(full);
        if (full) {
            job.setOutputFormat(OutputFormat.DESKTOP_FULL);
        } else {
            job.setOutputFormat(OutputFormat.ONLY_DATA);
        }
        job.setSurvey(survey);
        job.setIncludeData(true);
        job.setIncludeRecordFiles(includeRecordFiles);
        job.setRecordFilter(filter);
        backupJob = job;
        jobManager.start(job);
    }
    return getCurrentJob();
}
Also used : SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SurveyBackupJob

use of org.openforis.collect.io.SurveyBackupJob 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 3 with SurveyBackupJob

use of org.openforis.collect.io.SurveyBackupJob 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)

Example 4 with SurveyBackupJob

use of org.openforis.collect.io.SurveyBackupJob in project collect by openforis.

the class SurveyBackupJobProxy method getOutputFileName.

@ExternalizedProperty
public String getOutputFileName() {
    SurveyBackupJob job = (SurveyBackupJob) this.getJob();
    File outputFile = job.getOutputFile();
    return outputFile == null ? null : outputFile.getAbsolutePath();
}
Also used : SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) File(java.io.File) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Example 5 with SurveyBackupJob

use of org.openforis.collect.io.SurveyBackupJob in project collect by openforis.

the class DataRestoreJob method initializeTask.

@Override
protected void initializeTask(Worker task) {
    if (task instanceof SurveyBackupJob) {
        SurveyBackupJob t = (SurveyBackupJob) task;
        t.setFull(true);
        t.setIncludeData(true);
        t.setIncludeRecordFiles(true);
        t.setOutputFormat(OutputFormat.DESKTOP_FULL);
        t.setRecordFilter(new RecordFilter(publishedSurvey));
        t.setSurvey(publishedSurvey);
    } else if (task instanceof DataRestoreTask) {
        DataRestoreTask t = (DataRestoreTask) task;
        t.setRecordManager(recordManager);
        t.setUserManager(userManager);
        t.setUserGroupManager(userGroupManager);
        t.setRecordProvider(recordProvider);
        t.setTargetSurvey(publishedSurvey);
        t.setUser(user);
        t.setOverwriteStrategy(recordOverwriteStrategy);
        t.setEntryIdsToImport(entryIdsToImport);
        t.setIncludeRecordPredicate(includeRecordPredicate);
    } else if (task instanceof RecordFileRestoreTask) {
        RecordFileRestoreTask t = (RecordFileRestoreTask) task;
        t.setRecordManager(recordManager);
        t.setRecordFileManager(recordFileManager);
        t.setBackupFileExtractor(backupFileExtractor);
        t.setRecordProvider(recordProvider);
        t.setOverwriteStrategy(recordOverwriteStrategy);
        t.setEntryIdsToImport(entryIdsToImport);
        t.setSurvey(publishedSurvey);
    }
    super.initializeTask(task);
}
Also used : SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)6 RecordFilter (org.openforis.collect.model.RecordFilter)3 File (java.io.File)2 CollectEarthSurveyExportJob (org.openforis.collect.manager.CollectEarthSurveyExportJob)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)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