Java tutorial
/*$Id: AbstractStatusBrowsingController.java 15516 2010-04-13 18:57:03Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2006 ABM-utvikling * * * * Created on 21-Feb-2006 * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * * Public License for more details. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.abmstatistikk.web; import java.util.Map; import javax.servlet.http.HttpServletRequest; import no.abmu.abmstatistikk.service.StatusReportService; import no.abmu.common.constants.ViewNameConst; import no.abmu.common.schema.SchemaTypeNameAndVersion; import no.abmu.organisationregister.finders.organisationunit.OrgUnitFinderSpecificationBean; import no.abmu.util.pageholder.PageHolder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.util.StopWatch; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.servlet.ModelAndView; /** * Abstract <code>MultiActionController</code> that is basis * for all status browsing. * * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no * @author $Author: jens $ * @version $Rev: 15516 $ * @date $Date: 2010-04-13 20:57:03 +0200 (Tue, 13 Apr 2010) $ * @copyright ABM-Utvikling */ public abstract class AbstractStatusBrowsingController extends AbstractBaseController { private static final Log logger = (Log) LogFactory.getLog(AbstractStatusBrowsingController.class); private StatusReportService statusReportService; public void setStatusReportService(StatusReportService statusReportService) { this.statusReportService = statusReportService; } protected ModelAndView statusBrowser(HttpServletRequest request, String attribute, String organisationType, SchemaTypeNameAndVersion schemaTypeNameAndVersion, String view) { OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean(); finderBean.setOrganisationTypeName(organisationType); finderBean.setTodayAsActiveDate(); return statusBrowser(request, attribute, finderBean, schemaTypeNameAndVersion, view); } /** * Refreshable status browser. * @param request current HTTP request * @param attribute to use store RefreshablePageholder in current http session * @param organisationType name of organisation type * @param schemaType name of schema type * @param view - if sucess use this view as view in ModelAndView * @param year - report year * @return a ModelAndView to render the response */ /* protected ModelAndView statusBrowser( HttpServletRequest request, String attribute, String organisationType, String schemaType, String view, int year) { OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean(); finderBean.setOrganisationTypeName(organisationType); finderBean.setTodayAsActiveDate(); return statusBrowser(request, attribute, finderBean, schemaType, view, year); } */ /** * Refreshable status browser. * @param request current HTTP request * @param attribute to use store RefreshablePageholder in current http session * @param organisationType name of organisation type * @param schemaType name of schema type * @param view - if sucess use this view as view in ModelAndView * @param year - report year * @return a ModelAndView to render the response */ protected ModelAndView statusBrowser(HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion, String view) { logger.info("Executing statusBrowser on organisationType='" + finderBean.getOrganisationTypeName() + "' and schemaType='" + schemaTypeNameAndVersion.toString() + "'"); StopWatch stopWatch = new StopWatch("browseOrgType"); /* * This should be replaced with AOP in an XML spring config-file. */ if (!isSecureContext()) { return new ModelAndView(ViewNameConst.LOGOFF_VIEW); } stopWatch.start("Mav_for_browsing_organisationType"); Map model = statusBrowse(request, attribute, finderBean, schemaTypeNameAndVersion); stopWatch.stop(); logger.info("Getting ModelAndview for organisationType " + finderBean.getOrganisationTypeName() + " tok " + stopWatch.getTotalTimeMillis() + " milliseconds."); return new ModelAndView(view, model); } /** * Refreshable status browser. * @param request current HTTP request * @param attribute to use store RefreshablePageholder in current http session * @param organisationType name of organisation type * @param schemaType name of schema type * @param view - if sucess use this view as view in ModelAndView * @param year - report year * @return a ModelAndView to render the response */ /* protected ModelAndView statusBrowser( HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, String schemaType, String view, int year) { logger.info("Executing statusBrowser on organisationType='" + finderBean.getOrganisationTypeName() + "' and schemaType='" + schemaType + "'"); StopWatch stopWatch = new StopWatch("browseOrgType"); // This should be replaced with AOP in an XML spring config-file. if (!isSecureContext()) { return new ModelAndView(ViewNameConst.LOGOFF_VIEW); } stopWatch.start("Mav_for_browsing_organisationType"); Map model = statusBrowse(request, attribute, finderBean, schemaType, year); stopWatch.stop(); logger.info("Getting ModelAndview for organisationType " + finderBean.getOrganisationTypeName() + " tok " + stopWatch.getTotalTimeMillis() + " milliseconds."); return new ModelAndView(view, model); } */ protected ModelAndView countyStatusBrowser(HttpServletRequest request, String attribute, String organisationType, SchemaTypeNameAndVersion schemaTypeNameAndVersion, String view) { // This should be replaced with AOP in an XML spring config-file. if (!isSecureContext()) { logger.error("[refreshableCountyStatusBrowser]: no secureContext loging off"); return new ModelAndView(ViewNameConst.LOGOFF_VIEW); } Integer countyNumber = getCountyNumberFromRequestOrLoggedOnUser(request); if (null == countyNumber) { logger.error("[countyStatusBrowser]: could not get any countynumber, return to mainmenu."); return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU); } OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean(); finderBean.setOrganisationTypeName(organisationType); finderBean.setCountyNumber(countyNumber); finderBean.setTodayAsActiveDate(); Map model = statusBrowse(request, attribute, finderBean, schemaTypeNameAndVersion); return new ModelAndView(view, model); } /** * Refreshable status browser. * @param request current HTTP request * @param attribute to use store RefreshablePageholder in current http session * @param organisationType name of organisation type * @param schemaType name of schema type * @param view - if sucess use this view as view in ModelAndView * @param year - report year * @return a ModelAndView to render the response */ /* protected ModelAndView countyStatusBrowser( HttpServletRequest request, String attribute, String organisationType, String schemaType, String view, int year) { // This should be replaced with AOP in an XML spring config-file. if (!isSecureContext()) { logger.error("[refreshableCountyStatusBrowser]: no secureContext loging off"); return new ModelAndView(ViewNameConst.LOGOFF_VIEW); } Integer countyNumber = getCountyNumberFromRequestOrLoggedOnUser(request); if (null == countyNumber) { logger.error("[countyStatusBrowser]: could not get any countynumber, return to mainmenu."); return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU); } OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean(); finderBean.setOrganisationTypeName(organisationType); finderBean.setCountyNumber(countyNumber); finderBean.setTodayAsActiveDate(); Map model = statusBrowse(request, attribute, finderBean, schemaType, year); return new ModelAndView(view, model); } */ // //////////////////////////////////////////////////////////////////////// // // Private methods for status browsing // // //////////////////////////////////////////////////////////////////////// protected Map<String, Object> statusBrowse(HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion) { logger.info("Executing statusBrowse"); PageHolder pageHolder = (PageHolder) request.getSession(true).getAttribute(attribute); if (null == pageHolder) { pageHolder = statusReportService.createNewPageHolder(finderBean, schemaTypeNameAndVersion); request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return binder.getBindingResult().getModel(); } /* protected Map<String, Object> statusBrowse( HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, String schemaTypeName, int year) { logger.info("Executing statusBrowse"); PageHolder pageHolder = (PageHolder) request.getSession(true).getAttribute(attribute); if (null == pageHolder) { pageHolder = statusReportService.createNewPageHolder(finderBean, schemaTypeName, year); request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return binder.getBindingResult().getModel(); } */ }