use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class SurveyController method createNewSurveyFromTemplate.
private CollectSurvey createNewSurveyFromTemplate(String name, String langCode, TemplateType templateType) throws IdmlParseException, SurveyValidationException {
String templateFileName = String.format(IDM_TEMPLATE_FILE_NAME_FORMAT, templateType.name().toLowerCase(Locale.ENGLISH));
InputStream surveyFileIs = this.getClass().getResourceAsStream(templateFileName);
CollectSurvey survey = surveyManager.unmarshalSurvey(surveyFileIs, false, true);
survey.setName(name);
survey.setTemporary(true);
survey.setUri(surveyManager.generateSurveyUri(name));
survey.setDefaultLanguage(langCode);
SurveyTarget target;
switch(templateType) {
case COLLECT_EARTH:
case COLLECT_EARTH_IPCC:
target = SurveyTarget.COLLECT_EARTH;
break;
default:
target = SurveyTarget.COLLECT_DESKTOP;
}
survey.setTarget(target);
if (survey.getSamplingDesignCodeList() == null) {
survey.addSamplingDesignCodeList();
}
return survey;
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class SurveyController method downloadCsvExportResult.
@RequestMapping(value = "export/{surveyId}/result", method = GET)
public void downloadCsvExportResult(HttpServletResponse response) throws FileNotFoundException, IOException {
if (surveyBackupJob != null) {
File outputFile;
String outputFileExtension;
CollectSurvey survey;
String projectName;
if (surveyBackupJob instanceof CollectEarthSurveyExportJob) {
CollectEarthSurveyExportJob backupJob = (CollectEarthSurveyExportJob) surveyBackupJob;
outputFile = backupJob.getOutputFile();
outputFileExtension = COLLECT_EARTH_PROJECT_FILE_EXTENSION;
survey = backupJob.getSurvey();
projectName = survey.getName();
} else {
SurveyBackupJob backupJob = (SurveyBackupJob) surveyBackupJob;
outputFile = backupJob.getOutputFile();
outputFileExtension = backupJob.getOutputFormat().getOutputFileExtension();
survey = backupJob.getSurvey();
projectName = survey.getName();
if (backupJob.getOutputFormat() == SurveyBackupJob.OutputFormat.MOBILE) {
projectName += "_" + backupJob.getOutputSurveyDefaultLanguage();
}
}
String fileName = String.format("%s_%s.%s", projectName, Dates.formatCompactDateTime(survey.getModifiedDate()), outputFileExtension);
Controllers.writeFileToResponse(response, outputFile, fileName, Controllers.ZIP_CONTENT_TYPE);
}
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class SurveyController method closeSurvey.
@RequestMapping(value = "close/{id}", method = POST)
@ResponseBody
public SurveyView closeSurvey(@PathVariable int id) throws SurveyImportException {
CollectSurvey survey = surveyManager.getOrLoadSurveyById(id);
surveyManager.close(survey);
return generateView(survey, false);
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class SurveyController method unpublishSurvey.
@RequestMapping(value = "unpublish/{id}", method = POST)
@ResponseBody
public SurveyView unpublishSurvey(@PathVariable int id) throws SurveyStoreException {
User activeUser = sessionManager.getLoggedUser();
CollectSurvey survey = surveyManager.unpublish(id, activeUser);
return generateView(survey, false);
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class SurveyController method archiveSurvey.
@RequestMapping(value = "archive/{id}", method = POST)
@ResponseBody
public SurveyView archiveSurvey(@PathVariable int id) throws SurveyImportException {
CollectSurvey survey = surveyManager.getOrLoadSurveyById(id);
surveyManager.archive(survey);
return generateView(survey, false);
}
Aggregations