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.labor.service.impl;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Collections;
021: import java.util.Comparator;
022: import java.util.Date;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Map;
027:
028: import org.kuali.module.gl.bo.GlSummary;
029: import org.kuali.module.gl.bo.OriginEntryGroup;
030: import org.kuali.module.gl.bo.Transaction;
031: import org.kuali.module.gl.service.OriginEntryGroupService;
032: import org.kuali.module.gl.service.OriginEntryService;
033: import org.kuali.module.gl.service.impl.scrubber.DemergerReportData;
034: import org.kuali.module.gl.service.impl.scrubber.ScrubberReportData;
035: import org.kuali.module.gl.util.BalanceEncumbranceReport;
036: import org.kuali.module.gl.util.BalanceReport;
037: import org.kuali.module.gl.util.LedgerEntryHolder;
038: import org.kuali.module.gl.util.LedgerReport;
039: import org.kuali.module.gl.util.Message;
040: import org.kuali.module.gl.util.PosterOutputSummaryEntry;
041: import org.kuali.module.gl.util.PosterOutputSummaryReport;
042: import org.kuali.module.gl.util.Summary;
043: import org.kuali.module.gl.util.TransactionListingReport;
044: import org.kuali.module.gl.util.TransactionReport;
045: import org.kuali.module.labor.bo.LaborBalanceSummary;
046: import org.kuali.module.labor.document.LaborCorrectionDocument;
047: import org.kuali.module.labor.report.LaborCorrectionOnlineReport;
048: import org.kuali.module.labor.report.TransactionSummaryReport;
049: import org.kuali.module.labor.service.LaborLedgerBalanceService;
050: import org.kuali.module.labor.service.LaborOriginEntryService;
051: import org.kuali.module.labor.service.LaborReportService;
052: import org.kuali.module.labor.util.ReportRegistry;
053: import org.springframework.transaction.annotation.Transactional;
054:
055: /**
056: * This class provides a set of facilities to generate reports.
057: */
058: @Transactional
059: public class LaborReportServiceImpl implements LaborReportService {
060: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
061: .getLogger(LaborReportServiceImpl.class);
062:
063: private LaborOriginEntryService laborOriginEntryService;
064: private OriginEntryService originEntryService;
065: private OriginEntryGroupService originEntryGroupService;
066: private LaborLedgerBalanceService laborLedgerBalanceService;
067:
068: /**
069: * @see org.kuali.module.labor.service.LaborReportService#generateInputSummaryReport(java.util.Collection,
070: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
071: */
072: public void generateInputSummaryReport(
073: Collection<OriginEntryGroup> groups,
074: ReportRegistry reportInfo, String reportsDirectory,
075: Date runDate) {
076: LOG.info("generateInputSummaryReport() started");
077:
078: LedgerEntryHolder ledgerEntries;
079: ledgerEntries = groups.size() > 0 ? laborOriginEntryService
080: .getSummariedEntriesByGroups(groups)
081: : new LedgerEntryHolder();
082:
083: LedgerReport ledgerReport = new LedgerReport();
084: ledgerReport.generateReport(ledgerEntries, runDate, reportInfo
085: .reportTitle(), reportInfo.reportFilename(),
086: reportsDirectory);
087: }
088:
089: /**
090: * @see org.kuali.module.labor.service.LaborReportService#generateInputSummaryReport(org.kuali.module.gl.bo.OriginEntryGroup,
091: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
092: */
093: public void generateInputSummaryReport(OriginEntryGroup group,
094: ReportRegistry reportInfo, String reportsDirectory,
095: Date runDate) {
096: LOG.info("generateInputSummaryReport() started");
097:
098: List<OriginEntryGroup> groups = new ArrayList<OriginEntryGroup>();
099: groups.add(group);
100:
101: this .generateInputSummaryReport(groups, reportInfo,
102: reportsDirectory, runDate);
103: }
104:
105: /**
106: * @see org.kuali.module.labor.service.LaborReportService#generateErrorTransactionListing(org.kuali.module.gl.bo.OriginEntryGroup,
107: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
108: */
109: public void generateErrorTransactionListing(OriginEntryGroup group,
110: ReportRegistry reportInfo, String reportsDirectory,
111: Date runDate) {
112: LOG.info("generateErrorTransactionListing() started");
113:
114: Iterator entries = laborOriginEntryService
115: .getEntriesByGroup(group);
116: TransactionListingReport transactionListingReport = new TransactionListingReport();
117: transactionListingReport.generateReport(entries, runDate,
118: reportInfo.reportTitle(), reportInfo.reportFilename(),
119: reportsDirectory);
120: }
121:
122: /**
123: * @see org.kuali.module.labor.service.LaborReportService#generateStatisticsReport(java.util.List, java.util.Map,
124: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
125: */
126: public void generateStatisticsReport(List<Summary> reportSummary,
127: Map<Transaction, List<Message>> errors,
128: ReportRegistry reportInfo, String reportsDirectory,
129: Date runDate) {
130: LOG.info("generateStatisticsReport() started");
131:
132: TransactionReport transactionReport = new TransactionReport();
133: transactionReport.generateReport(errors, reportSummary,
134: runDate, reportInfo.reportTitle(), reportInfo
135: .reportFilename(), reportsDirectory);
136: }
137:
138: /**
139: * @see org.kuali.module.labor.service.LaborReportService#generateStatisticsReport(java.util.List,
140: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
141: */
142: public void generateStatisticsReport(List<String> reportSummary,
143: ReportRegistry reportInfo, String reportsDirectory,
144: Date runDate) {
145: LOG.info("generateStatisticsReport() started");
146:
147: TransactionSummaryReport transactionSummaryReport = new TransactionSummaryReport();
148: transactionSummaryReport.generateReport(reportSummary, runDate,
149: reportInfo.reportTitle(), reportInfo.reportFilename(),
150: reportsDirectory);
151: }
152:
153: /**
154: * @see org.kuali.module.labor.service.LaborReportService#generateOutputSummaryReport(java.util.Collection,
155: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
156: */
157: public void generateOutputSummaryReport(
158: Collection<OriginEntryGroup> groups,
159: ReportRegistry reportInfo, String reportsDirectory,
160: Date runDate) {
161: LOG.info("generateOutputSummaryReport() started");
162:
163: PosterOutputSummaryReport posterOutputSummaryReport = new PosterOutputSummaryReport();
164: Map<String, PosterOutputSummaryEntry> posterOutputSummary = laborOriginEntryService
165: .getPosterOutputSummaryByGroups(groups);
166: posterOutputSummaryReport.generateReport(posterOutputSummary,
167: runDate, reportInfo.reportTitle(), reportInfo
168: .reportFilename(), reportsDirectory);
169: }
170:
171: /**
172: * @see org.kuali.module.labor.service.LaborReportService#generateOutputSummaryReport(org.kuali.module.gl.bo.OriginEntryGroup,
173: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
174: */
175: public void generateOutputSummaryReport(OriginEntryGroup group,
176: ReportRegistry reportInfo, String reportsDirectory,
177: Date runDate) {
178: LOG.info("generateOutputSummaryReport() started");
179:
180: List<OriginEntryGroup> groups = new ArrayList<OriginEntryGroup>();
181: groups.add(group);
182: this .generateOutputSummaryReport(groups, reportInfo,
183: reportsDirectory, runDate);
184: }
185:
186: /**
187: * @see org.kuali.module.labor.service.LaborReportService#generateMonthlyBalanceSummaryReport(java.lang.Integer, java.util.List,
188: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
189: */
190: public void generateMonthlyBalanceSummaryReport(Integer fiscalYear,
191: List<String> balanceTypes, ReportRegistry reportInfo,
192: String reportsDirectory, Date runDate) {
193: LOG.info("generateMonthlyBalanceSummaryReport() started");
194:
195: List<LaborBalanceSummary> balanceSummary = laborLedgerBalanceService
196: .findBalanceSummary(fiscalYear, balanceTypes);
197: List<GlSummary> summary = new ArrayList<GlSummary>(
198: balanceSummary);
199:
200: BalanceReport report = new BalanceReport();
201: String filePrefix = reportInfo.reportFilename() + "_"
202: + fiscalYear;
203: String reportTitle = reportInfo.reportTitle()
204: + " for Fiscal Year " + fiscalYear;
205: report.generateReport(summary, balanceTypes, runDate,
206: reportTitle, filePrefix, reportsDirectory);
207: }
208:
209: /**
210: * @see org.kuali.module.labor.service.LaborReportService#generateBalanceSummaryReport(java.lang.Integer, java.util.List,
211: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
212: */
213: public void generateBalanceSummaryReport(Integer fiscalYear,
214: List<String> balanceTypes, ReportRegistry reportInfo,
215: String reportsDirectory, Date runDate) {
216: LOG.info("generateBalanceSummaryReport() started");
217:
218: List<LaborBalanceSummary> balanceSummary = laborLedgerBalanceService
219: .findBalanceSummary(fiscalYear, balanceTypes);
220: List<GlSummary> summary = new ArrayList<GlSummary>(
221: balanceSummary);
222:
223: BalanceEncumbranceReport report = new BalanceEncumbranceReport();
224: String filePrefix = reportInfo.reportFilename() + "_"
225: + fiscalYear;
226: String reportTitle = reportInfo.reportTitle()
227: + " for Fiscal Year " + fiscalYear;
228: report.generateReport(summary, balanceTypes, runDate,
229: reportTitle, filePrefix, reportsDirectory);
230: }
231:
232: /**
233: * @see org.kuali.module.labor.service.LaborReportService#generateFeedSummaryReport(org.kuali.module.gl.bo.OriginEntryGroup,
234: * org.kuali.module.labor.util.ReportRegistry, java.lang.String, java.util.Date)
235: */
236: public void generateGLSummaryReport(OriginEntryGroup group,
237: ReportRegistry reportInfo, String reportsDirectory,
238: Date runDate) {
239: LOG.info("generateFeedSummaryReport() started");
240:
241: List<OriginEntryGroup> groups = new ArrayList<OriginEntryGroup>();
242: groups.add(group);
243:
244: LedgerEntryHolder ledgerEntries;
245: ledgerEntries = groups.size() > 0 ? originEntryService
246: .getSummaryByGroupId(groups) : new LedgerEntryHolder();
247:
248: LedgerReport ledgerReport = new LedgerReport();
249: ledgerReport.generateReport(ledgerEntries, runDate, reportInfo
250: .reportTitle(), reportInfo.reportFilename(),
251: reportsDirectory);
252: }
253:
254: /**
255: * @see org.kuali.module.labor.service.LaborReportService#generateScrubberLedgerSummaryReportBatch(java.util.Collection,
256: * java.lang.String, java.util.Date)
257: */
258: public void generateScrubberLedgerSummaryReportBatch(
259: Collection groups, String reportsDirectory, Date runDate) {
260: // LOG.debug("generateScrubberLedgerSummaryReport() started");
261:
262: LedgerReport ledgerReport = new LedgerReport();
263: LedgerEntryHolder ledgerEntries = new LedgerEntryHolder();
264: if (groups.size() > 0) {
265: ledgerEntries = laborOriginEntryService
266: .getSummaryByGroupId(groups);
267: }
268:
269: ledgerReport.generateReport(ledgerEntries, runDate,
270: "Labor Ledger Report", "labor_scrubber_ledger",
271: reportsDirectory);
272: }
273:
274: /**
275: * @see org.kuali.module.labor.service.LaborReportService#generateScrubberLedgerSummaryReportOnline(org.kuali.module.gl.bo.OriginEntryGroup,
276: * java.lang.String, java.lang.String, java.util.Date)
277: */
278: public void generateScrubberLedgerSummaryReportOnline(
279: OriginEntryGroup group, String documentNumber,
280: String reportsDirectory, Date runDate) {
281: // LOG.debug("generateScrubberLedgerSummaryReport() started");
282:
283: LedgerReport ledgerReport = new LedgerReport();
284: LedgerEntryHolder ledgerEntries = new LedgerEntryHolder();
285:
286: Collection g = new ArrayList();
287: g.add(group);
288:
289: ledgerEntries = laborOriginEntryService.getSummaryByGroupId(g);
290:
291: ledgerReport.generateReport(ledgerEntries, runDate,
292: "Labor Ledger Report", "labor_scrubber_ledger_"
293: + documentNumber, reportsDirectory);
294: }
295:
296: /**
297: * @see org.kuali.module.labor.service.LaborReportService#generateBatchScrubberStatisticsReport(org.kuali.module.gl.service.impl.scrubber.ScrubberReportData,
298: * java.util.Map, java.lang.String, java.util.Date)
299: */
300: public void generateBatchScrubberStatisticsReport(
301: ScrubberReportData scrubberReport,
302: Map<Transaction, List<Message>> scrubberReportErrors,
303: String reportsDirectory, Date runDate) {
304: // LOG.debug("generateScrubberStatisticsReport() started");
305:
306: List tranKeys = new ArrayList();
307: tranKeys.addAll(scrubberReportErrors.keySet());
308:
309: Collections.sort(tranKeys, new Comparator<Transaction>() {
310: public int compare(Transaction t1, Transaction t2) {
311: StringBuffer sb1 = new StringBuffer();
312: sb1.append(t1.getFinancialDocumentTypeCode());
313: sb1.append(t1.getFinancialSystemOriginationCode());
314: sb1.append(t1.getDocumentNumber());
315: sb1.append(t1.getChartOfAccountsCode());
316: sb1.append(t1.getAccountNumber());
317: sb1.append(t1.getSubAccountNumber());
318: sb1.append(t1.getFinancialBalanceTypeCode());
319:
320: StringBuffer sb2 = new StringBuffer();
321: sb2.append(t2.getFinancialDocumentTypeCode());
322: sb2.append(t2.getFinancialSystemOriginationCode());
323: sb2.append(t2.getDocumentNumber());
324: sb2.append(t2.getChartOfAccountsCode());
325: sb2.append(t2.getAccountNumber());
326: sb2.append(t2.getSubAccountNumber());
327: sb2.append(t2.getFinancialBalanceTypeCode());
328: return sb1.toString().compareTo(sb2.toString());
329: }
330: });
331:
332: List summary = buildScrubberReportSummary(scrubberReport);
333:
334: TransactionReport transactionReport = new TransactionReport();
335: transactionReport.generateReport(tranKeys,
336: scrubberReportErrors, summary, runDate,
337: "Labor Scrubber Report ", "labor_scrubber_errors",
338: reportsDirectory);
339: }
340:
341: /**
342: * @see org.kuali.module.labor.service.LaborReportService#generateOnlineScrubberStatisticsReport(java.lang.Integer,
343: * org.kuali.module.gl.service.impl.scrubber.ScrubberReportData, java.util.Map, java.lang.String, java.lang.String,
344: * java.util.Date)
345: */
346: public void generateOnlineScrubberStatisticsReport(Integer groupId,
347: ScrubberReportData scrubberReport,
348: Map<Transaction, List<Message>> scrubberReportErrors,
349: String documentNumber, String reportsDirectory, Date runDate) {
350: // log.debug("generateScrubberStatisticsReport() started");
351:
352: List summary = buildScrubberReportSummary(scrubberReport);
353:
354: TransactionReport transactionReport = new TransactionReport();
355: transactionReport.generateReport(scrubberReportErrors, summary,
356: runDate, "Labor Scrubber Report ",
357: "labor_scrubber_errors_" + documentNumber,
358: reportsDirectory);
359: }
360:
361: /**
362: * @see org.kuali.module.labor.service.LaborReportService#generateScrubberDemergerStatisticsReports(org.kuali.module.gl.service.impl.scrubber.DemergerReportData,
363: * java.lang.String, java.util.Date)
364: */
365: public void generateScrubberDemergerStatisticsReports(
366: DemergerReportData demergerReport, String reportsDirectory,
367: Date runDate) {
368: // log.debug("generateScrubberDemergerStatisticsReports() started");
369:
370: List summary = buildDemergerReportSummary(demergerReport);
371:
372: Map<Transaction, List<Message>> empty = new HashMap<Transaction, List<Message>>();
373:
374: TransactionReport transactionReport = new TransactionReport();
375: transactionReport.generateReport(empty, summary, runDate,
376: "Labor Demerger Report ", "labor_demerger",
377: reportsDirectory);
378: }
379:
380: /**
381: * @see org.kuali.module.labor.service.LaborReportService#generateScrubberBadBalanceTypeListingReport(java.util.Collection,
382: * java.lang.String, java.util.Date)
383: */
384: public void generateScrubberBadBalanceTypeListingReport(
385: Collection groups, String reportsDirectory, Date runDate) {
386: // log.debug("generateScrubberBadBalanceTypeListingReport() started");
387:
388: Iterator i = null;
389: if (groups.size() > 0) {
390: i = laborOriginEntryService.getBadBalanceEntries(groups);
391: }
392:
393: TransactionListingReport rept = new TransactionListingReport();
394: rept
395: .generateReport(
396: i,
397: runDate,
398: "Labor Scrubber Input Transactions with Bad Balance Types",
399: "labor_scrubber_badbal", reportsDirectory);
400: }
401:
402: /**
403: * @see org.kuali.module.labor.service.LaborReportService#generateScrubberTransactionsOnline(org.kuali.module.gl.bo.OriginEntryGroup,
404: * java.lang.String, java.lang.String, java.util.Date)
405: */
406: public void generateScrubberTransactionsOnline(
407: OriginEntryGroup validGroup, String documentNumber,
408: String reportsDirectory, Date runDate) {
409: // log.debug("generateScrubberTransactionsOnline() started");
410:
411: Iterator ti = laborOriginEntryService
412: .getEntriesByGroupAccountOrder(validGroup);
413:
414: TransactionListingReport rept = new TransactionListingReport();
415: rept.generateReport(ti, runDate,
416: "Labor Output Transaction Listing From the Scrubber",
417: "labor_scrubber_listing_" + documentNumber,
418: reportsDirectory);
419: }
420:
421: /**
422: * @see org.kuali.module.labor.service.LaborReportService#generateScrubberRemovedTransactions(org.kuali.module.gl.bo.OriginEntryGroup,
423: * java.lang.String, java.util.Date)
424: */
425: public void generateScrubberRemovedTransactions(
426: OriginEntryGroup errorGroup, String reportsDirectory,
427: Date runDate) {
428: // log.debug("generateScrubberRemovedTransactions() started");
429:
430: Iterator ti = laborOriginEntryService
431: .getEntriesByGroupListingReportOrder(errorGroup);
432:
433: TransactionListingReport rept = new TransactionListingReport();
434: rept
435: .generateReport(
436: ti,
437: runDate,
438: "Labor Error Listing - Transactions Removed From the Scrubber",
439: "labor_scrubber_error_listing",
440: reportsDirectory);
441: }
442:
443: /**
444: * @see org.kuali.module.labor.service.LaborReportService#generateCorrectionOnlineReport(org.kuali.module.labor.document.LaborCorrectionDocument,
445: * java.lang.String, java.util.Date)
446: */
447: public void generateCorrectionOnlineReport(
448: LaborCorrectionDocument cDocument, String reportsDirectory,
449: Date runDate) {
450: LOG.debug("correctionOnlineReport() started");
451: LaborCorrectionOnlineReport correctionOnlineReport = new LaborCorrectionOnlineReport();
452: correctionOnlineReport.generateReport(cDocument,
453: reportsDirectory, runDate);
454: }
455:
456: /**
457: * Sets the originEntryGroupService attribute value.
458: *
459: * @param originEntryGroupService The originEntryGroupService to set.
460: */
461: public void setOriginEntryGroupService(
462: OriginEntryGroupService originEntryGroupService) {
463: this .originEntryGroupService = originEntryGroupService;
464: }
465:
466: /**
467: * Sets the laborOriginEntryService attribute value.
468: *
469: * @param laborOriginEntryService The laborOriginEntryService to set.
470: */
471: public void setLaborOriginEntryService(
472: LaborOriginEntryService laborOriginEntryService) {
473: this .laborOriginEntryService = laborOriginEntryService;
474: }
475:
476: /**
477: * Generate the header for the scrubber status report.
478: *
479: * @param scrubberReport
480: * @return list of report summaries to be printed
481: */
482: private List<Summary> buildScrubberReportSummary(
483: ScrubberReportData scrubberReport) {
484: List<Summary> reportSummary = new ArrayList<Summary>();
485:
486: reportSummary.add(new Summary(2, "UNSCRUBBED RECORDS READ",
487: new Integer(scrubberReport
488: .getNumberOfUnscrubbedRecordsRead())));
489: reportSummary.add(new Summary(3, "SCRUBBED RECORDS WRITTEN",
490: new Integer(scrubberReport
491: .getNumberOfScrubbedRecordsWritten())));
492: reportSummary.add(new Summary(4, "ERROR RECORDS WRITTEN",
493: new Integer(scrubberReport
494: .getNumberOfErrorRecordsWritten())));
495: reportSummary.add(new Summary(11,
496: "TOTAL OUTPUT RECORDS WRITTEN",
497: new Integer(scrubberReport
498: .getTotalNumberOfRecordsWritten())));
499: reportSummary.add(new Summary(12, "EXPIRED ACCOUNTS FOUND",
500: new Integer(scrubberReport
501: .getNumberOfExpiredAccountsFound())));
502:
503: return reportSummary;
504: }
505:
506: /**
507: * Generate the header for the demerger status report.
508: *
509: * @param demergerReport
510: * @return list of report summaries to be printed
511: */
512: private List<Summary> buildDemergerReportSummary(
513: DemergerReportData demergerReport) {
514: List<Summary> reportSummary = new ArrayList<Summary>();
515:
516: reportSummary.add(new Summary(1,
517: "SCRUBBER ERROR TRANSACTIONS READ", new Integer(
518: demergerReport.getErrorTransactionsRead())));
519: reportSummary
520: .add(new Summary(3, "DEMERGER ERRORS SAVED",
521: new Integer(demergerReport
522: .getErrorTransactionsSaved())));
523: reportSummary.add(new Summary(4,
524: "DEMERGER VALID TRANSACTIONS SAVED", new Integer(
525: demergerReport.getValidTransactionsSaved())));
526:
527: return reportSummary;
528: }
529:
530: /**
531: * Sets the laborLedgerBalanceService attribute value.
532: *
533: * @param laborLedgerBalanceService The laborLedgerBalanceService to set.
534: */
535: public void setLaborLedgerBalanceService(
536: LaborLedgerBalanceService laborLedgerBalanceService) {
537: this .laborLedgerBalanceService = laborLedgerBalanceService;
538: }
539:
540: /**
541: * Sets the originEntryService attribute value.
542: *
543: * @param originEntryService The originEntryService to set.
544: */
545: public void setOriginEntryService(
546: OriginEntryService originEntryService) {
547: this.originEntryService = originEntryService;
548: }
549: }
|