changeset 709:3b7e9ddf6bb1

New model to transport data and error reports of calculations. flys-artifacts/trunk@2165 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 20 Jun 2011 12:32:32 +0000
parents 757ff56b43b3
children cded0924193d
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation1.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation2.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation3.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CalculationResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java
diffstat 16 files changed, 191 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jun 20 12:32:32 2011 +0000
@@ -1,3 +1,24 @@
+2011-06-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/CalculationResult.java:
+	  New. Used to transport the data and the error report.
+
+	* src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/Calculation1.java,
+	  src/main/java/de/intevation/flys/artifacts/model/Calculation2.java,
+	  src/main/java/de/intevation/flys/artifacts/model/Calculation3.java,
+	  src/main/java/de/intevation/flys/artifacts/model/Calculation4.java,
+	  src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/Calculation.java,
+	  src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java,
+	  src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java,
+	  src/main/java/de/intevation/flys/exports/WaterlevelExporter.java,
+	  src/main/java/de/intevation/flys/exports/DurationCurveExporter.java:
+	  Use the CalculationResult now.
+
 2011-06-18  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/Calculation1.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon Jun 20 12:32:32 2011 +0000
@@ -37,10 +37,12 @@
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WstValueTable;
 import de.intevation.flys.artifacts.model.WstValueTableFactory;
+import de.intevation.flys.artifacts.model.Calculation;
 import de.intevation.flys.artifacts.model.Calculation1;
 import de.intevation.flys.artifacts.model.Calculation2;
 import de.intevation.flys.artifacts.model.Calculation3;
 import de.intevation.flys.artifacts.model.Calculation4;
+import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.Segment;
 
 
@@ -297,19 +299,18 @@
      *
      * @return an array of data triples that consist of W, Q and Kms.
      */
-    public WQKms[] getWaterlevelData()
-    throws NullPointerException
+    public CalculationResult getWaterlevelData()
     {
         logger.debug("WINFOArtifact.getWaterlevelData");
 
         River river = getRiver();
         if (river == null) {
-            throw new NullPointerException("No river selected.");
+            return error(new WQKms[0], "No river selected.");
         }
 
         double[] kms = getKms();
         if (kms == null) {
-            throw new NullPointerException("No Kms selected.");
+            return error(new WQKms[0], "No Kms selected.");
         }
 
         double[] qs   = getQs();
@@ -325,7 +326,7 @@
 
         WstValueTable wst = WstValueTableFactory.getTable(river);
         if (wst == null) {
-            throw new NullPointerException("No Wst found for selected river.");
+            return error(new WQKms[0], "No Wst found for selected river.");
         }
 
         double refKm = Double.NaN;
@@ -341,10 +342,8 @@
             }
         }
 
-        WQKms[] results = computeWaterlevelData(
+        return computeWaterlevelData(
             kms, qs, ws, wst, refKm, river.getKmUp());
-
-        return results;
     }
 
     /**
@@ -357,7 +356,7 @@
      *
      * @return an array of data triples that consist of W, Q and Kms.
      */
-    public static WQKms[] computeWaterlevelData(
+    public static CalculationResult computeWaterlevelData(
         double []     kms,
         double []     qs,
         double []     ws,
@@ -367,13 +366,9 @@
     ) {
         logger.info("WINFOArtifact.computeWaterlevelData");
 
-        Calculation1 calculation = new Calculation1(kms, qs, ws, refKm, up);
+        Calculation1 calc1 = new Calculation1(kms, qs, ws, refKm, up);
 
-        WQKms[] wqkms = calculation.calculate(wst);
-
-        // TODO: report problems to user
-
-        return wqkms;
+        return calc1.calculate(wst);
     }
 
 
@@ -382,32 +377,30 @@
      *
      * @return the data computed by a duration curve computation.
      */
-    public WQDay getDurationCurveData()
-    throws NullPointerException
-    {
+    public CalculationResult getDurationCurveData() {
         logger.debug("WINFOArtifact.getDurationCurveData");
 
         River r = getRiver();
 
         if (r == null) {
-            throw new NullPointerException("Cannot determine river.");
+            return error(null, "Cannot determine river.");
         }
 
         Gauge g = getGauge();
 
         if (g == null) {
-            throw new NullPointerException("Cannot determine gauge.");
+           return error(null, "Cannot determine gauge.");
         }
 
         double[] locations = getLocations();
 
         if (locations == null) {
-            throw new NullPointerException("Cannot determine location.");
+            return error(null, "Cannot determine location.");
         }
 
         WstValueTable wst = WstValueTableFactory.getTable(r);
         if (wst == null) {
-            throw new NullPointerException("No Wst found for selected river.");
+            return error(null, "No Wst found for selected river.");
         }
 
         return computeDurationCurveData(g, wst, locations[0]);
@@ -422,7 +415,7 @@
      *
      * @return the computed data.
      */
-    public static WQDay computeDurationCurveData(
+    public static CalculationResult computeDurationCurveData(
         Gauge           gauge,
         WstValueTable   wst,
         double          location)
@@ -436,7 +429,6 @@
 
         Calculation3 calculation = new Calculation3(location, days, qs);
 
-        // TODO: report the errors to the user.
         return calculation.calculate(wst);
     }
 
@@ -477,7 +469,7 @@
      *
      * @return the data computed by a discharge curve computation.
      */
-    public WQKms getComputedDischargeCurveData()
+    public CalculationResult getComputedDischargeCurveData()
     throws NullPointerException
     {
         logger.debug("WINFOArtifact.getComputedDischargeCurveData");
@@ -485,23 +477,21 @@
         River r = getRiver();
 
         if (r == null) {
-            throw new NullPointerException("Cannot determine river.");
+            return error(new WQKms[0], "Cannot determine river.");
         }
 
         double[] locations = getLocations();
 
         if (locations == null) {
-            throw new NullPointerException("Cannot determine location.");
+            return error(new WQKms[0], "Cannot determine location.");
         }
 
         WstValueTable wst = WstValueTableFactory.getTable(r);
         if (wst == null) {
-            throw new NullPointerException("No Wst found for selected river.");
+            return error(new WQKms[0], "No Wst found for selected river.");
         }
 
-        WQKms wqkms = computeDischargeCurveData(wst, locations[0]);
-
-        return wqkms;
+        return computeDischargeCurveData(wst, locations[0]);
     }
 
 
@@ -514,7 +504,7 @@
      * @return an object that contains tuples of W/Q values at the specified
      * location.
      */
-    public static WQKms computeDischargeCurveData(
+    public static CalculationResult computeDischargeCurveData(
         WstValueTable wst,
         double location)
     {
@@ -522,11 +512,11 @@
 
         Calculation2 calculation = new Calculation2(location);
 
-        WQKms wqkms = calculation.calculate(wst);
+        return calculation.calculate(wst);
+    }
 
-        // TODO: Report errors to the user
-
-        return wqkms;
+    protected static final CalculationResult error(Object data, String msg) {
+        return new CalculationResult(data, new Calculation(msg));
     }
 
     /**
@@ -535,41 +525,39 @@
      *
      * @return an array of WQKms object - one object for each given Q value.
      */
-    public WQKms [] getDischargeLongitudinalSectionData() {
+    public CalculationResult getDischargeLongitudinalSectionData() {
 
         logger.debug("WINFOArtifact.getDischargeLongitudinalSectionData");
 
         River river = getRiver();
         if (river == null) {
-            logger.error("No river selected.");
-            return new WQKms[0];
+            logger.debug("No river selected.");
+            return error(new WQKms[0], "No river selected.");
         }
 
         WstValueTable table = WstValueTableFactory.getTable(river);
         if (table == null) {
-            logger.error("No wst found for selected river.");
-            return new WQKms[0];
+            logger.debug("No wst found for selected river.");
+            return error(new WQKms[0], "No wst found for selected river.");
         }
 
         List<Segment> segments = getSegments();
 
         if (segments == null) {
-            logger.error("Cannot create segments.");
-            return new WQKms[0];
+            logger.debug("Cannot create segments.");
+            return error(new WQKms[0], "Cannot create segments.");
         }
 
         double [] range = getFromToStep();
 
         if (range == null) {
-            logger.error("Cannot figure out range.");
-            return new WQKms[0];
+            logger.debug("Cannot figure out range.");
+            return error(new WQKms[0], "Cannot figure out range.");
         }
 
         Calculation4 calc4 = new Calculation4(segments, river, isQ());
 
-        WQKms [] results = calc4.calculate(table, range[0], range[1], range[2]);
-
-        return results;
+        return calc4.calculate(table, range[0], range[1], range[2]);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java	Mon Jun 20 12:32:32 2011 +0000
@@ -44,6 +44,10 @@
     public Calculation() {
     }
 
+    public Calculation(String msg) {
+        addProblem(msg);
+    }
+
     protected List<Problem> checkProblems() {
         if (problems == null) {
             problems = new ArrayList<Problem>();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation1.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation1.java	Mon Jun 20 12:32:32 2011 +0000
@@ -32,7 +32,7 @@
         this.up    = up;
     }
 
-    public WQKms [] calculate(WstValueTable wst) {
+    public CalculationResult calculate(WstValueTable wst) {
 
         ArrayList<WQKms> results = new ArrayList<WQKms>();
 
@@ -72,7 +72,9 @@
             oldNumProblems = newNumProblems;
         }
         
-        return results.toArray(new WQKms[results.size()]);
+        return new CalculationResult(
+            results.toArray(new WQKms[results.size()]),
+            this);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation2.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation2.java	Mon Jun 20 12:32:32 2011 +0000
@@ -18,7 +18,7 @@
         this.km = km;
     }
 
-    public WQKms calculate(WstValueTable wst) {
+    public CalculationResult calculate(WstValueTable wst) {
 
         logger.debug("Calculation2.calculate");
 
@@ -26,7 +26,8 @@
 
         if (wqs == null || wqs[0].length == 0) {
             logger.debug("Cannot compute discharge curve data.");
-            return null;
+            addProblem("Cannot compute discharge curve data.");
+            return new CalculationResult(new WQKms[0], this);
         }
 
         double [] ws = wqs[0];
@@ -42,7 +43,7 @@
             wqkms.removeNaNs();
         }
 
-        return wqkms;
+        return new CalculationResult(new WQKms[] { wqkms }, this);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation3.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation3.java	Mon Jun 20 12:32:32 2011 +0000
@@ -20,7 +20,7 @@
         this.qs   = qs;
     }
 
-    public WQDay calculate(WstValueTable wst) {
+    public CalculationResult calculate(WstValueTable wst) {
 
         double [] ws = wst.interpolateW(km, qs, new double[qs.length], this);
 
@@ -31,7 +31,7 @@
             wqday.removeNaNs();
         }
 
-        return wqday;
+        return new CalculationResult(wqday, this);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java	Mon Jun 20 12:32:32 2011 +0000
@@ -84,7 +84,7 @@
         Collections.sort(segments, REF_CMP);
     }
 
-    public WQKms [] calculate(
+    public CalculationResult calculate(
         WstValueTable table,
         double from, double to, double step
     ) {
@@ -103,7 +103,7 @@
             logger.debug("no segments found");
             // TODO: I18N
             addProblem("no segments found");
-            return new WQKms[0];
+            return new CalculationResult(new WQKms[0], this);
         }
 
         int numResults = segments.get(0).values.length;
@@ -112,7 +112,7 @@
             logger.debug("no values given");
             // TODO: I18N
             addProblem("no values given");
-            return new WQKms[0];
+            return new CalculationResult(new WQKms[0], this);
         }
 
 
@@ -278,7 +278,7 @@
             results[i].setName(createName(i));
         }
 
-        return results;
+        return new CalculationResult(results, this);
     }
 
     protected String createName(int index) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CalculationResult.java	Mon Jun 20 12:32:32 2011 +0000
@@ -0,0 +1,35 @@
+package de.intevation.flys.artifacts.model;
+
+import java.io.Serializable;
+
+public class CalculationResult
+implements   Serializable
+{
+    protected Object      data;
+    protected Calculation report;
+
+    public CalculationResult() {
+    }
+
+    public CalculationResult(Object data, Calculation report) {
+        this.data   = data;
+        this.report = report;
+    }
+
+    public Object getData() {
+        return data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+
+    public Calculation getReport() {
+        return report;
+    }
+
+    public void setReport(Calculation report) {
+        this.report = report;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java	Mon Jun 20 12:32:32 2011 +0000
@@ -17,20 +17,20 @@
     private static Logger logger = Logger.getLogger(DurationCurveFacet.class);
 
 
-    public DurationCurveFacet(int index, String name, String description) {
-        super(index, name, description);
+    public DurationCurveFacet(String name, String description) {
+        super(0, name, description);
     }
 
 
     public Object getData(Artifact artifact, CallContext context) {
-        logger.debug("Get data for duration curve data at index: " + index);
-
-        WINFOArtifact winfo = (WINFOArtifact) artifact;
+        logger.debug("Get data for duration curve data");
 
-        WQDay[] wqday =
-            (WQDay[])winfo.compute(context, ComputeType.ADVANCE, false);
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        return wqday[index];
+        CalculationResult cr = (CalculationResult)winfo.compute(
+            context, ComputeType.ADVANCE, false);
+
+        return cr.getData();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java	Mon Jun 20 12:32:32 2011 +0000
@@ -24,10 +24,12 @@
     public Object getData(Artifact artifact, CallContext context) {
         logger.debug("Get data for waterlevels at index: " + index);
 
-        WINFOArtifact winfo = (WINFOArtifact) artifact;
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        WQKms[] wqkms =
-            (WQKms[])winfo.compute(context, ComputeType.ADVANCE, false);
+        CalculationResult res = (CalculationResult)
+            winfo.compute(context, ComputeType.ADVANCE, false);
+
+        WQKms [] wqkms = (WQKms [])res.getData();
 
         return wqkms[index];
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Mon Jun 20 12:32:32 2011 +0000
@@ -15,6 +15,7 @@
 import de.intevation.flys.artifacts.model.WaterlevelFacet;
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.WQKms;
+import de.intevation.flys.artifacts.model.CalculationResult;
 
 import de.intevation.flys.artifacts.resources.Resources;
 
@@ -47,37 +48,32 @@
     ) {
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        WQKms res;
+        CalculationResult res = old instanceof CalculationResult
+            ? (CalculationResult)old
+            : winfo.getComputedDischargeCurveData();
 
-        if (old instanceof WQKms []) {
-            res = ((WQKms [])old)[0];
-        }
-        else {
-            res = winfo.getComputedDischargeCurveData();
+        WQKms [] wqkms = (WQKms [])res.getData();
 
-            if (res == null) {
-                logger.debug("No results given.");
-                return null;
+        if (facets != null && wqkms.length > 0) {
+            for (int i = 0; i < wqkms.length; ++i) {
+
+                Object[] args = new Object[] {
+                    winfo.getRiver().getName(),
+                    wqkms[i].getName()
+                };
+
+                String name = Resources.getMsg(
+                    context.getMeta(),
+                    "chart.computed.discharge.curve.curve.label",
+                    "",
+                    args);
+
+                facets.add(new WaterlevelFacet(i, COMPUTED_DISCHARGE_Q, name));
             }
-        }
-
-        if (facets != null) {
-            Object[] args = new Object[] {
-                winfo.getRiver().getName(),
-                res.getName()
-            };
-
-            String name = Resources.getMsg(
-                context.getMeta(),
-                "chart.computed.discharge.curve.curve.label",
-                "",
-                args);
-
-            facets.add(new WaterlevelFacet(0, COMPUTED_DISCHARGE_Q, name));
             facets.add(new DataFacet(CSV, "CSV data"));
         }
 
-        return new WQKms[] { res };
+        return res;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Mon Jun 20 12:32:32 2011 +0000
@@ -14,6 +14,7 @@
 import de.intevation.flys.artifacts.model.WaterlevelFacet;
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WQCKms;
+import de.intevation.flys.artifacts.model.CalculationResult;
 
 import de.intevation.flys.artifacts.model.DataFacet;
 
@@ -33,36 +34,33 @@
         List<Facet>  facets, 
         Object       old
     ) {
-        WQKms [] res;
+        CalculationResult res;
 
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        if (old instanceof WQCKms []) {
-            res = (WQCKms [])old;
+        if (old instanceof CalculationResult) {
+            res = (CalculationResult)old;
         }
         else {
             res = winfo.getDischargeLongitudinalSectionData();
-
-            if (res == null) {
-                logger.debug("No results given.");
-                return null;
-            }
         }
 
         if (facets == null) {
             return res;
         }
 
-        for (int i = 0; i < res.length; i++) {
+        WQKms [] wqkms = (WQKms [])res.getData();
+
+        for (int i = 0; i < wqkms.length; i++) {
             String nameW = null;
             String nameQ = null;
 
             if (winfo.isQ()) {
-                nameQ = res[i].getName();
+                nameQ = wqkms[i].getName();
                 nameW = "W(" + nameQ + ")";
             }
             else {
-                nameW = res[i].getName();
+                nameW = wqkms[i].getName();
                 nameQ = "Q(" + nameQ + ")";
             }
 
@@ -75,7 +73,7 @@
             facets.add(w);
             facets.add(q);
 
-            if (res[i] instanceof WQCKms) {
+            if (wqkms[i] instanceof WQCKms) {
                 // TODO DO i18n
 
                 String nameC = nameW.replace(
@@ -89,7 +87,7 @@
             }
         }
 
-        if (res.length > 0) {
+        if (wqkms.length > 0) {
             facets.add(new DataFacet(CSV, "CSV data"));
             facets.add(new DataFacet(WST, "WST data"));
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java	Mon Jun 20 12:32:32 2011 +0000
@@ -10,12 +10,15 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
+
 import de.intevation.flys.artifacts.model.DurationCurveFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WQDay;
-import de.intevation.flys.artifacts.resources.Resources;
 
 import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.CalculationResult;
+
+import de.intevation.flys.artifacts.resources.Resources;
 
 
 /**
@@ -45,20 +48,18 @@
     ) {
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        WQDay res;
+        CalculationResult res;
 
-        if (old instanceof WQDay []) {
-            res = ((WQDay [])old)[0];
+        if (old instanceof CalculationResult) {
+            res = (CalculationResult)old;
         }
         else {
             res = winfo.getDurationCurveData();
-            if (res == null) {
-                logger.debug("No results given.");
-                return null;
-            }
         }
 
-        if (facets != null) {
+        WQDay wqday = (WQDay)res.getData();
+
+        if (wqday != null && facets != null) {
             Object[] args = new Object[] {
                 winfo.getRiver().getName()
             };
@@ -75,8 +76,8 @@
                 "",
                 args);
 
-            Facet w = new DurationCurveFacet(0, DURATION_W, nameW);
-            Facet q = new DurationCurveFacet(0, DURATION_Q, nameQ);
+            Facet w = new DurationCurveFacet(DURATION_W, nameW);
+            Facet q = new DurationCurveFacet(DURATION_Q, nameQ);
 
             facets.add(w);
             facets.add(q);
@@ -84,7 +85,7 @@
             facets.add(new DataFacet(CSV, "CSV data"));
         }
 
-        return new WQDay[] { res };
+        return res;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Mon Jun 20 12:32:32 2011 +0000
@@ -15,6 +15,7 @@
 import de.intevation.flys.artifacts.model.WQKms;
 
 import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.CalculationResult;
 
 
 public class WaterlevelState
@@ -35,33 +36,26 @@
     ) {
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        WQKms [] res;
-
-        if (old instanceof WQKms []) {
-            res = (WQKms [])old;
-        }
-        else {
-            res = winfo.getWaterlevelData();
-            if (res == null) {
-                logger.debug("No results given.");
-                return null;
-            }
-        }
+        CalculationResult res = old instanceof CalculationResult
+            ? (CalculationResult)old
+            : winfo.getWaterlevelData();
 
         if (facets == null) {
             return res;
         }
 
-        for (int i = 0; i < res.length; i++) {
+        WQKms [] wqkms = (WQKms [])res.getData();
+
+        for (int i = 0; i < wqkms.length; i++) {
             String nameW = null;
             String nameQ = null;
 
             if (winfo.isQ()) {
-                nameQ = res[i].getName();
+                nameQ = wqkms[i].getName();
                 nameW = "W(" + nameQ + ")";
             }
             else {
-                nameW = res[i].getName();
+                nameW = wqkms[i].getName();
                 nameQ = "Q(" + nameQ + ")";
             }
 
@@ -75,7 +69,7 @@
             facets.add(q);
         }
 
-        if (res.length > 0) {
+        if (wqkms.length > 0) {
             Facet wst = new DataFacet(WST, "WST data");
             Facet csv = new DataFacet(CSV, "CSV data");
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java	Mon Jun 20 12:32:32 2011 +0000
@@ -3,7 +3,6 @@
 import java.io.OutputStream;
 import java.text.NumberFormat;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.w3c.dom.Document;
@@ -15,6 +14,8 @@
 import de.intevation.artifacts.CallContext;
 
 import de.intevation.flys.artifacts.model.WQDay;
+import de.intevation.flys.artifacts.model.CalculationResult;
+
 import de.intevation.flys.utils.Formatter;
 
 
@@ -56,8 +57,11 @@
 
     @Override
     protected void addData(Object d) {
-        if (d instanceof WQDay []) {
-            data.addAll(Arrays.asList((WQDay [])d));
+        if (d instanceof CalculationResult) {
+            d = ((CalculationResult)d).getData();
+            if (d instanceof WQDay) {
+                data.add((WQDay)d);
+            }
         }
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java	Sat Jun 18 20:20:34 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java	Mon Jun 20 12:32:32 2011 +0000
@@ -14,6 +14,7 @@
 
 import de.intevation.artifacts.CallContext;
 
+import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.WQKms;
 
 import de.intevation.flys.utils.Formatter;
@@ -78,8 +79,11 @@
 
     @Override
     protected void addData(Object d) {
-        if (d instanceof WQKms []) {
-            data.add((WQKms [])d);
+        if (d instanceof CalculationResult) {
+            d = ((CalculationResult)d).getData();
+            if (d instanceof WQKms []) {
+                data.add((WQKms [])d);
+            }
         }
     }
 

http://dive4elements.wald.intevation.org