use of org.openforis.collect.io.SurveyBackupInfoExtractorJob in project collect by openforis.
the class SurveyController method prepareSurveyImport.
@RequestMapping(value = "prepareimport", method = POST, consumes = MULTIPART_FORM_DATA_VALUE)
@ResponseBody
public Response prepareSurveyImport(@RequestParam("file") MultipartFile multipartFile) throws IOException {
String fileName = multipartFile.getOriginalFilename();
File tempFile = Files.writeToTempFile(multipartFile.getInputStream(), multipartFile.getOriginalFilename(), "ofc_csv_data_import");
String extension = FilenameUtils.getExtension(fileName);
this.uploadedSurveyFile = tempFile;
if (surveyBackupInfoExtractorJob != null && surveyBackupInfoExtractorJob.isRunning()) {
surveyBackupInfoExtractorJob.abort();
}
surveyBackupInfoExtractorJob = jobManager.createJob(SurveyBackupInfoExtractorJob.class);
if (COLLECT_EARTH_PROJECT_FILE_EXTENSION.equalsIgnoreCase(extension)) {
File idmFile = extractIdmFromCEPFile(tempFile);
surveyBackupInfoExtractorJob.setFile(idmFile);
} else {
surveyBackupInfoExtractorJob.setFile(tempFile);
}
surveyBackupInfoExtractorJob.setValidate(false);
jobManager.start(surveyBackupInfoExtractorJob, false);
Response response = new Response();
if (surveyBackupInfoExtractorJob.isCompleted()) {
uploadedSurveyInfo = surveyBackupInfoExtractorJob.getInfo();
response.addObject("surveyBackupInfo", uploadedSurveyInfo);
SurveySummary existingSummary = surveyManager.loadSummaryByUri(uploadedSurveyInfo.getSurveyUri());
response.addObject("importingIntoExistingSurvey", existingSummary != null);
response.addObject("existingSurveyUserGroupId", existingSummary == null ? null : existingSummary.getUserGroupId());
return response;
} else {
response.setErrorStatus();
response.setErrorMessage(surveyBackupInfoExtractorJob.getErrorMessage());
return response;
}
}
Aggregations