use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.
the class RecordController method startCsvDataImportJob.
@RequestMapping(value = "survey/{surveyId}/data/csvimport/records", method = POST, consumes = MULTIPART_FORM_DATA_VALUE)
@ResponseBody
public JobView startCsvDataImportJob(@PathVariable("surveyId") int surveyId, @RequestParam("file") MultipartFile multipartFile, @RequestParam String rootEntityName, @RequestParam String importType, @RequestParam String steps, @RequestParam(required = false) Integer entityDefinitionId, @RequestParam(required = false) boolean validateRecords, @RequestParam(required = false) boolean deleteEntitiesBeforeImport, @RequestParam(required = false) String newRecordVersionName) throws IOException {
File file = Files.writeToTempFile(multipartFile.getInputStream(), multipartFile.getOriginalFilename(), "ofc_csv_data_import");
CollectSurvey survey = surveyManager.getById(surveyId);
CSVDataImportJob job = jobManager.createJob(TransactionalCSVDataImportJob.class);
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setDeleteExistingEntities(deleteEntitiesBeforeImport);
settings.setRecordValidationEnabled(validateRecords);
settings.setInsertNewRecords("newRecords".equals(importType));
settings.setNewRecordVersionName(newRecordVersionName);
CSVDataImportInput input = new CSVDataImportInput(file, survey, fromStepNames(steps), entityDefinitionId, settings);
job.setInput(input);
jobManager.start(job);
this.csvDataImportJob = job;
return new JobView(job);
}
use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.
the class RecordController method getFullBackupJobView.
@RequestMapping(value = "survey/{surveyId}/data/records/backupexportjob", method = GET)
@ResponseBody
public JobView getFullBackupJobView() {
if (fullBackupJob == null) {
return null;
} else {
JobView jobView = new JobView(fullBackupJob);
jobView.putExtra("dataBackupErrors", fullBackupJob.getDataBackupErrors());
return jobView;
}
}
use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.
the class RecordController method startRecordImport.
@RequestMapping(value = "survey/{surveyId}/data/import/records", method = POST)
@ResponseBody
public JobView startRecordImport(@PathVariable("surveyId") int surveyId, @RequestParam List<Integer> entryIdsToImport, @RequestParam(defaultValue = "true") boolean validateRecords) throws IOException {
RecordProvider recordProvider = dataRestoreSummaryJob.getRecordProvider();
recordProvider.setConfiguration(new RecordProviderConfiguration(true));
DataRestoreJob job = jobManager.createJob(TransactionalDataRestoreJob.class);
job.setFile(dataRestoreSummaryJob.getFile());
job.setUser(sessionManager.getLoggedUser());
job.setValidateRecords(validateRecords);
job.setRecordProvider(recordProvider);
job.setPackagedSurvey(dataRestoreSummaryJob.getPackagedSurvey());
job.setPublishedSurvey(dataRestoreSummaryJob.getPublishedSurvey());
job.setEntryIdsToImport(entryIdsToImport);
job.setRecordFilesToBeDeleted(dataRestoreSummaryJob.getSummary().getConflictingRecordFiles(entryIdsToImport));
job.setRestoreUploadedFiles(true);
job.setValidateRecords(validateRecords);
jobManager.start(job);
return new JobView(job);
}
use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.
the class RecordController method startCsvDataExportJob.
@RequestMapping(value = "survey/{surveyId}/data/records/startcsvexport", method = POST)
@ResponseBody
public JobView startCsvDataExportJob(@PathVariable("surveyId") int surveyId, @RequestBody CSVExportParametersForm parameters) throws IOException {
User user = sessionManager.getLoggedUser();
CollectSurvey survey = surveyManager.getById(surveyId);
csvDataExportJob = jobManager.createJob(CSVDataExportJob.class);
csvDataExportJob.setSurvey(survey);
csvDataExportJob.setOutputFile(File.createTempFile("collect-csv-data-export", ".zip"));
CSVDataExportParameters exportParameters = parameters.toExportParameters(survey, user, userGroupManager);
csvDataExportJob.setParameters(exportParameters);
jobManager.start(csvDataExportJob);
return new JobView(csvDataExportJob);
}
use of org.openforis.collect.web.controller.CollectJobController.JobView 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