comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4084:9178beeb7b05

Moved DIPS gauge number -> DIPS gauge index. flys-aft/trunk@3514 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 21 Dec 2011 15:16:58 +0000
parents 44dc38ca8492
children 067341e86375
comparison
equal deleted inserted replaced
4083:44dc38ca8492 4084:9178beeb7b05
1 package de.intevation.aft; 1 package de.intevation.aft;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 import java.util.HashMap;
5 4
6 import java.sql.ResultSet; 5 import java.sql.ResultSet;
7 import java.sql.SQLException; 6 import java.sql.SQLException;
8 7
9 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
10
11 import org.w3c.dom.Document;
12 import org.w3c.dom.NodeList;
13 import org.w3c.dom.Element;
14 9
15 import de.intevation.db.ConnectedStatements; 10 import de.intevation.db.ConnectedStatements;
16 11
17 public class River 12 public class River
18 extends IdPair 13 extends IdPair
31 26
32 public String getName() { 27 public String getName() {
33 return name; 28 return name;
34 } 29 }
35 30
36 public static Long numberToLong(String s) {
37 try {
38 return Long.valueOf(s.trim());
39 }
40 catch (NumberFormatException nfe) {
41 }
42 return null;
43 }
44
45 public static Map<Long, DIPSGauge> indexByNumber(Document document) {
46 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
47 NodeList nodes = document.getElementsByTagName("PEGELSTATION");
48 for (int i = nodes.getLength()-1; i >= 0; --i) {
49 Element element = (Element)nodes.item(i);
50 String numberString = element.getAttribute("NUMMER");
51 Long number = numberToLong(numberString);
52 if (number != null) {
53 DIPSGauge newG = new DIPSGauge(element);
54 DIPSGauge oldG = map.put(number, newG);
55 if (oldG != null) {
56 log.warn("DIPS: '" + newG.getName() +
57 "' collides with '" + oldG.getName() +
58 "' on gauge number " + number + ".");
59 }
60 }
61 else {
62 log.warn("DIPS: gauge '" + element.getAttribute("NAME") +
63 "' has invalid gauge number '" + numberString + "'");
64 }
65 }
66 return map;
67 }
68 31
69 public void sync(SyncContext context) throws SQLException { 32 public void sync(SyncContext context) throws SQLException {
70 log.info("sync river: " + this); 33 log.info("sync river: " + this);
71 34
72 Map<Long, DIPSGauge> dipsGauges = indexByNumber(context.getDips()); 35 Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges();
73 36
74 ConnectedStatements flysStatements = context.getFlysStatements(); 37 ConnectedStatements flysStatements = context.getFlysStatements();
75 ConnectedStatements aftStatements = context.getAftStatements(); 38 ConnectedStatements aftStatements = context.getAftStatements();
76 39
77 ResultSet messstellenRs = aftStatements 40 ResultSet messstellenRs = aftStatements
80 .setInt("GEWAESSER_NR", id2).executeQuery(); 43 .setInt("GEWAESSER_NR", id2).executeQuery();
81 44
82 while (messstellenRs.next()) { 45 while (messstellenRs.next()) {
83 String name = messstellenRs.getString("NAME"); 46 String name = messstellenRs.getString("NAME");
84 String num = messstellenRs.getString("MESSSTELLE_NR"); 47 String num = messstellenRs.getString("MESSSTELLE_NR");
85 Long number = numberToLong(num); 48 Long number = SyncContext.numberToLong(num);
86 if (number == null) { 49 if (number == null) {
87 log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'"); 50 log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'");
88 continue; 51 continue;
89 } 52 }
90 DIPSGauge dipsGauge = dipsGauges.get(number); 53 DIPSGauge dipsGauge = dipsGauges.get(number);

http://dive4elements.wald.intevation.org