Java tutorial
/*$Id: FinanceServiceHelperImpl.java 11356 2008-11-09 09:15:30Z 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.finances.service.hibernate3; import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.SortedSet; import no.abmu.common.browsing.OrganisationUnitForBrowsing; import no.abmu.common.constants.LocaleTypeNameConst; import no.abmu.common.constants.SchemaTypeNameConst; import no.abmu.common.jasperreports.SchemaList; import no.abmu.common.reporting.OrgUnitReport; import no.abmu.common.reporting.ReportStatus; import no.abmu.common.reporting.ReportStatusImpl; import no.abmu.finances.domain.BoolPostData; import no.abmu.finances.domain.DatePostData; import no.abmu.finances.domain.DoublePostData; import no.abmu.finances.domain.IntPostData; import no.abmu.finances.domain.MainReportData; import no.abmu.finances.domain.StringPostData; import no.abmu.finances.domain.SubReportData; import no.abmu.finances.finders.reportdata.ReportDataH3FinderSpecification; import no.abmu.finances.service.FinanceService; import no.abmu.finances.service.FinanceServiceHelper; import no.abmu.finances.utils.SummingUpFinanceApplication2010; import no.abmu.organisationregister.util.ProgressStatistics; import no.abmu.util.test.Assert; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.util.StopWatch; /** * Helper class for FinanceService. * * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no * @author $Author: jens $ * @version $Rev: 11356 $ * $Date: 2008-11-09 10:15:30 +0100 (Sun, 09 Nov 2008) $ * @since 2006-08-06 (Rev. 3361) * copyright ABM-Utvikling */ public class FinanceServiceHelperH3Impl implements FinanceServiceHelper { private static final String REPORT_EXIST = "Ja"; private static final String REPORT_IS_FINISH = "Ja"; private static final String REPORT_IS_NOT_FINISH = "Nei"; private static final Boolean YES = new Boolean(true); private static final Boolean NO = new Boolean(false); private static final Log logger = (Log) LogFactory.getLog(FinanceServiceHelperH3Impl.class); private FinanceService financeService; public FinanceServiceHelperH3Impl() { } public FinanceServiceHelperH3Impl(FinanceService financeService) { this.financeService = financeService; } public void setFinanceService(FinanceService financeService) { this.financeService = financeService; } public ReportStatus[] getReportStatusBySchemaTypeAndVersion( List<OrganisationUnitForBrowsing> orgUnitsForBrodwsing, String schemaTypeName, String version) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); String finishFieldNumber = getFinishFieldNumberForSchemaTypeAndVersion(schemaTypeName, version); List<ReportStatus> reportStatusAsList = new ArrayList<ReportStatus>(); for (OrganisationUnitForBrowsing orgForBrowse : orgUnitsForBrodwsing) { ReportDataH3FinderSpecification finderSpecification = new ReportDataH3FinderSpecification( schemaTypeName, version, orgForBrowse.getOrganisationUnitId()); MainReportData reportData = (MainReportData) financeService.findSingle(finderSpecification); reportStatusAsList.add(createReportStatus(orgForBrowse, reportData, finishFieldNumber)); } stopWatch.stop(); logger.info("Finish prosessing of reportStatus for schemaType:" + schemaTypeName + " with " + orgUnitsForBrodwsing.size() + " elements in " + stopWatch.getTotalTimeMillis() + " ms"); return reportStatusAsList.toArray(new ReportStatus[reportStatusAsList.size()]); } private ReportStatus createReportStatus(OrganisationUnitForBrowsing orgForBrowse, MainReportData reportData, String finishFieldNumber) { Boolean yes = new Boolean(true); if (reportData == null) { return new ReportStatusImpl(orgForBrowse); } BoolPostData boolPostData = (BoolPostData) reportData.getPostData(finishFieldNumber); if (boolPostData == null) { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST); } Boolean boolPostDataValue = boolPostData.getBoolValue(); if (boolPostDataValue == null) { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST); } if (boolPostDataValue.equals(yes)) { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST, REPORT_IS_FINISH); } else { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST, REPORT_IS_NOT_FINISH); } } public SchemaList getReportDataBySchemaTypeAndVersion(SchemaList jasperReportDataSource, String schemaTypeName, String version, String prefix) { HashMap report; Iterator iterator = jasperReportDataSource.iterator(); while (iterator.hasNext()) { report = (HashMap) iterator.next(); fillInReportValues(report, schemaTypeName, version, prefix); } return jasperReportDataSource; } public SchemaList getReportDataBySchemaTypeAndVersion(SortedSet<OrgUnitReport> orgSortedSet, String schemaTypeName, String schemaVersion, String prefix) { Assert.checkRequiredArgument("orgSortedSet", orgSortedSet); Assert.checkRequiredArgument("schemaTypeName", schemaTypeName); Assert.checkRequiredArgument("schemaVersion", schemaVersion); int numberOfReports = orgSortedSet.size(); SchemaList schemaList = new SchemaList(numberOfReports); ProgressStatistics ps = new ProgressStatistics(numberOfReports); for (OrgUnitReport orgUnitReport : orgSortedSet) { Map<String, Object> report = orgUnitReport.createReport(); fillInReportValues(report, schemaTypeName, schemaVersion, prefix); schemaList.add(report); ps.increaseCountAndDumpStatus(); } ps.dumpStatus(true); return schemaList; } private SchemaList getSubReportDataBySchemaTypeAndVersion(SchemaList jasperReportDataSource, String schemaTypeName, String schemaVersion, String subSchemaName, String prefix) { SchemaList newJasperReportDataSource = new SchemaList(); MainReportData mainReportData; HashMap report; Map subReport; String orgUnitName; String kommuneNr; List initiatives; SubReportData initiative = null; Integer iniativPriority; Iterator iterator = jasperReportDataSource.iterator(); while (iterator.hasNext()) { report = (HashMap) iterator.next(); orgUnitName = (String) report.get("name"); kommuneNr = (String) report.get("kommuneNr"); if (logger.isDebugEnabled()) { logger.debug("getSubReportDataBySchemaTypeAndVersion -- Starting on organisationUnit [" + orgUnitName + "] with municipality number [" + kommuneNr + "]"); } mainReportData = getMainReportData(report, schemaTypeName, schemaVersion); if (mainReportData == null) { if (logger.isDebugEnabled()) { logger.debug("getSubReportDataBySchemaTypeAndVersion " + "-- No Report exist for organisationUnit [" + orgUnitName + "]"); } continue; } timeStampReport(report); integerFromReportDataToJasperReport(report, mainReportData, 417, 417, prefix); initiatives = mainReportData.getSubReportDataList(subSchemaName); if (initiatives == null || initiatives.size() == 0) { if (logger.isDebugEnabled()) { logger.info("getSubReportDataBySchemaTypeAndVersion " + "-- No Iniatives exist for organisationUnit [" + orgUnitName + "]"); } continue; } if (logger.isDebugEnabled()) { logger.debug("getSubReportDataBySchemaTypeAndVersion " + "-- organisationUnit [" + orgUnitName + "] has [" + initiatives.size() + "]"); } for (int index = 0; index < initiatives.size(); index++) { iniativPriority = new Integer(index + 1); initiative = (SubReportData) initiatives.get(index); subReport = (HashMap) report.clone(); subReport.put("priority", iniativPriority); subReport = fillInSubReportValues(subReport, initiative, subSchemaName, schemaVersion, prefix); if (logger.isDebugEnabled()) { logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is [" + subReport.size() + "]"); } newJasperReportDataSource.add(subReport); } } return newJasperReportDataSource; } private SchemaList getSubReportDataBySchemaTypeAndVersion(SortedSet<OrgUnitReport> orgSortedSet, String schemaTypeName, String schemaVersion, String subSchemaName, String prefix) { SchemaList subReportData = new SchemaList(); for (OrgUnitReport orgUnitReport : orgSortedSet) { MainReportData mainReportData = getMainReportData(orgUnitReport.getOrganisationUnitId(), schemaTypeName, schemaVersion); if (mainReportData == null) { if (logger.isDebugEnabled()) { logger.debug( "getSubReportDataBySchemaTypeAndVersion " + "-- No Report exist for organisationUnit [" + orgUnitReport.getOrganisationUnitName() + "]"); } continue; } List<SubReportData> initiatives = mainReportData.getSubReportDataList(subSchemaName); if (initiatives == null || initiatives.size() == 0) { if (logger.isDebugEnabled()) { logger.info("getSubReportDataBySchemaTypeAndVersion " + "-- No Iniatives exist for organisationUnit [" + orgUnitReport.getOrganisationUnitName() + "]"); } continue; } for (int index = 0; index < initiatives.size(); index++) { SubReportData initiative = initiatives.get(index); Map<String, Object> subReport = orgUnitReport.createReport(); Integer iniativPriority = Integer.valueOf(index + 1); subReport.put("priority", iniativPriority); timeStampReport(subReport); integerFromReportDataToJasperReport(subReport, mainReportData, 417, 417, prefix); subReport = fillInSubReportValues(subReport, initiative, subSchemaName, schemaVersion, prefix); if (logger.isDebugEnabled()) { logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is [" + subReport.size() + "]"); } subReportData.add(subReport); } } return subReportData; } public SchemaList getSubReportDataBySchemaTypeAndVersion(Collection<OrgUnitReport> orgSortedSet, String schemaTypeName, String schemaVersion, String subSchemaName, Boolean isKKDIniativPdfReport, String prefix) { Assert.checkRequiredArgument("orgSortedSet", orgSortedSet); Assert.checkRequiredArgument("schemaTypeName", schemaTypeName); Assert.checkRequiredArgument("schemaVersion", schemaVersion); Assert.checkRequiredArgument("subSchemaName", subSchemaName); Assert.checkRequiredArgument("isKKDIniativPdfReport", isKKDIniativPdfReport); SchemaList subReportData = new SchemaList(); for (OrgUnitReport orgUnitReport : orgSortedSet) { MainReportData mainReportData = getMainReportData(orgUnitReport.getOrganisationUnitId(), schemaTypeName, schemaVersion); if (mainReportData == null) { if (logger.isDebugEnabled()) { logger.debug( "getSubReportDataBySchemaTypeAndVersion " + "-- No Report exist for organisationUnit [" + orgUnitReport.getOrganisationUnitName() + "]"); } continue; } List<SubReportData> initiatives = mainReportData.getSubReportDataList(subSchemaName); if (initiatives == null || initiatives.size() == 0) { if (logger.isDebugEnabled()) { logger.info("getSubReportDataBySchemaTypeAndVersion " + "-- No Iniatives exist for organisationUnit [" + orgUnitReport.getOrganisationUnitName() + "]"); } if (isKKDIniativPdfReport) { Map<String, Object> subReport = orgUnitReport.createReport(); subReport.put("priority", Integer.valueOf(1)); subReport.put("01", "Viderefring av driftstilskudd"); subReport.put("05", Integer.valueOf(0)); subReport.put("30", "Har ikke skt om kning i forhold til rets tilskudd."); timeStampReport(subReport); integerFromReportDataToJasperReport(subReport, mainReportData, 417, 417, prefix); subReportData.add(subReport); } continue; } for (int index = 0; index < initiatives.size(); index++) { SubReportData initiative = initiatives.get(index); Map<String, Object> subReport = orgUnitReport.createReport(); Integer iniativPriority = Integer.valueOf(index + 1); subReport.put("priority", iniativPriority); timeStampReport(subReport); integerFromReportDataToJasperReport(subReport, mainReportData, 417, 417, prefix); subReport = fillInSubReportValues(subReport, initiative, subSchemaName, schemaVersion, prefix); if (logger.isDebugEnabled()) { logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is [" + subReport.size() + "]"); } subReportData.add(subReport); } } return subReportData; } private SchemaList getSubReportDataForKkdInstitutionsBySchemaTypeAndVersion(SchemaList jasperReportDataSource, String schemaTypeName, String schemaVersion, String subSchemaName, String prefix) { SchemaList newJasperReportDataSource = new SchemaList(); MainReportData mainReportData; HashMap report; Map subReport; String orgUnitName; String kommuneNr; List initiatives; SubReportData initiative = null; Integer iniativPriority; Iterator iterator = jasperReportDataSource.iterator(); while (iterator.hasNext()) { report = (HashMap) iterator.next(); orgUnitName = (String) report.get("name"); kommuneNr = (String) report.get("kommuneNr"); if (logger.isDebugEnabled()) { logger.debug("getSubReportDataBySchemaTypeAndVersion -- Starting on organisationUnit [" + orgUnitName + "] with municipality number [" + kommuneNr + "]"); } mainReportData = getMainReportData(report, schemaTypeName, schemaVersion); if (mainReportData == null) { if (logger.isDebugEnabled()) { logger.debug("getSubReportDataBySchemaTypeAndVersion " + "-- No Report exist for organisationUnit [" + orgUnitName + "]"); } continue; } timeStampReport(report); integerFromReportDataToJasperReport(report, mainReportData, 417, 417, prefix); initiatives = mainReportData.getSubReportDataList(subSchemaName); if (initiatives == null || initiatives.size() == 0) { iniativPriority = Integer.valueOf(1); subReport = (HashMap) report.clone(); subReport.put("priority", iniativPriority); subReport.put("01", "Viderefring av driftstilskudd"); subReport.put("05", Integer.valueOf(0)); subReport.put("30", "Har ikke skt om kning i forhold til rets tilskudd."); if (logger.isDebugEnabled()) { logger.info("getSubReportDataBySchemaTypeAndVersion " + "-- No Iniatives exist for organisationUnit [" + orgUnitName + "]"); } newJasperReportDataSource.add(subReport); continue; } if (logger.isDebugEnabled()) { logger.debug("getSubReportDataBySchemaTypeAndVersion " + "-- organisationUnit [" + orgUnitName + "] has [" + initiatives.size() + "]"); } for (int index = 0; index < initiatives.size(); index++) { iniativPriority = new Integer(index + 1); initiative = (SubReportData) initiatives.get(index); subReport = (HashMap) report.clone(); timeStampReport(subReport); subReport.put("priority", iniativPriority); subReport = fillInSubReportValues(subReport, initiative, subSchemaName, schemaVersion, prefix); if (logger.isDebugEnabled()) { logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is [" + subReport.size() + "]"); } newJasperReportDataSource.add(subReport); } } return newJasperReportDataSource; } private MainReportData getMainReportData(Map<String, Object> report, String schemaTypeName, String version) { Assert.assertTrue("Key organisationUnitId has to be in report map", report.containsKey("organisationUnitId")); Long organisationUnitId = (Long) report.get("organisationUnitId"); Assert.assertNotNull("Long: organisationUnitId can not be null", organisationUnitId); ReportDataH3FinderSpecification finderSpecification = new ReportDataH3FinderSpecification(schemaTypeName, version, organisationUnitId); return (MainReportData) financeService.findSingle(finderSpecification); } private MainReportData getMainReportData(Long organisationUnitId, String schemaTypeName, String version) { Assert.assertNotNull("Long: organisationUnitId can not be null", organisationUnitId); ReportDataH3FinderSpecification finderSpecification = new ReportDataH3FinderSpecification(schemaTypeName, version, organisationUnitId); return (MainReportData) financeService.findSingle(finderSpecification); } private void fillInReportValues(Map<String, Object> report, String schemaTypeName, String version, String prefix) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] called with values SchemaTypeName='" + schemaTypeName + "' and version='" + version + "' prefix='" + prefix + "'"); } timeStampReport(report); MainReportData mainReportData = getMainReportData(report, schemaTypeName, version); if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_APPLICATION)) { if (version.equals("2007")) { fillInMuseumFinanceApplicationValues2007(report, mainReportData, prefix); } else if (version.equals("2008")) { fillInMuseumFinanceApplicationValues2008(report, mainReportData, prefix); } else if (version.equals("2009")) { fillInMuseumFinanceApplicationValues2009(report, mainReportData, prefix); } else if (version.equals("2010")) { fillInMuseumFinanceApplicationValues2010(report, mainReportData, prefix); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_HALFYEAR_REPORT)) { if (version.equals("2006")) { fillInMuseumFinanceHalfYearReportValues2006(report, mainReportData, prefix); } else if (version.equals("2007") || version.equals("2008")) { fillInMuseumFinanceHalfYearReportValues2007(report, mainReportData, prefix); } else if (version.equals("2009")) { fillInMuseumFinanceHalfYearReportValues2009(report, mainReportData, prefix); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(SchemaTypeNameConst.CULTURALRUCKSACK_SCHOOLYEAR_REPORT)) { if (version.equals("2007")) { fillInCulturalRucksackSchoolYearReportValues2007(report, mainReportData, prefix); } else if (version.equals("2008")) { fillInCulturalRucksackSchoolYearReportValues2008(report, mainReportData, prefix); } else if (version.equals("2009")) { fillInCulturalRucksackSchoolYearReportValues2009(report, mainReportData, prefix); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(SchemaTypeNameConst.KKD_CULTURAL_ACTIVITY_REPORT)) { if (version.equals("2007")) { fillInKkdCulturalActivityReport2007(report, mainReportData, prefix); } else if (version.equals("2008")) { fillInKkdCulturalActivityReport2008(report, mainReportData, prefix); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(SchemaTypeNameConst.ARCHIVE_STATISTIC)) { if (version.equals("2007")) { fillInArchiveStatistic2007(report, mainReportData, prefix); } else if (version.equals("2008")) { fillInArchiveStatistic2008(report, mainReportData, prefix); } else if (version.equals("2009")) { fillInArchiveStatistic2009(report, mainReportData, prefix); } else { String errorMessage = "The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."; logger.error(errorMessage); throw new IllegalArgumentException(errorMessage); } } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } // TODO Remove out comment code after proper testing of new code above. /* Replaced 2009-01-31 if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_APPLICATION) && (version.equals("2007"))) { if (logger.isErrorEnabled()) { logger.debug("[fillInReportValues] SchemaType eq: MUSEUM_FINANCE_APPLICATION and version " + version); } fillInMuseumFinanceApplicationValues2007(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_APPLICATION) && (version.equals("2008"))) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] SchemaType eq: MUSEUM_FINANCE_APPLICATION and version " + version); } fillInMuseumFinanceApplicationValues2008(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_APPLICATION) && (version.equals("2009"))) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] SchemaType eq: MUSEUM_FINANCE_APPLICATION and version " + version); } fillInMuseumFinanceApplicationValues2009(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_HALFYEAR_REPORT) && (version.equals("2006"))) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] SchemaType eq: MUSEUM_FINANCE_HALFYEAR_REPORT and version " + version); } fillInMuseumFinanceHalfYearReportValues2006(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.MUSEUM_FINANCE_HALFYEAR_REPORT) && (version.equals("2007") || version.equals("2008"))) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] SchemaType eq: MUSEUM_FINANCE_HALFYEAR_REPORT and version " + version); } fillInMuseumFinanceHalfYearReportValues2007(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.CULTURALRUCKSACK_SCHOOLYEAR_REPORT) && (version.equals("2007"))) { fillInCulturalRucksackSchoolYearReportValues2007(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.CULTURALRUCKSACK_SCHOOLYEAR_REPORT) && (version.equals("2008"))) { fillInCulturalRucksackSchoolYearReportValues2008(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.KKD_CULTURAL_ACTIVITY_REPORT) && (version.equals("2007"))) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] SchemaType eq: KKD_CULTURAL_ACTIVITY_REPORT and version " + version); } fillInKkdCulturalActivityReport2007(report, mainReportData); } else if (schemaTypeName.equals(SchemaTypeNameConst.ARCHIVE_STATISTIC) && (version.equals("2007"))) { fillInArchiveStatistic2007(report, mainReportData); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } */ } private Map<String, Object> fillInSubReportValues(Map<String, Object> m, SubReportData subReportData, String subSchemaName, String schemaVersion, String prefix) { if (subSchemaName.equals(SchemaTypeNameConst.SUB_SCHEMA_MUSEUM_FINANCE_INITIATIVE)) { if (schemaVersion.equals("2007")) { return fillInIniativeValues2007(m, subReportData, prefix); } else if (schemaVersion.equals("2008")) { return fillInIniativeValues2008(m, subReportData, prefix); } else if (schemaVersion.equals("2009")) { return fillInIniativeValues2009(m, subReportData, prefix); } else if (schemaVersion.equals("2010")) { return fillInIniativeValues2010(m, subReportData, prefix); } } String errorMessage = "The combination of subSchemaTypeName '" + subSchemaName + "' and schema version '" + schemaVersion + "' is unknown."; logger.error(errorMessage); throw new IllegalArgumentException(errorMessage); } private void fillInArchiveStatistic2009(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("[fillInArchiveStatistic2009]: mainReportData == null"); return; } fillInArchiveStatistic2008(m, mainReportData, prefix); } private void fillInArchiveStatistic2008(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("[fillInArchiveStatistic2008]: mainReportData == null"); return; } fillInArchiveStatistic2007(m, mainReportData, prefix); boolFromReportDataToJasperReport(m, mainReportData, 298, 298, prefix); integerFromReportDataToJasperReport(m, mainReportData, 299, 299, prefix); } private void fillInArchiveStatistic2007(Map<String, Object> m, MainReportData mainReportData, String prefix) { Long organisationUnitId = (Long) m.get("organisationUnitId"); String orgUnitName = (String) m.get("name"); if (logger.isDebugEnabled()) { logger.debug("START fillInArchiveStatistic2007 for OrgUnit id='" + organisationUnitId + "' name='" + orgUnitName + "'"); } if (mainReportData == null) { logger.info("fillInKkdCulturalActivityReport2007: mainReportData == null"); return; } integerFromReportDataToJasperReport(m, mainReportData, 300, 336, prefix); boolFromReportDataToJasperReport(m, mainReportData, 337, 340, prefix); integerFromReportDataToJasperReport(m, mainReportData, 341, 342, prefix); boolFromReportDataToJasperReport(m, mainReportData, 343, 345, prefix); integerFromReportDataToJasperReport(m, mainReportData, 346, 370, prefix); boolFromReportDataToJasperReport(m, mainReportData, 371, 373, prefix); integerFromReportDataToJasperReport(m, mainReportData, 374, 376, prefix); boolFromReportDataToJasperReport(m, mainReportData, 377, 377, prefix); doubleFromReportDataFloatToJasperReport(m, mainReportData, 378, 383, prefix); integerFromReportDataToJasperReport(m, mainReportData, 384, 384, prefix); boolFromReportDataToJasperReport(m, mainReportData, 385, 388, prefix); integerFromReportDataToJasperReport(m, mainReportData, 389, 397, prefix); boolFromReportDataToJasperReport(m, mainReportData, 398, 398, prefix); stringFromReportDataToJasperReport(m, mainReportData, 399, 399, prefix); } private void fillInKkdCulturalActivityReport2008(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("[fillInKkdCulturalActivityReport2008]: mainReportData == null"); return; } fillInKkdCulturalActivityReport2007(m, mainReportData, prefix); integerFromReportDataToJasperReport(m, mainReportData, 256, 256, prefix); } private void fillInKkdCulturalActivityReport2007(Map<String, Object> m, MainReportData mainReportData, String prefix) { Long organisationUnitId = (Long) m.get("organisationUnitId"); String orgUnitName = (String) m.get("name"); if (logger.isDebugEnabled()) { logger.debug("START fillInKkdCulturalActivityReport2007 for OrgUnit id='" + organisationUnitId + "' name='" + orgUnitName + "'"); } if (mainReportData == null) { logger.info("fillInKkdCulturalActivityReport2007: mainReportData == null"); return; } integerFromReportDataToJasperReport(m, mainReportData, 137, 178, prefix); doubleFromReportDataFloatToJasperReport(m, mainReportData, 179, 190, prefix); integerFromReportDataToJasperReport(m, mainReportData, 191, 199, prefix); doubleFromReportDataFloatToJasperReport(m, mainReportData, 200, 209, prefix); integerFromReportDataToJasperReport(m, mainReportData, 210, 215, prefix); doubleFromReportDataFloatToJasperReport(m, mainReportData, 216, 225, prefix); integerFromReportDataToJasperReport(m, mainReportData, 226, 253, prefix); boolFromReportDataToJasperReport(m, mainReportData, 254, 254, prefix); stringFromReportDataToJasperReport(m, mainReportData, 255, 255, prefix); if (logger.isDebugEnabled()) { logger.debug("FINISH fillInKkdCulturalActivityReport2007 for OrgUnit id='" + organisationUnitId + "' name='" + orgUnitName + "'"); } } private void fillInMuseumFinanceApplicationValues2010(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("[fillInMuseumFinanceApplicationValues2010]: mainReportData == null"); return; } fillInMuseumFinanceApplicationValues2009(m, mainReportData, prefix); stringFromReportDataToJasperReport(m, mainReportData, 403, 403, prefix); integerFromReportDataToJasperReport(m, mainReportData, 649, 654, prefix); boolFromReportDataToJasperReport(m, mainReportData, 655, 656, prefix); stringFromReportDataToJasperReport(m, mainReportData, 657, 658, prefix); financeApplicationField418For2010(m, mainReportData, prefix); } private void fillInMuseumFinanceApplicationValues2009(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("[fillInMuseumFinanceApplicationValues2009]: mainReportData == null"); return; } fillInMuseumFinanceApplicationValues2008(m, mainReportData, prefix); integerFromReportDataToJasperReport(m, mainReportData, 647, 648, prefix); financeApplicationField418For2009(m, mainReportData, prefix); } private void fillInMuseumFinanceApplicationValues2008(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("[fillInMuseumFinanceApplicationValues2008]: mainReportData == null"); return; } fillInMuseumFinanceApplicationValues2007(m, mainReportData, prefix); integerFromReportDataToJasperReport(m, mainReportData, 623, 646, prefix); return; } private Map<String, Object> fillInMuseumFinanceApplicationValues2007(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInMuseumFinanceApplicationValues2007: mainReportData == null"); return m; } stringFromReportDataToJasperReport(m, mainReportData, 401, 402, prefix); integerFromReportDataToJasperReport(m, mainReportData, 404, 618, prefix); boolFromReportDataToJasperReport(m, mainReportData, 619, 619, prefix); stringFromReportDataToJasperReport(m, mainReportData, 620, 620, prefix); boolFromReportDataToJasperReport(m, mainReportData, 621, 621, prefix); stringFromReportDataToJasperReport(m, mainReportData, 622, 622, prefix); return m; } private void financeApplicationField418For2010(Map<String, Object> m, MainReportData mainReportData, String prefix) { SummingUpFinanceApplication2010 summingUp = new SummingUpFinanceApplication2010(mainReportData); String fieldNameField418 = "418"; String key; if (prefix == null) { key = fieldNameField418; } else { key = prefix + fieldNameField418; } Integer fieldValueField418 = summingUp.getValueForField418(); m.put(key, fieldValueField418); } private void financeApplicationField418For2009(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (logger.isDebugEnabled()) { logger.debug("Executing financeApplicationField418For2009"); } Integer returnValue = 0; int indexFieldName = 418; int indexLastYearValue = 417; String subSchemaName = SchemaTypeNameConst.SUB_SCHEMA_MUSEUM_FINANCE_INITIATIVE; String fieldName = intTo3DigitString(indexFieldName); String fnLastYearValue = intTo3DigitString(indexLastYearValue); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } IntPostData lastYearIntPostData = (IntPostData) mainReportData.getPostData(fnLastYearValue); if (lastYearIntPostData != null) { Integer lastYearValue = lastYearIntPostData.getIntegerValue(); if (lastYearValue != null) { returnValue = lastYearValue; } } List<SubReportData> initiatives = mainReportData.getSubReportDataList(subSchemaName); if (initiatives == null) { if (logger.isDebugEnabled()) { logger.debug("No iniative"); } m.put(key, returnValue); return; } int indexIniativType = 2; int indexKkdApplicationAmount = 5; String fnIniativeType = intTo2DigitString(indexIniativType); String fnKkdApplicationAmount = intTo2DigitString(indexKkdApplicationAmount); for (SubReportData subReportData : initiatives) { StringPostData subStringPostData = (StringPostData) subReportData.getPostData(fnIniativeType); IntPostData subIntPostData = (IntPostData) subReportData.getPostData(fnKkdApplicationAmount); if (subStringPostData != null && subIntPostData != null) { String iniativType = subStringPostData.getStringValue(); Integer applicationAmount = subIntPostData.getIntegerValue(); if (iniativType != null && applicationAmount != null && iniativType.equals("Drift")) { returnValue += applicationAmount; } } } if (logger.isDebugEnabled()) { logger.debug("Executing financeApplicationField418For2009 returns: " + returnValue); } m.put(key, returnValue); } private void fillInMuseumFinanceHalfYearReportValues2009(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2007: mainReportData == null"); return; } fillInMuseumFinanceHalfYearReportValues2007(m, mainReportData, prefix); integerFromReportDataToJasperReport(m, mainReportData, 949, 954, prefix); return; } private void fillInMuseumFinanceHalfYearReportValues2007(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2007: mainReportData == null"); return; } fillInMuseumFinanceHalfYearReportValues2006(m, mainReportData, prefix); integerFromReportDataToJasperReport(m, mainReportData, 923, 946, prefix); return; } private Map<String, Object> fillInMuseumFinanceHalfYearReportValues2006(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2006: mainReportData == null"); return m; } integerFromReportDataToJasperReport(m, mainReportData, 704, 904, prefix); boolFromReportDataToJasperReport(m, mainReportData, 919, 919, prefix); stringFromReportDataToJasperReport(m, mainReportData, 920, 920, prefix); boolFromReportDataToJasperReport(m, mainReportData, 921, 921, prefix); return m; } private void fillInCulturalRucksackSchoolYearReportValues2009(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInCulturalRucksackSchoolYearReportValues2009: mainReportData == null"); return; } if (logger.isDebugEnabled()) { logger.debug("fillInCulturalRucksackSchoolYearReportValues2009: mainReportData != null"); } fillInCulturalRucksackSchoolYearReportValues2008(m, mainReportData, prefix); } private void fillInCulturalRucksackSchoolYearReportValues2008(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInCulturalRucksackSchoolYearReportValues2008: mainReportData == null"); return; } if (logger.isDebugEnabled()) { logger.debug("fillInCulturalRucksackSchoolYearReportValues2008: mainReportData != null"); } fillInCulturalRucksackSchoolYearReportValues2007(m, mainReportData, prefix); stringFromReportDataToJasperReport(m, mainReportData, 123, 123, prefix); integerFromReportDataToJasperReport(m, mainReportData, 124, 125, prefix); } private void fillInCulturalRucksackSchoolYearReportValues2007(Map<String, Object> m, MainReportData mainReportData, String prefix) { if (mainReportData == null) { logger.info("fillInCulturalRucksackSchoolYearReportValues2007: mainReportData == null"); return; } if (logger.isDebugEnabled()) { logger.debug("fillInCulturalRucksackSchoolYearReportValues2007: mainReportData != null"); } stringFromReportDataToJasperReport(m, mainReportData, 20, 22, prefix); boolFromReportDataToJasperReport(m, mainReportData, 23, 23, prefix); stringFromReportDataToJasperReport(m, mainReportData, 24, 24, prefix); boolFromReportDataToJasperReport(m, mainReportData, 25, 26, prefix); stringFromReportDataToJasperReport(m, mainReportData, 27, 28, prefix); integerFromReportDataToJasperReport(m, mainReportData, 29, 87, prefix); stringFromReportDataToJasperReport(m, mainReportData, 88, 90, prefix); integerFromReportDataToJasperReport(m, mainReportData, 91, 91, prefix); stringFromReportDataToJasperReport(m, mainReportData, 92, 93, prefix); boolFromReportDataToJasperReport(m, mainReportData, 94, 94, prefix); stringFromReportDataToJasperReport(m, mainReportData, 95, 95, prefix); boolFromReportDataToJasperReport(m, mainReportData, 96, 96, prefix); stringFromReportDataToJasperReport(m, mainReportData, 97, 97, prefix); integerFromReportDataToJasperReport(m, mainReportData, 98, 120, prefix); boolFromReportDataToJasperReport(m, mainReportData, 121, 121, prefix); stringFromReportDataToJasperReport(m, mainReportData, 122, 122, prefix); } private Map<String, Object> fillInIniativeValues2010(Map<String, Object> m, SubReportData subReportData, String prefix) { if (subReportData == null) { logger.info("fillInIniativeValues2010: subReportData == null"); return m; } stringFromSubReportDataToJasperReport(m, subReportData, 1, 1, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 5, 5, prefix); boolFromSubReportDataToJasperReport(m, subReportData, 6, 6, prefix); stringFromSubReportDataToJasperReport(m, subReportData, 8, 8, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 10, 10, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 13, 13, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 16, 16, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 19, 19, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 22, 22, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 25, 25, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 28, 28, prefix); stringFromSubReportDataToJasperReport(m, subReportData, 30, 30, prefix); return m; } private Map<String, Object> fillInIniativeValues2009(Map<String, Object> m, SubReportData subReportData, String prefix) { if (subReportData == null) { logger.info("fillInIniativeValues2009: subReportData == null"); return m; } fillInIniativeValues2008(m, subReportData, prefix); boolFromSubReportDataToJasperReport(m, subReportData, 31, 32, prefix); return m; } private Map<String, Object> fillInIniativeValues2008(Map<String, Object> m, SubReportData subReportData, String prefix) { if (subReportData == null) { logger.info("fillInIniativeValues2008: subReportData == null"); return m; } fillInIniativeValues2007(m, subReportData, prefix); stringFromSubReportDataToJasperReport(m, subReportData, 30, 30, prefix); return m; } private Map<String, Object> fillInIniativeValues2007(Map<String, Object> m, SubReportData subReportData, String prefix) { if (subReportData == null) { logger.info("fillInIniativeValues2007: subReportData == null"); return m; } stringFromSubReportDataToJasperReport(m, subReportData, 1, 2, prefix); dateFromSubReportDataToJasperReport(m, subReportData, 3, 4, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 5, 5, prefix); boolFromSubReportDataToJasperReport(m, subReportData, 6, 6, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 7, 7, prefix); stringFromSubReportDataToJasperReport(m, subReportData, 8, 8, prefix); integerFromSubReportDataToJasperReport(m, subReportData, 9, 29, prefix); return m; } private void boolFromReportDataToJasperReport(Map<String, Object> m, MainReportData mainReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("mainReportData", mainReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo3DigitString(i); BoolPostData boolPostData = (BoolPostData) mainReportData.getPostData(fieldName); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } boolPostDataToMap(m, boolPostData, key); } } private void boolFromSubReportDataToJasperReport(Map<String, Object> m, SubReportData subReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("subReportData", subReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo2DigitString(i); BoolPostData boolPostData = (BoolPostData) subReportData.getPostData(fieldName); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } boolPostDataToMap(m, boolPostData, key); } } private void boolPostDataToMap(Map<String, Object> m, BoolPostData boolPostData, String key) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("key", key); if (boolPostData != null) { Boolean boolPostDataValue = boolPostData.getBoolValue(); if (boolPostDataValue != null) { if (boolPostDataValue.equals(YES)) { m.put(key, "Ja"); } else if (boolPostDataValue.equals(NO)) { m.put(key, "Nei"); } } } } private void dateFromSubReportDataToJasperReport(Map<String, Object> m, SubReportData subReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("subReportData", subReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo2DigitString(i); DatePostData datePostData = (DatePostData) subReportData.getPostData(fieldName); if (datePostData != null) { Date datePostDataValue = datePostData.getDate(); if (datePostDataValue != null) { String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } m.put(key, datePostDataValue); } } } } private void integerFromReportDataToJasperReport(Map<String, Object> m, MainReportData mainReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("mainReportData", mainReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo3DigitString(i); IntPostData intPostData = (IntPostData) mainReportData.getPostData(fieldName); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } intPostDataToMap(m, intPostData, key); } } private void integerFromSubReportDataToJasperReport(Map<String, Object> m, SubReportData subReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("mainReportData", subReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo2DigitString(i); IntPostData intPostData = (IntPostData) subReportData.getPostData(fieldName); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } intPostDataToMap(m, intPostData, key); } } private void intPostDataToMap(Map<String, Object> m, IntPostData intPostData, String key) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("key", key); if (intPostData != null) { Integer intPostDataValue = intPostData.getIntegerValue(); if (intPostDataValue != null) { m.put(key, intPostDataValue); } } } /* private void floatFromReportDataToJasperReport( Map<String, Object> m, MainReportData mainReportData, int startIndex, int stopIndex) { String fieldName; FloatPostData floatPostData; Float floatPostDataValue; for (int i = startIndex; i <= stopIndex; i++) { fieldName = intTo3DigitString(i); floatPostData = (FloatPostData) mainReportData.getPostData(fieldName); if (floatPostData != null) { floatPostDataValue = floatPostData.getFloatValue(); if (floatPostDataValue != null) { m.put(fieldName, floatPostDataValue); } } } } */ private void doubleFromReportDataFloatToJasperReport(Map<String, Object> m, MainReportData mainReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("mainReportData", mainReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo3DigitString(i); DoublePostData doublePostData = (DoublePostData) mainReportData.getPostData(fieldName); if (doublePostData != null) { String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } Double doublePostDataValue = doublePostData.getDoubleValue(); if (doublePostDataValue != null) { m.put(key, doublePostDataValue.floatValue()); } } } } private void stringFromReportDataToJasperReport(Map<String, Object> m, MainReportData mainReportData, int startIndex, String prefix) { stringFromReportDataToJasperReport(m, mainReportData, startIndex, startIndex, prefix); } private void stringFromReportDataToJasperReport(Map<String, Object> m, MainReportData mainReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("mainReportData", mainReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo3DigitString(i); StringPostData stringPostData = (StringPostData) mainReportData.getPostData(fieldName); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } stringPostDataToMap(m, stringPostData, key); } } private void stringFromSubReportDataToJasperReport(Map<String, Object> m, SubReportData subReportData, int startIndex, int stopIndex, String prefix) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("subReportData", subReportData); for (int i = startIndex; i <= stopIndex; i++) { String fieldName = intTo2DigitString(i); StringPostData stringPostData = (StringPostData) subReportData.getPostData(fieldName); String key; if (prefix == null) { key = fieldName; } else { key = prefix + fieldName; } stringPostDataToMap(m, stringPostData, key); } } private void stringPostDataToMap(Map<String, Object> m, StringPostData stringPostData, String key) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("key", key); if (stringPostData != null) { String stringPostDataValue = stringPostData.getStringValue(); if (stringPostDataValue != null) { m.put(key, stringPostDataValue); } } } private String getFinishFieldNumberForSchemaTypeAndVersion(String schemaType, String version) { // This is just for first year has to be improved for later year by using version if (schemaType.equals(SchemaTypeNameConst.MUSEUM_FINANCE_APPLICATION)) { return "621"; } else if (schemaType.equals(SchemaTypeNameConst.MUSEUM_FINANCE_HALFYEAR_REPORT)) { return "921"; } else if (schemaType.equals(SchemaTypeNameConst.CULTURALRUCKSACK_SCHOOLYEAR_REPORT)) { return "121"; } else if (schemaType.equals(SchemaTypeNameConst.KKD_CULTURAL_ACTIVITY_REPORT)) { return "254"; } else if (schemaType.equals(SchemaTypeNameConst.ARCHIVE_STATISTIC)) { return "398"; } else { throw new IllegalArgumentException("Unknown schemaType '" + schemaType + "'"); } } private void timeStampReport(Map<String, Object> report) { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, LocaleTypeNameConst.BOKMAAL); report.put("timestamp", dateFormat.format(new Date())); } private String intTo3DigitString(int intNumber) { String number = String.valueOf(intNumber); return (number.length() == 3 ? number : (number.length() == 2 ? "0" + number : "00" + number)); } private String intTo2DigitString(int intNumber) { String number = String.valueOf(intNumber); return (number.length() == 2 ? number : "0" + number); } /** * Delete any character in a given string. * @param charsToDelete a set of characters to delete. * E.g. "az\n" will delete 'a's, 'z's and new lines. */ private static String deleteAny(String inString, String charsToDelete) { if (inString == null || charsToDelete == null) { return inString; } StringBuffer out = new StringBuffer(); for (int i = 0; i < inString.length(); i++) { char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { out.append(c); } } return out.toString(); } }