001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.module.cab.batch.service.impl;
017
018 import java.io.File;
019 import java.util.ArrayList;
020 import java.util.HashMap;
021 import java.util.List;
022 import java.util.Map;
023 import java.util.ResourceBundle;
024
025 import net.sf.jasperreports.engine.JRParameter;
026
027 import org.kuali.kfs.module.cab.batch.ExtractProcessLog;
028 import org.kuali.kfs.module.cab.batch.service.BatchExtractReportService;
029 import org.kuali.kfs.sys.KFSConstants.ReportGeneration;
030 import org.kuali.kfs.sys.report.ReportInfo;
031 import org.kuali.kfs.sys.service.ReportGenerationService;
032 import org.kuali.rice.kns.service.DateTimeService;
033
034 public class BatchExtractReportServiceImpl implements BatchExtractReportService {
035 protected ReportGenerationService reportGenerationService;
036 protected ReportInfo cabBatchStatusReportInfo;
037 protected ReportInfo cabBatchMismatchReportInfo;
038
039 protected DateTimeService dateTimeService;
040
041 /**
042 * @see org.kuali.kfs.module.cab.batch.service.BatchExtractReportService#generateStatusReportPDF(org.kuali.kfs.module.cab.batch.ExtractProcessLog)
043 */
044 public File generateStatusReportPDF(ExtractProcessLog extractProcessLog) {
045 String reportFileName = cabBatchStatusReportInfo.getReportFileName();
046 String reportDirectoty = cabBatchStatusReportInfo.getReportsDirectory();
047 String reportTemplateClassPath = cabBatchStatusReportInfo.getReportTemplateClassPath();
048 String reportTemplateName = cabBatchStatusReportInfo.getReportTemplateName();
049 ResourceBundle resourceBundle = cabBatchStatusReportInfo.getResourceBundle();
050 String subReportTemplateClassPath = cabBatchStatusReportInfo.getSubReportTemplateClassPath();
051 Map<String, String> subReports = cabBatchStatusReportInfo.getSubReports();
052 Map<String, Object> reportData = new HashMap<String, Object>();
053 reportData.put(JRParameter.REPORT_RESOURCE_BUNDLE, resourceBundle);
054 reportData.put(ReportGeneration.PARAMETER_NAME_SUBREPORT_DIR, subReportTemplateClassPath);
055 reportData.put(ReportGeneration.PARAMETER_NAME_SUBREPORT_TEMPLATE_NAME, subReports);
056 String template = reportTemplateClassPath + reportTemplateName;
057 String fullReportFileName = reportGenerationService.buildFullFileName(dateTimeService.getCurrentDate(), reportDirectoty, reportFileName, "");
058 List<ExtractProcessLog> dataSource = new ArrayList<ExtractProcessLog>();
059 dataSource.add(extractProcessLog);
060 reportGenerationService.generateReportToPdfFile(reportData, dataSource, template, fullReportFileName);
061 return new File(fullReportFileName + ".pdf");
062 }
063
064 /**
065 * @see org.kuali.kfs.module.cab.batch.service.BatchExtractReportService#generateMismatchReportPDF(org.kuali.kfs.module.cab.batch.ExtractProcessLog)
066 */
067 public File generateMismatchReportPDF(ExtractProcessLog extractProcessLog) {
068 String reportFileName = cabBatchMismatchReportInfo.getReportFileName();
069 String reportDirectoty = cabBatchMismatchReportInfo.getReportsDirectory();
070 String reportTemplateClassPath = cabBatchMismatchReportInfo.getReportTemplateClassPath();
071 String reportTemplateName = cabBatchMismatchReportInfo.getReportTemplateName();
072 ResourceBundle resourceBundle = cabBatchMismatchReportInfo.getResourceBundle();
073 String subReportTemplateClassPath = cabBatchMismatchReportInfo.getSubReportTemplateClassPath();
074 Map<String, String> subReports = cabBatchMismatchReportInfo.getSubReports();
075 Map<String, Object> reportData = new HashMap<String, Object>();
076 reportData.put(JRParameter.REPORT_RESOURCE_BUNDLE, resourceBundle);
077 reportData.put(ReportGeneration.PARAMETER_NAME_SUBREPORT_DIR, subReportTemplateClassPath);
078 reportData.put(ReportGeneration.PARAMETER_NAME_SUBREPORT_TEMPLATE_NAME, subReports);
079 String template = reportTemplateClassPath + reportTemplateName;
080 String fullReportFileName = reportGenerationService.buildFullFileName(dateTimeService.getCurrentDate(), reportDirectoty, reportFileName, "");
081 List<ExtractProcessLog> dataSource = new ArrayList<ExtractProcessLog>();
082 dataSource.add(extractProcessLog);
083 reportGenerationService.generateReportToPdfFile(reportData, dataSource, template, fullReportFileName);
084 return new File(fullReportFileName + ".pdf");
085 }
086
087 /**
088 * Gets the reportGenerationService attribute.
089 *
090 * @return Returns the reportGenerationService.
091 */
092 public ReportGenerationService getReportGenerationService() {
093 return reportGenerationService;
094 }
095
096 /**
097 * Sets the reportGenerationService attribute value.
098 *
099 * @param reportGenerationService The reportGenerationService to set.
100 */
101 public void setReportGenerationService(ReportGenerationService reportGenerationService) {
102 this.reportGenerationService = reportGenerationService;
103 }
104
105 /**
106 * Gets the cabBatchStatusReportInfo attribute.
107 *
108 * @return Returns the cabBatchStatusReportInfo.
109 */
110 public ReportInfo getCabBatchStatusReportInfo() {
111 return cabBatchStatusReportInfo;
112 }
113
114 /**
115 * Sets the cabBatchStatusReportInfo attribute value.
116 *
117 * @param cabBatchStatusReportInfo The cabBatchStatusReportInfo to set.
118 */
119 public void setCabBatchStatusReportInfo(ReportInfo cabBatchStatusReportInfo) {
120 this.cabBatchStatusReportInfo = cabBatchStatusReportInfo;
121 }
122
123
124 /**
125 * Gets the dateTimeService attribute.
126 *
127 * @return Returns the dateTimeService.
128 */
129 public DateTimeService getDateTimeService() {
130 return dateTimeService;
131 }
132
133 /**
134 * Sets the dateTimeService attribute value.
135 *
136 * @param dateTimeService The dateTimeService to set.
137 */
138 public void setDateTimeService(DateTimeService dateTimeService) {
139 this.dateTimeService = dateTimeService;
140 }
141
142 /**
143 * Gets the cabBatchMismatchReportInfo attribute.
144 *
145 * @return Returns the cabBatchMismatchReportInfo.
146 */
147 public ReportInfo getCabBatchMismatchReportInfo() {
148 return cabBatchMismatchReportInfo;
149 }
150
151 /**
152 * Sets the cabBatchMismatchReportInfo attribute value.
153 *
154 * @param cabBatchMismatchReportInfo The cabBatchMismatchReportInfo to set.
155 */
156 public void setCabBatchMismatchReportInfo(ReportInfo cabBatchMismatchReportInfo) {
157 this.cabBatchMismatchReportInfo = cabBatchMismatchReportInfo;
158 }
159 }