Пример #1
0
 /**
  * This method validates the displayedAnswers field. The field must contain a number greater than
  * zero.
  *
  * @param question - the question to be validated
  * @return true if all validation has passed, false otherwise
  */
 private boolean validateDisplayedAnswers(Question question) {
   if (question.getDisplayedAnswers() != null && question.getDisplayedAnswers() > 0) {
     return true;
   } else {
     if (question.getQuestionTypeId() == Constants.QUESTION_RESPONSE_TYPE_TEXT) {
       GlobalVariables.getMessageMap()
           .putError(
               Constants.QUESTION_DOCUMENT_FIELD_DISPLAYED_ANSWERS,
               KeyConstants.ERROR_QUESTION_DISPLAYED_ANSWERS_INVALID_AREAS);
     } else {
       GlobalVariables.getMessageMap()
           .putError(
               Constants.QUESTION_DOCUMENT_FIELD_DISPLAYED_ANSWERS,
               KeyConstants.ERROR_QUESTION_DISPLAYED_ANSWERS_INVALID_BOXES);
     }
     return false;
   }
 }
Пример #2
0
  /**
   * This method validates the maxAnswers field. The field must contain a number greater than zero.
   *
   * @param question - the question to be validated
   * @return true if all validation has passed, false otherwise
   */
  private boolean validateMaxAnswers(Question question) {
    boolean isValid = true;

    if (question.getMaxAnswers() == null || question.getMaxAnswers() <= 0) {
      isValid = false;
    }
    if (question.getQuestionTypeId() != Constants.QUESTION_RESPONSE_TYPE_LOOKUP
        && question.getMaxAnswers() != null
        && question.getDisplayedAnswers() != null
        && question.getMaxAnswers() > question.getDisplayedAnswers()) {
      isValid = false;
    }

    if (!isValid) {
      switch (question.getQuestionTypeId()) {
        case Constants.QUESTION_RESPONSE_TYPE_LOOKUP:
          GlobalVariables.getMessageMap()
              .putError(
                  Constants.QUESTION_DOCUMENT_FIELD_MAX_ANSWERS,
                  KeyConstants.ERROR_QUESTION_MAX_ANSWERS_INVALID_RETURNS);
          break;
        case Constants.QUESTION_RESPONSE_TYPE_TEXT:
          GlobalVariables.getMessageMap()
              .putError(
                  Constants.QUESTION_DOCUMENT_FIELD_MAX_ANSWERS,
                  KeyConstants.ERROR_QUESTION_MAX_ANSWERS_INVALID_ANSWERS_AREAS);
          break;
        default:
          GlobalVariables.getMessageMap()
              .putError(
                  Constants.QUESTION_DOCUMENT_FIELD_MAX_ANSWERS,
                  KeyConstants.ERROR_QUESTION_MAX_ANSWERS_INVALID_ANSWERS_BOXES);
          break;
      }
    }

    return isValid;
  }