changeset 4094:b20b710aa86f

Bubble up modifications up to main(). flys-aft/trunk@3605 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 05 Jan 2012 18:58:49 +0000
parents 7bddd4601707
children da9df3641578
files flys-aft/ChangeLog flys-aft/doc/conf.xml flys-aft/src/main/java/de/intevation/aft/River.java flys-aft/src/main/java/de/intevation/aft/Rivers.java flys-aft/src/main/java/de/intevation/aft/Sync.java
diffstat 5 files changed, 39 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/ChangeLog	Thu Jan 05 17:46:18 2012 +0000
+++ b/flys-aft/ChangeLog	Thu Jan 05 18:58:49 2012 +0000
@@ -1,3 +1,12 @@
+2012-01-05	Sascha L. Teichmann	<sascha.teichmann@inteavtion.de>
+
+	* doc/conf.xml: Added demo notification url.
+
+	* src/main/java/de/intevation/aft/River.java,
+	  src/main/java/de/intevation/aft/Rivers.java,
+	  src/main/java/de/intevation/aft/Sync.java: Modifications
+	  are bubbled up to main() to send notifactions.
+	  
 2012-01-05	Sascha L. Teichmann	<sascha.teichmann@inteavtion.de>
 
 	* src/main/java/de/intevation/aft/DischargeTable.java: Store
--- a/flys-aft/doc/conf.xml	Thu Jan 05 17:46:18 2012 +0000
+++ b/flys-aft/doc/conf.xml	Thu Jan 05 18:58:49 2012 +0000
@@ -1,5 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <sync>
+  <!-- If modified send messages -->
+  <notifications>
+    <notifaction url="http://example.com">
+      <caches>
+        <cache name="my-cache"/>
+      </caches>
+    </notifaction>
+  </notifications>
   <!-- The path to the DiPs file -->
   <dips>
     <file>/the/path/to/the/dips/file</file>
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Jan 05 17:46:18 2012 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Thu Jan 05 18:58:49 2012 +0000
@@ -35,7 +35,7 @@
     }
 
 
-    public void sync(SyncContext context) throws SQLException {
+    public boolean sync(SyncContext context) throws SQLException {
         log.info("sync river: " + this);
 
         Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges();
@@ -81,7 +81,6 @@
 
         messstellenRs.close();
 
-
         List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>();
 
         ResultSet gaugesRs = flysStatements
@@ -110,13 +109,14 @@
                 "' found in FLYS, AFT and DIPS. -> Update");
             updateGauges.add(aftDIPSGauge);
         }
+        gaugesRs.close();
 
-        createGauges(context, aftDIPSGauges);
+        boolean modified = createGauges(context, aftDIPSGauges);
 
-        gaugesRs.close();
+        return modified;
     }
 
-    protected void createGauges(
+    protected boolean createGauges(
         SyncContext          context,
         Map<Long, DIPSGauge> gauges
     )
@@ -130,6 +130,8 @@
         SymbolicStatement.Instance insertStmnt =
             flysStatements.getStatement("insert.gauge");
 
+        boolean modified = false;
+
         for (Map.Entry<Long, DIPSGauge> entry: gauges.entrySet()) {
             Long      officialNumber = entry.getKey();
             DIPSGauge gauge          = entry.getValue();
@@ -167,12 +169,12 @@
 
                 gauge.setFlysId(gaugeId);
                 createDischargeTables(context, officialNumber, gauge);
-
                 flysStatements.commitTransaction();
+                modified = true;
             }
             catch (SQLException sqle) {
                 flysStatements.rollbackTransaction();
-                throw sqle;
+                log.error(sqle, sqle);
             }
             finally {
                 if (rs != null) {
@@ -180,6 +182,8 @@
                 }
             }
         }
+
+        return modified;
     }
 
     protected void createDischargeTables(
--- a/flys-aft/src/main/java/de/intevation/aft/Rivers.java	Thu Jan 05 17:46:18 2012 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/Rivers.java	Thu Jan 05 18:58:49 2012 +0000
@@ -20,7 +20,7 @@
     public Rivers() {
     }
 
-    public void sync(SyncContext context) throws SQLException {
+    public boolean sync(SyncContext context) throws SQLException {
 
         log.info("sync: rivers");
 
@@ -57,9 +57,13 @@
 
         aftRs.close();
 
+        boolean modified = false;
+
         for (River river: commonRivers) {
-            river.sync(context);
+            modified |= river.sync(context);
         }
+
+        return modified;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-aft/src/main/java/de/intevation/aft/Sync.java	Thu Jan 05 17:46:18 2012 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java	Thu Jan 05 18:58:49 2012 +0000
@@ -23,6 +23,8 @@
 
     public static final String XPATH_DIPS   = "/sync/dips/file/text()";
     public static final String XPATH_REPAIR = "/sync/dips/repair/text()";
+    public static final String XPATH_NOTIFICATIONS =
+        "/sync/notifications/notification";
 
     public static final String CONFIG_FILE =
         System.getProperty("config.file", "config.xml");
@@ -93,6 +95,8 @@
             new ConnectionBuilder(FLYS, config);
 
         SyncContext syncContext = null;
+
+        boolean modified = false;
         try {
             syncContext = new SyncContext(
                 aftConnectionBuilder.getConnectedStatements(),
@@ -100,7 +104,7 @@
                 dips);
             syncContext.init();
             Rivers rivers = new Rivers();
-            rivers.sync(syncContext);
+            modified = rivers.sync(syncContext);
         }
         catch (SQLException sqle) {
             log.error("syncing failed", sqle);

http://dive4elements.wald.intevation.org