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();
}
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);
}
}
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);
}
}
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();
}
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);
}
Aggregations