changeset 6859:3ccbc278f2e6

(issue1347) Add SQ Relation fields for measurement station information
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 19 Aug 2013 11:41:09 +0200
parents b5e2d18cc341
children affcedb306da
files artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationJRDataSource.java artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationExporter.java
diffstat 3 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Mon Aug 19 11:40:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Mon Aug 19 11:41:09 2013 +0200
@@ -9,11 +9,13 @@
 package org.dive4elements.river.artifacts.access;
 
 import java.util.Date;
+import java.util.List;
 
 import org.apache.log4j.Logger;
 
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.model.DateRange;
+import org.dive4elements.river.model.MeasurementStation;
 
 public class SQRelationAccess
 extends      RiverAccess
@@ -28,6 +30,8 @@
 
     private String      method;
 
+    protected MeasurementStation measurementStation;
+
     public SQRelationAccess() {
     }
 
@@ -80,5 +84,30 @@
         }
         return method;
     }
+
+    public String getMeasurementStationName() {
+        MeasurementStation station = getMeasurementStation();
+        return station == null ? null : station.getName();
+    }
+
+    public String getMeasurementStationGaugeName() {
+        MeasurementStation station = getMeasurementStation();
+        return station == null ? null : station.getGaugeName();
+    }
+
+    public MeasurementStation getMeasurementStation() {
+        if (measurementStation != null) {
+            return measurementStation;
+        }
+        List<MeasurementStation> candidates = MeasurementStation.getStationsAtKM(
+                getRiver(), getLocation());
+        if (candidates != null) {
+            // Just take the first one as we only use the name
+            // and that "should" be unique at the location
+            measurementStation = candidates.get(0);
+        }
+
+        return measurementStation;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationJRDataSource.java	Mon Aug 19 11:40:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationJRDataSource.java	Mon Aug 19 11:41:09 2013 +0200
@@ -73,6 +73,12 @@
         else if ("periods".equals(fieldName)) {
             value = metaData.get("periods");
         }
+        else if ("msName".equals(fieldName)) {
+            value = metaData.get("msName");
+        }
+        else if ("msGauge".equals(fieldName)) {
+            value = metaData.get("msGauge");
+        }
         else if ("km".equals(fieldName)) {
             value = data.get(index)[0];
         }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationExporter.java	Mon Aug 19 11:40:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationExporter.java	Mon Aug 19 11:41:09 2013 +0200
@@ -261,6 +261,19 @@
                                             locale,
                                             PDF_HEADER_MODE,
                                             "SQRelation"));
+
+        String measurementStationName = access.getMeasurementStationName();
+
+        if (measurementStationName != null) {
+            source.addMetaData("msName", measurementStationName);
+        }
+
+        String measurementStationGaugeName = access.getMeasurementStationGaugeName();
+
+        if (measurementStationGaugeName != null) {
+            source.addMetaData("msGauge", measurementStationGaugeName);
+        }
+
     }
 
     @Override

http://dive4elements.wald.intevation.org