Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/River.java @ 4083:44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
flys-aft/trunk@3513 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 21 Dec 2011 14:56:29 +0000 |
parents | d13011e53022 |
children | 9178beeb7b05 |
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 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public class River |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 extends IdPair |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 private static Logger log = Logger.getLogger(River.class); |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 protected String name; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public River() { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public River(int id1, int id2, String name) { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 super(id1, id2); |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 this.name = name; |
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 String getName() { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 return name; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
36 public static Long numberToLong(String s) { |
4082
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
37 try { |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
38 return Long.valueOf(s.trim()); |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
39 } |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
40 catch (NumberFormatException nfe) { |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
41 } |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
42 return null; |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
43 } |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
44 |
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
45 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
|
46 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>(); |
4078
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
47 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
48 for (int i = nodes.getLength()-1; i >= 0; --i) { |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
49 Element element = (Element)nodes.item(i); |
4082
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
50 String numberString = element.getAttribute("NUMMER"); |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
51 Long number = numberToLong(numberString); |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
52 if (number != null) { |
4082
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
53 DIPSGauge newG = new DIPSGauge(element); |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
54 DIPSGauge oldG = map.put(number, newG); |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
55 if (oldG != null) { |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
56 log.warn("DIPS: '" + newG.getName() + |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
57 "' collides with '" + oldG.getName() + |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
58 "' on gauge number " + number + "."); |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
59 } |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
60 } |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
61 else { |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
62 log.warn("DIPS: gauge '" + element.getAttribute("NAME") + |
d13011e53022
Make DIPS check more verbose
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4081
diff
changeset
|
63 "' has invalid gauge number '" + numberString + "'"); |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
64 } |
4078
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
65 } |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
66 return map; |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
67 } |
0944cdd2ee90
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
68 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
69 public void sync(SyncContext context) throws SQLException { |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 log.info("sync river: " + this); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
71 |
4081
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
72 Map<Long, DIPSGauge> dipsGauges = indexByNumber(context.getDips()); |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
73 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
74 ConnectedStatements flysStatements = context.getFlysStatements(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
75 ConnectedStatements aftStatements = context.getAftStatements(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4076
diff
changeset
|
76 |
4076
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
77 ResultSet messstellenRs = aftStatements |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
78 .getStatement("select.messstelle") |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
79 .clearParameters() |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
80 .setInt("GEWAESSER_NR", id2).executeQuery(); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
81 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
82 while (messstellenRs.next()) { |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
83 String name = messstellenRs.getString("NAME"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
84 String num = messstellenRs.getString("MESSSTELLE_NR"); |
4081
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
85 Long number = numberToLong(num); |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
86 if (number == null) { |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
87 log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'"); |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
88 continue; |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
89 } |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
90 DIPSGauge dipsGauge = dipsGauges.get(number); |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
91 if (dipsGauges == null) { |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
92 log.warn("MESSSTELLE '" + name + "' not found in DIPS."); |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
93 continue; |
7a7b0f0cb653
Check if AFT gauges are in DIPS, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4079
diff
changeset
|
94 } |
4076
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
95 } |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
96 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
97 messstellenRs.close(); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
98 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
99 ResultSet gaugesRs = flysStatements |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
100 .getStatement("select.gauges") |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
101 .clearParameters() |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
102 .setInt("river_id", id1).executeQuery(); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
103 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
104 while (gaugesRs.next()) { |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
105 int gaugeId = gaugesRs.getInt("id"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
106 String name = gaugesRs.getString("name"); |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
107 } |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
108 |
039413d7e394
Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
109 gaugesRs.close(); |
4079
42094f01afa6
Added model for DIPS gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
110 |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 public String toString() { |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 return "[River: name=" + name + ", " + super.toString() + "]"; |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 } |
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |