Search in sources :

Example 1 with Response

use of org.openforis.commons.web.Response in project collect by openforis.

the class SessionController method setActiveSurvey.

@RequestMapping(value = "survey", method = POST)
@ResponseBody
public Response setActiveSurvey(@RequestParam int surveyId) {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    sessionManager.setActiveSurvey(survey);
    return new Response();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.openforis.commons.web.Response) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Response

use of org.openforis.commons.web.Response 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 3 with Response

use of org.openforis.commons.web.Response in project collect by openforis.

the class SurveyController method startSurveyFileImport.

@RequestMapping(value = "startimport", method = POST)
@ResponseBody
public Response startSurveyFileImport(@Valid SurveyImportParameters params, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        Response res = new Response();
        res.setErrorStatus();
        res.addObject("errors", bindingResult.getFieldErrors());
        return res;
    }
    String surveyName = params.getName();
    UserGroup userGroup = userGroupManager.loadById(params.getUserGroupId());
    String uploadedFileNameExtension = FilenameUtils.getExtension(this.uploadedSurveyFile.getName());
    AbstractSurveyRestoreJob job;
    if (Files.XML_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
        job = jobManager.createJob(XMLSurveyRestoreJob.class);
    } else if (COLLECT_EARTH_PROJECT_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
        job = jobManager.createJob(CESurveyRestoreJob.class);
    } else {
        job = jobManager.createJob(SurveyRestoreJob.class);
    }
    job.setFile(this.uploadedSurveyFile);
    job.setSurveyName(surveyName);
    job.setSurveyUri(uploadedSurveyInfo == null ? null : uploadedSurveyInfo.getSurveyUri());
    job.setUserGroup(userGroup);
    job.setRestoreIntoPublishedSurvey(false);
    job.setValidateSurvey(false);
    job.setActiveUser(sessionManager.getLoggedUser());
    jobManager.start(job);
    this.surveyImportJob = job;
    Response res = new Response();
    res.setObject(new SurveyImportJobView(job));
    return res;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractSurveyRestoreJob(org.openforis.collect.io.AbstractSurveyRestoreJob) XMLSurveyRestoreJob(org.openforis.collect.io.XMLSurveyRestoreJob) UserGroup(org.openforis.collect.model.UserGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Response

use of org.openforis.commons.web.Response in project collect by openforis.

the class SurveyController method getClonedSurveyId.

@RequestMapping(value = "cloned/id", method = GET)
@ResponseBody
public Response getClonedSurveyId() {
    Response response = new Response();
    if (surveyCloneJob == null || !surveyCloneJob.isCompleted()) {
        response.setErrorStatus();
        response.setErrorMessage("Survey clone job not found");
    } else {
        response.setObject(surveyCloneJob.getOutputSurvey().getId());
    }
    return response;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Response

use of org.openforis.commons.web.Response in project collect by openforis.

the class SurveyController method cloneIntoTemporarySurvey.

@Transactional
@RequestMapping(value = "cloneintotemporary/{surveyId}", method = POST)
@ResponseBody
public Response cloneIntoTemporarySurvey(@PathVariable int surveyId) throws Exception {
    Response response = new Response();
    User loggedUser = sessionManager.getLoggedUser();
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    if (survey.isPublished()) {
        String surveyUri = survey.getUri();
        CollectSurvey temporarySurvey = surveyManager.createTemporarySurveyFromPublished(surveyUri, loggedUser);
        response.setObject(temporarySurvey.getId());
    } else {
        response.setErrorStatus();
        response.setErrorMessage(String.format("Survey with id %d is not published as expected", surveyId));
    }
    return response;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) User(org.openforis.collect.model.User) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Response (org.openforis.commons.web.Response)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 AbstractFormUpdateValidationResponse (org.openforis.commons.web.AbstractFormUpdateValidationResponse)3 ObjectError (org.springframework.validation.ObjectError)3 DataQuery (org.openforis.collect.datacleansing.DataQuery)2 SurveySummary (org.openforis.collect.model.SurveySummary)2 UserGroup (org.openforis.collect.model.UserGroup)2 Transactional (org.springframework.transaction.annotation.Transactional)2 File (java.io.File)1 DataCleansingChain (org.openforis.collect.datacleansing.DataCleansingChain)1 DataCleansingChainExecutorJob (org.openforis.collect.datacleansing.DataCleansingChainExecutorJob)1 DataQueryExecutorJob (org.openforis.collect.datacleansing.DataQueryExecutorJob)1 DataQueryExecutorJobInput (org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput)1 DataQueryGroup (org.openforis.collect.datacleansing.DataQueryGroup)1 DataReportGeneratorJob (org.openforis.collect.datacleansing.DataReportGeneratorJob)1 AbstractSurveyRestoreJob (org.openforis.collect.io.AbstractSurveyRestoreJob)1 SurveyBackupInfoExtractorJob (org.openforis.collect.io.SurveyBackupInfoExtractorJob)1