changeset 3986:b7bdef1831ac

Removed heavy weight data from the gauge discharge curve facet.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 30 Sep 2012 13:55:28 +0200
parents a4930c43b806
children b328da465fe9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java
diffstat 3 files changed, 43 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sun Sep 30 13:23:05 2012 +0200
+++ b/flys-artifacts/ChangeLog	Sun Sep 30 13:55:28 2012 +0200
@@ -1,3 +1,15 @@
+2012-09-30	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java:
+	  Removed heavy weight backend data (gauge) from facet.
+	  The relevant data is already available in the artifact.
+
+	  !!! Facets should be only used to retrieve data with the help of
+	  !!! the artifact. If the artifact already stores the data or
+	  !!! is able to fetch it for the facet don't replicated it in
+	  !!! the members of the facet.
+
 2012-09-30	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java	Sun Sep 30 13:23:05 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java	Sun Sep 30 13:55:28 2012 +0200
@@ -67,7 +67,7 @@
 
         Gauge gauge = FLYSUtils.getReferenceGauge(this);
 
-        Facet gfacet = new GaugeDischargeCurveFacet(rivername, gauge);
+        Facet gfacet = new GaugeDischargeCurveFacet();
 
         List<Facet> fs = new ArrayList<Facet>(1);
         fs.add(gfacet);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java	Sun Sep 30 13:23:05 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java	Sun Sep 30 13:55:28 2012 +0200
@@ -9,8 +9,14 @@
 import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
+
 import de.intevation.flys.model.Gauge;
 
+import de.intevation.flys.utils.FLYSUtils;
+
+import org.apache.log4j.Logger;
+
 /**
  * A Facet that returns discharge curve data at a gauge
  *
@@ -19,19 +25,35 @@
 public class GaugeDischargeCurveFacet
 extends      DefaultFacet
 {
-    private Gauge gauge;
-    private String river;
+    private static final Logger log =
+        Logger.getLogger(GaugeDischargeCurveFacet.class);
 
-    public GaugeDischargeCurveFacet(String river, Gauge gauge) {
+    public GaugeDischargeCurveFacet() {
         super(0, "facet.gauge.discharge_curve", "facet.gauge.discharge_curve");
-        this.river = river;
-        this.gauge = gauge;
     }
 
     @Override
     public Object getData(Artifact art, CallContext context) {
 
-        DischargeTables dt = new DischargeTables(river, gauge.getName());
+        if (!(art instanceof FLYSArtifact)) {
+            log.warn("Invalid artifact type");
+            return null;
+        }
+
+        FLYSArtifact flys = (FLYSArtifact)art;
+
+        String river = flys.getDataAsString("river");
+
+        Gauge gauge = FLYSUtils.getReferenceGauge(flys);
+
+        if (river == null || gauge == null) {
+            log.warn("Unknown river or gauge");
+            return null;
+        }
+
+        String name = gauge.getName();
+
+        DischargeTables dt = new DischargeTables(river, name);
 
         Map<String, double [][]> map = dt.getValues(100d);
 
@@ -41,13 +63,12 @@
         }
         double [] kms = new double[values[0].length];
         Arrays.fill(kms, gauge.getStation().doubleValue());
-        return new WQKms(kms, values[0], values[1], gauge.getName());
+        return new WQKms(kms, values[0], values[1], name);
     }
 
     @Override
     public Facet deepCopy() {
-        GaugeDischargeCurveFacet copy =
-            new GaugeDischargeCurveFacet(this.river, this.gauge);
+        GaugeDischargeCurveFacet copy = new GaugeDischargeCurveFacet();
         copy.set(this);
         return copy;
     }

http://dive4elements.wald.intevation.org