Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java @ 8633:8bff94ea044f
(issue1754) Unify PDF and CSV export and invert presentation if start > end
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 26 Mar 2015 18:21:18 +0100 |
parents | ce325339e9ba |
children | 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
8632:5533aa8f8b73 | 8633:8bff94ea044f |
---|---|
30 | 30 |
31 import org.dive4elements.artifacts.CallMeta; | 31 import org.dive4elements.artifacts.CallMeta; |
32 import org.dive4elements.artifacts.common.utils.Config; | 32 import org.dive4elements.artifacts.common.utils.Config; |
33 | 33 |
34 import org.dive4elements.river.artifacts.WINFOArtifact; | 34 import org.dive4elements.river.artifacts.WINFOArtifact; |
35 import org.dive4elements.river.artifacts.D4EArtifact; | |
35 import org.dive4elements.river.artifacts.access.RangeAccess; | 36 import org.dive4elements.river.artifacts.access.RangeAccess; |
36 | 37 |
37 import org.dive4elements.river.artifacts.model.CalculationResult; | 38 import org.dive4elements.river.artifacts.model.CalculationResult; |
38 import org.dive4elements.river.artifacts.model.WKms; | 39 import org.dive4elements.river.artifacts.model.WKms; |
39 import org.dive4elements.river.artifacts.model.WKmsJRDataSource; | 40 import org.dive4elements.river.artifacts.model.WKmsJRDataSource; |
64 public static final String JASPER_FILE = "export.wdifferences.pdf.file"; | 65 public static final String JASPER_FILE = "export.wdifferences.pdf.file"; |
65 | 66 |
66 /** The storage that contains all WKms objects for the different facets. */ | 67 /** The storage that contains all WKms objects for the different facets. */ |
67 protected List<WKms[]> data; | 68 protected List<WKms[]> data; |
68 | 69 |
70 protected List<String[]> stringData; | |
71 | |
69 public WDifferencesExporter() { | 72 public WDifferencesExporter() { |
70 data = new ArrayList<WKms[]>(); | 73 data = new ArrayList<WKms[]>(); |
71 } | 74 } |
72 | 75 |
73 /** | 76 /** |
76 @Override | 79 @Override |
77 public void generate() | 80 public void generate() |
78 throws IOException | 81 throws IOException |
79 { | 82 { |
80 log.debug("WDifferencesExporter.generate"); | 83 log.debug("WDifferencesExporter.generate"); |
81 | 84 if (stringData == null) { |
85 D4EArtifact arti = (D4EArtifact) master; | |
86 RangeAccess access = new RangeAccess(arti); | |
87 stringData = data2StringArrays(access.getFrom() > access.getTo()); | |
88 } | |
82 if (facet == null) { | 89 if (facet == null) { |
83 throw new IOException("invalid (null) facet for exporter"); | 90 throw new IOException("invalid (null) facet for exporter"); |
84 } | 91 } |
85 else if (facet.equals(AbstractExporter.FACET_CSV)) { | 92 else if (facet.equals(AbstractExporter.FACET_CSV)) { |
86 generateCSV(); | 93 generateCSV(); |
120 protected void writeCSVData(CSVWriter writer) { | 127 protected void writeCSVData(CSVWriter writer) { |
121 log.info("WDifferencesExporter.writeData"); | 128 log.info("WDifferencesExporter.writeData"); |
122 | 129 |
123 writeCSVHeader(writer); | 130 writeCSVHeader(writer); |
124 | 131 |
125 for (WKms[] tmp: data) { | 132 writer.writeAll(stringData); |
126 for (WKms wkms: tmp) { | |
127 wKms2CSV(writer, wkms); | |
128 } | |
129 } | |
130 } | 133 } |
131 | 134 |
132 | 135 |
133 /** | 136 /** |
134 * Lets csvwriter write the header (first line in file). | 137 * Lets csvwriter write the header (first line in file). |
142 msg(WDIFF_CSV_W_HEADER, WDIFF_DEFAULT_CSV_W_HEADER) | 145 msg(WDIFF_CSV_W_HEADER, WDIFF_DEFAULT_CSV_W_HEADER) |
143 }); | 146 }); |
144 } | 147 } |
145 | 148 |
146 | 149 |
147 protected void wKms2CSV(CSVWriter writer, WKms wkms) { | |
148 log.debug("WDifferencesExporter.wKms2CSV"); | |
149 | |
150 NumberFormat kmf = getKmFormatter(); | |
151 NumberFormat wf = getWFormatter(); | |
152 int size = wkms.size(); | |
153 | |
154 for (int i = 0; i < size; i ++) { | |
155 | |
156 writer.writeNext(new String[] { | |
157 kmf.format(wkms.getKm(i)), | |
158 wf.format(wkms.getW(i)) | |
159 }); | |
160 } | |
161 } | |
162 | |
163 | |
164 /** | 150 /** |
165 * Returns the number formatter for kilometer values. | 151 * Returns the number formatter for kilometer values. |
166 * | 152 * |
167 * @return the number formatter for kilometer values. | 153 * @return the number formatter for kilometer values. |
168 */ | 154 */ |
178 */ | 164 */ |
179 protected NumberFormat getWFormatter() { | 165 protected NumberFormat getWFormatter() { |
180 return Formatter.getWaterlevelW(context); | 166 return Formatter.getWaterlevelW(context); |
181 } | 167 } |
182 | 168 |
169 protected List<String[]> data2StringArrays(boolean inverted) { | |
170 NumberFormat kmf = getKmFormatter(); | |
171 NumberFormat wf = getWFormatter(); | |
172 List<String[]> retval = new ArrayList<String[]>(); | |
173 | |
174 for (WKms[] tmp: data) { | |
175 for (WKms wkms: tmp) { | |
176 int size = wkms.size(); | |
177 if (inverted) { | |
178 for (int i = size - 1; i >= 0; i--) { | |
179 retval.add(new String[] { | |
180 kmf.format(wkms.getKm(i)), | |
181 wf.format(wkms.getW(i)) | |
182 }); | |
183 } | |
184 } else { | |
185 for (int i = 0; i < size; i++) { | |
186 retval.add(new String[] { | |
187 kmf.format(wkms.getKm(i)), | |
188 wf.format(wkms.getW(i)) | |
189 }); | |
190 } | |
191 } | |
192 } | |
193 } | |
194 return retval; | |
195 } | |
183 | 196 |
184 @Override | 197 @Override |
185 protected void writePDF(OutputStream out) { | 198 protected void writePDF(OutputStream out) { |
186 WKmsJRDataSource source = createJRData(); | 199 WKmsJRDataSource source = createJRData(); |
187 | 200 |
208 | 221 |
209 protected WKmsJRDataSource createJRData() { | 222 protected WKmsJRDataSource createJRData() { |
210 WKmsJRDataSource source = new WKmsJRDataSource(); | 223 WKmsJRDataSource source = new WKmsJRDataSource(); |
211 | 224 |
212 addMetaData(source); | 225 addMetaData(source); |
213 for (WKms[] tmp: data) { | 226 for (String[] str: stringData) { |
214 for (WKms wkms: tmp) { | 227 source.addData(str); |
215 addWKmsData(source, wkms); | |
216 } | |
217 } | 228 } |
218 return source; | 229 return source; |
219 } | 230 } |
220 | 231 |
221 | 232 |
244 locale, | 255 locale, |
245 PDF_HEADER_MODE, | 256 PDF_HEADER_MODE, |
246 "W Differences")); | 257 "W Differences")); |
247 } | 258 } |
248 | 259 |
249 protected void addWKmsData(WKmsJRDataSource source, WKms wkms) { | |
250 NumberFormat kmf = getKmFormatter(); | |
251 NumberFormat wf = getWFormatter(); | |
252 int size = wkms.size(); | |
253 | |
254 for (int i = 0; i < size; i ++) { | |
255 | |
256 source.addData(new String[] { | |
257 kmf.format(wkms.getKm(i)), | |
258 wf.format(wkms.getW(i)) | |
259 }); | |
260 } | |
261 } | |
262 | |
263 } | 260 } |
264 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 261 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |