annotate artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeCurveExporter.java @ 7077:0a337f0005c2 generator-refactoring

Extended init() of OutGenerator to take name of the out to serve.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 20 Sep 2013 16:34:09 +0200
parents af13ceeba52a
children 41567bf1e131
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
9 package org.dive4elements.river.exports;
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.io.OutputStream;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import java.text.NumberFormat;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import java.text.DateFormat;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import java.util.ArrayList;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import java.util.Date;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.util.List;
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
17 import java.util.Map;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
18 import java.util.HashMap;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
19 import java.util.Locale;
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import org.w3c.dom.Document;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 import org.apache.log4j.Logger;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import au.com.bytecode.opencsv.CSVWriter;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
27 import net.sf.jasperreports.engine.JasperExportManager;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
28 import net.sf.jasperreports.engine.JasperFillManager;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
29 import net.sf.jasperreports.engine.JasperPrint;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
30 import net.sf.jasperreports.engine.JRException;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
31
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
32 import org.dive4elements.artifacts.common.utils.Config;
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
34 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
35 import org.dive4elements.artifacts.CallMeta;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
36
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
37 import org.dive4elements.river.artifacts.D4EArtifact;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
38 import org.dive4elements.river.artifacts.model.CalculationResult;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
39 import org.dive4elements.river.artifacts.model.HistoricalDischargeData;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
40 import org.dive4elements.river.artifacts.model.Timerange;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
41 import org.dive4elements.river.artifacts.model.WQTimerange;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
42 import org.dive4elements.river.artifacts.model.WQTJRDataSource;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
43 import org.dive4elements.river.artifacts.resources.Resources;
5865
73da40528cf2 River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
44 import org.dive4elements.river.utils.RiverUtils;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5421
diff changeset
45 import org.dive4elements.river.utils.Formatter;
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 /**
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 */
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 public class HistoricalDischargeCurveExporter extends AbstractExporter {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 private static final Logger logger =
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 Logger.getLogger(HistoricalDischargeCurveExporter.class);
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public static final String CSV_TIMERANGE_HEADER =
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 "export.historical.discharge.csv.header.timerange";
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 public static final String CSV_WATERLEVEL_HEADER =
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 "export.historical.discharge.csv.header.waterlevel";
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 public static final String CSV_DISCHARGE_HEADER =
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 "export.historical.discharge.csv.header.discharge";
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 public static final String CSV_DIFF_HEADER =
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 "export.historical.discharge.csv.header.diff";
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 public static final String CSV_GAUGENAME_HEADER =
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 "export.historical.discharge.csv.header.gaugename";
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
72 public static final String PDF_HEADER_MODE =
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
73 "export.historical.discharge.pdf.mode";
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
74
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
75 public static final String JASPER_FILE =
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
76 "export.historical.discharge.pdf.file";
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 protected List<WQTimerange[]> data;
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
7077
0a337f0005c2 Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
80 public HistoricalDischargeCurveExporter() {
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 data = new ArrayList<WQTimerange[]>();
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 @Override
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 protected void addData(Object d) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 logger.debug("Add data of class: " + d.getClass());
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 if (d instanceof CalculationResult) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 d = ((CalculationResult) d).getData();
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 logger.debug("Internal data of CalculationResult: " + d.getClass());
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
4241
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
93 if (d instanceof HistoricalDischargeData) {
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
94 d = (WQTimerange[]) ((HistoricalDischargeData) d).getWQTimeranges();
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
95
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
96 if (d instanceof WQTimerange[]) {
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
97 logger.debug("Add new data of type WQTimerange");
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
98 data.add((WQTimerange[]) d);
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4197
diff changeset
99 }
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 @Override
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 protected void writeCSVData(CSVWriter writer) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 logger.info("HistoricalDischargeCurveExporter.writeCSVData");
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 logger.debug("CSV gets " + data.size() + " WQTimerange[] objects.");
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 writeCSVHeader(writer);
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 for (WQTimerange[] arr: data) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 for (WQTimerange wqt: arr) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 wqt2CSV(writer, wqt);
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 @Override
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 protected void writePDF(OutputStream out) {
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
122 WQTJRDataSource source = createJRData();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
123
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
124 String jasperFile = Resources.getMsg(
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
125 context.getMeta(),
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
126 JASPER_FILE,
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
127 "/jasper/historical-discharge_en.jasper");
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
128 String confPath = Config.getConfigDirectory().toString();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
129
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
130 Map parameters = new HashMap();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
131 parameters.put("ReportTitle", "Exported Data");
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
132 try {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
133 JasperPrint print = JasperFillManager.fillReport(
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
134 confPath + jasperFile,
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
135 parameters,
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
136 source);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
137 JasperExportManager.exportReportToPdfStream(print, out);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
138 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
139 catch(JRException je) {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
140 logger.warn("Error generating PDF Report!");
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
141 je.printStackTrace();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
142 }
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 protected void writeCSVHeader(CSVWriter writer) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 writer.writeNext(new String[] {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 msg(CSV_TIMERANGE_HEADER, CSV_TIMERANGE_HEADER),
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 msg(CSV_WATERLEVEL_HEADER, CSV_WATERLEVEL_HEADER),
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 msg(CSV_DISCHARGE_HEADER, CSV_DISCHARGE_HEADER),
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 msg(CSV_DIFF_HEADER, CSV_DIFF_HEADER),
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 msg(CSV_GAUGENAME_HEADER, CSV_GAUGENAME_HEADER)
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 });
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 protected void wqt2CSV(CSVWriter writer, WQTimerange wqt) {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 logger.debug("Add next WQTimerange to CSV");
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159
2588
7dd45896e941 Issue 459.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2331
diff changeset
160 DateFormat df = Formatter.getMediumDateFormat(context);
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 NumberFormat wf = Formatter.getHistoricalDischargeW(context);
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 NumberFormat qf = Formatter.getHistoricalDischargeQ(context);
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2286
diff changeset
164 double[] wq = new double[3];
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 String gaugeName = getReferenceGaugename();
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
4171
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
168 List<WQTimerange.TimerangeItem> sorted = wqt.sort();
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
169
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
170 for (int i = 0, n = sorted.size(); i < n; i++) {
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
171 WQTimerange.TimerangeItem item = sorted.get(i);
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
172
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
173 Timerange tr = item.timerange;
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 Date start = new Date(tr.getStart());
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 Date end = new Date(tr.getEnd());
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176
4171
1d8faeedda0c Sort calculation results of a historical discharge calculation based on their start date.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2588
diff changeset
177 item.get(wq);
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 writer.writeNext(new String[] {
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 df.format(start) + " - " + df.format(end),
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 wf.format(wq[0]),
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 qf.format(wq[1]),
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2286
diff changeset
183 qf.format(wq[2]),
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 gaugeName
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 });
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
190 protected WQTJRDataSource createJRData() {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
191 WQTJRDataSource source = new WQTJRDataSource();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
192
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
193 addMetaData(source);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
194 for (WQTimerange[] arr: data) {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
195 for (WQTimerange wqt: arr) {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
196 addWQTData(source, wqt);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
197 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
198 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
199
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
200 return source;
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
201 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
202
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
203
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
204 protected void addMetaData(WQTJRDataSource source) {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
205 CallMeta meta = context.getMeta();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
206
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
207 D4EArtifact flys = (D4EArtifact) master;
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
208
5865
73da40528cf2 River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
209 source.addMetaData ("river", RiverUtils.getRivername(flys));
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
210
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
211 Locale locale = Resources.getLocale(meta);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
212 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
213
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
214 source.addMetaData("date", df.format(new Date()));
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
215
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
216 source.addMetaData("calculation", Resources.getMsg(
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
217 locale,
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
218 PDF_HEADER_MODE,
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
219 "Historical Discharge"));
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
220 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
221
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
222
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
223 protected void addWQTData(WQTJRDataSource source, WQTimerange wqt) {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
224 DateFormat df = Formatter.getShortDateFormat(context);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
225 NumberFormat wf = Formatter.getHistoricalDischargeW(context);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
226 NumberFormat qf = Formatter.getHistoricalDischargeQ(context);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
227
2331
2c96222dd773 Picked rev4034 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
228 double[] wq = new double[3];
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
229
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
230 String gaugeName = getReferenceGaugename();
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
231
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
232 for (int i = 0, n = wqt.size(); i < n; i++) {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
233 Timerange tr = wqt.getTimerange(i);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
234 Date start = new Date(tr.getStart());
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
235 Date end = new Date(tr.getEnd());
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
236
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
237 wqt.get(i, wq);
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
238
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
239 source.addData(new String[] {
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
240 df.format(start) + " - " + df.format(end),
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
241 wf.format(wq[0]),
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
242 qf.format(wq[1]),
2331
2c96222dd773 Picked rev4034 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
243 qf.format(wq[2]),
2286
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
244 gaugeName
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
245 });
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
246 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
247 }
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
248
89ca1e8572e4 Added PDF export for historical discharge curve calculations.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2258
diff changeset
249
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
250 public String getReferenceGaugename() {
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
251 return RiverUtils.getReferenceGaugeName((D4EArtifact) master);
2258
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
252 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253 }
ea173e4c07c7 Added a CSV export for historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org