Search in sources :

Example 91 with ActionErrors

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

the class LoginFilter method doFilter.

/**
     * This function implements the login filter it checks if user is not login
     * it forces the user to login by redirecting him to login page
     */
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    request.setCharacterEncoding("UTF-8");
    String complUri = request.getRequestURI();
    int index = complUri.lastIndexOf("/");
    String uri = complUri.substring(index + 1);
    try {
        if (uri == null || uri.equalsIgnoreCase(LoginConstants.LOGINPAGEURI) || uri.equalsIgnoreCase(LoginConstants.LOGINACTION)) {
            logger.debug("Inside Filter uri is for login page");
            chain.doFilter(req, res);
        } else {
            if (request.getSession(false) == null) {
                logger.debug("Inside Filter session is null");
                ActionErrors error = new ActionErrors();
                error.add(LoginConstants.SESSIONTIMEOUT, new ActionMessage(LoginConstants.SESSIONTIMEOUT));
                request.setAttribute(Globals.ERROR_KEY, error);
                request.getRequestDispatcher(LoginConstants.LOGINPAGEURI).forward(req, res);
                // ((HttpServletResponse)res).sendRedirect(request.getContextPath()+LoginConstants.LOGINPAGEURI);
                return;
            }
            UserContext userContext = (UserContext) request.getSession(false).getAttribute(Constants.USERCONTEXT);
            if (null == userContext || null == userContext.getId()) {
                // send back to login page with error message
                ((HttpServletResponse) res).sendRedirect(request.getContextPath() + LoginConstants.LOGINPAGEURI);
                return;
            } else {
                ((HttpServletRequest) req).getSession(false).setAttribute(Constants.RANDOMNUM, new Random().nextLong());
                chain.doFilter(req, res);
            }
        }
    } catch (IllegalStateException ise) {
        logger.error("Inside Filter ISE" + ise.getMessage());
        ActionMessage error = new ActionMessage(LoginConstants.IllEGALSTATE);
        request.setAttribute(Globals.ERROR_KEY, error);
        ((HttpServletResponse) res).sendRedirect(request.getContextPath() + LoginConstants.LOGINPAGEURI);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Random(java.util.Random) ActionMessage(org.apache.struts.action.ActionMessage) HttpServletResponse(javax.servlet.http.HttpServletResponse) ActionErrors(org.apache.struts.action.ActionErrors)

Example 92 with ActionErrors

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

the class FeeActionFormTest method isAmountValid.

private boolean isAmountValid(FeeActionForm form) {
    ActionErrors errors = new ActionErrors();
    form.validateAmount(errors, locale);
    return errors.size() == 0;
}
Also used : ActionErrors(org.apache.struts.action.ActionErrors)

Example 93 with ActionErrors

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

the class PersonnelSettingsActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    String method = request.getParameter(Methods.method.toString());
    if (method.equals(Methods.preview.toString())) {
        if (StringUtils.isBlank(getFirstName())) {
            addError(errors, PersonnelConstants.FIRSTNAME, PersonnelConstants.ERRORMANDATORY, PersonnelConstants.FIRST_NAME);
        } else if (getFirstName().length() > PersonnelConstants.PERSONNELLENGTH) {
            addError(errors, PersonnelConstants.FIRSTNAME, PersonnelConstants.MAXIMUM_LENGTH, PersonnelConstants.FIRST_NAME, PersonnelConstants.PERSONNELNAMELENGTH);
        }
        if (StringUtils.isBlank(getLastName())) {
            addError(errors, PersonnelConstants.LASTNAME, PersonnelConstants.ERRORMANDATORY, PersonnelConstants.LAST_NAME);
        } else if (getLastName().length() > PersonnelConstants.PERSONNELLENGTH) {
            addError(errors, PersonnelConstants.LASTNAME, PersonnelConstants.MAXIMUM_LENGTH, PersonnelConstants.LAST_NAME, PersonnelConstants.PERSONNELNAMELENGTH);
        }
        if (StringUtils.isBlank(getGender())) {
            addError(errors, PersonnelConstants.GENDERVALUE, PersonnelConstants.MANDATORYSELECT, PersonnelConstants.GENDERVALUE);
        }
        if (getDisplayName().length() > PersonnelConstants.PERSONNELDISPLAYNAMELENGTH) {
            addError(errors, PersonnelConstants.DISPLAYNAME, PersonnelConstants.MAXIMUM_LENGTH, PersonnelConstants.DISPLAY_NAME, PersonnelConstants.PERSONNELDISPLAYLENGTH);
        }
        validateEmail(errors);
    }
    if (!method.equals(Methods.validate.toString())) {
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : ActionErrors(org.apache.struts.action.ActionErrors)

Example 94 with ActionErrors

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

the class CustSearchAction method mainSearch.

@TransactionDemarcate(joinToken = true)
public ActionForward mainSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    CustSearchActionForm actionForm = (CustSearchActionForm) form;
    Short officeId = getShortValue(actionForm.getOfficeId());
    String searchString = actionForm.getSearchString();
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USERCONTEXT, request.getSession());
    super.search(mapping, form, request, response);
    if (searchString == null || searchString.equals("")) {
        ActionErrors errors = new ActionErrors();
        errors.add(CustomerSearchConstants.NAMEMANDATORYEXCEPTION, new ActionMessage(CustomerSearchConstants.NAMEMANDATORYEXCEPTION));
        request.setAttribute(Globals.ERROR_KEY, errors);
        return mapping.findForward(ActionForwards.mainSearch_success.toString());
    }
    if (officeId != null && officeId != 0) {
        addSeachValues(searchString, officeId.toString(), new OfficePersistence().getOffice(officeId).getOfficeName(), request);
    } else {
        addSeachValues(searchString, officeId.toString(), new OfficePersistence().getOffice(userContext.getBranchId()).getOfficeName(), request);
    }
    searchString = SearchUtils.normalizeSearchString(searchString);
    if (searchString.equals("")) {
        throw new CustomerException(CustomerSearchConstants.NAMEMANDATORYEXCEPTION);
    }
    if (actionForm.getFilters() == null) {
        actionForm.setFilters(new SearchFiltersDto());
    }
    QueryResult customerSearchResult = new CustomerPersistence().search(searchString, officeId, userContext.getId(), userContext.getBranchId(), actionForm.getFilters());
    SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerSearchResult, request);
    return mapping.findForward(ActionForwards.mainSearch_success.toString());
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) CustSearchActionForm(org.mifos.customers.struts.actionforms.CustSearchActionForm) UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) SearchFiltersDto(org.mifos.dto.screen.SearchFiltersDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) ActionErrors(org.apache.struts.action.ActionErrors) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 95 with ActionErrors

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

the class CenterCustActionForm method validateFields.

/*
     * Validation is done in the order that the fields appear on the UI.
     *
     * @see org.mifos.customers.struts.actionforms.CustomerActionForm#
     * validateFields(javax.servlet.http.HttpServletRequest, java.lang.String)
     */
@Override
protected ActionErrors validateFields(HttpServletRequest request, String method) throws ApplicationException {
    ActionErrors errors = new ActionErrors();
    if (method.equals(Methods.preview.toString())) {
        validateName(errors);
        validateLO(errors);
        validateMeeting(request, errors);
    } else if (method.equals(Methods.editPreview.toString())) {
        validateName(errors);
        CenterBO center = (CenterBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
        if (center.isActive()) {
            validateLO(errors);
        }
    }
    if (method.equals(Methods.preview.toString()) || method.equals(Methods.editPreview.toString())) {
        validateMfiJoiningDate(request, errors);
        validateConfigurableMandatoryFields(request, errors, EntityType.CENTER);
        validateCustomFieldsForCustomers(request, errors);
    }
    // fees are only editable in preview and come last
    if (method.equals(Methods.preview.toString())) {
        validateFees(request, errors);
    }
    return errors;
}
Also used : CenterBO(org.mifos.customers.center.business.CenterBO) 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