no.abmu.abmstatistikk.web.AbstractReportController.java Source code

Java tutorial

Introduction

Here is the source code for no.abmu.abmstatistikk.web.AbstractReportController.java

Source

/*$Id: AbstractReportController.java 16244 2011-02-04 09:07:59Z jens $*/
/*
****************************************************************************
*                                                                          *
*                   (c) Copyright 2006 ABM-utvikling                       *
*                                                                          *
*                         Created on 27-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.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;

import net.sf.jasperreports.engine.JRParameter;
import no.abmu.abmstatistikk.constants.SchemaListReportNameConst;
import no.abmu.abmstatistikk.service.BackgroundReportService;
import no.abmu.abmstatistikk.service.ReportService;
import no.abmu.common.LoggedOnStatusInfo;
import no.abmu.common.RequestUtil;
import no.abmu.common.constants.SubSchemaName;
import no.abmu.common.constants.ViewNameConst;
import no.abmu.common.jasperreports.SchemaList;
import no.abmu.common.logo.SchemaPdfLogo;
import no.abmu.common.reporting.OrgUnitReport;
import no.abmu.common.schema.SchemaName;
import no.abmu.common.schema.SchemaTypeNameAndVersion;
import no.abmu.common.schema.SubSchemaTypeNameAndVersion;
import no.abmu.organisationregister.domain.OrganisationTypeNameConst;
import no.abmu.organisationregister.finders.organisationunit.KkdReportFinderSpecification;
import no.abmu.organisationregister.finders.organisationunit.OrgUnitFinderSpecificationBean;
import no.abmu.util.date.DateUtil;
import no.abmu.util.test.Assert;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

/**
 * Abstract <code>MultiActionController</code> that is ment to be basis 
 * for all Pdf and excel report, not statusreport or commentreport.
 *
 * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no
 * @author $Author: jens $
 * @version $Rev: 16244 $
 * $Date: 2011-02-04 10:07:59 +0100 (Fri, 04 Feb 2011) $
 * Copyright ABM-Utvikling
*/
public abstract class AbstractReportController extends AbstractBaseController {

    private static final Log logger = (Log) LogFactory.getLog(AbstractReportController.class);

    private ReportService reportService;

    @Autowired
    private BackgroundReportService backgroundReportService;

    public void setReportService(ReportService reportService) {
        this.reportService = reportService;
    }

    protected ModelAndView createMAVForOrganisationUnit(HttpServletRequest request, String view,
            SchemaTypeNameAndVersion schemaTypeNameAndVersion) {

        Assert.checkRequiredArgument("request", request);
        Assert.checkRequiredArgument("view", view);
        Assert.checkRequiredArgument("schemaTypeAndName", schemaTypeNameAndVersion);

        StopWatch stopWatch = new StopWatch();
        stopWatch.start("private_createMAVForOrganisationUnit");

        if (noLoggedOnStatusInfo(request)) {
            logger.error("No loggedOnStatus exists, logout.");
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
        }

        Long workingSchemaOrgUnitId = changeWorkingSchemaOrgUnitIdOrGetCurrent(request);
        if (workingSchemaOrgUnitId == null) {
            logger.error("No workingSchemaOrgUnitId or LoggedOnOrgUnitId exists, log off");
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);

        }

        //        String schemaVersion = Integer.toString(reportPeriod);
        OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean();
        finderBean.setOrganisationUnitId(workingSchemaOrgUnitId);

        SchemaList jasperReportDataSource = reportService.createFullReportData(finderBean,
                schemaTypeNameAndVersion);

        if (schemaTypeNameAndVersion.getYear() >= 2009
                && schemaTypeNameAndVersion.getSchemaName().equals(SchemaName.KUD_CULTURAL_ACTIVITY_REPORT)) {
            int reportPeriod = schemaTypeNameAndVersion.getYear();

            int oneYearBack = reportPeriod - 1;
            String prefixOneYearBack = "LastYear";
            SchemaTypeNameAndVersion kudActivitySchemaAndVersionOneYearBack = SchemaTypeNameAndVersion
                    .newInstance(SchemaName.KUD_CULTURAL_ACTIVITY_REPORT, oneYearBack);

            reportService.getReportDataForOrganisationUnits(jasperReportDataSource,
                    kudActivitySchemaAndVersionOneYearBack, prefixOneYearBack);

            int twoYearBack = reportPeriod - 2;
            String prefixTwoYearBack = "YearBeforeLastYear";
            SchemaTypeNameAndVersion kudActivitySchemaAndVersionTwoYearBack = SchemaTypeNameAndVersion
                    .newInstance(SchemaName.KUD_CULTURAL_ACTIVITY_REPORT, twoYearBack);
            reportService.getReportDataForOrganisationUnits(jasperReportDataSource,
                    kudActivitySchemaAndVersionTwoYearBack, prefixTwoYearBack);

        }

        SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();

        SchemaPdfLogo pdfLogo = SchemaPdfLogo.newInstance(schemaTypeNameAndVersion);

        Locale locale = sessionLocaleResolver.resolveLocale(request);
        logger.info("We are using locale=[" + locale.toString() + "]");

        int reportPeriod = schemaTypeNameAndVersion.getYear();
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("logourl", pdfLogo.getLogoUrl());
        model.put("logoheight", pdfLogo.getLogoHeight());
        model.put("logowidth", pdfLogo.getLogoWidth());
        model.put("reportData", jasperReportDataSource);
        model.put("abmstatistikk.reportPeriod", Integer.toString(reportPeriod));
        model.put("abmstatistikk.budgetYear", Integer.toString(reportPeriod + 1));
        model.put(JRParameter.REPORT_LOCALE, locale);

        ModelAndView mav = new ModelAndView(view, model);

        stopWatch.stop();
        if (logger.isDebugEnabled()) {
            logger.debug("[private:createMAVForOrganisationUnit] tok[" + stopWatch.getTotalTimeMillis() + "] ms");
        }

        return mav;
    }

    protected Map<String, Object> basicReportData(OrgUnitFinderSpecificationBean finderBean,
            SchemaTypeNameAndVersion schemaTypeNameAndVersion, String baseView) {

        if (logger.isDebugEnabled()) {
            logger.info("[basicReportData]: Start");
        }

        //        SchemaList schemaList = reportService.createBasicReportData(finderBean, schemaTypeNameAndVersion);
        //
        //        return new ModelAndView(baseView, getModel(schemaList));

        backgroundReportService.createBasicReportData(finderBean, schemaTypeNameAndVersion, baseView);

        Map model = getModel(null);
        model.put("doneReports", backgroundReportService.getReportsDone());

        //System.out.println("done:"+backgroundReportService.getReportsDone().toString());

        return model;
    }

    protected ModelAndView basicExcelReportData(OrgUnitFinderSpecificationBean finderBean,
            SchemaTypeNameAndVersion schemaTypeNameAndVersion, String baseView, String commentFieldKey) {

        if (logger.isDebugEnabled()) {
            logger.info("[basicbasicReportData]: Start");
        }

        SchemaList schemaList = reportService.createBasicReportData(finderBean, schemaTypeNameAndVersion);
        //        schemaList.removeLineFeedFromString(commentFieldKey);

        return new ModelAndView(baseView, getModel(schemaList));
    }

    protected Map<String, Object> financeApplicationReport(OrgUnitFinderSpecificationBean finderBean,
            Comparator<OrgUnitReport> comparator, SchemaTypeNameAndVersion financeSchemaAndVersion,
            SchemaTypeNameAndVersion statisticOrReportingSchemaAndVersion) {

        final SubSchemaName financeApplicationInitiatives = SubSchemaName.KUD_FINANCE_INITIATIVE;

        KkdReportFinderSpecification finderSpecification = new KkdReportFinderSpecification(finderBean);
        Collection<OrgUnitReport> orgUnitReports = reportService.getOrganisationReport(finderSpecification);
        SortedSet<OrgUnitReport> reports = new TreeSet<OrgUnitReport>(comparator);
        reports.addAll(orgUnitReports);

        SortedSet<OrgUnitReport> financeSortedSet = new TreeSet<OrgUnitReport>(reports);
        SchemaList financeApplication = reportService.getReportDataForOrganisationUnits(financeSortedSet,
                financeSchemaAndVersion);

        SubSchemaTypeNameAndVersion subSchemaTypeNameAndVersion = new SubSchemaTypeNameAndVersion(
                financeSchemaAndVersion, financeApplicationInitiatives);

        SortedSet<OrgUnitReport> iniativesSortedSet = new TreeSet<OrgUnitReport>(reports);
        SchemaList initiatives = reportService.getSubReportDataForOrganisationUnits(iniativesSortedSet,
                subSchemaTypeNameAndVersion);

        SchemaList statisticReport = reportService.getReportDataForOrganisationUnits(reports,
                statisticOrReportingSchemaAndVersion);

        Map<String, Object> model = new HashMap<String, Object>();

        model.put(SchemaListReportNameConst.FINANCE_APPLICATION, financeApplication);
        model.put(SchemaListReportNameConst.INITIATIVES, initiatives);
        model.put(SchemaListReportNameConst.STATISTIC_REPORT, statisticReport);

        return model;
    }

    protected Map<String, Object> financeHalfYearReport(OrgUnitFinderSpecificationBean finderBean,
            Comparator<OrgUnitReport> comparator, int financeReportingYear) {

        SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion
                .newInstance(SchemaName.KUD_FINANCE_HALFYEAR_REPORT, financeReportingYear);

        KkdReportFinderSpecification finderSpecification = new KkdReportFinderSpecification(finderBean);
        Collection<OrgUnitReport> orgUnitReports = reportService.getOrganisationReport(finderSpecification);
        SortedSet<OrgUnitReport> reports = new TreeSet<OrgUnitReport>(comparator);
        reports.addAll(orgUnitReports);

        SortedSet<OrgUnitReport> financehalfYearSortedSet = new TreeSet<OrgUnitReport>(reports);
        SchemaList halfYearReport = reportService.getReportDataForOrganisationUnits(financehalfYearSortedSet,
                schemaTypeNameAndVersion);

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(SchemaListReportNameConst.FINANCE_HALFYEAR_REPORT, halfYearReport);

        // Special treatment of halfyear reports from 2009 and later.
        if (financeReportingYear >= 2009) {
            SchemaTypeNameAndVersion financeSchemaTypeNameAndVersion = SchemaTypeNameAndVersion
                    .newInstance(SchemaName.KUD_FINANCE_APPLICATION, financeReportingYear + 1);

            SortedSet<OrgUnitReport> financeSortedSet = new TreeSet<OrgUnitReport>(reports);
            SchemaList financeApplication = reportService.getReportDataForOrganisationUnits(financeSortedSet,
                    financeSchemaTypeNameAndVersion);

            model.put(SchemaListReportNameConst.FINANCE_APPLICATION, financeApplication);
        }

        return model;
    }

    protected Map<String, Object> subReportData(OrgUnitFinderSpecificationBean finderBean,
            SubSchemaTypeNameAndVersion subSchemaTypeNameAndVersion, Comparator<OrgUnitReport> comparator) {

        KkdReportFinderSpecification finderSpecification = new KkdReportFinderSpecification(finderBean);

        SchemaList jasperReportDataSource = reportService.getSubReportDataForOrganisationUnits(finderSpecification,
                comparator, subSchemaTypeNameAndVersion);

        Map<String, Object> model = getModel(jasperReportDataSource);
        model.put("abmstatistikk.reportPeriod", subSchemaTypeNameAndVersion.getVersion());

        return model;
    }

    /**
     * Creating kkd supreport model data for specified 
     * finderBean, schemaName, 
     * schemaVersion, and subSchemaName.
     * 
     * @param finderBean
     * @param schemaName
     * @param schemaVersion
     * @param subSchemaName
     * @return
     */
    protected Map<String, Object> kkdSubReportData(OrgUnitFinderSpecificationBean finderBean,
            Comparator<OrgUnitReport> comparator, SubSchemaTypeNameAndVersion subSchemaTypeNameAndVersion) {

        Boolean isKKDIniativPdfReport = true;

        KkdReportFinderSpecification finderSpecification = new KkdReportFinderSpecification(finderBean);

        SchemaList jasperReportDataSource = reportService.getSubReportDataForOrganisationUnits(finderSpecification,
                comparator, subSchemaTypeNameAndVersion, isKKDIniativPdfReport);

        Map<String, Object> model = getModel(jasperReportDataSource);
        model.put("abmstatistikk.reportPeriod", subSchemaTypeNameAndVersion.getVersion());

        return model;
    }

    protected ModelAndView basicReportDataByCounty(HttpServletRequest request,
            OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion,
            String viewName) {

        Assert.checkRequiredArgument("request", request);
        Assert.checkRequiredArgument("finderBean", finderBean);
        Assert.checkRequiredArgument("schemaTypeNameAndVersion", schemaTypeNameAndVersion);
        Assert.checkRequiredArgument("viewName", viewName);

        if (logger.isDebugEnabled()) {
            logger.debug("[basicReportDataByCounty]: Start");
        }

        /*
         * This should be replaced with AOP in an XML spring config-file.
         */
        if (!isSecureContext()) {
            logger.error("[reportDataByCounty]: no secureContext loging off");
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
        }

        Integer countyNumber = getCountyNumberFromRequestOrLoggedOnUser(request);
        if (null == countyNumber) {
            logger.error("[basicReportDataByCounty]: could not get any countyNumber, return to mainmenu.");
            return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU);
        }

        finderBean.setCountyNumber(countyNumber);

        SchemaList jasperReportDataSource = reportService.createBasicReportData(finderBean,
                schemaTypeNameAndVersion);

        SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
        Locale locale = sessionLocaleResolver.resolveLocale(request);
        logger.info("We are using locale=[" + locale.toString() + "]");
        int reportPeriod = schemaTypeNameAndVersion.getYear();
        Map<String, Object> model = getModel(jasperReportDataSource);
        model.put("abmstatistikk.reportPeriod", Integer.toString(reportPeriod));
        model.put("abmstatistikk.budgetYear", Integer.toString(reportPeriod + 1));
        model.put(JRParameter.REPORT_LOCALE, locale);

        ModelAndView mav = new ModelAndView(viewName, model);
        return mav;
    }

    protected ModelAndView basicReportDataByMuncipality(HttpServletRequest request,
            OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion,
            String viewName) {

        Assert.checkRequiredArgument("request", request);
        Assert.checkRequiredArgument("finderBean", finderBean);
        Assert.checkRequiredArgument("schemaTypeNameAndVersion", schemaTypeNameAndVersion);
        Assert.checkRequiredArgument("viewName", viewName);

        if (logger.isDebugEnabled()) {
            logger.debug("Executing: reportDataByMuncipality");
        }

        /*
         * This should be replaced with AOP in an XML spring config-file.
         */
        if (!isSecureContext()) {
            logger.error("[reportDataByMuncipality]: no secureContext loging off");
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
        }

        Integer municipalityNumber = getMuncipalityNumberFromRequestOrLoggedOnUser(request);
        if (null == municipalityNumber) {
            logger.error("[reportDataByMuncipality]: could not get any municipality number, return to mainmenu.");
            return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU);
        }

        StopWatch stopWatch = new StopWatch();
        stopWatch.start("private_createByMuncipalityReportData");

        finderBean.setMuncipalityNumber(municipalityNumber);

        SchemaList jasperReportDataSource = reportService.createBasicReportData(finderBean,
                schemaTypeNameAndVersion);

        Map<String, Object> model = getModel(jasperReportDataSource);
        model.put("abmstatistikk.reportPeriod", schemaTypeNameAndVersion.getVersion());

        ModelAndView mav = new ModelAndView(viewName, model);

        stopWatch.stop();
        logger.info("[private:createByMuncipalityReportData] tok[" + stopWatch.getTotalTimeMillis() + "] ms");

        return mav;

    }

    protected ModelAndView reportDataForOrganisationUnitWithChildren(HttpServletRequest request,
            SchemaTypeNameAndVersion schemaTypeNameAndVersion, String view) {

        if (logger.isDebugEnabled()) {
            logger.debug("Executing: reportDataForOrganisationUnitWithChildren");
        }

        /*
         * This should be replaced with AOP in an XML spring config-file.
         */
        if (!isSecureContext()) {
            logger.error("[reportDataForOrganisationUnitWithChildren]: no secureContext loging off");
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
        }

        Long organisationUnitId = getLoggedOnOrganisationUnitId(request);
        if (null == organisationUnitId) {
            logger.error("[reportDataForOrganisationUnitWithChildren]: "
                    + " could not get any organisationUnit for logged on user, return to mainmenu.");
            return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU);
        }

        SchemaList schemaList = reportService.createReportDataByOrgUnitWithChildren(organisationUnitId,
                schemaTypeNameAndVersion);

        return new ModelAndView(view, getModel(schemaList));
    }

    protected ModelAndView budgetApplicationForOrganisationUnit(HttpServletRequest request, String view, int year) {

        final SchemaTypeNameAndVersion financeSchemaTypeAndVersion = SchemaTypeNameAndVersion
                .newInstance(SchemaName.KUD_FINANCE_APPLICATION, year);
        final SubSchemaName subSchemaTypeName = SubSchemaName.KUD_FINANCE_INITIATIVE;
        ModelAndView mav;
        boolean hasInitiativ = false;

        //        String baseSchemaTypeName = applicationSchemaBasedOnYear(year);

        logger.debug("[budgetApplicationForOrganisationUnit] start");

        //        Long organisationUnitId = getWorkingSchemaOrgUnitId(request);
        // Fix start
        Long workingSchemaOrgUnitId = new Long(0);
        String parameter = request.getParameter("workingSchemaOrgUnitId");
        LoggedOnStatusInfo lsi = RequestUtil.getLoggedOnStatusInfo(request);
        if (lsi == null) {
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
        }

        if (parameter != null) {
            workingSchemaOrgUnitId = new Long(Long.parseLong(parameter));
        } else {
            workingSchemaOrgUnitId = lsi.getWorkingSchemaOrgUnitId();
            if (null == workingSchemaOrgUnitId || workingSchemaOrgUnitId.intValue() == 0) {
                workingSchemaOrgUnitId = lsi.getLoggedOnOrgUnitId();
            }

        }
        Long organisationUnitId = workingSchemaOrgUnitId;
        // Fix end        

        if (null == organisationUnitId) {
            return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
        }

        OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean();
        finderBean.setOrganisationUnitId(organisationUnitId);

        logger.debug("[budgetApplicationForOrganisationUnit] getting main report");
        //        String schemaVersion = Integer.toString(year);

        SchemaList jasperReportDataSource = reportService.createFullReportData(finderBean,
                financeSchemaTypeAndVersion);

        jasperReportDataSource.setName("MainReport");
        logger.debug("[budgetApplicationForOrganisationUnit] getting subreport");

        // Application year 2011 is first year with historical data two year back
        if (year >= 2011) {
            int oneYearBack = year - 1;
            SchemaTypeNameAndVersion financeSchemaOneYearBack = SchemaTypeNameAndVersion
                    .newInstance(SchemaName.KUD_FINANCE_APPLICATION, oneYearBack);
            //            String schemaTypeOneYearBack = applicationSchemaBasedOnYear(oneYearBack);
            //            String schemaVersionOneYearBack = Integer.toString(oneYearBack);
            String prefixOneYearBack = "LastYear";
            reportService.getReportDataForOrganisationUnits(jasperReportDataSource, financeSchemaOneYearBack,
                    prefixOneYearBack);

            int twoYearBack = year - 2;
            SchemaTypeNameAndVersion financeSchemaTwoYearBack = SchemaTypeNameAndVersion
                    .newInstance(SchemaName.KUD_FINANCE_APPLICATION, twoYearBack);
            //            String schemaTypeTwoYearBack = applicationSchemaBasedOnYear(twoYearBack);
            //            String schemaVersionTwoYearBack = Integer.toString(twoYearBack);
            String prefixTwoYearBack = "YearBeforeLastYear";
            reportService.getReportDataForOrganisationUnits(jasperReportDataSource, financeSchemaTwoYearBack,
                    prefixTwoYearBack);
        }

        KkdReportFinderSpecification finderSpecification = new KkdReportFinderSpecification(finderBean);
        Collection<OrgUnitReport> orgUnitReports = reportService.getOrganisationReport(finderSpecification);

        SubSchemaTypeNameAndVersion subSchemaTypeNameAndVersion = new SubSchemaTypeNameAndVersion(
                financeSchemaTypeAndVersion, subSchemaTypeName);

        SchemaList subReportDataSource = reportService.getSubReportDataForOrganisationUnits(orgUnitReports,
                subSchemaTypeNameAndVersion);

        subReportDataSource.setName("subReport");
        subReportDataSource.setRewindAfterBottomHit(true);

        if (subReportDataSource.size() > 0) {
            hasInitiativ = true;
        }

        SchemaPdfLogo pdfLogo = SchemaPdfLogo.newInstance(financeSchemaTypeAndVersion);

        Map<String, Object> model = new HashMap<String, Object>();
        model.put("logourl", pdfLogo.getLogoUrl());
        model.put("logoheight", pdfLogo.getLogoHeight());
        model.put("logowidth", pdfLogo.getLogoWidth());
        model.put("reportData", jasperReportDataSource);
        model.put("subReportData", subReportDataSource);
        //        model.put("subReportData2", subReportDataSource2);
        model.put("hasInitiativ", hasInitiativ);

        logger.debug("[budgetApplicationForOrganisationUnit] create ModelAndView");

        mav = new ModelAndView(view, model);

        logger.debug("[budgetApplicationForOrganisationUnit] return new ModelAndView");

        return mav;
    }

    protected String getViewNameForKkdInstitutionActivityReport(HttpServletRequest request, Date activeDate,
            int reportPeriod) {

        Long orgUnitId = changeWorkingSchemaOrgUnitIdOrGetCurrent(request);
        if (orgUnitId == null) {
            logger.error("getViewNameForKkdInstitutionActivityReport: no workingOrgUnitId, exit to main menu.");
            return ViewNameConst.REDIRECT_2_MAIN_MENU;
        }

        List<String> orgTypeNames = new ArrayList<String>();
        orgTypeNames.add(OrganisationTypeNameConst.KKD_GENERAL_ARTS);
        orgTypeNames.add(OrganisationTypeNameConst.KKD_VISUAL_ARTS);
        orgTypeNames.add(OrganisationTypeNameConst.KKD_DRAMATIC_ART);
        orgTypeNames.add(OrganisationTypeNameConst.KKD_DRAMATIC_ART_70);
        orgTypeNames.add(OrganisationTypeNameConst.KKD_KNUTEPUNKT);
        orgTypeNames.add(OrganisationTypeNameConst.KKD_MUSIC);
        orgTypeNames.add(OrganisationTypeNameConst.KKD_MUSIC_70);

        Map<String, String> orgTypeNameAndView = new HashMap<String, String>();
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_GENERAL_ARTS, "kkdAllmentJasperReportPdf");
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_VISUAL_ARTS, "kkdBilledkunstJasperReportPdf");
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_DRAMATIC_ART, "kkdDramaticArtJasperReportPdf");
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_DRAMATIC_ART_70, "kkdDramaticArt70JasperReportPdf");
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_KNUTEPUNKT, "kkdKnutepunktJasperReportPdf");
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_MUSIC, "kkdMusicJasperReportPdf");
        orgTypeNameAndView.put(OrganisationTypeNameConst.KKD_MUSIC_70, "kkdMusic70JasperReportPdf");

        String hasOrgTypeName = reportService.getActiveOrganisationTypeName(orgUnitId, orgTypeNames, activeDate);
        if (hasOrgTypeName == null) {
            StringBuilder sb = new StringBuilder();
            sb.append("getViewNameForKkdInstitutionActivityReport: ");
            sb.append("no expected organisationTypeName for organisationUnit with Id ==> ");
            sb.append(orgUnitId);
            logger.error(sb.toString());
            return ViewNameConst.REDIRECT_2_MAIN_MENU;
        }

        String viewNameBase = orgTypeNameAndView.get(hasOrgTypeName);

        return createViewName(viewNameBase, reportPeriod);
    }

    protected String createViewName(String baseName, int reportPeriod) {
        Assert.checkRequiredArgument("baseName", baseName);

        StringBuilder sb = new StringBuilder();

        sb.append(baseName).append(reportPeriod).append("View");

        return sb.toString();
    }

    protected String createViewName(String baseName, int reportPeriod, String appendix) {

        Assert.checkRequiredArgument("baseName", baseName);
        Assert.checkRequiredArgument("appendix", appendix);

        StringBuilder sb = new StringBuilder();

        sb.append(baseName).append(reportPeriod).append(appendix);

        return sb.toString();
    }
    // ////////////////////////////////////////////////////////////////////////
    //
    // Private methods 
    //
    // ////////////////////////////////////////////////////////////////////////

    private Map<String, Object> getModel(SchemaList schemaList) {
        // logger.info("XXXXXXXXXXXXXXXXXXXX getModel: Start XXXXXXXXXXXXXXXXXXXX ");
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("logourl", "images/logo_ABM-utvikling8.jpg");
        model.put("reportData", schemaList);
        // logger.info("XXXXXXXXXXXXXXXXXXXX getModel: Start XXXXXXXXXXXXXXXXXXXX ");
        return model;
    }

    public BackgroundReportService getBackgroundReportService() {
        return backgroundReportService;
    }

    public void setBackgroundReportService(BackgroundReportService backgroundReportService) {
        this.backgroundReportService = backgroundReportService;
    }

}