changeset 2310:ecb76933362f

Added PDF export to reference curve calculation. flys-artifacts/trunk@3988 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 09 Feb 2012 10:21:16 +0000
parents 92640472e563
children b8df8d1476ba
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/doc/conf/jasper/reference.jasper flys-artifacts/doc/conf/jasper/reference_en.jasper flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQJRDataSource.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 11 files changed, 185 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Feb 09 10:21:16 2012 +0000
@@ -1,3 +1,27 @@
+2012-02-09  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Added PDF export to reference curve calculation.
+
+	* src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java:
+	  Added PDF export.
+
+	* src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java,
+	  doc/conf/artifacts/winfo.xml:
+	  Add facet for PDF export to state.
+
+	* src/main/java/de/intevation/flys/artifacts/model/WWQQJRDataSource.java:
+	  New. Datasource for JasperReports containing reference curve data.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties:
+	  Added i18n strings for JasperReports template file and calculation mode.
+
+	* doc/conf/jasper/reference.jasper,
+	  doc/conf/jasper/reference_en.jasper:
+	  New. Templates for reference curve PDF export.
+
 2012-02-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java(getReferenceEndKms):
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Feb 09 10:21:16 2012 +0000
@@ -208,6 +208,7 @@
                 <outputmode name="reference_curve_export" mime-type="text/plain" type="export">
                     <facets>
                         <facet name="csv" description="facet.reference_curve_export.csv" />
+                        <facet name="pdf" description="facet.reference_curve_export.pdf" />
                     </facets>
                 </outputmode>
                 <outputmode name="reference_curve_report" description="output.reference_curve_report" mime-type="text/xml" type="report">
Binary file flys-artifacts/doc/conf/jasper/reference.jasper has changed
Binary file flys-artifacts/doc/conf/jasper/reference_en.jasper has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQJRDataSource.java	Thu Feb 09 10:21:16 2012 +0000
@@ -0,0 +1,114 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.log4j.Logger;
+
+import net.sf.jasperreports.engine.JRDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JRField;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class WWQQJRDataSource implements JRDataSource
+{
+    /** The logger used in this exporter.*/
+    private static Logger logger = Logger.getLogger(WWQQJRDataSource.class);
+
+    /**
+     *
+     */
+    private ArrayList<String[]> data;
+    private HashMap<String, String> metaData;
+
+    private int index = -1;
+
+    /**
+     *
+     */
+    public WWQQJRDataSource()
+    {
+        data = new ArrayList<String[]>();
+        metaData = new HashMap<String, String>();
+    }
+
+
+    /**
+     *
+     */
+    public void addData(String[] data) {
+        this.data.add(data);
+    }
+
+
+    /**
+     *
+     */
+    public void addMetaData(String key, String value) {
+        this.metaData.put(key, value);
+    }
+
+
+    /**
+     *
+     */
+    public boolean next() throws JRException
+    {
+        index++;
+
+        return (index < data.size());
+    }
+
+
+    /**
+     *
+     */
+    public Object getFieldValue(JRField field) throws JRException
+    {
+        Object value = "";
+        String fieldName = field.getName();
+        if ("river".equals(fieldName)) {
+            value = metaData.get("river");
+        }
+        if ("date".equals(fieldName)) {
+            value = metaData.get("date");
+        }
+        if ("calculation".equals(fieldName)) {
+            value = metaData.get("calculation");
+        }
+        if ("reference".equals(fieldName)) {
+            value = metaData.get("reference");
+        }
+        if ("location".equals(fieldName)) {
+            value = metaData.get("location");
+        }
+        if ("km1".equals(fieldName)) {
+            value = data.get(index)[0];
+        }
+        if ("location1".equals(fieldName)) {
+            value = data.get(index)[1];
+        }
+        if ("W1".equals(fieldName)) {
+            value = data.get(index)[2];
+        }
+        if ("Q1".equals(fieldName)) {
+            value = data.get(index)[3];
+        }
+        if ("km2".equals(fieldName)) {
+            value = data.get(index)[4];
+        }
+        if ("location2".equals(fieldName)) {
+            value = data.get(index)[5];
+        }
+        if ("W2".equals(fieldName)) {
+            value = data.get(index)[6];
+        }
+        if ("Q2".equals(fieldName)) {
+            value = data.get(index)[7];
+        }
+        return value;
+    }
+}
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java	Thu Feb 09 10:21:16 2012 +0000
@@ -69,10 +69,11 @@
         }
 
         if (wws.length > 0) {
-            // TODO: Add CSV/PDF facets.
-            logger.debug("Adding CSV data facet.");
+            logger.debug("Adding CSV and PDF data facet.");
             Facet csv = new DataFacet (CSV, "CSV data", ComputeType.ADVANCE, hash, id);
+            Facet pdf = new DataFacet (PDF, "PDF data", ComputeType.ADVANCE, hash, id);
             facets.add(csv);
+            facets.add(pdf);
         }
 
         if (res.getReport().hasProblems()) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java	Thu Feb 09 10:21:16 2012 +0000
@@ -6,13 +6,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
-/*
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Date;
 import java.text.DateFormat;
 import java.util.Locale;
-*/
 
 import org.w3c.dom.Document;
 
@@ -20,30 +18,22 @@
 
 import au.com.bytecode.opencsv.CSVWriter;
 
-/*
 import net.sf.jasperreports.engine.JasperExportManager;
 import net.sf.jasperreports.engine.JasperFillManager;
 import net.sf.jasperreports.engine.JasperPrint;
 import net.sf.jasperreports.engine.JRException;
-*/
 import de.intevation.artifacts.CallContext;
-/*
 import de.intevation.artifacts.CallMeta;
 import de.intevation.artifacts.common.utils.Config;
-*/
 
 import de.intevation.flys.artifacts.FLYSArtifact;
-/*
 import de.intevation.flys.artifacts.WINFOArtifact;
-*/
 
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.WWQQ;
-import de.intevation.flys.artifacts.model.WKmsJRDataSource;
-/*
+import de.intevation.flys.artifacts.model.WWQQJRDataSource;
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.utils.Formatter;
-*/
 
 import de.intevation.flys.utils.FLYSUtils;
 
@@ -214,13 +204,12 @@
 
     @Override
     protected void writePDF(OutputStream out) {
-        /*
-        WKmsJRDataSource source = createJRData();
+        WWQQJRDataSource source = createJRData();
 
         String jasperFile = Resources.getMsg(
                                 context.getMeta(),
                                 JASPER_FILE,
-                                "/jasper/wdifferences_en.jasper");
+                                "/jasper/reference_en.jasper");
         String confPath = Config.getConfigDirectory().toString();
 
         Map parameters = new HashMap();
@@ -236,29 +225,23 @@
             logger.warn("Error generating PDF Report!");
             je.printStackTrace();
         }
-        */
-        logger.error("ReferenceCurveExporter: PDF export not implemented.");
     }
 
-    protected WKmsJRDataSource createJRData() {
-        /*
-        WKmsJRDataSource source = new WKmsJRDataSource();
+    protected WWQQJRDataSource createJRData() {
+        WWQQJRDataSource source = new WWQQJRDataSource();
 
         addMetaData(source);
-        for (WKms[] tmp: data) {
-            for (WKms wkms: tmp) {
-                addWKmsData(source, wkms);
+
+        for (WWQQ[] tmp: data) {
+            for (WWQQ ww: tmp) {
+                addWWQQData(source, ww);
             }
         }
         return source;
-        */
-        return null;
     }
 
 
-    // TODO implement for pdf export.
-    /*
-    protected void addMetaData(WKmsJRDataSource source) {
+    protected void addMetaData(WWQQJRDataSource source) {
         CallMeta meta = context.getMeta();
 
         WINFOArtifact flys = (WINFOArtifact) master;
@@ -270,28 +253,41 @@
 
         source.addMetaData("date", df.format(new Date()));
 
-        String differences = FLYSUtils.getWDifferences(flys, context);
-        source.addMetaData("differences", differences);
-
         source.addMetaData("calculation", Resources.getMsg(
                                             locale,
                                             PDF_HEADER_MODE,
-                                            "W Differences"));
+                                            "Reference Curve"));
     }
 
-    protected void addWKmsData(WKmsJRDataSource source, WKms wkms) {
-        NumberFormat kmf  = getKmFormatter();
-        NumberFormat wf   = getWFormatter();
-        int          size = wkms.size();
 
-        for (int i = 0; i < size; i ++) {
+    protected void addWWQQData(WWQQJRDataSource source, WWQQ ww) {
+        NumberFormat kmf = getKmFormatter();
+        NumberFormat wf  = getWFormatter();
+        NumberFormat qf  = getQFormatter();
 
+        int          size = ww.size();
+
+        FLYSArtifact flys       = (FLYSArtifact) master;
+
+        String startLocationDescription = FLYSUtils.getLocationDescription(
+            flys, ww.getStartKm());
+
+        String endLocationDescription = FLYSUtils.getLocationDescription(
+            flys, ww.getEndKm());
+
+        // TODO missing 'relative' W(cm).
+        for (int i = 0; i < size; i ++) {
             source.addData(new String[] {
-                kmf.format(wkms.getKm(i)),
-                wf.format(wkms.getW(i))
+                kmf.format(ww.getStartKm()),
+                startLocationDescription,
+                wf.format(ww.getW1(i)),
+                qf.format(ww.getQ1(i)), // "Q"
+                kmf.format(ww.getEndKm()),
+                endLocationDescription,
+                wf.format(ww.getW2(i)),
+                qf.format(ww.getQ2(i)) // "Q"
             });
         }
     }
-    */
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/resources/messages.properties	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Thu Feb 09 10:21:16 2012 +0000
@@ -136,11 +136,13 @@
 export.duration.pdf.mode = Durationcurve
 export.wdifferences.pdf.mode = W Differences
 export.historical.discharge.pdf.mode = Historical Discharge
+export.reference_curve.pdf.mode = Reference Curve
 export.computed.discharge.pdf.file = /jasper/computed-discharge_en.jasper
 export.duration.pdf.file = /jasper/duration_en.jasper
 export.waterlevel.pdf.file = /jasper/waterlevel_en.jasper
 export.wdifferences.pdf.file = /jasper/wdifferences_en.jasper
 export.historical.discharge.pdf.file = /jasper/historical-discharge_en.jasper
+export.reference_curve.pdf.file = /jasper/reference_en.jasper
 
 floodmap.wmsbackground = Background Map
 floodmap.riveraxis = River Axis
--- a/flys-artifacts/src/main/resources/messages_de.properties	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Thu Feb 09 10:21:16 2012 +0000
@@ -136,11 +136,13 @@
 export.duration.pdf.mode = Dauerlinie
 export.wdifferences.pdf.mode = W Differenzen
 export.historical.discharge.pdf.mode = Historischer Abfluss
+export.reference_curve.pdf.mode = Bezugslinie
 export.computed.discharge.pdf.file = /jasper/computed-discharge.jasper
 export.duration.pdf.file = /jasper/duration.jasper
 export.waterlevel.pdf.file = /jasper/waterlevel.jasper
 export.wdifferences.pdf.file = /jasper/wdifferences.jasper
 export.historical.discharge.pdf.file = /jasper/historical-discharge.jasper
+export.reference_curve.pdf.file = /jasper/reference.jasper
 
 floodmap.wmsbackground = Hintergrundkarte
 floodmap.riveraxis = Flussachse
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Thu Feb 09 10:21:16 2012 +0000
@@ -136,11 +136,13 @@
 export.duration.pdf.mode = Dauerline
 export.wdifferences.pdf.mode = W Differenzen
 export.historical.discharge.pdf.mode = Historischer Abfluss
+export.reference_curve.pdf.mode = Bezugslinie
 export.computed.discharge.pdf.file = /jasper/computed-discharge.jasper
 export.duration.pdf.file = /jasper/duration.jasper
 export.waterlevel.pdf.file = /jasper/waterlevel.jasper
 export.wdifferences.pdf.file = /jasper/wdifferences.jasper
 export.historical.discharge.pdf.file = /jasper/historical-discharge.jasper
+export.reference_curve.pdf.file = /jasper/reference.jasper
 
 floodmap.wmsbackground = Hintergrundkarte
 floodmap.riveraxis = Flussachse
--- a/flys-artifacts/src/main/resources/messages_en.properties	Thu Feb 09 10:08:14 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Thu Feb 09 10:21:16 2012 +0000
@@ -132,11 +132,13 @@
 export.duration.pdf.mode = Durationcurve
 export.wdifferences.pdf.mode = W Differences
 export.historical.discharge.pdf.mode = Historical Discharge
+export.reference_curve.pdf.mode = Reference Curve
 export.computed.discharge.pdf.file = /jasper/computed-discharge_en.jasper
 export.duration.pdf.file = /jasper/duration_en.jasper
 export.waterlevel.pdf.file = /jasper/waterlevel_en.jasper
 export.wdifferences.pdf.file = /jasper/wdifferences_en.jasper
 export.historical.discharge.pdf.file = /jasper/historical-discharge_en.jasper
+export.reference_curve.pdf.file = /jasper/reference_en.jasper
 
 floodmap.wmsbackground = Background Map
 floodmap.riveraxis = River Axis

http://dive4elements.wald.intevation.org