changeset 4754:04377ccef10a

AFT: Reject AFT gauges which are not inside the calculation range of the corresponding FLYS river.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 03 Jan 2013 14:39:48 +0100
parents a310aceb2e51
children ba8c2147b4ff
files flys-aft/src/main/java/de/intevation/aft/River.java flys-aft/src/main/resources/sql/aft-common.properties
diffstat 2 files changed, 73 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Jan 03 14:19:45 2013 +0100
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Jan 03 14:39:48 2013 +0100
@@ -70,44 +70,59 @@
         ConnectedStatements flysStatements = context.getFlysStatements();
         ConnectedStatements aftStatements  = context.getAftStatements();
 
+        String riverName = getName();
+
+        Map<Long, DIPSGauge> aftDIPSGauges = new HashMap<Long, DIPSGauge>();
+
         ResultSet messstellenRs = aftStatements
             .getStatement("select.messstelle")
             .clearParameters()
             .setInt("GEWAESSER_NR", id2).executeQuery();
 
-        String riverName = getName();
-
-        Map<Long, DIPSGauge> aftDIPSGauges = new HashMap<Long, DIPSGauge>();
+        try {
+            while (messstellenRs.next()) {
+                String name    = messstellenRs.getString("NAME");
+                String num     = messstellenRs.getString("MESSSTELLE_NR");
+                double station = messstellenRs.getDouble("STATIONIERUNG");
 
-        while (messstellenRs.next()) {
-            String name = messstellenRs.getString("NAME");
-            String num  = messstellenRs.getString("MESSSTELLE_NR");
-            Long number = SyncContext.numberToLong(num);
-            if (number == null) {
-                log.warn("AFT: Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'");
-                continue;
+                if (messstellenRs.wasNull()) {
+                    log.warn("AFT: STATION of MESSSTELLE '"+name+"' is NULL -> ignored.");
+                    continue;
+                }
+
+                if (!inside(station)) {
+                    log.warn("AFT: MESSSTELLE '"+name+"' out of calculation range -> ignored.");
+                    continue;
+                }
+
+                Long number = SyncContext.numberToLong(num);
+                if (number == null) {
+                    log.warn("AFT: Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'");
+                    continue;
+                }
+                DIPSGauge dipsGauge = dipsGauges.get(number);
+                if (dipsGauge == null) {
+                    log.warn(
+                        "DIPS: MESSSTELLE '" + name + "' not found in DIPS. " +
+                        "Gauge number used for lookup: " + number);
+                    continue;
+                }
+                String gaugeRiver = dipsGauge.getRiverName();
+                if (!gaugeRiver.equalsIgnoreCase(riverName)) {
+                    log.warn(
+                        "DIPS: MESSSTELLE '" + name +
+                        "' is assigned to river '" + gaugeRiver +
+                        "'. Needs to be on '" + riverName + "'.");
+                    continue;
+                }
+                dipsGauge.setAftName(name);
+                dipsGauge.setOfficialNumber(number);
+                aftDIPSGauges.put(number, dipsGauge);
             }
-            DIPSGauge dipsGauge = dipsGauges.get(number);
-            if (dipsGauge == null) {
-                log.warn(
-                    "DIPS: MESSSTELLE '" + name + "' not found in DIPS. " +
-                    "Gauge number used for lookup: " + number);
-                continue;
-            }
-            String gaugeRiver = dipsGauge.getRiverName();
-            if (!gaugeRiver.equalsIgnoreCase(riverName)) {
-                log.warn(
-                    "DIPS: MESSSTELLE '" + name +
-                    "' is assigned to river '" + gaugeRiver +
-                    "'. Needs to be on '" + riverName + "'.");
-                continue;
-            }
-            dipsGauge.setAftName(name);
-            dipsGauge.setOfficialNumber(number);
-            aftDIPSGauges.put(number, dipsGauge);
         }
-
-        messstellenRs.close();
+        finally {
+            messstellenRs.close();
+        }
 
         List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>();
 
@@ -116,28 +131,32 @@
             .clearParameters()
             .setInt("river_id", id1).executeQuery();
 
-        while (gaugesRs.next()) {
-            int gaugeId = gaugesRs.getInt("id");
-            String name = gaugesRs.getString("name");
-            long   number = gaugesRs.getLong("official_number");
-            if (gaugesRs.wasNull()) {
-                log.warn("FLYS: Gauge '" + name +
-                    "' has no official number. Ignored.");
-                continue;
+        try {
+            while (gaugesRs.next()) {
+                int gaugeId = gaugesRs.getInt("id");
+                String name = gaugesRs.getString("name");
+                long   number = gaugesRs.getLong("official_number");
+                if (gaugesRs.wasNull()) {
+                    log.warn("FLYS: Gauge '" + name +
+                        "' has no official number. Ignored.");
+                    continue;
+                }
+                Long key = Long.valueOf(number);
+                DIPSGauge aftDIPSGauge = aftDIPSGauges.remove(key);
+                if (aftDIPSGauge == null) {
+                    log.warn("FLYS: Gauge '" + name + "' number " + number +
+                        " is not found in AFT/DIPS.");
+                    continue;
+                }
+                aftDIPSGauge.setFlysId(gaugeId);
+                log.info("Gauge '" + name +
+                    "' found in FLYS, AFT and DIPS. -> Update");
+                updateGauges.add(aftDIPSGauge);
             }
-            Long key = Long.valueOf(number);
-            DIPSGauge aftDIPSGauge = aftDIPSGauges.remove(key);
-            if (aftDIPSGauge == null) {
-                log.warn("FLYS: Gauge '" + name + "' number " + number +
-                    " is not found in AFT/DIPS.");
-                continue;
-            }
-            aftDIPSGauge.setFlysId(gaugeId);
-            log.info("Gauge '" + name +
-                "' found in FLYS, AFT and DIPS. -> Update");
-            updateGauges.add(aftDIPSGauge);
         }
-        gaugesRs.close();
+        finally {
+            gaugesRs.close();
+        }
 
         boolean modified = createGauges(context, aftDIPSGauges);
 
--- a/flys-aft/src/main/resources/sql/aft-common.properties	Thu Jan 03 14:19:45 2013 +0100
+++ b/flys-aft/src/main/resources/sql/aft-common.properties	Thu Jan 03 14:39:48 2013 +0100
@@ -1,5 +1,8 @@
 select.gewaesser = SELECT GEWAESSER_NR, NAME FROM SL_GEWAESSER
-select.messstelle = SELECT NAME, MESSSTELLE_NR FROM MESSSTELLE WHERE GEWAESSER_NR = :GEWAESSER_NR
+select.messstelle = \
+    SELECT NAME, MESSSTELLE_NR, STATIONIERUNG \
+    FROM MESSSTELLE \
+    WHERE GEWAESSER_NR = :GEWAESSER_NR
 select.abflusstafel = SELECT ABFLUSSTAFEL_NR, \
                              ABFLUSSTAFEL_BEZ, \
                              strftime('%s', GUELTIG_VON) * 1000 AS GUELTIG_VON, \

http://dive4elements.wald.intevation.org