comparison 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
comparison
equal deleted inserted replaced
4753:a310aceb2e51 4754:04377ccef10a
68 Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges(); 68 Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges();
69 69
70 ConnectedStatements flysStatements = context.getFlysStatements(); 70 ConnectedStatements flysStatements = context.getFlysStatements();
71 ConnectedStatements aftStatements = context.getAftStatements(); 71 ConnectedStatements aftStatements = context.getAftStatements();
72 72
73 String riverName = getName();
74
75 Map<Long, DIPSGauge> aftDIPSGauges = new HashMap<Long, DIPSGauge>();
76
73 ResultSet messstellenRs = aftStatements 77 ResultSet messstellenRs = aftStatements
74 .getStatement("select.messstelle") 78 .getStatement("select.messstelle")
75 .clearParameters() 79 .clearParameters()
76 .setInt("GEWAESSER_NR", id2).executeQuery(); 80 .setInt("GEWAESSER_NR", id2).executeQuery();
77 81
78 String riverName = getName(); 82 try {
79 83 while (messstellenRs.next()) {
80 Map<Long, DIPSGauge> aftDIPSGauges = new HashMap<Long, DIPSGauge>(); 84 String name = messstellenRs.getString("NAME");
81 85 String num = messstellenRs.getString("MESSSTELLE_NR");
82 while (messstellenRs.next()) { 86 double station = messstellenRs.getDouble("STATIONIERUNG");
83 String name = messstellenRs.getString("NAME"); 87
84 String num = messstellenRs.getString("MESSSTELLE_NR"); 88 if (messstellenRs.wasNull()) {
85 Long number = SyncContext.numberToLong(num); 89 log.warn("AFT: STATION of MESSSTELLE '"+name+"' is NULL -> ignored.");
86 if (number == null) { 90 continue;
87 log.warn("AFT: Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'"); 91 }
88 continue; 92
89 } 93 if (!inside(station)) {
90 DIPSGauge dipsGauge = dipsGauges.get(number); 94 log.warn("AFT: MESSSTELLE '"+name+"' out of calculation range -> ignored.");
91 if (dipsGauge == null) { 95 continue;
92 log.warn( 96 }
93 "DIPS: MESSSTELLE '" + name + "' not found in DIPS. " + 97
94 "Gauge number used for lookup: " + number); 98 Long number = SyncContext.numberToLong(num);
95 continue; 99 if (number == null) {
96 } 100 log.warn("AFT: Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'");
97 String gaugeRiver = dipsGauge.getRiverName(); 101 continue;
98 if (!gaugeRiver.equalsIgnoreCase(riverName)) { 102 }
99 log.warn( 103 DIPSGauge dipsGauge = dipsGauges.get(number);
100 "DIPS: MESSSTELLE '" + name + 104 if (dipsGauge == null) {
101 "' is assigned to river '" + gaugeRiver + 105 log.warn(
102 "'. Needs to be on '" + riverName + "'."); 106 "DIPS: MESSSTELLE '" + name + "' not found in DIPS. " +
103 continue; 107 "Gauge number used for lookup: " + number);
104 } 108 continue;
105 dipsGauge.setAftName(name); 109 }
106 dipsGauge.setOfficialNumber(number); 110 String gaugeRiver = dipsGauge.getRiverName();
107 aftDIPSGauges.put(number, dipsGauge); 111 if (!gaugeRiver.equalsIgnoreCase(riverName)) {
108 } 112 log.warn(
109 113 "DIPS: MESSSTELLE '" + name +
110 messstellenRs.close(); 114 "' is assigned to river '" + gaugeRiver +
115 "'. Needs to be on '" + riverName + "'.");
116 continue;
117 }
118 dipsGauge.setAftName(name);
119 dipsGauge.setOfficialNumber(number);
120 aftDIPSGauges.put(number, dipsGauge);
121 }
122 }
123 finally {
124 messstellenRs.close();
125 }
111 126
112 List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>(); 127 List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>();
113 128
114 ResultSet gaugesRs = flysStatements 129 ResultSet gaugesRs = flysStatements
115 .getStatement("select.gauges") 130 .getStatement("select.gauges")
116 .clearParameters() 131 .clearParameters()
117 .setInt("river_id", id1).executeQuery(); 132 .setInt("river_id", id1).executeQuery();
118 133
119 while (gaugesRs.next()) { 134 try {
120 int gaugeId = gaugesRs.getInt("id"); 135 while (gaugesRs.next()) {
121 String name = gaugesRs.getString("name"); 136 int gaugeId = gaugesRs.getInt("id");
122 long number = gaugesRs.getLong("official_number"); 137 String name = gaugesRs.getString("name");
123 if (gaugesRs.wasNull()) { 138 long number = gaugesRs.getLong("official_number");
124 log.warn("FLYS: Gauge '" + name + 139 if (gaugesRs.wasNull()) {
125 "' has no official number. Ignored."); 140 log.warn("FLYS: Gauge '" + name +
126 continue; 141 "' has no official number. Ignored.");
127 } 142 continue;
128 Long key = Long.valueOf(number); 143 }
129 DIPSGauge aftDIPSGauge = aftDIPSGauges.remove(key); 144 Long key = Long.valueOf(number);
130 if (aftDIPSGauge == null) { 145 DIPSGauge aftDIPSGauge = aftDIPSGauges.remove(key);
131 log.warn("FLYS: Gauge '" + name + "' number " + number + 146 if (aftDIPSGauge == null) {
132 " is not found in AFT/DIPS."); 147 log.warn("FLYS: Gauge '" + name + "' number " + number +
133 continue; 148 " is not found in AFT/DIPS.");
134 } 149 continue;
135 aftDIPSGauge.setFlysId(gaugeId); 150 }
136 log.info("Gauge '" + name + 151 aftDIPSGauge.setFlysId(gaugeId);
137 "' found in FLYS, AFT and DIPS. -> Update"); 152 log.info("Gauge '" + name +
138 updateGauges.add(aftDIPSGauge); 153 "' found in FLYS, AFT and DIPS. -> Update");
139 } 154 updateGauges.add(aftDIPSGauge);
140 gaugesRs.close(); 155 }
156 }
157 finally {
158 gaugesRs.close();
159 }
141 160
142 boolean modified = createGauges(context, aftDIPSGauges); 161 boolean modified = createGauges(context, aftDIPSGauges);
143 162
144 modified |= updateGauges(context, updateGauges); 163 modified |= updateGauges(context, updateGauges);
145 164

http://dive4elements.wald.intevation.org