Search in sources :

Example 1 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireFlowAdapter method validateResponses.

public ActionErrors validateResponses(HttpServletRequest request, QuestionResponseCapturer form) {
    List<QuestionGroupDetail> groups = form.getQuestionGroups();
    QuestionnaireServiceFacade questionnaireServiceFacade = serviceLocator.getService(request);
    if ((groups == null) || (questionnaireServiceFacade == null)) {
        return null;
    }
    ActionErrors errors = new ActionErrors();
    try {
        questionnaireServiceFacade.validateResponses(groups);
    } catch (ValidationException e) {
        if (e.hasChildExceptions()) {
            for (ValidationException ve : e.getChildExceptions()) {
                if (ve instanceof MandatoryAnswerNotFoundException) {
                    errors.add(ClientConstants.ERROR_REQUIRED, new ActionMessage(ClientConstants.ERROR_REQUIRED, ve.getIdentifier()));
                } else if (ve instanceof BadNumericResponseException) {
                    populateNumericError((BadNumericResponseException) ve, errors);
                }
            }
        }
    }
    setQuestionnaireAttributesToRequest(request, form);
    return errors;
}
Also used : BadNumericResponseException(org.mifos.platform.questionnaire.exceptions.BadNumericResponseException) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ValidationException(org.mifos.platform.validations.ValidationException) MandatoryAnswerNotFoundException(org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException) ActionMessage(org.apache.struts.action.ActionMessage) QuestionnaireServiceFacade(org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade) ActionErrors(org.apache.struts.action.ActionErrors)

Example 2 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorImpl method sectionsHaveInvalidOrders.

private boolean sectionsHaveInvalidOrders(List<SectionDto> sections, ValidationException parentException) {
    boolean invalid = false;
    if (!allSectionsHaveOrders(sections)) {
        parentException.addChildException(new ValidationException(SECTION_ORDER_NOT_PROVIDED));
        invalid = true;
    } else if (!allSectionsHaveUniqueOrders(sections)) {
        parentException.addChildException(new ValidationException(SECTION_ORDER_DUPLICATE));
        invalid = true;
    }
    return invalid;
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException)

Example 3 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorImpl method sectionsHaveInvalidNames.

private boolean sectionsHaveInvalidNames(List<SectionDto> sections, ValidationException parentException) {
    boolean invalid = false;
    if (!allSectionsHaveNames(sections)) {
        parentException.addChildException(new ValidationException(SECTION_TITLE_NOT_PROVIDED));
        invalid = true;
    } else if (!allSectionsHaveUniqueNames(sections)) {
        parentException.addChildException(new ValidationException(SECTION_TITLE_DUPLICATE));
        invalid = true;
    }
    return invalid;
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException)

Example 4 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorImpl method validateForDefineQuestionGroup.

@Override
public void validateForDefineQuestionGroup(QuestionGroupDto questionGroupDto, boolean withDuplicateQuestionTextCheck) {
    ValidationException parentException = new ValidationException(GENERIC_VALIDATION);
    validateQuestionGroupTitle(questionGroupDto, parentException);
    List<EventSourceDto> eventSourceDtos = questionGroupDto.getEventSourceDtos();
    if (eventSourceDtos == null || eventSourceDtos.size() == 0) {
        throw new SystemException(INVALID_EVENT_SOURCE);
    } else {
        for (EventSourceDto eventSourceDto : eventSourceDtos) {
            validateEventSource(eventSourceDto, parentException);
        }
    }
    validateSections(questionGroupDto.getSections(), parentException, withDuplicateQuestionTextCheck);
    if (parentException.hasChildExceptions()) {
        throw parentException;
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) SystemException(org.mifos.framework.exceptions.SystemException) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 5 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class ValidationExceptionTest method generateValidationException.

private ValidationException generateValidationException() {
    ValidationException validationException = new ValidationException(TOP_LEVEL_EXCEPTION);
    validationMethod1(validationException);
    validationMethod2(validationException);
    validationMethod3(validationException);
    return validationException;
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException)

Aggregations

ValidationException (org.mifos.platform.validations.ValidationException)58 Test (org.junit.Test)48 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)30 Arrays.asList (java.util.Arrays.asList)27 List (java.util.List)27 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)8 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)7 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)6 MandatoryAnswerNotFoundException (org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException)6 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)5 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 QuestionnaireServiceFacade (org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade)2 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)2 MessageResolver (org.springframework.binding.message.MessageResolver)2 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 Before (org.junit.Before)1