comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4085:067341e86375

Separate FLYS gauges to be updated or to create. flys-aft/trunk@3523 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 22 Dec 2011 12:07:29 +0000
parents 9178beeb7b05
children aad1886ea226
comparison
equal deleted inserted replaced
4084:9178beeb7b05 4085:067341e86375
1 package de.intevation.aft; 1 package de.intevation.aft;
2 2
3 import java.util.List;
4 import java.util.ArrayList;
5 import java.util.HashMap;
3 import java.util.Map; 6 import java.util.Map;
4 7
5 import java.sql.ResultSet; 8 import java.sql.ResultSet;
6 import java.sql.SQLException; 9 import java.sql.SQLException;
7 10
40 ResultSet messstellenRs = aftStatements 43 ResultSet messstellenRs = aftStatements
41 .getStatement("select.messstelle") 44 .getStatement("select.messstelle")
42 .clearParameters() 45 .clearParameters()
43 .setInt("GEWAESSER_NR", id2).executeQuery(); 46 .setInt("GEWAESSER_NR", id2).executeQuery();
44 47
48 String riverName = getName();
49
50 Map<Long, DIPSGauge> aftDIPSGauges = new HashMap<Long, DIPSGauge>();
51
45 while (messstellenRs.next()) { 52 while (messstellenRs.next()) {
46 String name = messstellenRs.getString("NAME"); 53 String name = messstellenRs.getString("NAME");
47 String num = messstellenRs.getString("MESSSTELLE_NR"); 54 String num = messstellenRs.getString("MESSSTELLE_NR");
48 Long number = SyncContext.numberToLong(num); 55 Long number = SyncContext.numberToLong(num);
49 if (number == null) { 56 if (number == null) {
50 log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'"); 57 log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'");
51 continue; 58 continue;
52 } 59 }
53 DIPSGauge dipsGauge = dipsGauges.get(number); 60 DIPSGauge dipsGauge = dipsGauges.get(number);
54 if (dipsGauges == null) { 61 if (dipsGauge == null) {
55 log.warn("MESSSTELLE '" + name + "' not found in DIPS."); 62 log.warn(
63 "MESSSTELLE '" + name + "' not found in DIPS. " +
64 "Gauge number used for lookup: " + number);
56 continue; 65 continue;
57 } 66 }
67 String gaugeRiver = dipsGauge.getRiverName();
68 if (!gaugeRiver.equalsIgnoreCase(riverName)) {
69 log.warn(
70 "MESSSTELLE '" + name +
71 "' is assigned to river '" + gaugeRiver +
72 "'. Needs to be on '" + riverName + "'.");
73 continue;
74 }
75 dipsGauge.setAftName(name);
76 aftDIPSGauges.put(number, dipsGauge);
58 } 77 }
59 78
60 messstellenRs.close(); 79 messstellenRs.close();
80
81
82 List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>();
61 83
62 ResultSet gaugesRs = flysStatements 84 ResultSet gaugesRs = flysStatements
63 .getStatement("select.gauges") 85 .getStatement("select.gauges")
64 .clearParameters() 86 .clearParameters()
65 .setInt("river_id", id1).executeQuery(); 87 .setInt("river_id", id1).executeQuery();
66 88
67 while (gaugesRs.next()) { 89 while (gaugesRs.next()) {
68 int gaugeId = gaugesRs.getInt("id"); 90 int gaugeId = gaugesRs.getInt("id");
69 String name = gaugesRs.getString("name"); 91 String name = gaugesRs.getString("name");
92 long number = gaugesRs.getLong("official_number");
93 if (gaugesRs.wasNull()) {
94 log.warn("FLYS: Gauge '" + name +
95 "' has no official number. Ignored.");
96 continue;
97 }
98 Long key = Long.valueOf(number);
99 DIPSGauge aftDIPSGauge = aftDIPSGauges.remove(key);
100 if (aftDIPSGauge == null) {
101 log.warn("FLYS: Gauge '" + name + "' number " + number +
102 " is not found in AFT/DIPS.");
103 continue;
104 }
105 aftDIPSGauge.setFlysId(gaugeId);
106 log.info("Gauge '" + name +
107 "' found in FLYS, AFT and DIPS. -> Update");
108 updateGauges.add(aftDIPSGauge);
70 } 109 }
71 110
72 gaugesRs.close(); 111 gaugesRs.close();
73 112
113 for (DIPSGauge gauge: aftDIPSGauges.values()) {
114 log.info("Gauge '" + gauge.getAftName() +
115 "' not in FLYS but in AFT/DIPS. -> Create");
116 }
74 } 117 }
75 118
76 public String toString() { 119 public String toString() {
77 return "[River: name=" + name + ", " + super.toString() + "]"; 120 return "[River: name=" + name + ", " + super.toString() + "]";
78 } 121 }

http://dive4elements.wald.intevation.org