9150
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.common; |
|
11 |
|
12 import java.util.Collection; |
|
13 |
|
14 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
|
15 |
|
16 import net.sf.jasperreports.engine.JRException; |
|
17 |
|
18 /** |
|
19 * @author Domenico Nardi Tironi |
|
20 */ |
9195
|
21 public abstract class AbstractCalculationExportableResult extends AbstractCalculationResult { |
9150
|
22 |
|
23 private static final long serialVersionUID = 1L; |
|
24 |
|
25 public AbstractCalculationExportableResult(final String label, final Collection<ResultRow> rows) { |
|
26 super(label, rows); |
|
27 } |
|
28 |
9195
|
29 public abstract void writeCSVHeader(ExportContextCSV exportContextCSV, final RiverInfo river); |
9150
|
30 |
9195
|
31 public final void writeCsv(final ExportContextCSV exportContextCSV) { |
9150
|
32 |
9195
|
33 writeCSVResultMetadata(exportContextCSV); |
9150
|
34 // wenn resultsmetadata null sind!? keine neue zeile |
|
35 // writer.writeNext(new String[] { "" }); // break line in den Implementationen, |
|
36 // weil es sein kann, dass KEINE ResultMetadata geschrieben werden; dann wäre eine Leerzeile überflüssig |
|
37 |
|
38 /* now the value rows */ |
|
39 final Collection<ResultRow> rows = getRows(); |
|
40 for (final ResultRow row : rows) |
9195
|
41 writeCSVRow(exportContextCSV, row); |
9150
|
42 } |
|
43 |
9195
|
44 protected abstract void writeCSVResultMetadata(final ExportContextCSV exportContextCSV); |
9150
|
45 |
9195
|
46 protected void writeCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
|
47 final String[] formattedRow = formatCSVRow(exportContextCSV, row); |
9150
|
48 exportContextCSV.writeCSVLine(formattedRow); |
|
49 } |
|
50 |
9195
|
51 protected abstract String[] formatCSVRow(ExportContextCSV exportContextCSV, final ResultRow row); |
9150
|
52 |
9195
|
53 protected abstract String[] formatPDFRow(ExportContextPDF exportContextPDF, ResultRow row); |
9150
|
54 |
9195
|
55 public JasperDesigner addReport(final ExportContextPDF exportContext, final JasperReporter reporter, final MetaAndTableJRDataSource source) |
|
56 throws JRException { |
9150
|
57 |
|
58 final JasperDesigner design = reporter.addReport(getJasperFile(), source); |
9195
|
59 addJRTableHeader(exportContext, source); |
|
60 addJRTableData(exportContext, source); |
9150
|
61 return design; |
|
62 } |
|
63 |
|
64 protected abstract String getJasperFile(); |
|
65 |
9195
|
66 protected abstract void addJRTableHeader(ExportContextPDF exportContext, MetaAndTableJRDataSource source); |
9150
|
67 |
9195
|
68 private void addJRTableData(final ExportContextPDF exportContext, final MetaAndTableJRDataSource source) { |
9150
|
69 |
|
70 final Collection<ResultRow> rows = getRows(); |
|
71 |
|
72 for (final ResultRow row : rows) { |
|
73 |
9195
|
74 final String[] formattedRow = formatPDFRow(exportContext, row); |
9150
|
75 source.addData(formattedRow); |
|
76 } |
|
77 } |
|
78 } |