use of org.apache.struts.action.ActionMessage in project head by mifos.
the class RepayLoanActionForm method validateDate.
protected ActionErrors validateDate(String date, String fieldName) {
ActionErrors errors = null;
java.sql.Date sqlDate = null;
if (date != null && !date.equals("")) {
try {
sqlDate = getDateAsSentFromBrowser(date);
if (DateUtils.whichDirection(sqlDate) > 0) {
errors = new ActionErrors();
errors.add(AccountConstants.ERROR_FUTUREDATE, new ActionMessage(AccountConstants.ERROR_FUTUREDATE, fieldName));
}
} catch (InvalidDateException ide) {
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;
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class RepayLoanActionForm method validatePaymentDate.
public ActionErrors validatePaymentDate(String transactionDate, String fieldName) {
ActionErrors errors = null;
if (transactionDate != null && !transactionDate.equals("")) {
try {
if (lastPaymentDate != null && dateFallsBeforeDate(getDateAsSentFromBrowser(transactionDate), lastPaymentDate)) {
errors = new ActionErrors();
errors.add(AccountConstants.ERROR_PAYMENT_DATE_BEFORE_LAST_PAYMENT, new ActionMessage(AccountConstants.ERROR_PAYMENT_DATE_BEFORE_LAST_PAYMENT, fieldName));
}
} catch (InvalidDateException ide) {
errors = new ActionErrors();
errors.add(AccountConstants.ERROR_INVALIDDATE, new ActionMessage(AccountConstants.ERROR_INVALIDDATE, fieldName));
}
}
return errors;
}
use of org.apache.struts.action.ActionMessage 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();
}
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class MifosExceptionHandler method execute.
/**
* Figures the type of exception and thus gets the page to which it should
* be forwarded. If the exception is of type {@link SystemException} it is
* forwarded to standard page which is obtained using Exception Config. If
* the exception is of type {@link ApplicationException} the page to which
* the request is forwarded is figured out using the string
* <method_invoked>+failure which should be defined in the ActionConfig.
*/
@Override
public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException {
ActionForward forwardToBeReturned = null;
String input = null;
String parameter = null;
ActionMessage error = null;
if (ex instanceof ServiceUnavailableException) {
forwardToBeReturned = new ActionForward(ae.getPath());
error = new ActionMessage(((ServiceUnavailableException) ex).getKey(), ((ServiceUnavailableException) ex).getValues());
}
if (ex instanceof ConnectionNotFoundException) {
forwardToBeReturned = new ActionForward(ae.getPath());
error = new ActionMessage(((ConnectionNotFoundException) ex).getKey(), ((ConnectionNotFoundException) ex).getValues());
}
if (ex instanceof SystemException) {
forwardToBeReturned = new ActionForward(ae.getPath());
error = new ActionMessage(((SystemException) ex).getKey(), ((SystemException) ex).getValues());
} else if (ex instanceof PageExpiredException) {
forwardToBeReturned = new ActionForward(ae.getPath());
error = new ActionMessage(((PageExpiredException) ex).getKey(), ((PageExpiredException) ex).getValues());
} else if (ex instanceof ApplicationException || ex instanceof BusinessRuleException) {
String key = ex instanceof ApplicationException ? ((ApplicationException) ex).getKey() : ((BusinessRuleException) ex).getMessageKey();
Object[] values = ex instanceof ApplicationException ? ((ApplicationException) ex).getValues() : ((BusinessRuleException) ex).getMessageValues();
error = new ActionMessage(key, values);
parameter = request.getParameter("method");
// jsp to which the user should be returned is identified by
// methodname_failure e.g. if there is an exception in create the
// failure forward would be create_failure if input is not null it
// also tries to append that to parameter to find the action
// forward.If that is not availablee it still tries to find the
// forward with the actionforward being parameter_failure
input = request.getParameter("input");
if (null != input) {
parameter = parameter + "_" + input;
}
forwardToBeReturned = mapping.findForward(parameter + "_failure");
if (null == forwardToBeReturned) {
forwardToBeReturned = mapping.findForward(request.getParameter("method") + "_failure");
}
// is coming
if (null == forwardToBeReturned) {
input = mapping.getInput();
if (null != input) {
forwardToBeReturned = new ActionForward("ExceptionForward", input, false, null);
} else {
forwardToBeReturned = super.execute(ex, ae, mapping, formInstance, request, response);
// further statements
return forwardToBeReturned;
}
}
}
logException(ex);
// This will store the exception in the scope mentioned so that
// it can be displayed on the UI
this.storeException(request, error.getKey(), error, forwardToBeReturned, ae.getScope());
return forwardToBeReturned;
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class PictureFormFile method addWarningMessages.
private void addWarningMessages(HttpServletRequest request, ProcessRulesDto processRules, int age) throws PageExpiredException {
SessionUtils.removeAttribute("processRules", request);
if (processRules.isGovernmentIdValidationFailing()) {
SessionUtils.addWarningMessage(request, CustomerConstants.CLIENT_WITH_SAME_GOVT_ID_EXIST_IN_CLOSED);
SessionUtils.setAttribute("processRules", processRules, request);
}
if (processRules.isDuplicateNameOnBlackListedClient()) {
SessionUtils.addWarningMessage(request, CustomerConstants.CLIENT_WITH_SAME_NAME_DOB_EXIST_IN_BLACKLISTED);
SessionUtils.setAttribute("processRules", processRules, request);
}
if (processRules.isDuplicateNameOnClosedClient()) {
SessionUtils.addWarningMessage(request, CustomerConstants.CLIENT_WITH_SAME_NAME_DOB_EXIST_IN_CLOSED);
SessionUtils.setAttribute("processRules", processRules, request);
}
if (processRules.isGovermentIdValidationUnclosedFailing()) {
SessionUtils.addWarningMessage(request, CustomerConstants.CLIENT_WITH_SAME_GOVT_ID_EXIST_IN_UNCLOSED);
SessionUtils.setAttribute("processRules", processRules, request);
}
if (processRules.isduplicateNameOnClient()) {
SessionUtils.addWarningMessage(request, CustomerConstants.CLIENT_WITH_SAME_NAME_EXIST);
SessionUtils.setAttribute("processRules", processRules, request);
}
if (ClientRules.isAgeCheckEnabled() && ClientRules.isAgeCheckWarningInsteadOfErrorEnabled()) {
if (age > ClientRules.getMaximumAgeForNewClient() || age < ClientRules.getMinimumAgeForNewClient()) {
SessionUtils.addWarningMessage(request, new ActionMessage(CustomerConstants.CLIENT_AGE_OUT_OF_BOUNDS, ClientRules.getMinimumAgeForNewClient(), ClientRules.getMaximumAgeForNewClient()));
}
}
}
Aggregations