| Total Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package easytests.api.v1.validators; |
||
| 14 | public void validateQuestion(QuestionModelInterface questionModel) throws Exception { |
||
| 15 | int rightAnswersCount = 0; |
||
| 16 | |||
| 17 | for (AnswerModelInterface answerModel: questionModel.getAnswers()) { |
||
| 18 | this.answersValidator.validateAnswer(answerModel); |
||
| 19 | if (answerModel.getRight()) { |
||
| 20 | ++rightAnswersCount; |
||
| 21 | } |
||
| 22 | } |
||
| 23 | switch (questionModel.getQuestionType().getId()) { |
||
| 24 | case 1: |
||
| 25 | if (rightAnswersCount == 0) { |
||
| 26 | throw new BadRequestException("Right Answer must be exist"); |
||
| 27 | } |
||
| 28 | if (rightAnswersCount > 1) { |
||
| 29 | throw new BadRequestException("This Question can have only one right Answer"); |
||
| 30 | } |
||
| 31 | break; |
||
| 32 | |||
| 33 | case 2: |
||
| 34 | if (rightAnswersCount == 0) { |
||
| 35 | throw new BadRequestException("Right Answers must be exist"); |
||
| 36 | } |
||
| 37 | if (rightAnswersCount == 1) { |
||
| 38 | throw new BadRequestException("This Question can't have only one right Answer"); |
||
| 39 | } |
||
| 40 | if (rightAnswersCount == questionModel.getAnswers().size()) { |
||
| 41 | throw new BadRequestException("This Question can't have all right Answers"); |
||
| 42 | } |
||
| 43 | break; |
||
| 44 | |||
| 45 | case 3: |
||
| 46 | break; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * TODO |
||
| 50 | * Add check for Numeric And Text Answers |
||
| 51 | */ |
||
| 52 | default: break; |
||
| 53 | } |
||
| 56 |