changeset 2851:acb8d08f59a2

Parse and store MINFO waterlevel differences; added config option to skip this process. flys-backend/trunk@4305 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 26 Apr 2012 09:48:49 +0000 (2012-04-26)
parents a1402c16152f
children 875a87b8489f
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/Config.java flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java
diffstat 3 files changed, 77 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Thu Apr 26 09:46:32 2012 +0000
+++ b/flys-backend/ChangeLog	Thu Apr 26 09:48:49 2012 +0000
@@ -1,3 +1,13 @@
+2012-04-26  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/Config.java: Added a config
+	  option to skip parsing MINFO waterlevel differences:
+
+	    -Dflys.backend.importer.skip.waterlevel.differences=True
+
+	* src/main/java/de/intevation/flys/importer/ImportRiver.java: Parse and
+	  store MINFO specific waterlevel differences.
+
 2012-04-26  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Thu Apr 26 09:46:32 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Thu Apr 26 09:48:49 2012 +0000
@@ -62,6 +62,9 @@
     public static final String SKIP_WATERLEVELS =
         "flys.backend.importer.skip.waterlevels";
 
+    public static final String SKIP_WATERLEVEL_DIFFERENCES =
+        "flys.backend.importer.skip.waterlevel.differences";
+
 
     public static final Config INSTANCE = new Config();
 
@@ -147,5 +150,9 @@
     public boolean skipWaterlevels() {
         return Boolean.getBoolean(SKIP_WATERLEVELS);
     }
+
+    public boolean skipWaterlevelDifferences() {
+        return Boolean.getBoolean(SKIP_WATERLEVEL_DIFFERENCES);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Thu Apr 26 09:46:32 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Thu Apr 26 09:48:49 2012 +0000
@@ -36,6 +36,7 @@
 import de.intevation.flys.importer.parsers.SedimentDensityParser;
 import de.intevation.flys.importer.parsers.SedimentYieldParser;
 import de.intevation.flys.importer.parsers.WstParser;
+import de.intevation.flys.importer.parsers.WaterlevelDifferencesParser;
 import de.intevation.flys.importer.parsers.WaterlevelParser;
 
 import org.hibernate.Session;
@@ -93,6 +94,8 @@
 
     public static final String MINFO_WATERLEVELS_DIR = "Wasserspiegellagen";
 
+    public static final String MINFO_WATERLEVEL_DIFF_DIR = "Wasserspiegeldifferenzen";
+
 
     protected String name;
 
@@ -134,6 +137,8 @@
 
     protected List<ImportWaterlevel> waterlevels;
 
+    protected List<ImportWaterlevelDifference> waterlevelDiffs;
+
     protected ImportWst wst;
 
     protected ImportUnit wstUnit;
@@ -156,6 +161,7 @@
         flowVelocityMeasurements  = new ArrayList<ImportFlowVelocityMeasurement>();
         sedimentYields            = new ArrayList<ImportSedimentYield>();
         waterlevels               = new ArrayList<ImportWaterlevel>();
+        waterlevelDiffs           = new ArrayList<ImportWaterlevelDifference>();
     }
 
     public ImportRiver(
@@ -225,6 +231,7 @@
         parseFlowVelocity();
         parseSedimentYield();
         parseWaterlevels();
+        parseWaterlevelDifferences();
     }
 
     public void parseFloodProtection() throws IOException {
@@ -462,6 +469,8 @@
             return;
         }
 
+        log.info("Parse waterlevels");
+
         File minfo  = getMinfoDir();
         File fixDir = new File(minfo, MINFO_FIXATIONS_DIR);
         File wspDir = new File(fixDir, MINFO_WATERLEVELS_DIR);
@@ -479,9 +488,36 @@
             parser.parse(file);
         }
 
-        log.info("Parse waterlevels");
+        waterlevels = parser.getWaterlevels();
+    }
 
-        waterlevels = parser.getWaterlevels();
+
+    protected void parseWaterlevelDifferences() throws IOException {
+        if (Config.INSTANCE.skipWaterlevelDifferences()) {
+            log.info("skip parsing waterlevel differences");
+            return;
+        }
+
+        log.info("Parse waterlevel differences");
+
+        File minfo  = getMinfoDir();
+        File fixDir = new File(minfo, MINFO_FIXATIONS_DIR);
+        File diffDir = new File(fixDir, MINFO_WATERLEVEL_DIFF_DIR);
+
+        File[] files = diffDir.listFiles();
+
+        if (files == null) {
+            log.warn("Cannot read directory '" + diffDir + "'");
+            return;
+        }
+
+        WaterlevelDifferencesParser parser = new WaterlevelDifferencesParser();
+
+        for (File file: files) {
+            parser.parse(file);
+        }
+
+        waterlevelDiffs = parser.getDifferences();
     }
 
 
@@ -855,6 +891,7 @@
         storeFlowVelocity();
         storeSedimentYield();
         storeWaterlevels();
+        storeWaterlevelDifferences();
     }
 
     public void storeWstUnit() {
@@ -1128,6 +1165,27 @@
     }
 
 
+    public void storeWaterlevelDifferences() {
+        if (!Config.INSTANCE.skipWaterlevelDifferences()) {
+            log.info("store waterlevel differences");
+
+            River river = getPeer();
+
+            for (ImportWaterlevelDifference diff: waterlevelDiffs) {
+                try {
+                    diff.storeDependencies(river);
+                }
+                catch (SQLException sqle) {
+                    log.error("Error while storing waterlevel diff.", sqle);
+                }
+                catch (ConstraintViolationException cve) {
+                    log.error("Error while storing waterlevel diff.", cve);
+                }
+            }
+        }
+    }
+
+
     public void storeAnnotations() {
         if (!Config.INSTANCE.skipAnnotations()) {
             River river = getPeer();

http://dive4elements.wald.intevation.org