Exemplo n.º 1
0
 private void validateNumberOfQuestions(CreateQuestion createQuestion, Errors errors) {
   ValidationUtils.rejectIfEmpty(
       errors,
       "createQuestion.numCorrect",
       "required.numCorrect",
       "Correct answers have to be minimum 1");
   ValidationUtils.rejectIfEmpty(
       errors,
       "createQuestion.numIncorrect",
       "required.numIncorrect",
       "Incorrect answers have to be minimum 3");
   if (createQuestion.getNumCorrect() + createQuestion.getNumIncorrect() <= 0)
     errors.rejectValue("", "invalid.answer.number", "you need to add at lest one answer");
 }
Exemplo n.º 2
0
 private void validateAnswerFields(CreateQuestion createQuestion, Errors errors) {
   Question question = createQuestion.getQuestion();
   if (question.getAnswers().size()
       != createQuestion.getNumCorrect() + createQuestion.getNumIncorrect())
     errors.rejectValue("", "invalid.answers", "all answers are mandatory");
   for (Answer answer : question.getAnswers()) {
     if (!answer.isValid()) {
       errors.rejectValue(
           "",
           "invalid.answers",
           "all answers and their hints are mandatory and cannot be left blank");
       return;
     }
   }
 }
Exemplo n.º 3
0
 private void validateTopicHasQuestions(CreateQuestion createQuestion, Errors errors) {
   int count =
       this.questionService.getNumberOfQuestionsInTheTopic(createQuestion.getTopic(), errors);
   if (count == 0)
     errors.rejectValue(
         "", "invalid.answers", "topic has no answers. select a topic that has one");
 }