| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.services.implementations; |
| 20 |
|
|
| 21 |
|
import java.io.File; |
| 22 |
|
import java.io.IOException; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
import java.util.List; |
| 25 |
|
import java.util.Locale; |
| 26 |
|
import java.util.Map; |
| 27 |
|
|
| 28 |
|
import javax.servlet.ServletOutputStream; |
| 29 |
|
import javax.servlet.http.HttpServletRequest; |
| 30 |
|
import javax.servlet.http.HttpServletResponse; |
| 31 |
|
import javax.servlet.http.HttpSession; |
| 32 |
|
import javax.swing.JFrame; |
| 33 |
|
|
| 34 |
|
import net.sf.jasperreports.engine.JRDataSource; |
| 35 |
|
import net.sf.jasperreports.engine.JRException; |
| 36 |
|
import net.sf.jasperreports.engine.JRExporterParameter; |
| 37 |
|
import net.sf.jasperreports.engine.JasperExportManager; |
| 38 |
|
import net.sf.jasperreports.engine.JasperFillManager; |
| 39 |
|
import net.sf.jasperreports.engine.JasperPrint; |
| 40 |
|
import net.sf.jasperreports.engine.JasperReport; |
| 41 |
|
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; |
| 42 |
|
import net.sf.jasperreports.engine.export.JRCsvExporter; |
| 43 |
|
import net.sf.jasperreports.engine.export.JRHtmlExporter; |
| 44 |
|
import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; |
| 45 |
|
import net.sf.jasperreports.engine.export.JRXlsExporter; |
| 46 |
|
import net.sf.jasperreports.engine.util.JRLoader; |
| 47 |
|
import net.sf.jasperreports.view.JRViewer; |
| 48 |
|
|
| 49 |
|
import org.apache.struts.action.ActionMapping; |
| 50 |
|
import org.apache.struts.util.RequestUtils; |
| 51 |
|
import org.itracker.core.resources.ITrackerResources; |
| 52 |
|
import org.itracker.model.Issue; |
| 53 |
|
import org.itracker.model.Report; |
| 54 |
|
import org.itracker.persistence.dao.ReportDAO; |
| 55 |
|
import org.itracker.services.ReportService; |
| 56 |
|
import org.itracker.services.exceptions.ReportException; |
| 57 |
|
import org.itracker.web.util.Constants; |
| 58 |
|
|
|
|
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 18 |
Complexity Density: 0.26 |
|
| 59 |
|
public class ReportServiceImpl implements ReportService { |
| 60 |
|
|
| 61 |
|
private final ReportDAO reportDAO; |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 63 |
0
|
public ReportServiceImpl(ReportDAO reportDAO) {... |
| 64 |
0
|
this.reportDAO = reportDAO; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 68 |
0
|
public List<Report> getAllReports() {... |
| 69 |
0
|
return reportDAO.findAll(); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 73 |
0
|
public int getNumberReports() {... |
| 74 |
0
|
return reportDAO.findAll().size(); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 78 |
0
|
public Report createReport(Report report) {... |
| 79 |
|
|
| 80 |
|
|
| 81 |
0
|
reportDAO.save(report); |
| 82 |
0
|
return report; |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 85 |
0
|
private JasperPrint generateReport(Report report,... |
| 86 |
|
Map<String, Object> parameters, Object datasource) { |
| 87 |
0
|
try { |
| 88 |
|
|
| 89 |
0
|
JasperReport jasperReport = getJasperReport(report); |
| 90 |
0
|
JasperPrint jasperPrint = JasperFillManager.fillReport( |
| 91 |
|
jasperReport, parameters, (JRDataSource) datasource); |
| 92 |
0
|
return jasperPrint; |
| 93 |
|
} catch (JRException e) { |
| 94 |
0
|
throw new ReportException(e); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
0
|
private JasperReport getJasperReport(Report report) throws JRException {... |
| 100 |
0
|
return (JasperReport) JRLoader.loadObject(report.getReportDefinition()); |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 103 |
0
|
public ReportDAO getReportDAO() {... |
| 104 |
0
|
return reportDAO; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
@deprecated |
| 112 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 4 |
Complexity Density: 0.2 |
|
| 113 |
0
|
public void outputPDF(List<Issue> reportDataArray, Report report,... |
| 114 |
|
Locale userLocale, String reportOutput, HttpSession session, |
| 115 |
|
HttpServletRequest request, HttpServletResponse response, |
| 116 |
|
ActionMapping mapping) { |
| 117 |
|
|
| 118 |
0
|
try { |
| 119 |
|
|
| 120 |
|
|
| 121 |
0
|
JRBeanCollectionDataSource beanCollectionDataSource; |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
0
|
beanCollectionDataSource = new JRBeanCollectionDataSource( |
| 133 |
|
reportDataArray); |
| 134 |
|
|
| 135 |
|
|
| 136 |
0
|
Map<String, Object> parameters = new HashMap<String, Object>(); |
| 137 |
0
|
String reportTitle = report.getName(); |
| 138 |
0
|
if (report.getNameKey() != null) { |
| 139 |
0
|
reportTitle = ITrackerResources.getString(report.getNameKey()); |
| 140 |
|
} |
| 141 |
0
|
parameters.put("ReportTitle", reportTitle); |
| 142 |
0
|
parameters.put("BaseDir", new File(".")); |
| 143 |
0
|
JasperPrint jasperPrint = generateReport(report, parameters, |
| 144 |
|
beanCollectionDataSource); |
| 145 |
|
|
| 146 |
|
|
| 147 |
0
|
JRViewer jrViewer = new JRViewer(jasperPrint); |
| 148 |
0
|
JFrame frame = new JFrame(); |
| 149 |
0
|
frame.add(jrViewer); |
| 150 |
|
|
| 151 |
|
|
| 152 |
0
|
response.setHeader("Content-Type", "application/pdf"); |
| 153 |
0
|
ServletOutputStream out = response.getOutputStream(); |
| 154 |
|
|
| 155 |
0
|
JasperExportManager.exportReportToPdfStream(jasperPrint, out); |
| 156 |
|
|
| 157 |
0
|
out.flush(); |
| 158 |
0
|
out.close(); |
| 159 |
|
} catch (JRException e) { |
| 160 |
|
|
| 161 |
0
|
throw new ReportException(e); |
| 162 |
|
} catch (IOException e) { |
| 163 |
0
|
throw new ReportException(e); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
|
@deprecated |
| 169 |
|
@param |
| 170 |
|
@param |
| 171 |
|
@param |
| 172 |
|
@throws |
| 173 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 174 |
0
|
public void outputCSV(HttpServletRequest request,... |
| 175 |
|
HttpServletResponse response, ActionMapping mapping) |
| 176 |
|
throws ReportException { |
| 177 |
0
|
try { |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
0
|
JRCsvExporter exporter = new JRCsvExporter(); |
| 184 |
|
|
| 185 |
0
|
response.setHeader("Content-Disposition", |
| 186 |
|
"inline; filename=\"itrackerreport.csv\""); |
| 187 |
0
|
response.setHeader("Content-Type", "text/csv; charset=UTF-8"); |
| 188 |
0
|
ServletOutputStream out = response.getOutputStream(); |
| 189 |
|
|
| 190 |
0
|
exporter.setParameter(JRExporterParameter.JASPER_PRINT, null); |
| 191 |
0
|
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); |
| 192 |
0
|
exporter.exportReport(); |
| 193 |
|
|
| 194 |
0
|
out.flush(); |
| 195 |
0
|
out.close(); |
| 196 |
|
} catch (Exception e) { |
| 197 |
|
|
| 198 |
0
|
throw new ReportException(e.getMessage()); |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
@param |
| 206 |
|
|
| 207 |
|
@deprecated |
| 208 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 209 |
0
|
public void outputXLS(HttpServletRequest request,... |
| 210 |
|
HttpServletResponse response, ActionMapping mapping) |
| 211 |
|
throws ReportException { |
| 212 |
0
|
try { |
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
0
|
JRXlsExporter exporter = new JRXlsExporter(); |
| 219 |
|
|
| 220 |
0
|
response.setHeader("Content-Disposition", |
| 221 |
|
"inline; filename=\"itrackerreport.xls\""); |
| 222 |
0
|
response.setHeader("Content-Type", |
| 223 |
|
"application/vnd.ms-excel; charset=UTF-8"); |
| 224 |
0
|
ServletOutputStream out = response.getOutputStream(); |
| 225 |
|
|
| 226 |
0
|
exporter.setParameter(JRExporterParameter.JASPER_PRINT, null); |
| 227 |
0
|
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); |
| 228 |
0
|
exporter.exportReport(); |
| 229 |
|
|
| 230 |
0
|
out.flush(); |
| 231 |
0
|
out.close(); |
| 232 |
|
} catch (Exception e) { |
| 233 |
|
|
| 234 |
0
|
throw new ReportException(e.getMessage()); |
| 235 |
|
} |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
|
@param |
| 242 |
|
|
| 243 |
|
@deprecated |
| 244 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 2 |
Complexity Density: 0.12 |
|
| 245 |
0
|
public void outputHTML(HttpServletRequest request,... |
| 246 |
|
HttpServletResponse response, ActionMapping mapping) |
| 247 |
|
throws ReportException { |
| 248 |
0
|
try { |
| 249 |
|
|
| 250 |
|
|
| 251 |
|
|
| 252 |
|
|
| 253 |
|
|
| 254 |
0
|
JRHtmlExporter exporter = new JRHtmlExporter(); |
| 255 |
|
|
| 256 |
0
|
Map<Object, Object> imagesMap = new HashMap<Object, Object>(); |
| 257 |
0
|
HttpSession session = request.getSession(true); |
| 258 |
0
|
session.setAttribute(Constants.REPORT_IMAGEMAP_KEY, imagesMap); |
| 259 |
|
|
| 260 |
0
|
response.setHeader("Content-Disposition", |
| 261 |
|
"inline; filename=\"itrackerreport.html\""); |
| 262 |
0
|
response.setHeader("Content-Type", "text/html; charset=UTF-8"); |
| 263 |
0
|
ServletOutputStream out = response.getOutputStream(); |
| 264 |
|
|
| 265 |
0
|
exporter.setParameter(JRExporterParameter.JASPER_PRINT, null); |
| 266 |
0
|
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); |
| 267 |
0
|
exporter |
| 268 |
|
.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); |
| 269 |
|
|
| 270 |
|
|
| 271 |
0
|
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, |
| 272 |
|
RequestUtils.printableURL(RequestUtils.absoluteURL(request, |
| 273 |
|
RequestUtils.forwardURL(request, mapping |
| 274 |
|
.findForward("imagesurl")))) |
| 275 |
|
+ "?image="); |
| 276 |
|
|
| 277 |
0
|
exporter.exportReport(); |
| 278 |
|
|
| 279 |
0
|
out.flush(); |
| 280 |
0
|
out.close(); |
| 281 |
|
} catch (Exception e) { |
| 282 |
|
|
| 283 |
0
|
throw new ReportException(e.getMessage()); |
| 284 |
|
} |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
} |