diff flys-aft/src/main/java/de/intevation/aft/River.java @ 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 f939e1e6cfa4
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);
 

http://dive4elements.wald.intevation.org