comparison etl/src/main/java/org/dive4elements/river/etl/aft/River.java @ 6894:389bf6b7d371

Backed out changeset 60f39ee19473
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 21 Aug 2013 16:14:29 +0200
parents 60f39ee19473
children e5675e85ac38
comparison
equal deleted inserted replaced
6893:60f39ee19473 6894:389bf6b7d371
13 13
14 import java.sql.ResultSet; 14 import java.sql.ResultSet;
15 import java.sql.SQLException; 15 import java.sql.SQLException;
16 16
17 import java.util.ArrayList; 17 import java.util.ArrayList;
18 import java.util.Comparator;
19 import java.util.HashMap; 18 import java.util.HashMap;
20 import java.util.List; 19 import java.util.List;
21 import java.util.Map; 20 import java.util.Map;
22 import java.util.TreeMap;
23 21
24 import org.apache.log4j.Logger; 22 import org.apache.log4j.Logger;
25 23
26 public class River 24 public class River
27 extends IdPair 25 extends IdPair
136 ResultSet gaugesRs = flysStatements 134 ResultSet gaugesRs = flysStatements
137 .getStatement("select.gauges") 135 .getStatement("select.gauges")
138 .clearParameters() 136 .clearParameters()
139 .setInt("river_id", id1).executeQuery(); 137 .setInt("river_id", id1).executeQuery();
140 138
141 TreeMap<Double, String> station2gaugeName = new TreeMap<Double, String>(
142 new Comparator<Double>() {
143 @Override
144 public int compare(Double a, Double b) {
145 double diff = a - b;
146 if (diff < -0.0001) return -1;
147 if (diff > 0.0001) return +1;
148 return 0;
149 }
150 });
151
152 try { 139 try {
153 while (gaugesRs.next()) { 140 while (gaugesRs.next()) {
154 int gaugeId = gaugesRs.getInt("id"); 141 int gaugeId = gaugesRs.getInt("id");
155 String name = gaugesRs.getString("name"); 142 String name = gaugesRs.getString("name");
156 long number = gaugesRs.getLong("official_number"); 143 long number = gaugesRs.getLong("official_number");
157 double station = gaugesRs.getDouble("station");
158 station2gaugeName.put(station, name);
159
160 if (gaugesRs.wasNull()) { 144 if (gaugesRs.wasNull()) {
161 log.warn("FLYS: Gauge '" + name + 145 log.warn("FLYS: Gauge '" + name +
162 "' has no official number. Ignored."); 146 "' has no official number. Ignored.");
163 continue; 147 continue;
164 } 148 }
177 } 161 }
178 finally { 162 finally {
179 gaugesRs.close(); 163 gaugesRs.close();
180 } 164 }
181 165
182 boolean modified = createGauges( 166 boolean modified = createGauges(context, aftDIPSGauges);
183 context, aftDIPSGauges, station2gaugeName);
184 167
185 modified |= updateGauges(context, updateGauges); 168 modified |= updateGauges(context, updateGauges);
186 169
187 return modified; 170 return modified;
188 } 171 }
379 return false; 362 return false;
380 } 363 }
381 364
382 protected boolean createGauges( 365 protected boolean createGauges(
383 SyncContext context, 366 SyncContext context,
384 Map<Long, DIPSGauge> gauges, 367 Map<Long, DIPSGauge> gauges
385 Map<Double, String> station2gaugeName
386 ) 368 )
387 throws SQLException 369 throws SQLException
388 { 370 {
389 ConnectedStatements flysStatements = context.getFlysStatements(); 371 ConnectedStatements flysStatements = context.getFlysStatements();
390 372
400 Long officialNumber = entry.getKey(); 382 Long officialNumber = entry.getKey();
401 DIPSGauge gauge = entry.getValue(); 383 DIPSGauge gauge = entry.getValue();
402 384
403 log.info("Gauge '" + gauge.getAftName() + 385 log.info("Gauge '" + gauge.getAftName() +
404 "' not in FLYS but in AFT/DIPS. -> Create"); 386 "' not in FLYS but in AFT/DIPS. -> Create");
405
406 String flysGaugeName = station2gaugeName.get(gauge.getStation());
407 if (flysGaugeName != null) {
408 log.warn("FLYS: AFT gauge " + gauge.getName() +
409 " has same station as FLYS gauge " + flysGaugeName +
410 " -> ignored.");
411 continue;
412 }
413 387
414 if (!gauge.hasDatums()) { 388 if (!gauge.hasDatums()) {
415 log.warn("DIPS: Gauge '" + 389 log.warn("DIPS: Gauge '" +
416 gauge.getAftName() + "' has no datum. Ignored."); 390 gauge.getAftName() + "' has no datum. Ignored.");
417 continue; 391 continue;

http://dive4elements.wald.intevation.org