# HG changeset patch
# User gernotbelger
# Date 1532536586 -7200
# Node ID 8024e51e828a7e3f926d609df36cd0d003e2fae4
# Parent 8b3ecb1a7e162a356c838a05b5d6eecf2a536cfc
pdf export, issue 2.3.4.1.2
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/doc/conf/artifacts/bundu.xml
--- a/artifacts/doc/conf/artifacts/bundu.xml Wed Jul 25 16:20:27 2018 +0200
+++ b/artifacts/doc/conf/artifacts/bundu.xml Wed Jul 25 18:36:26 2018 +0200
@@ -122,14 +122,14 @@
-
+
-
+
@@ -405,7 +405,7 @@
-
+
@@ -454,7 +454,7 @@
-
+
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/doc/conf/artifacts/fixanalysis.xml
--- a/artifacts/doc/conf/artifacts/fixanalysis.xml Wed Jul 25 16:20:27 2018 +0200
+++ b/artifacts/doc/conf/artifacts/fixanalysis.xml Wed Jul 25 18:36:26 2018 +0200
@@ -104,20 +104,18 @@
-
-
+
+
-
-
-
-
-
-
-
+
-
+
+
+
+
+
@@ -128,7 +126,7 @@
-
+
@@ -301,6 +299,6 @@
-
+
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/doc/conf/jasper/templates/fixanalysis.delta_wt.jrxml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/doc/conf/jasper/templates/fixanalysis.delta_wt.jrxml Wed Jul 25 18:36:26 2018 +0200
@@ -0,0 +1,255 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/src/main/java/org/dive4elements/river/artifacts/common/DefaultCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/DefaultCalculationResult.java Wed Jul 25 16:20:27 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/DefaultCalculationResult.java Wed Jul 25 18:36:26 2018 +0200
@@ -17,6 +17,8 @@
*/
public class DefaultCalculationResult extends AbstractCalculationResult {
+ private static final long serialVersionUID = 1L;
+
public DefaultCalculationResult(final String label, final Collection rows) {
super(label, rows);
// do nothing,
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/src/main/java/org/dive4elements/river/artifacts/common/DefaultCalculationResults.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/DefaultCalculationResults.java Wed Jul 25 18:36:26 2018 +0200
@@ -0,0 +1,26 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ * Björnsen Beratende Ingenieure GmbH
+ * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.common;
+
+import org.apache.commons.lang.math.DoubleRange;
+import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
+
+/**
+ * @author Gernot Belger
+ */
+public class DefaultCalculationResults extends AbstractCalculationResults {
+
+ private static final long serialVersionUID = 1L;
+
+ public DefaultCalculationResults(final String calcModeLabel, final String user, final RiverInfo river, final DoubleRange calcRange) {
+ super(calcModeLabel, user, river, calcRange);
+ }
+
+}
\ No newline at end of file
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/src/main/java/org/dive4elements/river/artifacts/common/JasperReporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/common/JasperReporter.java Wed Jul 25 16:20:27 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/JasperReporter.java Wed Jul 25 18:36:26 2018 +0200
@@ -62,13 +62,9 @@
}
public void exportPDF(final OutputStream out) throws JRException {
-
final List compiledReports = new ArrayList<>();
-
final List sourcesWithPages = new ArrayList<>();
-
final List jasperPrintList = new ArrayList<>();
-
if (this.designs.size() == 1) {
final JasperDesigner designer = this.designs.get(0);
final JasperDesign jDesign = designer.getDesign();
diff -r 8b3ecb1a7e16 -r 8024e51e828a artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java Wed Jul 25 16:20:27 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java Wed Jul 25 18:36:26 2018 +0200
@@ -20,23 +20,34 @@
import org.apache.log4j.Logger;
import org.dive4elements.artifacts.CallMeta;
import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.access.RiverAccess;
+import org.dive4elements.river.artifacts.common.DefaultCalculationResults;
+import org.dive4elements.river.artifacts.common.ExportContextPDF;
+import org.dive4elements.river.artifacts.common.GeneralResultType;
+import org.dive4elements.river.artifacts.common.JasperReporter;
+import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.fixings.AnalysisPeriod;
import org.dive4elements.river.artifacts.model.fixings.FixAnalysisResult;
import org.dive4elements.river.artifacts.model.fixings.QWD;
import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils;
+import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
import org.dive4elements.river.exports.AbstractExporter;
import org.dive4elements.river.utils.Formatter;
import org.dive4elements.river.utils.KMIndex;
import au.com.bytecode.opencsv.CSVWriter;
+import net.sf.jasperreports.engine.JRException;
/** Exports fixation analysis deltaw(t) computation results to csv. */
public class DeltaWtExporter extends AbstractExporter {
/** Private log. */
private static Logger log = Logger.getLogger(DeltaWtExporter.class);
+ private static final String JASPER_FILE = "/jasper/templates/fixanalysis.delta_wt.jrxml";
+
public static final String CSV_KM_HEADER = "export.fixings.deltawt.csv.header.km";
public static final String CSV_DELTA_W_HEADER = "export.fixings.deltawt.csv.header.deltaw";
@@ -106,6 +117,17 @@
writeCSVHeader(writer);
+ final TreeMap> sorted = getRows();
+ for (final ArrayList list : sorted.values()) {
+ for (final String[] row : list) {
+ writer.writeNext(row);
+ }
+ }
+
+ writer.flush();
+ }
+
+ private TreeMap> getRows() {
final NumberFormat kmF = getKMFormatter();
final NumberFormat dwF = getDeltaWFormatter();
final NumberFormat qF = getQFormatter();
@@ -142,9 +164,9 @@
}
}
- if (debug) {
- log.debug("AnalysisPeriods: " + this.analysisPeriods.size());
- }
+ // if (debug) {
+ // log.debug("AnalysisPeriods: " + this.analysisPeriods.size());
+ // }
final String analysisTemplate = getAnalysisTemplate();
@@ -183,14 +205,8 @@
}
}
}
+ return sorted;
- for (final ArrayList list : sorted.values()) {
- for (final String[] row : list) {
- writer.writeNext(row);
- }
- }
-
- writer.flush();
}
/** Template to create "State" strings like A1,A2... */
@@ -241,10 +257,44 @@
msg(CSV_TRANGE_HEADER, DEFAULT_CSV_TRANGE_DESC_HEADER), msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER) });
}
+ private void addMetaData(final MetaAndTableJRDataSource source) {
+ final D4EArtifact flys = (D4EArtifact) this.master;
+ final String user = CalculationUtils.findArtifactUser(this.context, flys);
+ final RangeAccess ra = new RangeAccess(flys);
+ final RiverInfo ri = new RiverInfo(ra.getRiver());
+
+ final DefaultCalculationResults results = new DefaultCalculationResults(msg("calculation.analysis"), user, ri, ra.getRange());
+ final ExportContextPDF contextPdf = new ExportContextPDF(this.context, results);
+ contextPdf.addJRMetaDataDefaults(source);
+ contextPdf.addJRMetaDataUSINFO(source);
+
+ /* column headings */
+ contextPdf.addJRMetadata(source, "station_header", GeneralResultType.station);
+ contextPdf.addJRMetadata(source, "fix_date", msg(CSV_T_HEADER));
+ contextPdf.addJRMetadata(source, "fix_q", msg(CSV_Q_HEADER));
+ contextPdf.addJRMetadata(source, "fix_w", msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER, new Object[] { ri.getWstUnit() }));
+ contextPdf.addJRMetadata(source, "fix_state", msg(CSV_TRANGE_HEADER));
+ contextPdf.addJRMetadata(source, "fix_delta_w", msg(CSV_DELTA_W_HEADER));
+ }
+
@Override
protected void writePDF(final OutputStream out) {
- // TODO: Implement me!
- // wird doch NICHT erledigt vom WaterlevelExporter
+ final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource();
+ final String jasperFile = Resources.getMsg(this.context.getMeta(), JASPER_FILE);
+ addMetaData(source);
+ try {
+ final TreeMap> sorted = getRows(); // Custom Result could be nice, too...
+ for (final ArrayList list : sorted.values()) {
+ for (final String[] row : list) {
+ source.addData(row);
+ }
+ }
+ final JasperReporter reporter = new JasperReporter();
+ reporter.addReport(jasperFile, source);
+ reporter.exportPDF(out);
+ }
+ catch (final JRException je) {
+ log.warn("Error generating PDF Report!", je);
+ }
}
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file