Java tutorial
/*$Id: QuestionnaireServiceHelperH3Impl.java 15846 2010-11-25 23:06:40Z 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.questionnaire.service; import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; 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.common.schema.SchemaTypeNameAndVersion; import no.abmu.common.schema.SubSchemaTypeNameAndVersion; import no.abmu.organisationregister.util.ProgressStatistics; import no.abmu.questionnaire.domain.constants.QuestionnaireNameConst; import no.abmu.questionnaire.domain.data.BigDecimalFieldData; import no.abmu.questionnaire.domain.data.BooleanFieldData; import no.abmu.questionnaire.domain.data.DateFieldData; import no.abmu.questionnaire.domain.data.FieldData; import no.abmu.questionnaire.domain.data.LongFieldData; import no.abmu.questionnaire.domain.data.MuseumHovedOmraadeFieldData; import no.abmu.questionnaire.domain.data.MuseumOrganizationFormFieldData; import no.abmu.questionnaire.domain.data.QuestionnaireData; import no.abmu.questionnaire.domain.data.StringFieldData; import no.abmu.questionnaire.domain.data.SubSchemaData; import no.abmu.questionnaire.domain.data.YesNoPartlyFieldData; import no.abmu.questionnaire.domain.data.SchoolHasFieldData; import no.abmu.questionnaire.domain.metadata.QuestionnaireName; import no.abmu.questionnaire.domain.util.LoggingOfFieldData; import no.abmu.questionnaire.finders.QuestionnaireDataH3FinderSpecification; import no.abmu.questionnaire.finders.QuestionnaireNameCriteraFinder; import no.abmu.questionnaire.util.SummingUpFinanceApplication2010; import no.abmu.util.test.Assert; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.orm.hibernate3.SessionFactoryUtils; import org.springframework.util.StopWatch; /** * Helper class for FinanceService. * * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no * @author $Author: jens $ * @version $Rev: 15846 $ * $Date: 2010-11-26 00:06:40 +0100 (Fri, 26 Nov 2010) $ * @since 2006-08-06 (Rev. 3361) * copyright ABM-Utvikling */ public class QuestionnaireServiceHelperH3Impl implements QuestionnaireServiceHelper { 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 String BOOLFIELD_POSITIVE_VALUE = "Ja"; private static final String BOOLFIELD_NEGATIVE_VALUE = "Nei"; private static final Log logger = (Log) LogFactory.getLog(QuestionnaireServiceHelperH3Impl.class); private SessionFactory sessionFactory; private QuestionnaireService questionnaireService; public QuestionnaireServiceHelperH3Impl() { } public QuestionnaireServiceHelperH3Impl(QuestionnaireService questionnaireService) { this.questionnaireService = questionnaireService; } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public void setQuestionnaireService(QuestionnaireService questionnaireService) { this.questionnaireService = questionnaireService; } public ReportStatus[] getReportStatusBySchemaTypeNameAndVersion( List<OrganisationUnitForBrowsing> orgUnitsForBrowsing, SchemaTypeNameAndVersion schemaTypeNameAndVersion) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); String codeFieldNumber = schemaTypeNameAndVersion.getCodeFinishField(); String dbSchemaName = schemaTypeNameAndVersion.getDbSchemaName(); String version = schemaTypeNameAndVersion.getVersion(); List<ReportStatus> reportStatusAsList = new ArrayList<ReportStatus>(); for (OrganisationUnitForBrowsing orgForBrowse : orgUnitsForBrowsing) { QuestionnaireData questionnaireData = getQuestionnaireData(orgForBrowse.getOrganisationUnitId(), dbSchemaName, version); reportStatusAsList.add(createReportStatus(orgForBrowse, questionnaireData, codeFieldNumber)); } stopWatch.stop(); logger.info("Finish prosessing of reportStatus for schemaTypeNameAndVersion:" + schemaTypeNameAndVersion + " with " + orgUnitsForBrowsing.size() + " elements in " + stopWatch.getTotalTimeMillis() + " ms"); return reportStatusAsList.toArray(new ReportStatus[reportStatusAsList.size()]); } private ReportStatus createReportStatus(OrganisationUnitForBrowsing orgForBrowse, QuestionnaireData questionnaireData, String finishFieldNumber) { Boolean yes = true; if (questionnaireData == null) { return new ReportStatusImpl(orgForBrowse); } BooleanFieldData booleanFieldData = (BooleanFieldData) questionnaireData.getFieldData(finishFieldNumber); if (booleanFieldData == null) { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST); } Boolean booleanFieldDataValue = booleanFieldData.getValue(); if (booleanFieldDataValue == null) { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST); } if (booleanFieldDataValue.equals(yes)) { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST, REPORT_IS_FINISH); } else { return new ReportStatusImpl(orgForBrowse, REPORT_EXIST, REPORT_IS_NOT_FINISH); } } public SchemaList getSchemaDataBySchemaTypeNameAndVersion(SchemaList jasperReportDataSource, SchemaTypeNameAndVersion schemaTypeNameAndVersion) { Assert.assertTrue("Has to be of type questionnaire", schemaTypeNameAndVersion.isSchemaOfTypeQuestionnaire()); String dbSchemaName = schemaTypeNameAndVersion.getDbSchemaName(); String version = schemaTypeNameAndVersion.getVersion(); Map<String, Object> report; Iterator<Map<String, Object>> iterator = jasperReportDataSource.iterator(); while (iterator.hasNext()) { report = iterator.next(); fillInReportValues(report, dbSchemaName, version); } return jasperReportDataSource; } public SchemaList getSchemaDataBySchemaTypeNameAndVersion(SortedSet<OrgUnitReport> orgSortedSet, SchemaTypeNameAndVersion schemaTypeNameAndVersion) { Assert.checkRequiredArgument("orgSortedSet", orgSortedSet); Assert.checkRequiredArgument("schemaTypeNameAndVersion", schemaTypeNameAndVersion); String dbSchemaName = schemaTypeNameAndVersion.getDbSchemaName(); String version = schemaTypeNameAndVersion.getVersion(); 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, dbSchemaName, version); schemaList.add(report); ps.increaseCountAndDumpStatus(); } ps.dumpStatus(true); return schemaList; } public SchemaList getSubSchemaDataBySchemaTypeAndVersion(Collection<OrgUnitReport> orgSortedSet, SubSchemaTypeNameAndVersion subSchemaTypeNameAndVersion, Boolean isKKDIniativPdfReport) { Assert.checkRequiredArgument("orgSortedSet", orgSortedSet); Assert.checkRequiredArgument("subSchemaTypeNameAndVersion", subSchemaTypeNameAndVersion); Assert.checkRequiredArgument("isKKDIniativPdfReport", isKKDIniativPdfReport); String dbSchemaName = subSchemaTypeNameAndVersion.getDbSchemaName(); String version = subSchemaTypeNameAndVersion.getVersion(); String subSchemaName = subSchemaTypeNameAndVersion.getSubSchemaNameAsString(); SchemaList subSchemaData = new SchemaList(); for (OrgUnitReport orgUnitReport : orgSortedSet) { QuestionnaireData questionnaireData = getQuestionnaireData(orgUnitReport.getOrganisationUnitId(), dbSchemaName, version); if (questionnaireData == null) { if (logger.isDebugEnabled()) { logger.debug( "getSubSchemaDataBySchemaTypeAndVersion " + "-- No Report exist for organisationUnit [" + orgUnitReport.getOrganisationUnitName() + "]"); } continue; } List<SubSchemaData> initiatives = questionnaireData.getSubSchemaDataList(subSchemaName); if (initiatives == null || initiatives.size() == 0) { if (logger.isDebugEnabled()) { logger.info("getSubSchemaDataBySchemaTypeAndVersion " + "-- No Iniatives exist for organisationUnit [" + orgUnitReport.getOrganisationUnitName() + "]"); } if (isKKDIniativPdfReport) { Map<String, Object> subReport = orgUnitReport.createReport(); subReport.put("priority", 1); subReport.put("01", "Viderefring av driftstilskudd"); subReport.put("05", 0); subReport.put("30", "Har ikke skt om kning i forhold til rets tilskudd."); timeStampReport(subReport); valueFromReportDataToJasperReport(subReport, questionnaireData, 417, 417); subSchemaData.add(subReport); } continue; } for (int index = 0; index < initiatives.size(); index++) { SubSchemaData initiative = initiatives.get(index); Map<String, Object> subReport = orgUnitReport.createReport(); Integer iniativPriority = index + 1; subReport.put("priority", iniativPriority); timeStampReport(subReport); valueFromReportDataToJasperReport(subReport, questionnaireData, 417, 417); subReport = fillInSubReportValues(subReport, initiative, subSchemaName, version); if (logger.isDebugEnabled()) { logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is [" + subReport.size() + "]"); } subSchemaData.add(subReport); } } return subSchemaData; } private QuestionnaireData getQuestionnaireData(Map<String, Object> schema, String schemaTypeName, String version) { Assert.assertTrue("Key organisationUnitId has to be in schema map", schema.containsKey("organisationUnitId")); Long organisationUnitId = (Long) schema.get("organisationUnitId"); Assert.assertNotNull("Long: organisationUnitId can not be null", organisationUnitId); return getQuestionnaireData(organisationUnitId, schemaTypeName, version); } private QuestionnaireData getQuestionnaireData(Long organisationUnitId, String schemaTypeName, String version) { Assert.checkRequiredArgument("organisationUnitId", organisationUnitId); Assert.checkRequiredArgument("schemaTypeName", schemaTypeName); Assert.checkRequiredArgument("version", version); QuestionnaireDataH3FinderSpecification finderSpecification = new QuestionnaireDataH3FinderSpecification( schemaTypeName, version, organisationUnitId); logger.info("getQuestionnaireData finderSpecification==> " + finderSpecification.toString()); QuestionnaireData questionnaireData = null; try { questionnaireData = questionnaireService.findQuestionnaireData(finderSpecification); } catch (IllegalArgumentException e) { logger.error("Can't find questionnaireData for finder ==>" + finderSpecification.toString(), e); } return questionnaireData; } public QuestionnaireName retrieveQuestionnaireName(String schemaNameString) { Session session = SessionFactoryUtils.getSession(sessionFactory, true); Criteria criteria = new QuestionnaireNameCriteraFinder(schemaNameString).createCriteria(session); List<Object> results = criteria.list(); if (results.size() > 0) { return (QuestionnaireName) results.get(0); } else { return null; } } private void fillInReportValues(Map<String, Object> report, String schemaTypeName, String version) { if (logger.isDebugEnabled()) { logger.debug("[fillInReportValues] called with values SchemaTypeName='" + schemaTypeName + "' and version='" + version + "'."); } timeStampReport(report); QuestionnaireData questionnaireData = getQuestionnaireData(report, schemaTypeName, version); if (schemaTypeName.equals(QuestionnaireNameConst.ARCHIVE_STATISTIC)) { fillInQuestionnaireData(report, questionnaireData); } else if (schemaTypeName.equals(QuestionnaireNameConst.KUD_FINANCE_APPLICATION)) { if (version.equals("2011")) { fillInMuseumFinanceApplicationValues2011(report, questionnaireData); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(QuestionnaireNameConst.KUD_FINANCE_HALFYEAR_REPORT)) { if (version.equals("2010")) { fillInMuseumFinanceHalfYearReportValues2010(report, questionnaireData); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(QuestionnaireNameConst.KUD_CULTURAL_ACTIVITY_REPORT)) { if (version.equals("2009")) { fillInKkdCulturalActivityReport2009(report, questionnaireData); } else { throw new IllegalArgumentException("The combination of schemaTypeName '" + schemaTypeName + "' and version '" + version + "' is unknown."); } } else if (schemaTypeName.equals(QuestionnaireNameConst.MUSEUM_STATISTIC)) { fillInQuestionnaireData(report, questionnaireData); } else { fillInQuestionnaireData(report, questionnaireData); // throw new IllegalArgumentException("The combination of schemaTypeName '" // + schemaTypeName + "' and version '" + version + "' is unknown."); } } private Map<String, Object> fillInSubReportValues(Map<String, Object> m, SubSchemaData subSchemaData, String subSchemaName, String schemaVersion) { if (subSchemaName.equals(SchemaTypeNameConst.SUB_SCHEMA_MUSEUM_FINANCE_INITIATIVE)) { if (schemaVersion.equals("2007")) { return fillInIniativeValues2007(m, subSchemaData); } else if (schemaVersion.equals("2008")) { return fillInIniativeValues2008(m, subSchemaData); } else if (schemaVersion.equals("2009")) { return fillInIniativeValues2009(m, subSchemaData); } else if (schemaVersion.equals("2010")) { return fillInIniativeValues2010(m, subSchemaData); } else if (schemaVersion.equals("2011")) { return fillInIniativeValues2011(m, subSchemaData); } } String errorMessage = "The combination of subSchemaTypeName '" + subSchemaName + "' and schema version '" + schemaVersion + "' is unknown."; logger.error(errorMessage); throw new IllegalArgumentException(errorMessage); } private void fillInQuestionnaireData(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInQuestionnaireData]: questionnaireData == null"); return; } Map<String, FieldData> fieldDataMap = questionnaireData.getFieldData(); Set<String> keys = fieldDataMap.keySet(); for (String key : keys) { FieldData fieldData = fieldDataMap.get(key); if (fieldData != null && fieldData.getUntypedValue() != null) { fieldDataToMap(m, fieldData); } logger.debug("FieldData Key='" + key + "' code='" + fieldDataMap.get(key).getCode() + "' value=[" + LoggingOfFieldData.fieldDataValueAsString(fieldData) + "]"); } } private void fieldDataToMap(Map<String, Object> m, FieldData fieldData) { Assert.checkRequiredArgument("m", m); Assert.checkRequiredArgument("fieldData", fieldData); Assert.assertNotNull("value", fieldData.getUntypedValue()); String code = fieldData.getCode(); Assert.assertNotNull("code", code); //add comments m.put("c" + code, fieldData.getComment()); if (fieldData instanceof BooleanFieldData) { BooleanFieldData booleanFieldData = (BooleanFieldData) fieldData; if (booleanFieldData.isBooleanValue()) { m.put(code, "Ja"); } else { m.put(code, "Nei"); } } else if (fieldData instanceof MuseumHovedOmraadeFieldData) { MuseumHovedOmraadeFieldData hovedOmraadefieldDate = (MuseumHovedOmraadeFieldData) fieldData; String value = hovedOmraadefieldDate.getValueAsString(); m.put(code, value); } else if (fieldData instanceof YesNoPartlyFieldData) { YesNoPartlyFieldData yesNoPartlyFieldData = (YesNoPartlyFieldData) fieldData; String value = yesNoPartlyFieldData.getValueAsString(); m.put(code, value); } else if (fieldData instanceof SchoolHasFieldData) { SchoolHasFieldData yesNoPartlyFieldData = (SchoolHasFieldData) fieldData; String value = yesNoPartlyFieldData.getValueAsString(); m.put(code, value); } else if (fieldData instanceof MuseumOrganizationFormFieldData) { MuseumOrganizationFormFieldData organizationFormFieldData = (MuseumOrganizationFormFieldData) fieldData; String value = organizationFormFieldData.getValueAsString(); m.put(code, value); } else if (fieldData instanceof BigDecimalFieldData) { BigDecimalFieldData bigDecimalFieldData = (BigDecimalFieldData) fieldData; Double doubleValue = bigDecimalFieldData.getBigDecimalValue().doubleValue(); m.put(code, doubleValue); } else if (fieldData instanceof LongFieldData) { LongFieldData longFieldData = (LongFieldData) fieldData; Long longValue = longFieldData.getLongValue(); m.put(code, longValue); } else if (fieldData instanceof DateFieldData) { DateFieldData dateFieldData = (DateFieldData) fieldData; // Date dateValue = dateFieldData.getDateValue(); String stringValue = dateFieldData.getValueAsString(); m.put(code, stringValue); } else if (fieldData instanceof StringFieldData) { StringFieldData stringFieldData = (StringFieldData) fieldData; String stringValue = stringFieldData.getStringValue(); m.put(code, stringValue); } } private void fillInKkdCulturalActivityReport2009(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInKkdCulturalActivityReport2009]: questionnaireData == null"); return; } fillInKkdCulturalActivityReport2008(m, questionnaireData); } private void fillInKkdCulturalActivityReport2008(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInKkdCulturalActivityReport2008]: questionnaireData == null"); return; } fillInKkdCulturalActivityReport2007(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 256, 256); } private void fillInKkdCulturalActivityReport2007(Map<String, Object> m, QuestionnaireData questionnaireData) { 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 (questionnaireData == null) { logger.info("fillInKkdCulturalActivityReport2007: questionnaireData == null"); return; } valueFromReportDataToJasperReport(m, questionnaireData, 137, 253); boolFromReportDataToJasperReport(m, questionnaireData, 254, 254); valueFromReportDataToJasperReport(m, questionnaireData, 255, 255); if (logger.isDebugEnabled()) { logger.debug("FINISH fillInKkdCulturalActivityReport2007 for OrgUnit id='" + organisationUnitId + "' name='" + orgUnitName + "'"); } } private void fillInMuseumFinanceApplicationValues2011(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInMuseumFinanceApplicationValues2011]: questionnaireData == null"); return; } fillInMuseumFinanceApplicationValues2010(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 659, 660); } private void fillInMuseumFinanceApplicationValues2010(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInMuseumFinanceApplicationValues2010]: questionnaireData == null"); return; } fillInMuseumFinanceApplicationValues2009(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 403, 403); valueFromReportDataToJasperReport(m, questionnaireData, 649, 654); boolFromReportDataToJasperReport(m, questionnaireData, 655, 656); valueFromReportDataToJasperReport(m, questionnaireData, 657, 658); financeApplicationField418For2010(m, questionnaireData); } private void fillInMuseumFinanceApplicationValues2009(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInMuseumFinanceApplicationValues2009]: questionnaireData == null"); return; } fillInMuseumFinanceApplicationValues2008(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 647, 648); financeApplicationField418For2009(m, questionnaireData); } private void fillInMuseumFinanceApplicationValues2008(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("[fillInMuseumFinanceApplicationValues2008]: questionnaireData == null"); return; } fillInMuseumFinanceApplicationValues2007(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 623, 646); } private Map<String, Object> fillInMuseumFinanceApplicationValues2007(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("fillInMuseumFinanceApplicationValues2007: questionnaireData == null"); return m; } valueFromReportDataToJasperReport(m, questionnaireData, 401, 402); valueFromReportDataToJasperReport(m, questionnaireData, 404, 618); boolFromReportDataToJasperReport(m, questionnaireData, 619, 619); valueFromReportDataToJasperReport(m, questionnaireData, 620, 620); boolFromReportDataToJasperReport(m, questionnaireData, 621, 621); valueFromReportDataToJasperReport(m, questionnaireData, 622, 622); return m; } private void financeApplicationField418For2010(Map<String, Object> m, QuestionnaireData questionnaireData) { SummingUpFinanceApplication2010 summingUp = new SummingUpFinanceApplication2010(questionnaireData); String fieldNameField418 = "418"; Long fieldValueField418 = summingUp.getValueForField418(); // Currently we need to cast to Integer Integer field418AsInteger = Integer.valueOf(fieldValueField418.intValue()); m.put(fieldNameField418, field418AsInteger); } private void financeApplicationField418For2009(Map<String, Object> m, QuestionnaireData questionnaireData) { if (logger.isDebugEnabled()) { logger.debug("Executing financeApplicationField418For2009"); } Long returnValue = 0L; int indexFieldName = 418; int indexLastYearValue = 417; String subSchemaName = SchemaTypeNameConst.SUB_SCHEMA_MUSEUM_FINANCE_INITIATIVE; String fieldName = intTo3DigitString(indexFieldName); String fnLastYearValue = intTo3DigitString(indexLastYearValue); LongFieldData lastYearLongFieldData = (LongFieldData) questionnaireData.getFieldData(fnLastYearValue); if (lastYearLongFieldData != null) { Long lastYearValue = lastYearLongFieldData.getValue(); if (lastYearValue != null) { returnValue = lastYearValue; } } List<SubSchemaData> initiatives = questionnaireData.getSubSchemaDataList(subSchemaName); if (initiatives == null) { if (logger.isDebugEnabled()) { logger.debug("No initiative"); } m.put(fieldName, returnValue); return; } int indexInitiativeType = 2; int indexKkdApplicationAmount = 5; String fnInitiativeType = intTo2DigitString(indexInitiativeType); String fnKkdApplicationAmount = intTo2DigitString(indexKkdApplicationAmount); for (SubSchemaData subSchemaData : initiatives) { StringFieldData subStringPostData = (StringFieldData) subSchemaData.getFieldData(fnInitiativeType); LongFieldData subIntPostData = (LongFieldData) subSchemaData.getFieldData(fnKkdApplicationAmount); if (subStringPostData != null && subIntPostData != null) { String initiativeType = subStringPostData.getStringValue(); Long applicationAmount = subIntPostData.getValue(); if (initiativeType != null && applicationAmount != null && initiativeType.equals("Drift")) { returnValue += applicationAmount; } } } if (logger.isDebugEnabled()) { logger.debug("Executing financeApplicationField418For2009 returns: " + returnValue); } m.put(fieldName, returnValue); } private Map<String, Object> fillInMuseumFinanceHalfYearReportValues2006(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2006: questionnaireData == null"); return m; } valueFromReportDataToJasperReport(m, questionnaireData, 704, 904); boolFromReportDataToJasperReport(m, questionnaireData, 919, 919); valueFromReportDataToJasperReport(m, questionnaireData, 920, 920); boolFromReportDataToJasperReport(m, questionnaireData, 921, 921); return m; } private void fillInMuseumFinanceHalfYearReportValues2007(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2007: questionnaireData == null"); return; } fillInMuseumFinanceHalfYearReportValues2006(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 923, 946); } private void fillInMuseumFinanceHalfYearReportValues2010(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2010: questionnaireData == null"); return; } fillInMuseumFinanceHalfYearReportValues2009(m, questionnaireData); } private void fillInMuseumFinanceHalfYearReportValues2009(Map<String, Object> m, QuestionnaireData questionnaireData) { if (questionnaireData == null) { logger.info("fillInMuseumFinanceHalfYearReportValues2007: questionnaireData == null"); return; } fillInMuseumFinanceHalfYearReportValues2007(m, questionnaireData); valueFromReportDataToJasperReport(m, questionnaireData, 949, 954); } private Map<String, Object> fillInIniativeValues2007(Map<String, Object> m, SubSchemaData subSchemaData) { if (subSchemaData == null) { logger.info("fillInIniativeValues2007: subSchemaData == null"); return m; } valueFromSubReportDataToJasperReport(m, subSchemaData, 1, 5); boolFromSubReportDataToJasperReport(m, subSchemaData, 6, 6); valueFromSubReportDataToJasperReport(m, subSchemaData, 7, 29); return m; } private Map<String, Object> fillInIniativeValues2008(Map<String, Object> m, SubSchemaData subSchemaData) { if (subSchemaData == null) { logger.info("fillInIniativeValues2008: subSchemaData == null"); return m; } fillInIniativeValues2007(m, subSchemaData); valueFromSubReportDataToJasperReport(m, subSchemaData, 30, 30); return m; } private Map<String, Object> fillInIniativeValues2009(Map<String, Object> m, SubSchemaData subSchemaData) { if (subSchemaData == null) { logger.info("fillInIniativeValues2009: subSchemaData == null"); return m; } fillInIniativeValues2008(m, subSchemaData); boolFromSubReportDataToJasperReport(m, subSchemaData, 31, 32); return m; } private Map<String, Object> fillInIniativeValues2010(Map<String, Object> m, SubSchemaData subSchemaData) { if (subSchemaData == null) { logger.info("fillInIniativeValues2010: subSchemaData == null"); return m; } valueFromSubReportDataToJasperReport(m, subSchemaData, 1, 1); valueFromSubReportDataToJasperReport(m, subSchemaData, 5, 5); boolFromSubReportDataToJasperReport(m, subSchemaData, 6, 6); valueFromSubReportDataToJasperReport(m, subSchemaData, 8, 8); valueFromSubReportDataToJasperReport(m, subSchemaData, 10, 10); valueFromSubReportDataToJasperReport(m, subSchemaData, 13, 13); valueFromSubReportDataToJasperReport(m, subSchemaData, 16, 16); valueFromSubReportDataToJasperReport(m, subSchemaData, 19, 19); valueFromSubReportDataToJasperReport(m, subSchemaData, 22, 22); valueFromSubReportDataToJasperReport(m, subSchemaData, 25, 25); valueFromSubReportDataToJasperReport(m, subSchemaData, 28, 28); valueFromSubReportDataToJasperReport(m, subSchemaData, 30, 30); return m; } private Map<String, Object> fillInIniativeValues2011(Map<String, Object> m, SubSchemaData subSchemaData) { if (subSchemaData == null) { logger.info("fillInIniativeValues2010: subSchemaData == null"); return m; } fillInIniativeValues2010(m, subSchemaData); return m; } private void boolFromReportDataToJasperReport(Map<String, Object> m, QuestionnaireData questionnaireData, int startIndex, int stopIndex) { String fieldName; BooleanFieldData booleanFieldData; Boolean booleanFieldDataValue; Boolean yes = true; Boolean no = false; for (int i = startIndex; i <= stopIndex; i++) { fieldName = intTo3DigitString(i); booleanFieldData = (BooleanFieldData) questionnaireData.getFieldData(fieldName); if (booleanFieldData != null) { booleanFieldDataValue = booleanFieldData.getValue(); if (booleanFieldDataValue != null) { if (booleanFieldDataValue.equals(yes)) { m.put(fieldName, "Ja"); } else if (booleanFieldDataValue.equals(no)) { m.put(fieldName, "Nei"); } } } } } private void boolFromSubReportDataToJasperReport(Map<String, Object> m, SubSchemaData subSchemaData, int startIndex, int stopIndex) { String fieldName; BooleanFieldData booleanFieldData; Boolean booleanFieldDataValue; Boolean yes = true; Boolean no = false; for (int i = startIndex; i <= stopIndex; i++) { fieldName = intTo2DigitString(i); booleanFieldData = (BooleanFieldData) subSchemaData.getFieldData(fieldName); if (booleanFieldData != null) { booleanFieldDataValue = booleanFieldData.getValue(); if (booleanFieldDataValue != null) { if (booleanFieldDataValue.equals(yes)) { m.put(fieldName, "Ja"); } else if (booleanFieldDataValue.equals(no)) { m.put(fieldName, "Nei"); } } } } } private void valueFromReportDataToJasperReport(Map<String, Object> m, QuestionnaireData questionnaireData, int startIndex, int stopIndex) { String fieldName; FieldData fieldData; for (int i = startIndex; i <= stopIndex; i++) { fieldName = intTo3DigitString(i); fieldData = questionnaireData.getFieldData(fieldName); if (fieldData != null) { castFromNewToOldDataTypes(m, fieldData); } } } private void castFromNewToOldDataTypes(Map<String, Object> m, FieldData fieldData) { Assert.checkRequiredArgument("JapserReport Map m", m); Assert.checkRequiredArgument("fieldData", fieldData); // If value is null we do nothing. if (fieldData.getUntypedValue() == null) { return; } if (fieldData instanceof LongFieldData) { LongFieldData longFieldData = (LongFieldData) fieldData; m.put(longFieldData.getCode(), Integer.valueOf(longFieldData.getLongValue().intValue())); } else if (fieldData instanceof BigDecimalFieldData) { BigDecimalFieldData bigDecimalFieldData = (BigDecimalFieldData) fieldData; m.put(bigDecimalFieldData.getCode(), bigDecimalFieldData.getBigDecimalValue().floatValue()); } else if (fieldData instanceof BooleanFieldData) { BooleanFieldData booleanFieldData = (BooleanFieldData) fieldData; m.put(booleanFieldData.getCode(), (booleanFieldData.getValue() ? BOOLFIELD_POSITIVE_VALUE : BOOLFIELD_NEGATIVE_VALUE)); } else if (fieldData instanceof StringFieldData) { StringFieldData stringFieldData = (StringFieldData) fieldData; stringFieldData.getStringValue(); m.put(stringFieldData.getCode(), stringFieldData.getStringValue()); } else { throw new IllegalArgumentException( "Data type in fieldData '" + fieldData.getClass().getName() + "'. is unknown."); } } private void valueFromSubReportDataToJasperReport(Map<String, Object> m, SubSchemaData subSchemaData, int startIndex, int stopIndex) { String fieldName; FieldData fieldData; for (int i = startIndex; i <= stopIndex; i++) { fieldName = intTo2DigitString(i); fieldData = subSchemaData.getFieldData(fieldName); if (fieldData != null) { castFromNewToOldDataTypes(m, fieldData); } } } 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); } }