# HG changeset patch # User Sascha L. Teichmann # Date 1324555649 0 # Node ID 067341e86375d23177f3aea13d485e07c6f1aa20 # Parent 9178beeb7b05fd59d86cd13720fa583c5108341e Separate FLYS gauges to be updated or to create. flys-aft/trunk@3523 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9178beeb7b05 -r 067341e86375 flys-aft/ChangeLog --- a/flys-aft/ChangeLog Wed Dec 21 15:16:58 2011 +0000 +++ b/flys-aft/ChangeLog Thu Dec 22 12:07:29 2011 +0000 @@ -1,3 +1,13 @@ +2011-12-22 Sascha L. Teichmann + + * src/main/java/de/intevation/aft/River.java: Figure out + which gauges must be updated, which must be created. + + * src/main/java/de/intevation/aft/DIPSGauge.java: Store + info from AFT and FLYS, too. + + * src/main/resources/sql/flys-common.properties: Fetch the + official number, too. 2011-12-20 Sascha L. Teichmann * src/main/java/de/intevation/aft/River.java: Removed diff -r 9178beeb7b05 -r 067341e86375 flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java --- a/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java Wed Dec 21 15:16:58 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java Thu Dec 22 12:07:29 2011 +0000 @@ -67,14 +67,21 @@ protected String name; + protected String riverName; + protected List datums; + protected int flysId; + + protected String aftName; + public DIPSGauge() { } public DIPSGauge(Element element) { - name = element.getAttribute("NAME"); + name = element.getAttribute("NAME"); + riverName = element.getAttribute("GEWAESSER"); String aeoString = element.getAttribute("EINZUGSGEBIET_AEO"); if (aeoString.length() == 0) { @@ -100,5 +107,27 @@ public String getName() { return name; } + + public String getRiverName() { + return riverName; + } + + public int getFlysId() { + return flysId; + } + + public void setFlysId(int flysId) { + this.flysId = flysId; + } + + public String getAftName() { + return aftName != null ? aftName : name; + } + + public void setAftName(String aftName) { + this.aftName = aftName; + } + + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9178beeb7b05 -r 067341e86375 flys-aft/src/main/java/de/intevation/aft/River.java --- a/flys-aft/src/main/java/de/intevation/aft/River.java Wed Dec 21 15:16:58 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Thu Dec 22 12:07:29 2011 +0000 @@ -1,5 +1,8 @@ package de.intevation.aft; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; import java.util.Map; import java.sql.ResultSet; @@ -42,6 +45,10 @@ .clearParameters() .setInt("GEWAESSER_NR", id2).executeQuery(); + String riverName = getName(); + + Map aftDIPSGauges = new HashMap(); + while (messstellenRs.next()) { String name = messstellenRs.getString("NAME"); String num = messstellenRs.getString("MESSSTELLE_NR"); @@ -51,14 +58,29 @@ continue; } DIPSGauge dipsGauge = dipsGauges.get(number); - if (dipsGauges == null) { - log.warn("MESSSTELLE '" + name + "' not found in DIPS."); + if (dipsGauge == null) { + log.warn( + "MESSSTELLE '" + name + "' not found in DIPS. " + + "Gauge number used for lookup: " + number); continue; } + String gaugeRiver = dipsGauge.getRiverName(); + if (!gaugeRiver.equalsIgnoreCase(riverName)) { + log.warn( + "MESSSTELLE '" + name + + "' is assigned to river '" + gaugeRiver + + "'. Needs to be on '" + riverName + "'."); + continue; + } + dipsGauge.setAftName(name); + aftDIPSGauges.put(number, dipsGauge); } messstellenRs.close(); + + List updateGauges = new ArrayList(); + ResultSet gaugesRs = flysStatements .getStatement("select.gauges") .clearParameters() @@ -67,10 +89,31 @@ 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); } gaugesRs.close(); + for (DIPSGauge gauge: aftDIPSGauges.values()) { + log.info("Gauge '" + gauge.getAftName() + + "' not in FLYS but in AFT/DIPS. -> Create"); + } } public String toString() { diff -r 9178beeb7b05 -r 067341e86375 flys-aft/src/main/resources/sql/flys-common.properties --- a/flys-aft/src/main/resources/sql/flys-common.properties Wed Dec 21 15:16:58 2011 +0000 +++ b/flys-aft/src/main/resources/sql/flys-common.properties Thu Dec 22 12:07:29 2011 +0000 @@ -1,2 +1,2 @@ select.river = SELECT id, name FROM rivers -select.gauges = SELECT id, name FROM gauges WHERE river_id = :river_id +select.gauges = SELECT id, name, official_number FROM gauges WHERE river_id = :river_id