/* (non-Javadoc)
* @see com.agiletec.plugins.jpsurvey.apsadmin.survey.IQuestionAction#saveQuestion()
*/
public String saveQuestion() {
Question question = null;
try {
if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
question = new Question();
question.setSurveyId(this.getSurveyId());
question.setSingleChoice(true);
}
if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
question = this.getSurveyManager().loadQuestion(this.getQuestionId());
question.setSingleChoice(this.getSingleChoice() == SINGLE_CHOICE_ID);
if (!question.isSingleChoice()) {
question.setMaxResponseNumber(this.getMaxResponseNumber());
question.setMinResponseNumber(this.getMinResponseNumber());
// THIS WILL NOT PRESERVE THE SINGLE/MULTIPLE CHOICE OPTION
// check if the min and max answer are present
if (question.getChoices().size() < this.getMinResponseNumber()) {
// the choices are fewer than those mandatory
this.addActionError(this.getText("message.question.tooFewChoices",
new String[]{String.valueOf(question.getChoices().size()), String.valueOf(this.getMinResponseNumber())}));
return "wrongAnswerNumber";
}
if (this.getMinResponseNumber() > this.getMaxResponseNumber()) {
// the number of mandatory choices is smaller than the number of the allowed ones.
this.addActionError(this.getText("message.question.incorrectChoicesRange",
new String[]{String.valueOf(this.getMinResponseNumber()), String.valueOf(this.getMaxResponseNumber())}));
return "wrongAnswerNumber";
}
if (question.getChoices().size() < this.getMaxResponseNumber()) {
// the number of choices is smaller than the one a user can pick
this.addActionError(this.getText("message.question.fewChoices",
new String[]{String.valueOf(question.getChoices().size()), String.valueOf(this.getMaxResponseNumber())}));
return "wrongAnswerNumber";
}
} else {
question.setMaxResponseNumber(0);
question.setMinResponseNumber(0);
}
}
question.setQuestions(this.getQuestions());
if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
this.getSurveyManager().saveQuestionInSortedPosition(question);
this.setQuestionId(question.getId());
this.setStrutsAction(ApsAdminSystemConstants.EDIT);
return "editSingleQuestion";
}
if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
this.getSurveyManager().updateQuestion(question);