Search in sources :

Example 11 with SurveySummary

use of org.openforis.collect.model.SurveySummary 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)

Example 12 with SurveySummary

use of org.openforis.collect.model.SurveySummary 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 13 with SurveySummary

use of org.openforis.collect.model.SurveySummary in project collect by openforis.

the class SurveyCreationParametersValidator method validateSurveyNameUniqueness.

private boolean validateSurveyNameUniqueness(SurveyCreationParameters parameters, Errors errors) {
    String name = parameters.getName();
    SurveySummary existingSummary = surveyManager.loadSummaryByName(name);
    if (existingSummary != null) {
        errors.rejectValue(NAME_FIELD, NAME_ALREADY_IN_USE_MESSAGE_KEY);
        return false;
    } else {
        return true;
    }
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary)

Example 14 with SurveySummary

use of org.openforis.collect.model.SurveySummary in project collect by openforis.

the class ModelDaoIntegrationTest method testSurveyNotFoundByName.

@Test
public void testSurveyNotFoundByName() {
    SurveySummary survey = surveyManager.loadSummaryByName("!!!!!!");
    assertNull(survey);
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 15 with SurveySummary

use of org.openforis.collect.model.SurveySummary in project collect by openforis.

the class SurveyImportVM method updateForm.

protected void updateForm() {
    String surveyName = null;
    if (uploadedSurveyUri != null) {
        SurveySummary surveySummary = surveyManager.loadSummaryByUri(uploadedSurveyUri);
        if (surveySummary == null) {
            // new survey
            updatingExistingSurvey = false;
            updatingPublishedSurvey = false;
            surveyName = getFormSurveyName();
            if (StringUtils.isEmpty(surveyName)) {
                surveyName = uploadedSurveyName;
            }
            if (StringUtils.isEmpty(surveyName)) {
                surveyName = suggestSurveyName(uploadedFileName);
            }
        } else {
            // updating existing survey
            updatingExistingSurvey = true;
            updatingPublishedSurvey = !surveySummary.isTemporary();
            surveyName = surveySummary.getName();
        }
    }
    form.put(SURVEY_NAME_FIELD, surveyName);
    notifyChange("updatingPublishedSurvey", "updatingExistingSurvey", "form");
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary)

Aggregations

SurveySummary (org.openforis.collect.model.SurveySummary)34 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 Record (org.jooq.Record)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ArrayList (java.util.ArrayList)5 OfcSurveyRecord (org.openforis.collect.persistence.jooq.tables.records.OfcSurveyRecord)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 UserGroup (org.openforis.collect.model.UserGroup)2 SurveyImportException (org.openforis.collect.persistence.SurveyImportException)2 Response (org.openforis.commons.web.Response)2 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1