Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationExportableResult.java @ 9150:23945061daec
gigantic refactoring: exporter, result, results
to support multiple jaspers -> collisions
author | gernotbelger |
---|---|
date | Thu, 14 Jun 2018 16:56:31 +0200 |
parents | |
children | 9b2e46090099 |
comparison
equal
deleted
inserted
replaced
9149:5be112fba832 | 9150:23945061daec |
---|---|
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 */ | |
21 public abstract class AbstractCalculationExportableResult<RESULTS extends AbstractCalculationResults> extends AbstractCalculationResult { | |
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 | |
29 public abstract void writeCSVHeader(ExportContextCSV exportContextCSV, final RESULTS results, final RiverInfo river); | |
30 | |
31 public final void writeCsv(final ExportContextCSV exportContextCSV, final RESULTS results) { | |
32 | |
33 writeCSVResultMetadata(exportContextCSV, results); | |
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) | |
41 writeCSVRow(exportContextCSV, results, row); | |
42 } | |
43 | |
44 protected abstract void writeCSVResultMetadata(final ExportContextCSV exportContextCSV, final RESULTS results); | |
45 | |
46 protected void writeCSVRow(final ExportContextCSV exportContextCSV, final RESULTS results, final ResultRow row) { | |
47 final String[] formattedRow = formatCSVRow(exportContextCSV, results, row); | |
48 exportContextCSV.writeCSVLine(formattedRow); | |
49 | |
50 } | |
51 | |
52 protected abstract String[] formatCSVRow(ExportContextCSV exportContextCSV, final RESULTS results, final ResultRow row); | |
53 | |
54 protected abstract String[] formatPDFRow(ExportContextCSV exportContextPDF, RESULTS results, ResultRow row); | |
55 | |
56 public JasperDesigner addReport(final ExportContextCSV exportContextPDF, final RESULTS results, final JasperReporter reporter, | |
57 final MetaAndTableJRDataSource source) throws JRException { | |
58 | |
59 final JasperDesigner design = reporter.addReport(getJasperFile(), source); | |
60 addJRTableHeader(exportContextPDF, source, results); | |
61 addJRTableData(exportContextPDF, source, results); | |
62 return design; | |
63 } | |
64 | |
65 protected abstract String getJasperFile(); | |
66 | |
67 protected abstract void addJRTableHeader(ExportContextCSV exportContextPDF, MetaAndTableJRDataSource source, RESULTS results); | |
68 | |
69 private void addJRTableData(final ExportContextCSV exportContextPDF, final MetaAndTableJRDataSource source, final RESULTS results) { | |
70 | |
71 final Collection<ResultRow> rows = getRows(); | |
72 | |
73 for (final ResultRow row : rows) { | |
74 | |
75 final String[] formattedRow = formatPDFRow(exportContextPDF, results, row); | |
76 source.addData(formattedRow); | |
77 } | |
78 } | |
79 } |