changeset 4077:97de7a552b79

Load DIPS XML flys-aft/trunk@3452 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 16 Dec 2011 16:21:59 +0000
parents 039413d7e394
children 0944cdd2ee90
files 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 flys-aft/src/main/java/de/intevation/aft/SyncContext.java
diffstat 5 files changed, 103 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/doc/conf.xml	Fri Dec 16 11:26:12 2011 +0000
+++ b/flys-aft/doc/conf.xml	Fri Dec 16 16:21:59 2011 +0000
@@ -1,5 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <sync>
+  <!-- The path to the DiPs file -->
+  <dips file="/the/path/to/the/dips/file"/>
   <!-- The FLYS side -->
   <side name="flys">
     <db>
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Fri Dec 16 11:26:12 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Fri Dec 16 16:21:59 2011 +0000
@@ -26,13 +26,12 @@
         return name;
     }
 
-    public void sync(
-        ConnectedStatements aftStatements,
-        ConnectedStatements flysStatements
-    )
-    throws SQLException
-    {
+    public void sync(SyncContext context) throws SQLException {
         log.info("sync river: " + this);
+
+        ConnectedStatements flysStatements = context.getFlysStatements();
+        ConnectedStatements aftStatements  = context.getAftStatements();
+
         ResultSet messstellenRs = aftStatements
             .getStatement("select.messstelle")
             .clearParameters()
--- a/flys-aft/src/main/java/de/intevation/aft/Rivers.java	Fri Dec 16 11:26:12 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/Rivers.java	Fri Dec 16 16:21:59 2011 +0000
@@ -20,14 +20,13 @@
     public Rivers() {
     }
 
-    public void sync(
-        ConnectedStatements aftStatements,
-        ConnectedStatements flysStatements
-    )
-    throws SQLException
-    {
+    public void sync(SyncContext context) throws SQLException {
+
         log.info("sync: rivers");
 
+        ConnectedStatements flysStatements = context.getFlysStatements();
+        ConnectedStatements aftStatements  = context.getAftStatements();
+
         Map<String, Integer> flysRivers = new HashMap<String, Integer>();
 
         ResultSet flysRs = flysStatements
@@ -60,7 +59,7 @@
         aftRs.close();
 
         for (River river: commonRivers) {
-            river.sync(aftStatements, flysStatements);
+            river.sync(context);
         }
     }
 }
--- a/flys-aft/src/main/java/de/intevation/aft/Sync.java	Fri Dec 16 11:26:12 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java	Fri Dec 16 16:21:59 2011 +0000
@@ -6,16 +6,19 @@
 
 import org.w3c.dom.Document;
 
+import javax.xml.xpath.XPathConstants;
+
 import de.intevation.utils.XML;
 
 import de.intevation.db.ConnectionBuilder;
-import de.intevation.db.ConnectedStatements;
 
 public class Sync
 {
     public static final String FLYS = "flys";
     public static final String AFT  = "aft";
 
+    public static final String XPATH_DIPS = "/sync/dips/@file";
+
     public static final String CONFIG_FILE =
         System.getProperty("config.file", "config.xml");
 
@@ -35,30 +38,50 @@
             System.exit(1);
         }
 
+        String dipsF = (String)XML.xpath(
+            config, XPATH_DIPS, XPathConstants.STRING, null, null);
+
+        if (dipsF == null || dipsF.length() == 0) {
+            System.err.println("Cannot find path to DiPS xml in config.");
+            System.exit(1);
+        }
+
+        File dipsFile = new File(dipsF);
+
+        if (!dipsFile.isFile() || !dipsFile.canRead()) {
+            System.err.println("Cannot find '" + dipsF + "'");
+            System.exit(1);
+        }
+
+        Document dips = XML.parseDocument(dipsFile, Boolean.FALSE);
+
+        if (dips == null) {
+            System.err.println("Cannot load DiPs document.");
+            System.exit(1);
+        }
+
         ConnectionBuilder aftConnectionBuilder =
             new ConnectionBuilder(AFT, config);
 
         ConnectionBuilder flysConnectionBuilder =
             new ConnectionBuilder(FLYS, config);
 
-        ConnectedStatements aftStatements  = null;
-        ConnectedStatements flysStatements = null;
+        SyncContext syncContext = null;
         try {
-            aftStatements  = aftConnectionBuilder.getConnectedStatements();
-            flysStatements = flysConnectionBuilder.getConnectedStatements();
+            syncContext = new SyncContext(
+                aftConnectionBuilder.getConnectedStatements(),
+                flysConnectionBuilder.getConnectedStatements(),
+                dips);
             Rivers rivers = new Rivers();
-            rivers.sync(aftStatements, flysStatements);
+            rivers.sync(syncContext);
         }
         catch (SQLException sqle) {
             sqle.printStackTrace();
             System.err.println("syncing failed: " + sqle.getMessage());
         }
         finally {
-            if (aftStatements != null) {
-                aftStatements.close();
-            }
-            if (flysStatements != null) {
-                flysStatements.close();
+            if (syncContext != null) {
+                syncContext.close();
             }
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Fri Dec 16 16:21:59 2011 +0000
@@ -0,0 +1,56 @@
+package de.intevation.aft;
+
+import de.intevation.db.ConnectedStatements;
+
+import org.w3c.dom.Document;
+
+public class SyncContext
+{
+    protected ConnectedStatements aftStatements;
+    protected ConnectedStatements flysStatements;
+    protected Document            dips;
+
+    public SyncContext() {
+    }
+
+    public SyncContext(
+        ConnectedStatements aftStatements,
+        ConnectedStatements flysStatements,
+        Document            dips
+    ) {
+        this.aftStatements  = aftStatements;
+        this.flysStatements = flysStatements;
+        this.dips           = dips;
+    }
+
+    public ConnectedStatements getAftStatements() {
+        return aftStatements;
+    }
+
+    public void setAftStatements(ConnectedStatements aftStatements) {
+        this.aftStatements = aftStatements;
+    }
+
+    public ConnectedStatements getFlysStatements() {
+        return flysStatements;
+    }
+
+    public void setFlysStatements(ConnectedStatements flysStatements) {
+        this.flysStatements = flysStatements;
+    }
+
+    public Document getDips() {
+        return dips;
+    }
+
+    public void setDips(Document dips) {
+        this.dips = dips;
+    }
+
+    void close() {
+        aftStatements.close();
+        flysStatements.close();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+

http://dive4elements.wald.intevation.org