comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4775:d9f1202cef78

Do the pairing of FLYS and AFT discharge tables by the field 'ABFLUSSTAFEL.BFG_ID' in AFT and 'discharge_table.bfg_id' in FLYS. TODO: Create new column in discharge_tabel.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sat, 05 Jan 2013 14:52:55 +0100
parents 9dcc32fc5167
children 2b7f44c80857
comparison
equal deleted inserted replaced
4774:9dcc32fc5167 4775:d9f1202cef78
177 DIPSGauge gauge 177 DIPSGauge gauge
178 ) 178 )
179 throws SQLException 179 throws SQLException
180 { 180 {
181 log.info("FLYS: Updating gauge '" + gauge.getAftName() + "'."); 181 log.info("FLYS: Updating gauge '" + gauge.getAftName() + "'.");
182 // We need to load all discharge tables from both database 182 // We need to load all discharge tables from both databases
183 // of the gauge and do some pairing based on their descriptions. 183 // of the gauge and do some pairing based on their bfg_id.
184 184
185 boolean modified = false; 185 boolean modified = false;
186 186
187 ConnectedStatements flysStatements = context.getFlysStatements(); 187 ConnectedStatements flysStatements = context.getFlysStatements();
188 188
194 194
195 List<DischargeTable> aftDTs = 195 List<DischargeTable> aftDTs =
196 DischargeTable.loadAftDischargeTables( 196 DischargeTable.loadAftDischargeTables(
197 context, gauge.getOfficialNumber()); 197 context, gauge.getOfficialNumber());
198 198
199 Map<String, DischargeTable> desc2FlysDT = 199 Map<String, DischargeTable> bfgId2FlysDT =
200 new HashMap<String, DischargeTable>(); 200 new HashMap<String, DischargeTable>();
201 201
202 for (DischargeTable dt: flysDTs) { 202 for (DischargeTable dt: flysDTs) {
203 String description = dt.getDescription(); 203 String bfgId = dt.getBfgId();
204 if (description == null) { 204 if (bfgId == null) {
205 log.warn("FLYS: discharge table " + dt.getId() 205 log.warn("FLYS: discharge table " + dt.getId()
206 + " has no description. Ignored."); 206 + " has no bfg_id. Ignored.");
207 continue; 207 continue;
208 } 208 }
209 desc2FlysDT.put(description, dt); 209 bfgId2FlysDT.put(bfgId, dt);
210 } 210 }
211 211
212 List<DischargeTable> createDTs = new ArrayList<DischargeTable>(); 212 List<DischargeTable> createDTs = new ArrayList<DischargeTable>();
213 213
214 for (DischargeTable aftDT: aftDTs) { 214 for (DischargeTable aftDT: aftDTs) {
215 String description = aftDT.getDescription(); 215 String bfgId = aftDT.getBfgId();
216 DischargeTable flysDT = desc2FlysDT.remove(description); 216 DischargeTable flysDT = bfgId2FlysDT.remove(bfgId);
217 if (flysDT != null) { 217 if (flysDT != null) {
218 // Found in AFT and FLYS. 218 // Found in AFT and FLYS.
219 log.info("FLYS: Discharge table '" + description 219 log.info("FLYS: Discharge table '" + bfgId
220 + "' found in AFT and FLYS. -> update"); 220 + "' found in AFT and FLYS. -> update");
221 // Create the W/Q diff. 221 // Create the W/Q diff.
222 modified |= writeWQChanges(context, flysDT, aftDT); 222 modified |= writeWQChanges(context, flysDT, aftDT);
223 } 223 }
224 else { 224 else {
225 log.info("FLYS: Discharge table '" + description 225 log.info("FLYS: Discharge table '" + bfgId
226 + "' not found in FLYS. -> create"); 226 + "' not found in FLYS. -> create");
227 createDTs.add(aftDT); 227 createDTs.add(aftDT);
228 } 228 }
229 } 229 }
230 230
231 for (String description: desc2FlysDT.keySet()) { 231 for (String bfgId: bfgId2FlysDT.keySet()) {
232 log.info("FLYS: Discharge table '" + description 232 log.info("FLYS: Discharge table '" + bfgId
233 + "' found in FLYS but not in AFT. -> ignore"); 233 + "' found in FLYS but not in AFT. -> ignore");
234 } 234 }
235 235
236 log.info("FLYS: Copy " + createDTs.size() + 236 log.info("FLYS: Copy " + createDTs.size() +
237 " discharge tables over from AFT."); 237 " discharge tables over from AFT.");

http://dive4elements.wald.intevation.org