Search in sources :

Example 1 with SurveyBackupInfoExtractorJob

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;
    }
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) SurveyBackupInfoExtractorJob(org.openforis.collect.io.SurveyBackupInfoExtractorJob) SurveySummary(org.openforis.collect.model.SurveySummary) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

File (java.io.File)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SurveyBackupInfoExtractorJob (org.openforis.collect.io.SurveyBackupInfoExtractorJob)1 SurveySummary (org.openforis.collect.model.SurveySummary)1 Response (org.openforis.commons.web.Response)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1