Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/SyncContext.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 | 97de7a552b79 |
children | 859b4781554a |
rev | line source |
---|---|
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.aft; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
3 import java.util.Map; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
4 import java.util.HashMap; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
5 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
6 import org.w3c.dom.Document; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
7 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.db.ConnectedStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
10 import org.w3c.dom.NodeList; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
11 import org.w3c.dom.Element; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
12 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
13 import org.apache.log4j.Logger; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public class SyncContext |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 { |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
17 private static Logger log = Logger.getLogger(SyncContext.class); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
18 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
19 protected ConnectedStatements aftStatements; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
20 protected ConnectedStatements flysStatements; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
21 protected Document dips; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
22 protected Map<Long, DIPSGauge> numberToGauge; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public SyncContext() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public SyncContext( |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ConnectedStatements aftStatements, |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 ConnectedStatements flysStatements, |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 Document dips |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 ) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 this.aftStatements = aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.flysStatements = flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 this.dips = dips; |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
35 numberToGauge = indexByNumber(dips); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public ConnectedStatements getAftStatements() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 return aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public void setAftStatements(ConnectedStatements aftStatements) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 this.aftStatements = aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public ConnectedStatements getFlysStatements() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 return flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 public void setFlysStatements(ConnectedStatements flysStatements) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 this.flysStatements = flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public Document getDips() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 return dips; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 public void setDips(Document dips) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 this.dips = dips; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 void close() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 aftStatements.close(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 flysStatements.close(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
66 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
67 public static Long numberToLong(String s) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
68 try { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
69 return Long.valueOf(s.trim()); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
70 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
71 catch (NumberFormatException nfe) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
72 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
73 return null; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
74 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
75 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
76 public Map<Long, DIPSGauge> getDIPSGauges() { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
77 return numberToGauge; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
78 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
79 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
80 protected static Map<Long, DIPSGauge> indexByNumber(Document document) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
81 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>(); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
82 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
83 for (int i = nodes.getLength()-1; i >= 0; --i) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
84 Element element = (Element)nodes.item(i); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
85 String numberString = element.getAttribute("NUMMER"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
86 Long number = numberToLong(numberString); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
87 if (number != null) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
88 DIPSGauge newG = new DIPSGauge(element); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
89 DIPSGauge oldG = map.put(number, newG); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
90 if (oldG != null) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
91 log.warn("DIPS: '" + newG.getName() + |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
92 "' collides with '" + oldG.getName() + |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
93 "' on gauge number " + number + "."); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
94 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
95 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
96 else { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
97 log.warn("DIPS: gauge '" + element.getAttribute("NAME") + |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
98 "' has invalid gauge number '" + numberString + "'"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
99 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
100 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
101 return map; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
102 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
103 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 |