View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.gl.batch.service.impl;
17  
18  import java.text.ParseException;
19  import java.text.SimpleDateFormat;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.kuali.ole.coa.businessobject.OrganizationReversion;
24  import org.kuali.ole.gl.GeneralLedgerConstants;
25  import org.kuali.ole.gl.batch.service.OrganizationReversionProcess;
26  import org.kuali.ole.gl.batch.service.OrganizationReversionProcessService;
27  import org.kuali.ole.sys.OLEConstants;
28  import org.kuali.ole.sys.OLEKeyConstants;
29  import org.kuali.ole.sys.context.SpringContext;
30  import org.kuali.ole.sys.service.ReportWriterService;
31  import org.kuali.ole.sys.service.impl.OleParameterConstants;
32  import org.kuali.rice.core.api.config.property.ConfigurationService;
33  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
34  import org.springframework.transaction.annotation.Transactional;
35  
36  /**
37   * The base implementation of OrganizationReversionProcessService
38   */
39  @Transactional
40  public class OrganizationReversionProcessServiceImpl implements OrganizationReversionProcessService {
41      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionProcessServiceImpl.class);
42      
43      private static final String ORGANIZATION_REVERSION_PRIOR_YEAR_ACCOUNT_PROCESS_BEAN_NAME = "glOrganizationReversionPriorYearAccountProcess";
44      private static final String ORGANIZATION_REVERSION_CURRENT_YEAR_ACCOUNT_PROCESS_BEAN_NAME = "glOrganizationReversionCurrentYearAccountProcess";
45  
46      private static final String DATE_FORMAT = "yyyy-MM-dd";
47  
48      private ReportWriterService organizationReversionReportWriterService;
49      private ParameterService parameterService;
50      private ConfigurationService configurationService;
51  
52      /**
53       * Gets the organizationReversionReportWriterService attribute. 
54       * @return Returns the organizationReversionReportWriterService.
55       */
56      public ReportWriterService getOrganizationReversionReportWriterService() {
57          return organizationReversionReportWriterService;
58      }
59  
60      /**
61       * Sets the organizationReversionReportWriterService attribute value.
62       * @param organizationReversionReportWriterService The organizationReversionReportWriterService to set.
63       */
64      public void setOrganizationReversionReportWriterService(ReportWriterService organizationReversionReportWriterService) {
65          this.organizationReversionReportWriterService = organizationReversionReportWriterService;
66      }
67  
68      /**
69       * Runs the Organization Reversion Year End Process for the end of a fiscal year (ie, a process that
70       * runs before the fiscal year end, and thus uses current account, etc.)
71       * 
72       * @param outputGroup the origin entry group that this process should save entries to
73       * @param jobParameters the parameters used in the process
74       * @param organizationReversionCounts a Map of named statistics generated by running the process
75       * @see org.kuali.ole.gl.batch.service.OrganizationReversionProcessService#organizationReversionProcessEndOfYear(org.kuali.ole.gl.businessobject.OriginEntryGroup, java.util.Map, java.util.Map)
76       */
77      public void organizationReversionPriorYearAccountProcess(Map jobParameters, Map<String, Integer> organizationReversionCounts) {
78          if (LOG.isDebugEnabled()) {
79              LOG.debug("organizationReversionProcessEndOfYear() started");
80          }
81          OrganizationReversionProcess orp = SpringContext.getBean(OrganizationReversionProcess.class,OrganizationReversionProcessServiceImpl.ORGANIZATION_REVERSION_PRIOR_YEAR_ACCOUNT_PROCESS_BEAN_NAME);
82  
83          orp.organizationReversionProcess(jobParameters, organizationReversionCounts);
84          
85          writeReports(orp, jobParameters, organizationReversionCounts);
86      }
87  
88      /**
89       * Organization Reversion Year End Process for the beginning of a fiscal year (ie, the process as it runs
90       * after the fiscal year end, thus using prior year account, etc.)
91       * 
92       * @param jobParameters the parameters used in the process
93       * @param organizationReversionCounts a Map of named statistics generated by running the process
94       * @see org.kuali.ole.gl.batch.service.OrganizationReversionProcessService#organizationReversionProcessBeginningOfYear(org.kuali.ole.gl.businessobject.OriginEntryGroup, java.util.Map, java.util.Map)
95       */
96      public void organizationReversionCurrentYearAccountProcess(Map jobParameters, Map<String, Integer> organizationReversionCounts) {
97          if (LOG.isDebugEnabled()) {
98              LOG.debug("organizationReversionProcessEndOfYear() started");
99          }
100         OrganizationReversionProcess orp = SpringContext.getBean(OrganizationReversionProcess.class,OrganizationReversionProcessServiceImpl.ORGANIZATION_REVERSION_CURRENT_YEAR_ACCOUNT_PROCESS_BEAN_NAME);
101 
102         LOG.info("processing organization reversions for current year accounts");
103         orp.organizationReversionProcess(jobParameters, organizationReversionCounts);
104         
105         writeReports(orp, jobParameters, organizationReversionCounts);
106     }
107 
108     /**
109      * Returns a Map with the properly initialized parameters for an organization reversion job that is about to run
110      * @return a Map holding parameters for the job
111      * @see org.kuali.ole.gl.batch.service.OrganizationReversionProcessService#getJobParameters()
112      */
113     public Map getJobParameters() {
114         // Get job parameters
115         Map jobParameters = new HashMap();
116         String strTransactionDate = getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM);
117         jobParameters.put(OLEConstants.UNALLOC_OBJECT_CD, getParameterService().getParameterValueAsString(OrganizationReversion.class, GeneralLedgerConstants.OrganizationReversionProcess.UNALLOC_OBJECT_CODE_PARM));
118         jobParameters.put(OLEConstants.BEG_BUD_CASH_OBJECT_CD, getParameterService().getParameterValueAsString(OrganizationReversion.class, GeneralLedgerConstants.OrganizationReversionProcess.CARRY_FORWARD_OBJECT_CODE));
119         jobParameters.put(OLEConstants.FUND_BAL_OBJECT_CD, getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FUND_BALANCE_OBJECT_CODE_PARM));
120         String strUniversityFiscalYear = getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM);
121 
122         try {
123             SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
124             java.util.Date jud = sdf.parse(strTransactionDate);
125             jobParameters.put(OLEConstants.TRANSACTION_DT, new java.sql.Date(jud.getTime()));
126         }
127         catch (ParseException e) {
128             throw new IllegalArgumentException("TRANSACTION_DT is an invalid date");
129         }
130         try {
131             jobParameters.put(OLEConstants.UNIV_FISCAL_YR, new Integer(strUniversityFiscalYear));
132         }
133         catch (NumberFormatException nfe) {
134             throw new IllegalArgumentException("UNIV_FISCAL_YR is an invalid year");
135         }
136         return jobParameters;
137     }
138     
139     /**
140      * 
141      * @param organizationReversionProcess
142      * @param jobParameters
143      * @param counts
144      */
145     public void writeReports(OrganizationReversionProcess organizationReversionProcess, Map jobParameters, Map<String, Integer> counts) {
146         // write job parameters
147         for (Object jobParameterKeyAsObject : jobParameters.keySet()) {
148             if (jobParameterKeyAsObject != null) {
149                 final String jobParameterKey = jobParameterKeyAsObject.toString();
150                 getOrganizationReversionReportWriterService().writeParameterLine("%32s %10s", jobParameterKey, jobParameters.get(jobParameterKey));
151             }
152         }
153         
154         // write statistics
155         getOrganizationReversionReportWriterService().writeStatisticLine("NUMBER OF GLBL RECORDS READ....: %10d", counts.get("balancesRead"));
156         getOrganizationReversionReportWriterService().writeStatisticLine("NUMBER OF GLBL RECORDS SELECTED: %10d", counts.get("balancesSelected"));
157         getOrganizationReversionReportWriterService().writeStatisticLine("NUMBER OF SEQ RECORDS WRITTEN..: %10d", counts.get("recordsWritten"));
158         getOrganizationReversionReportWriterService().pageBreak();
159         
160         // write ledger report
161         getOrganizationReversionReportWriterService().writeSubTitle(getConfigurationService().getPropertyValueAsString(OLEKeyConstants.MESSAGE_REPORT_YEAR_END_ORGANIZATION_REVERSION_LEDGER_TITLE_LINE));
162         organizationReversionProcess.writeLedgerSummaryReport(getOrganizationReversionReportWriterService());
163     }
164 
165     /**
166      * Sets the implementation of ParameterService to use
167      * @param parameterService an implementation of ParameterService
168      */
169     public void setParameterService(ParameterService parameterService) {
170         this.parameterService = parameterService;
171     }
172 
173     /**
174      * Sets the implementation of the ConfigurationService to use
175      * @param configurationService an implementation of the ConfigurationService
176      */
177     public void setConfigurationService(ConfigurationService configurationService) {
178         this.configurationService = configurationService;
179     }
180 
181     /**
182      * Gets the parameterService attribute. 
183      * @return Returns the parameterService.
184      */
185     public ParameterService getParameterService() {
186         return parameterService;
187     }
188 
189     /**
190      * Gets the configurationService attribute. 
191      * @return Returns the configurationService.
192      */
193     public ConfigurationService getConfigurationService() {
194         return configurationService;
195     }
196 }