Java tutorial
/*$Id: ABMStatistikkCommentReportController.java 15572 2010-04-27 13:45:13Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2006 ABM-utvikling * * * * 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.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import no.abmu.abmstatistikk.service.CommentReportService; import no.abmu.common.jasperreports.SchemaList; import no.abmu.common.schema.SchemaName; import no.abmu.common.schema.SchemaTypeNameAndVersion; import no.abmu.organisationregister.domain.OrganisationTypeNameConst; import no.abmu.organisationregister.finders.organisationunit.OrgUnitFinderSpecificationBean; import no.abmu.util.date.DateUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.util.StopWatch; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; /** * <code>ABMStatistikkCommentReportController</code> is a multiaction * controller that is ment to handle all comment reports. * * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no * @author $Author: jens $ * @version $Rev: 15572 $ * @since 2006-09-29 (rev. 3403) * $Date: 2010-04-27 15:45:13 +0200 (Tue, 27 Apr 2010) $ * copyright ABM-Utvikling */ public class ABMStatistikkCommentReportController extends MultiActionController { public static final int STATISTICAL_YEAR = 2009; public static final Date STATISTICAL_DATE = DateUtil.parseISODate("2009-12-30"); private static final Log logger = (Log) LogFactory.getLog(ABMStatistikkCommentReportController.class); private CommentReportService commentReportService; public void setCommentReportService(CommentReportService commentReportService) { this.commentReportService = commentReportService; } // //////////////////////////////////////////////////////////////////////// // // CommentReport for fagbibliotek. // // //////////////////////////////////////////////////////////////////////// /** * Custom handler handleCommentReportFagBibExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException * @throws */ public ModelAndView handleCommentReportFagBibExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.FAG_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.ACADEMIC_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "fagBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } // //////////////////////////////////////////////////////////////////////// // // CommentReport for museum. // // //////////////////////////////////////////////////////////////////////// /** * Custom handler handleCommentReportMuseumExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportMuseumExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.MUSEUM; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.MUSEUM_STATISTIC, STATISTICAL_YEAR); // View String viewName = "museumCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportReportingMuseumExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportReportingMuseumExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.REPORTINGMUSEUM; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.MUSEUM_STATISTIC, STATISTICAL_YEAR); // View String viewName = "reportingMuseumCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } // //////////////////////////////////////////////////////////////////////// // // CommentReport for folkebibliotek. // // //////////////////////////////////////////////////////////////////////// /** * Custom handler handleCommentReportPublicLibrariesExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportPublicLibrariesExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.PUBLIC_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.PUBLIC_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "folkeBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportMobileLibrariesExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportMobileLibrariesExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.MOBILE_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.MOBILE_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "mobilBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportPrisonLibrariesExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportPrisonLibrariesExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.PRISON_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.PRISON_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "fengselsBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportHospitalLibrariesExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportHospitalLibrariesExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.HOSPITAL_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.HOSPITAL_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "pasientBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportPrimarySchoolExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportPrimarySchoolExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.PRIMARY_SCHOOL_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.PRIMARY_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "grunnskoleBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportHighSchoolLibrariesExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportHighSchoolLibrariesExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.HIGH_SCHOOL_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.HIGH_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "vgsBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportCountyLibrariesExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportCountyLibrariesExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.FYLKES_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.COUNTY_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "fylkesBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportPublicLibrariesSvalbardExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportPublicLibrariesSvalbardExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.FOLKEBIBLIOTEK_SVALBARD; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.PUBLIC_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "folkeBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportPrimarySchoolSvalbardExcel. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportPrimarySchoolSvalbardExcel(HttpServletRequest request, HttpServletResponse response) throws ServletException { // OrganisationType String organisationType = OrganisationTypeNameConst.GRUNNSKOLEBIBLIOTEK_SVALBARD; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.PRIMARY_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "grunnskoleBibCommentsReportXlsView"; return commentReportData(organisationType, schemaTypeNameAndVersion, viewName); } /** * Custom handler handleCommentReportPrimarySchoolExcelFile. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportPrimarySchoolExcelFile(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.info(" XXXXXXXXXXXXXXXXXXX createMAVOrganisationTypeAndSchemaToFile: START "); StopWatch stopWatch = new StopWatch(); stopWatch.start("handleCommentReportPrimarySchoolExcelFile"); // OrganisationType String organisationType = OrganisationTypeNameConst.PRIMARY_SCHOOL_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.PRIMARY_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "grunnskoleBibCommentsReportXlsViewToFile"; ModelAndView mav = commentReportData(organisationType, schemaTypeNameAndVersion, viewName); stopWatch.stop(); logger.info("[private:handleCommentReportPrimarySchoolExcelFile] tok [" + stopWatch.getTotalTimeMillis() + "] ms"); logger.info(" XXXXXXXXXXXXXXXXXXX handleCommentReportPrimarySchoolExcelFile: STOP "); return mav; } /** * Custom handler handleCommentReportHighSchoolLibrariesExcelFile. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render the response * @throws ServletException */ public ModelAndView handleCommentReportHighSchoolLibrariesExcelFile(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.info(" XXXXXXXXXXXXXXXXXXX handleCommentReportHighSchoolLibrariesExcelFile: START "); StopWatch stopWatch = new StopWatch(); stopWatch.start("handleCommentReportHighSchoolLibrariesExcelFile"); // OrganisationType String organisationType = OrganisationTypeNameConst.HIGH_SCHOOL_LIBRARY; // Schema SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion .newInstance(SchemaName.HIGH_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR); // View String viewName = "vgsBibCommentsReportXlsViewToFile"; ModelAndView mav = commentReportData(organisationType, schemaTypeNameAndVersion, viewName); stopWatch.stop(); logger.info("[private:handleCommentReportHighSchoolLibrariesExcelFile] tok [" + stopWatch.getTotalTimeMillis() + "] ms"); logger.info(" XXXXXXXXXXXXXXXXXXX handleCommentReportHighSchoolLibrariesExcelFile: FINISH "); return mav; } // //////////////////////////////////////////////////////////////////////// // // Private methods. // // //////////////////////////////////////////////////////////////////////// /** * Create report data. * @param organisationTypeName * @param viewName * @param year * @return */ private ModelAndView commentReportData(String organisationType, SchemaTypeNameAndVersion schemaTypeNameAndVersion, String viewName) { Map<String, Object> model = new HashMap<String, Object>(); logger.info("[commentReportData]: Start"); OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean(); finderBean.setOrganisationTypeName(organisationType); finderBean.setActiveDate(STATISTICAL_DATE); SchemaList schemaList = commentReportService.createCommentReport(finderBean, schemaTypeNameAndVersion); model.put("reportData", schemaList); logger.info("[commentReportData]: contains " + schemaList.size() + " elements."); return new ModelAndView(viewName, model); } }