# HG changeset patch # User Sascha L. Teichmann # Date 1349006128 -7200 # Node ID b7bdef1831ac676c3fcbb5eb1808abf18c292c8d # Parent a4930c43b806c965372bd1cb75df283d7312a3c8 Removed heavy weight data from the gauge discharge curve facet. diff -r a4930c43b806 -r b7bdef1831ac flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java, diff -r a4930c43b806 -r b7bdef1831ac flys-artifacts/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 fs = new ArrayList(1); fs.add(gfacet); diff -r a4930c43b806 -r b7bdef1831ac flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java --- 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 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; }