Search in sources :

Example 36 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class CustomerSearchFormBean method validateCustomerSearchStep.

/**
     * validateXXXX is invoked on transition from state 
     */
public void validateCustomerSearchStep(ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    validator.validate(this, messages);
}
Also used : MessageContext(org.springframework.binding.message.MessageContext)

Example 37 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class CustomizedTextFormBean method doValidation.

private void doValidation(ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    validator.validate(this, messages);
}
Also used : MessageContext(org.springframework.binding.message.MessageContext)

Example 38 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class UserFormBean method validateEnterUserDetailsStep.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION", justification = "should be the exception thrown by jodatime but not sure what it is right now.")
public void validateEnterUserDetailsStep(ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    validator.validate(this, messages);
    try {
        this.dateOfBirth = new DateTime().withDate(this.dateOfBirthYear.intValue(), this.dateOfBirthMonth.intValue(), this.dateOfBirthDay.intValue());
    } catch (Exception e) {
        messages.addMessage(new MessageBuilder().error().source("dateOfBrith").code("NotValid.UserFormBean.dateOfBrith").defaultText("dateOfBirth is not valid").build());
    }
    try {
        this.passwordExpirationDate = new DateTime().withDate(this.passwordExpirationDateYear.intValue(), this.passwordExpirationDateMonth.intValue(), this.passwordExpirationDateDay.intValue());
    } catch (Exception e) {
        messages.addMessage(new MessageBuilder().error().source("passwordExpirationDate").code("NotValid.UserFormBean.passwordExpirationDate").defaultText("Password expiration date is not valid").build());
    }
    try {
        this.mfiJoiningDate = new DateTime().withDate(this.mfiJoiningDateYear.intValue(), this.mfiJoiningDateMonth.intValue(), this.mfiJoiningDateDay.intValue());
    } catch (Exception e) {
        messages.addMessage(new MessageBuilder().error().source("mfiJoiningDate").code("NotValid.UserFormBean.mfiJoiningDate").defaultText("mfiJoiningDate is not valid").build());
    }
    if (this.password.trim().isEmpty() || this.confirmedPassword.trim().isEmpty()) {
        messages.addMessage(new MessageBuilder().error().source("password").code("NotEmpty.UserFormBean.password").defaultText("password is not correct.").build());
    } else if (this.password.trim().length() < 6) {
        messages.addMessage(new MessageBuilder().error().source("password").code("Min.UserFormBean.password").defaultText("password must have six characters at least.").build());
    } else if (!this.password.equals(this.confirmedPassword)) {
        messages.addMessage(new MessageBuilder().error().source("password").code("NotEqual.UserFormBean.password").defaultText("password is not correct.").build());
    }
    this.address.validate(messages, "UserFormBean");
    // validate additional fields
    for (CustomFieldDto additionalField : this.customFields) {
        switch(additionalField.getFieldType().intValue()) {
            case 0:
                break;
            case 1:
                validateNumericField(messages, additionalField);
                break;
            case 2:
                validateIfMandatoryField(messages, additionalField);
                break;
            case 3:
                for (DateFieldBean dateFieldBean : this.customDateFields) {
                    if (dateFieldBean.getId().equals(additionalField.getFieldId())) {
                        validateAndBindDateField(messages, additionalField, dateFieldBean);
                    }
                }
                break;
            default:
                break;
        }
    }
    if (messages.hasErrorMessages()) {
        this.prepateForReEdit();
    }
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MessageContext(org.springframework.binding.message.MessageContext) DateTime(org.joda.time.DateTime)

Example 39 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class LoanRepaymentFormBean method validateEnterLoanRepaymentDetails.

public void validateEnterLoanRepaymentDetails(ValidationContext context) {
    MessageContext messageContext = context.getMessageContext();
    Errors errors = validator.checkConstraints(this);
    if (errors.hasErrors()) {
        for (FieldError fieldError : errors.getFieldErrors()) {
            String arg = "";
            if ("paymentAmount".equals(fieldError.getField())) {
                arg = "Amount";
            }
            messageContext.addMessage(buildValidationMessage("errors.mandatory", fieldError.getField(), arg));
        }
    }
    if (dateValidator == null) {
        dateValidator = new DateValidator();
    }
    //payment date validation
    if (!dateValidator.formsValidDate(paymentDateDD, paymentDateMM, paymentDateYY)) {
        messageContext.addMessage(buildValidationMessage("errors.invaliddate", "paymentDate", "accounts.date_of_trxn"));
    } else if (getPaymentDate().isAfter(new LocalDate())) {
        messageContext.addMessage(buildValidationMessage("errors.futuredate", "paymentDate", "accounts.date_of_trxn"));
    } else if (getPaymentDate().isBefore(lastPaymentDate)) {
        messageContext.addMessage(buildValidationMessage("errors.payment.date.before.last.payment", "paymentDate", "accounts.date_of_trxn"));
    }
    //receipt date validation
    if (isReceiptDateSpecified() && !dateValidator.formsValidDate(receiptDateDD, receiptDateMM, receiptDateYY)) {
        messageContext.addMessage(buildValidationMessage("errors.invaliddate", "receiptDate", "accounts.receiptdate"));
    }
    //amount validation
    if (paymentAmount != null && paymentAmount.doubleValue() <= 0) {
        messageContext.addMessage(buildValidationMessage("error.penalty.incorrectDouble", "paymentAmount", "Amount"));
    }
    if (messageContext.hasErrorMessages()) {
        this.truePrintReceipt = this.printReceipt;
        this.printReceipt = false;
    }
}
Also used : DateValidator(org.mifos.clientportfolio.loan.ui.DateValidator) Errors(org.springframework.validation.Errors) FieldError(org.springframework.validation.FieldError) MessageContext(org.springframework.binding.message.MessageContext) LocalDate(org.joda.time.LocalDate)

Example 40 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class LoanAccountFormBeanTest method shouldContainValidationMessageOnInterestRateFieldWhenInterestRateViolatesAllowedRange.

@Test
public void shouldContainValidationMessageOnInterestRateFieldWhenInterestRateViolatesAllowedRange() {
    // setup
    loanAccountFormBean.setInterestRate(200);
    // exercise test
    loanAccountFormBean.validateEnterAccountDetailsStep(context);
    // verification
    MessageContext messageContext = context.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    assertThat(messages.length, is(1));
    Message message = messages[0];
    assertThat(message.getSource().toString(), is("interestRate"));
    assertThat(message.getText().toString(), containsString("loanAccountFormBean.InterestRate.invalid"));
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Aggregations

MessageContext (org.springframework.binding.message.MessageContext)51 Test (org.junit.Test)18 Message (org.springframework.binding.message.Message)16 MessageBuilder (org.springframework.binding.message.MessageBuilder)9 ArrayList (java.util.ArrayList)5 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)4 UnsatisfiedAuthenticationPolicyException (org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException)4 LocalDate (org.joda.time.LocalDate)4 BigDecimal (java.math.BigDecimal)3 GeneralSecurityException (java.security.GeneralSecurityException)3 HashMap (java.util.HashMap)3 AccountLockedException (javax.security.auth.login.AccountLockedException)3 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)3 PreventedException (org.apereo.cas.authentication.PreventedException)3 DateTime (org.joda.time.DateTime)3 LoanCreationInstallmentDto (org.mifos.dto.domain.LoanCreationInstallmentDto)2 LoanScheduleDto (org.mifos.dto.screen.LoanScheduleDto)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 ErrorEntry (org.mifos.platform.validations.ErrorEntry)2