Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/River.java @ 4079:42094f01afa6
Added model for DIPS gauges.
flys-aft/trunk@3454 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 17:34:11 +0000 |
parents | 0944cdd2ee90 |
children | 7a7b0f0cb653 |
rev | line source |
---|---|
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.aft; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
4078
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
3 import java.util.Map; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
4 import java.util.HashMap; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
5 |
4076
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
6 import java.sql.ResultSet; |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.sql.SQLException; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import org.apache.log4j.Logger; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
4078
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
11 import org.w3c.dom.Document; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
12 import org.w3c.dom.NodeList; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
13 import org.w3c.dom.Element; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
14 |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.db.ConnectedStatements; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
17 import java.util.regex.Matcher; |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
18 import java.util.regex.Pattern; |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
19 |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public class River |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 extends IdPair |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 private static Logger log = Logger.getLogger(River.class); |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
25 public static final Pattern NUMBER = Pattern.compile("0*([0-9]+)"); |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
26 |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 protected String name; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public River() { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public River(int id1, int id2, String name) { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 super(id1, id2); |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 this.name = name; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public String getName() { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 return name; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
41 public static Long numberToLong(String s) { |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
42 Matcher m = NUMBER.matcher(s); |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
43 if (!m.matches()) return null; |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
44 String ns = m.group(1); |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
45 return Long.valueOf(ns.length() == 0 ? "0": ns); |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
46 } |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
47 |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
48 public static Map<Long, DIPSGauge> indexByNumber(Document document) { |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
49 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>(); |
4078
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
50 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
51 for (int i = nodes.getLength()-1; i >= 0; --i) { |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
52 Element element = (Element)nodes.item(i); |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
53 Long number = numberToLong(element.getAttribute("NUMMER")); |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
54 if (number != null) { |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
55 map.put(number, new DIPSGauge(element)); |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
56 } |
4078
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
57 } |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
58 return map; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
59 } |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
60 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
61 public void sync(SyncContext context) throws SQLException { |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 log.info("sync river: " + this); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
63 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
64 ConnectedStatements flysStatements = context.getFlysStatements(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
65 ConnectedStatements aftStatements = context.getAftStatements(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
66 |
4076
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
67 ResultSet messstellenRs = aftStatements |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
68 .getStatement("select.messstelle") |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
69 .clearParameters() |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
70 .setInt("GEWAESSER_NR", id2).executeQuery(); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
71 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
72 while (messstellenRs.next()) { |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
73 String name = messstellenRs.getString("NAME"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
74 String num = messstellenRs.getString("MESSSTELLE_NR"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
75 System.err.println(name + ": " + num); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
76 } |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
77 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
78 messstellenRs.close(); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
79 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
80 ResultSet gaugesRs = flysStatements |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
81 .getStatement("select.gauges") |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
82 .clearParameters() |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
83 .setInt("river_id", id1).executeQuery(); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
84 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
85 while (gaugesRs.next()) { |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
86 int gaugeId = gaugesRs.getInt("id"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
87 String name = gaugesRs.getString("name"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
88 System.err.println(name + ": " + gaugeId); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
89 } |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
90 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
91 gaugesRs.close(); |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
92 |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
93 Map<Long, DIPSGauge> map = indexByNumber(context.getDips()); |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 public String toString() { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 return "[River: name=" + name + ", " + super.toString() + "]"; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |