Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/Sync.java @ 5225:a075f26a516c
Use range object to get lower and upper km for dgm.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 12 Mar 2013 08:07:34 +0100 |
parents | f939e1e6cfa4 |
children |
rev | line source |
---|---|
4067
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.aft; |
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
3 import de.intevation.db.ConnectionBuilder; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
4 |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
5 import de.intevation.utils.XML; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
6 |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
7 import java.io.File; |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
8 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
9 import java.net.MalformedURLException; |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
10 import java.net.URL; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
11 |
4073
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
12 import java.sql.SQLException; |
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
13 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
14 import javax.xml.xpath.XPathConstants; |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
15 |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
16 import org.apache.log4j.Logger; |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
17 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
18 import org.w3c.dom.Document; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
19 import org.w3c.dom.Element; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
20 import org.w3c.dom.NodeList; |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
21 |
4067
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 public class Sync |
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 { |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
24 private static Logger log = Logger.getLogger(Sync.class); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
25 |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
26 public static final String FLYS = "flys"; |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
27 public static final String AFT = "aft"; |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
28 |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
29 public static final String XPATH_DIPS = "/sync/dips/file/text()"; |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
30 public static final String XPATH_REPAIR = "/sync/dips/repair/text()"; |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
31 |
4094
b20b710aa86f
Bubble up modifications up to main().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
32 public static final String XPATH_NOTIFICATIONS = |
b20b710aa86f
Bubble up modifications up to main().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
33 "/sync/notifications/notification"; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
34 |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
35 public static final String CONFIG_FILE = |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
36 System.getProperty("config.file", "config.xml"); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
37 |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
38 public static void sendNotifications(Document config) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
39 NodeList notifications = (NodeList)XML.xpath( |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
40 config, XPATH_NOTIFICATIONS, XPathConstants.NODESET, null, null); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
41 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
42 if (notifications == null) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
43 return; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
44 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
45 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
46 for (int i = 0, N = notifications.getLength(); i < N; ++i) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
47 Element notification = (Element)notifications.item(i); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
48 String urlString = notification.getAttribute("url"); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
49 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
50 URL url; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
51 try { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
52 url = new URL(urlString); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
53 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
54 catch (MalformedURLException mfue) { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4104
diff
changeset
|
55 log.warn("NOTIFY: Invalid URL '" + urlString + "'. Ignored.", mfue); |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
56 continue; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
57 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
58 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
59 Notification n = new Notification(notification); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
60 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
61 Document result = n.sendPOST(url); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
62 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
63 if (result != null) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
64 log.info("Send notifcation to '" + urlString + "'."); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
65 log.info(XML.toString(result)); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
66 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
67 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
68 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
69 |
4067
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 public static void main(String [] args) { |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
71 |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
72 File configFile = new File(CONFIG_FILE); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
73 |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
74 if (!configFile.isFile() || !configFile.canRead()) { |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
75 log.error("cannot read config file"); |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
76 System.exit(1); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
77 } |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
78 |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
79 Document config = XML.parseDocument(configFile, Boolean.FALSE); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
80 |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
81 if (config == null) { |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
82 log.error("Cannot load config file."); |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
83 System.exit(1); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
84 } |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
85 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
86 String dipsF = (String)XML.xpath( |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
87 config, XPATH_DIPS, XPathConstants.STRING, null, null); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
88 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
89 if (dipsF == null || dipsF.length() == 0) { |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
90 log.error("Cannot find path to DIPS XML in config."); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
91 System.exit(1); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
92 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
93 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
94 File dipsFile = new File(dipsF); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
95 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
96 if (!dipsFile.isFile() || !dipsFile.canRead()) { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4104
diff
changeset
|
97 log.error("DIPS: Cannot find '" + dipsF + "'."); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
98 System.exit(1); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
99 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
100 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
101 Document dips = XML.parseDocument(dipsFile, Boolean.FALSE); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
102 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
103 if (dips == null) { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4104
diff
changeset
|
104 log.error("DIPS: Cannot load DIPS document."); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
105 System.exit(1); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
106 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
107 |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
108 String repairF = (String)XML.xpath( |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
109 config, XPATH_REPAIR, XPathConstants.STRING, null, null); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
110 |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
111 if (repairF != null && repairF.length() > 0) { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
112 File repairFile = new File(repairF); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
113 if (!repairFile.isFile() || !repairFile.canRead()) { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4104
diff
changeset
|
114 log.warn("REPAIR: Cannot open DIPS repair XSLT file."); |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
115 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
116 else { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
117 Document fixed = XML.transform(dips, repairFile); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
118 if (fixed == null) { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4104
diff
changeset
|
119 log.warn("REPAIR: Fixing DIPS failed."); |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
120 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
121 else { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
122 dips = fixed; |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
123 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
124 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
125 } |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
126 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
127 int exitCode = 0; |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
128 |
4073
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
129 ConnectionBuilder aftConnectionBuilder = |
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
130 new ConnectionBuilder(AFT, config); |
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
131 |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
132 ConnectionBuilder flysConnectionBuilder = |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
133 new ConnectionBuilder(FLYS, config); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4067
diff
changeset
|
134 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
135 SyncContext syncContext = null; |
4094
b20b710aa86f
Bubble up modifications up to main().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
136 |
b20b710aa86f
Bubble up modifications up to main().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
137 boolean modified = false; |
4073
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
138 try { |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
139 syncContext = new SyncContext( |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
140 aftConnectionBuilder.getConnectedStatements(), |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
141 flysConnectionBuilder.getConnectedStatements(), |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
142 dips); |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
143 syncContext.init(); |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4073
diff
changeset
|
144 Rivers rivers = new Rivers(); |
4094
b20b710aa86f
Bubble up modifications up to main().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
145 modified = rivers.sync(syncContext); |
4073
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
146 } |
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
147 catch (SQLException sqle) { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4104
diff
changeset
|
148 log.error("SYNC: Syncing failed.", sqle); |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
149 exitCode = 1; |
4073
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
150 } |
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
151 finally { |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
152 if (syncContext != null) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4075
diff
changeset
|
153 syncContext.close(); |
4075
dbd0b3b1b8b8
Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4073
diff
changeset
|
154 } |
4073
2c70fae83d0c
start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
155 } |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
156 |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
157 if (modified) { |
4104
cdcf98245e36
Commit/rollback changes if a gauge is only updated.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4095
diff
changeset
|
158 log.info("Modifications found."); |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
159 sendNotifications(config); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
160 } |
4104
cdcf98245e36
Commit/rollback changes if a gauge is only updated.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4095
diff
changeset
|
161 else { |
cdcf98245e36
Commit/rollback changes if a gauge is only updated.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4095
diff
changeset
|
162 log.info("No modifications found."); |
cdcf98245e36
Commit/rollback changes if a gauge is only updated.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4095
diff
changeset
|
163 } |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4094
diff
changeset
|
164 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
165 if (exitCode != 0) { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
166 System.exit(1); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
167 } |
4067
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 } |
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
d5aed044ca0d
Added AFT sync module.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |