/** * Method execute * * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ActionErrors errors = new ActionErrors(); ActionMessages messages = new ActionMessages(); HttpSession session = request.getSession(); QueryForm queryForm = (QueryForm) form; if (session.isNew() || (session.getAttribute(Constants.LOGIN_OBJECT) == null)) { return mapping.findForward(Constants.FORWARD_PUBLIC_LOGIN); } String applicationName = ""; if (session.getAttribute(Constants.LOGIN_OBJECT) != null) { applicationName = (String) session.getAttribute(Constants.APPLICATION_NAME); } // Set Search Result Page information SearchResultPage searchResultPage = new SearchResultPage(); searchResultPage.setTotalResultSize(0); if (session.getAttribute(Constants.LOGLEVEL_MAP) == null) { session.setAttribute(Constants.LOGLEVEL_MAP, SystemManager.getLogLevelMap()); } if (session.getAttribute(Constants.SERVER_NAME_COLLECTION) == null) { try { session.setAttribute( Constants.SERVER_NAME_COLLECTION, SystemManager.getServerNameCollection()); } catch (Exception e) { searchResultPage.setSearchResultMessage(e.getMessage()); session.setAttribute(Constants.SEARCH_RESULTS_PAGE, searchResultPage); return mapping.findForward(Constants.FORWARD_QUERY); } } if (!StringUtils.isBlankOrNull(queryForm.getActivity())) { queryForm.setActivity(null); if (!isQueryFormValidated(queryForm, searchResultPage)) { session.setAttribute(Constants.SEARCH_RESULTS_PAGE, searchResultPage); return mapping.findForward(Constants.FORWARD_QUERY_RESULTS); } session.setAttribute(Constants.CURRENT_FORM, queryForm); session.removeAttribute(Constants.SEARCH_RESULTS_PAGE); session.removeAttribute(Constants.VIEW_PAGE_NUMBER); try { boolean success = performQuery(queryForm, request); } catch (Exception e) { searchResultPage.setSearchResultMessage(e.getMessage()); // Set Search Results session.setAttribute(Constants.SEARCH_RESULTS_PAGE, searchResultPage); } return mapping.findForward(Constants.FORWARD_QUERY_RESULTS); } else { queryForm.setActivity(null); // set Query Form default Values. java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(ApplicationConstants.DATE_FORMAT); java.text.SimpleDateFormat timeFormat = new java.text.SimpleDateFormat(ApplicationConstants.TIME_FORMAT); Date currentDate = new Date(System.currentTimeMillis()); Calendar cal = Calendar.getInstance(); cal.setTime(currentDate); queryForm.setEndDate(dateFormat.format(cal.getTime())); queryForm.setEndTime(timeFormat.format(cal.getTime())); cal.add(Calendar.HOUR, -1); queryForm.setStartDate(dateFormat.format(cal.getTime())); queryForm.setStartTime(timeFormat.format(cal.getTime())); queryForm.setApplication(applicationName); queryForm.setRecordCount(new Integer(Constants.DEFAULT_PAGE_SIZE).toString()); session.setAttribute(Constants.CURRENT_FORM, queryForm); } return mapping.findForward(Constants.FORWARD_QUERY); }
private boolean performQuery(QueryForm queryForm, HttpServletRequest request) throws Exception { HttpSession session = request.getSession(); // try // { Query query = new QueryImpl(); try { query.setCriteria(getSearchCriteria(queryForm, request)); } catch (QuerySpecificationException e1) { e1.printStackTrace(); throw e1; } catch (SearchCriteriaSpecificationException e1) { e1.printStackTrace(); throw e1; } catch (Exception e1) { e1.printStackTrace(); throw e1; } int totalResultSize = 0; try { totalResultSize = query.totalResultSize(); } catch (QuerySpecificationException e) { e.printStackTrace(); throw e; } if (totalResultSize > 0) { // Query results Collection resultCollection = null; try { resultCollection = query.query(1, new Integer(queryForm.getRecordCount()).intValue()); } catch (NumberFormatException e) { e.printStackTrace(); } catch (QuerySpecificationException e) { e.printStackTrace(); } List resultList = (List) resultCollection; // Set Search Result Page information SearchResultPage searchResultPage = new SearchResultPage(); searchResultPage.setTotalResultSize(totalResultSize); searchResultPage.setPageSize(new Integer(queryForm.getRecordCount()).intValue()); searchResultPage.setCurrentPageNumber(1); searchResultPage.setSearchResultMessage(Constants.RESULTS_MESSAGE); searchResultPage.setSearchResultObjects(resultList); searchResultPage.getLastPageNumber(); // Set Search Results session.setAttribute(Constants.SEARCH_RESULTS_PAGE, searchResultPage); session.setAttribute( Constants.VIEW_PAGE_NUMBER, new Integer(searchResultPage.getCurrentPageNumber())); return true; } else { // Set Search Result Page information SearchResultPage searchResultPage = new SearchResultPage(); searchResultPage.setTotalResultSize(totalResultSize); searchResultPage.setSearchResultMessage(Constants.NO_RESULTS_MESSAGE); // Set Search Results session.setAttribute(Constants.SEARCH_RESULTS_PAGE, searchResultPage); return false; } }