Search in sources :

Example 6 with ActionErrors

use of org.apache.struts.action.ActionErrors in project head by mifos.

the class SavingsApplyAdjustmentActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = new ActionErrors();
    if (null == request.getAttribute(Constants.CURRENTFLOWKEY)) {
        request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    }
    try {
        if (method != null && method.equals("preview")) {
            SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
            AccountPaymentEntity payment = savings.findPaymentById(this.paymentId);
            if (payment == null || savings.getLastPmntAmnt() == 0 || !(new SavingsHelper().getPaymentActionType(payment).equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue()) || new SavingsHelper().getPaymentActionType(payment).equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue()))) {
                errors.add(SavingsConstants.INVALID_LAST_PAYMENT, new ActionMessage(SavingsConstants.INVALID_LAST_PAYMENT));
            } else {
                if (StringUtils.isBlank(getLastPaymentAmount())) {
                    errors.add(SavingsConstants.INVALID_ADJUSTMENT_AMOUNT, new ActionMessage(SavingsConstants.INVALID_ADJUSTMENT_AMOUNT));
                }
                if (StringUtils.isNotBlank(getLastPaymentAmount())) {
                    Locale locale = getUserContext(request).getPreferredLocale();
                    validateAmount(errors, locale);
                }
                if (StringUtils.isNotBlank(getNote()) && getNote().length() > CustomerConstants.COMMENT_LENGTH) {
                    errors.add(AccountConstants.MAX_NOTE_LENGTH, new ActionMessage(AccountConstants.MAX_NOTE_LENGTH, AccountConstants.COMMENT_LENGTH));
                }
                validateDate(errors);
                errors.add(super.validate(mapping, request));
            }
        }
    } catch (ApplicationException ae) {
        errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : Locale(java.util.Locale) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SavingsHelper(org.mifos.accounts.savings.util.helpers.SavingsHelper) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ActionMessage(org.apache.struts.action.ActionMessage) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) ActionErrors(org.apache.struts.action.ActionErrors)

Example 7 with ActionErrors

use of org.apache.struts.action.ActionErrors in project head by mifos.

the class SavingsClosureActionForm method validate.

@Override
public ActionErrors validate(@SuppressWarnings("unused") ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = new ActionErrors();
    if (method.equals("load") || method.equals("previous") || method.equals("validate") || method.equals("close") || method.equals("cancel")) {
    } else {
        String amount = getAmount();
        if (!("0.0".equals(amount))) {
            if (StringUtils.isNotBlank(amount)) {
                if (StringUtils.isBlank(getPaymentTypeId())) {
                    errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.paymentType")));
                }
            }
        }
        if (this.getReceiptDate() != null && !this.getReceiptDate().equals("")) {
            ActionErrors dateError = validateDate(this.getReceiptDate(), getLocalizedMessage("Savings.receiptDate"));
            if (dateError != null && !dateError.isEmpty()) {
                errors.add(dateError);
            }
        }
        if (StringUtils.isBlank(getCustomerId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.ClientName")));
        }
        if (StringUtils.isBlank(getNotes())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.notes")));
        }
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 8 with ActionErrors

use of org.apache.struts.action.ActionErrors in project head by mifos.

the class SavingsDepositWithdrawalActionForm method validateDate.

private ActionErrors validateDate(String date, String fieldName) {
    ActionErrors errors = null;
    java.sql.Date sqlDate = null;
    if (date != null && !date.equals("")) {
        try {
            sqlDate = DateUtils.getDateAsSentFromBrowser(date);
            if (DateUtils.whichDirection(sqlDate) > 0) {
                errors = new ActionErrors();
                errors.add(AccountConstants.ERROR_FUTUREDATE, new ActionMessage(AccountConstants.ERROR_FUTUREDATE, fieldName));
            }
        } catch (InvalidDateException e) {
            errors = new ActionErrors();
            errors.add(AccountConstants.ERROR_INVALIDDATE, new ActionMessage(AccountConstants.ERROR_INVALIDDATE, fieldName));
        }
    } else {
        errors = new ActionErrors();
        errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, fieldName));
    }
    return errors;
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 9 with ActionErrors

use of org.apache.struts.action.ActionErrors in project head by mifos.

the class SavingsDepositWithdrawalActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = null;
    if (method != null && method.equals(Methods.preview.toString())) {
        errors = new ActionErrors();
        if (StringUtils.isBlank(getTrxnTypeId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.paymentType")));
        }
        if (StringUtils.isBlank(getAmount())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.amount")));
        }
        if (StringUtils.isNotBlank(getAmount())) {
            Locale locale = getUserContext(request).getPreferredLocale();
            DoubleConversionResult conversionResult = validateAmount(getAmount(), AccountConstants.ACCOUNT_AMOUNT, errors);
            if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
                addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
            }
        }
        if (StringUtils.isBlank(getPaymentTypeId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.modeOfPayment")));
        }
        ActionErrors dateError = validateDate(this.trxnDate, getLocalizedMessage("Savings.dateOfTrxn"));
        if (dateError != null && !dateError.isEmpty()) {
            errors.add(dateError);
        }
        dateError = validateTrxnDate(this.trxnDate, getLocalizedMessage("Savings.dateOfTrxn"));
        if (dateError != null && !dateError.isEmpty()) {
            errors.add(dateError);
        }
        if (this.getReceiptDate() != null && !this.getReceiptDate().equals("")) {
            dateError = validateDate(getReceiptDate(), getLocalizedMessage("Savings.receiptDate"));
            if (dateError != null && !dateError.isEmpty()) {
                errors.add(dateError);
            }
        }
        if (StringUtils.isBlank(getCustomerId())) {
            errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, getLocalizedMessage("Savings.ClientName")));
        }
    }
    if (null != errors && !errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : Locale(java.util.Locale) ActionMessage(org.apache.struts.action.ActionMessage) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) ActionErrors(org.apache.struts.action.ActionErrors)

Example 10 with ActionErrors

use of org.apache.struts.action.ActionErrors in project head by mifos.

the class LoanDisbursementActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    ActionErrors errors1 = super.validate(mapping, request);
    if (errors1 != null) {
        errors.add(errors1);
    }
    String method = request.getParameter(MethodNameConstants.METHOD);
    if (isPreviewMethod(method) && getPaymentAmountGreaterThanZero() && StringUtils.isBlank(paymentModeOfPayment)) {
        String errorMessage = this.getLocalizedMessage("loan.paymentid");
        errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, errorMessage));
    }
    if (isPreviewMethod(method) && getPaymentAmountGreaterThanZero() && !StringUtils.isBlank(paymentModeOfPayment) && Short.valueOf(paymentModeOfPayment).equals(transferPaymentTypeId) && StringUtils.isBlank(accountForTransfer)) {
        String errorMessage = this.getLocalizedMessage("loan.accountForTransfer");
        errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, errorMessage));
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Aggregations

ActionErrors (org.apache.struts.action.ActionErrors)144 ActionMessage (org.apache.struts.action.ActionMessage)68 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)20 Locale (java.util.Locale)19 ResourceBundle (java.util.ResourceBundle)13 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)12 Test (org.junit.Test)9 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)7 Date (java.sql.Date)5 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)4 ReportsPersistence (org.mifos.reports.persistence.ReportsPersistence)4 DateTime (org.joda.time.DateTime)3 PaymentDataHtmlBean (org.mifos.accounts.loan.struts.uihelpers.PaymentDataHtmlBean)3 ReportsCategoryBO (org.mifos.reports.business.ReportsCategoryBO)3 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)2 ArrayList (java.util.ArrayList)2 ServletContext (javax.servlet.ServletContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2