/** * This method validates the question response type and any additional properties related to the * response type. * * @param maintenanceDocument - the maintenance document of the question to be validated * @return true if all validation has passed, false otherwise */ private boolean validateQuestionResponseType(MaintenanceDocument maintenanceDocument) { boolean isValid = true; Question question = (Question) maintenanceDocument.getNewMaintainableObject().getDataObject(); if (question.getQuestionTypeId() == null) { isValid &= false; GlobalVariables.getMessageMap() .putError( Constants.QUESTION_DOCUMENT_FIELD_QUESTION_TYPE_ID, KeyConstants.ERROR_QUESTION_RESPONSE_TYPE_NOT_SPECIFIED); } else { switch (question.getQuestionTypeId()) { case Constants.QUESTION_RESPONSE_TYPE_YES_NO: isValid &= validateResponseTypeYesNo(question); break; case Constants.QUESTION_RESPONSE_TYPE_YES_NO_NA: isValid &= validateResponseTypeYesNoNa(question); break; case Constants.QUESTION_RESPONSE_TYPE_NUMBER: isValid &= validateResponseTypeNumber(question); break; case Constants.QUESTION_RESPONSE_TYPE_DATE: isValid &= validateResponseTypeDate(question); break; case Constants.QUESTION_RESPONSE_TYPE_TEXT: isValid &= validateResponseTypeText(question); break; case Constants.QUESTION_RESPONSE_TYPE_LOOKUP: isValid &= validateResponseTypeLookup(question); break; default: isValid &= false; GlobalVariables.getMessageMap() .putError( Constants.QUESTION_DOCUMENT_FIELD_QUESTION_TYPE_ID, KeyConstants.ERROR_QUESTION_RESPONSE_TYPE_INVALID); break; } } return isValid; }
/** * 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; }
/** * 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; } }