001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.batch;
017:
018: import java.text.SimpleDateFormat;
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Date;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.kuali.kfs.batch.AbstractStep;
026: import org.kuali.kfs.bo.Options;
027: import org.kuali.kfs.service.OptionsService;
028: import org.kuali.module.gl.GLConstants;
029: import org.kuali.module.gl.bo.OriginEntrySource;
030: import org.kuali.module.gl.service.OriginEntryGroupService;
031: import org.kuali.module.gl.service.ReportService;
032:
033: /**
034: * A step to generate summary reports from a recent poster run
035: */
036: public class PosterSummaryReportStep extends AbstractStep {
037: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
038: .getLogger(PosterSummaryReportStep.class);
039: private static final String DATE_FORMAT = "MMdd";
040: private static final String BUD = "bud";
041: private static final String ACT = "act";
042: private static final String ENC = "enc";
043: public ReportService reportService;
044: public OptionsService optionsService;
045: public OriginEntryGroupService originEntryGroupService;
046:
047: /**
048: * Runs the process that generates poster summary reports.
049: *
050: * @param jobName the name of the job this step is being run as part of
051: * @return true if the job completed successfully, false if otherwise
052: * @see org.kuali.kfs.batch.Step#execute(java.lang.String)
053: */
054: public synchronized boolean execute(String jobName) {
055: final String CURRENT_YEAR_LOWER = getParameterService()
056: .getParameterValue(getClass(),
057: GLConstants.GlSummaryReport.CURRENT_YEAR_LOWER);
058: final String CURRENT_YEAR_UPPER = getParameterService()
059: .getParameterValue(getClass(),
060: GLConstants.GlSummaryReport.CURRENT_YEAR_UPPER);
061: final String CURRENT_AND_LAST_YEAR = getParameterService()
062: .getParameterValue(
063: getClass(),
064: GLConstants.GlSummaryReport.CURRENT_AND_LAST_YEAR);
065:
066: Options currentYear = optionsService.getCurrentYearOptions();
067: Options nextYear = optionsService.getOptions(currentYear
068: .getUniversityFiscalYear() + 1);
069: Options previousYear = optionsService.getOptions(currentYear
070: .getUniversityFiscalYear() - 1);
071:
072: Date runDate = getDateTimeService().getCurrentDate();
073: SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
074: String md = sdf.format(runDate);
075: this .generatePosterOutputReport(runDate);
076: if ((md.compareTo(CURRENT_YEAR_UPPER) > 0)
077: || (md.compareTo(CURRENT_YEAR_LOWER) < 0)) {
078: // Current year
079: reportService.generateGlSummary(runDate, currentYear, BUD);
080: reportService.generateGlSummary(runDate, currentYear, ACT);
081: reportService.generateGlEncumbranceSummary(runDate,
082: currentYear, ENC);
083: } else if ((md.compareTo(CURRENT_AND_LAST_YEAR) > 0)) {
084: // Current year and Last year
085: reportService.generateGlSummary(runDate, currentYear, BUD);
086: reportService.generateGlSummary(runDate, previousYear, BUD);
087: reportService.generateGlSummary(runDate, currentYear, ACT);
088: reportService.generateGlSummary(runDate, previousYear, ACT);
089: reportService.generateGlEncumbranceSummary(runDate,
090: currentYear, ENC);
091: reportService.generateGlEncumbranceSummary(runDate,
092: previousYear, ENC);
093: } else {
094: // Current year and next year
095: reportService.generateGlSummary(runDate, currentYear, BUD);
096: reportService.generateGlSummary(runDate, nextYear, BUD);
097: reportService.generateGlSummary(runDate, currentYear, ACT);
098: reportService.generateGlSummary(runDate, nextYear, ACT);
099: reportService.generateGlEncumbranceSummary(runDate,
100: currentYear, ENC);
101: reportService.generateGlEncumbranceSummary(runDate,
102: nextYear, ENC);
103: }
104: return true;
105: }
106:
107: /**
108: * Generates reports about the output of a poster run.
109: *
110: * @param runDate the date the poster was run.
111: */
112: private void generatePosterOutputReport(Date runDate) {
113: List originEntrySourceCodeList = new ArrayList();
114: originEntrySourceCodeList
115: .add(OriginEntrySource.MAIN_POSTER_VALID);
116: originEntrySourceCodeList
117: .add(OriginEntrySource.REVERSAL_POSTER_VALID);
118: originEntrySourceCodeList
119: .add(OriginEntrySource.ICR_POSTER_VALID);
120: Collection originEntryGroups = new ArrayList();
121: for (Iterator groupIterator = originEntrySourceCodeList
122: .iterator(); groupIterator.hasNext();) {
123: String originEntrySourceCode = (String) groupIterator
124: .next();
125: originEntryGroups
126: .add(originEntryGroupService
127: .getGroupWithMaxIdFromSource(originEntrySourceCode));
128: }
129: reportService.generatePosterOutputTransactionSummaryReport(
130: runDate, originEntryGroups);
131: }
132:
133: /**
134: * Sets the reportService attribute, allowing the injection of an implementation of that service
135: *
136: * @param reportService the reportService implementation to set
137: * @see org.kuali.module.gl.service.ReportService
138: */
139: public void setReportService(ReportService reportService) {
140: this .reportService = reportService;
141: }
142:
143: /**
144: * Sets the optionsService attribute, allowing the injection of an implementation of that service
145: *
146: * @param os the optionsService implementation to set
147: * @see org.kuali.kfs.service.OptionsService
148: */
149: public void setOptionsService(OptionsService os) {
150: optionsService = os;
151: }
152:
153: /**
154: * Sets the originEntryGroupService attribute value.
155: *
156: * @param originEntryGroupService The originEntryGroupService to set.
157: * @see org.kuali.module.gl.service.OriginEntryGroupService
158: */
159: public void setOriginEntryGroupService(
160: OriginEntryGroupService originEntryGroupService) {
161: this.originEntryGroupService = originEntryGroupService;
162: }
163: }
|