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();
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations