Search in sources :

Example 16 with ActionMessage

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

the class SavingsActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    ActionErrors errors = new ActionErrors();
    String mandatoryAmount = getLocalizedMessage(SavingsConstants.MANDATORY_AMOUNT_FOR_DEPOSIT_KEY);
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    if (method.equals("getPrdOfferings") || method.equals("create") || method.equals("edit") || method.equals("update") || method.equals("get") || method.equals("validate")) {
    } else {
        errors.add(super.validate(mapping, request));
        if (method.equals("preview") || method.equals("editPreview")) {
            try {
                SavingsOfferingBO savingsOffering = (SavingsOfferingBO) SessionUtils.getAttribute(SavingsConstants.PRDOFFERING, request);
                if (savingsOffering.getSavingsType().getId().equals(SavingsType.MANDATORY.getValue()) && StringUtils.isBlank(getRecommendedAmount())) {
                    // check for mandatory amount
                    errors.add(SavingsConstants.MANDATORY, new ActionMessage(SavingsConstants.MANDATORY, mandatoryAmount));
                }
                if (StringUtils.isNotBlank(getRecommendedAmount())) {
                    if (savingsOffering.getSavingsType().equals(SavingsType.MANDATORY)) {
                        validateAmount(getRecommendedAmount(), SavingsConstants.MANDATORY_AMOUNT_FOR_DEPOSIT_KEY, errors);
                    } else {
                        validateAmount(getRecommendedAmount(), SavingsConstants.RECOMMENDED_AMOUNT_FOR_DEPOSIT_KEY, errors);
                    }
                }
                validateCustomFields(request, errors);
            } catch (PageExpiredException e) {
                errors.add(SavingsConstants.MANDATORY, new ActionMessage(SavingsConstants.MANDATORY, mandatoryAmount));
            }
        }
    }
    if (!errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) ActionMessage(org.apache.struts.action.ActionMessage) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ActionErrors(org.apache.struts.action.ActionErrors)

Example 17 with ActionMessage

use of org.apache.struts.action.ActionMessage 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 18 with ActionMessage

use of org.apache.struts.action.ActionMessage 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 19 with ActionMessage

use of org.apache.struts.action.ActionMessage 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 20 with ActionMessage

use of org.apache.struts.action.ActionMessage 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)

Aggregations

ActionMessage (org.apache.struts.action.ActionMessage)166 ActionErrors (org.apache.struts.action.ActionErrors)70 ActionMessages (org.apache.struts.action.ActionMessages)45 ResourceBundle (java.util.ResourceBundle)29 JspException (javax.servlet.jsp.JspException)22 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)22 Iterator (java.util.Iterator)21 Locale (java.util.Locale)19 List (java.util.List)9 ActionForward (org.apache.struts.action.ActionForward)9 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)8 ArrayList (java.util.ArrayList)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)7 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)7 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 IOException (java.io.IOException)6 Date (java.sql.Date)6 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4