changeset 2839:163c037f2c7e

Added config option to skip parsing sediment yield data and prepared the importer to read/store those data. flys-backend/trunk@4272 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 19 Apr 2012 07:34:50 +0000
parents 75446c47ef77
children 71175502d868
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 flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.java
diffstat 4 files changed, 91 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Thu Apr 19 07:15:25 2012 +0000
+++ b/flys-backend/ChangeLog	Thu Apr 19 07:34:50 2012 +0000
@@ -1,3 +1,17 @@
+2012-04-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/Config.java: Added new config
+	  option to skip parsing sediment yield data:
+
+	     -Dflys.backend.importer.skip.sediment.yield=true
+
+	* src/main/java/de/intevation/flys/importer/ImportRiver.java: Prepared the
+	  importer to parse sediment yield data.
+
+	* src/main/java/de/intevation/flys/importer/ImportSedimentYield.java:
+	  storeDependencies() now throws SQLExceptions and
+	  ConstraintViolationExceptions.
+
 2012-04-19  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/ImportGrainFraction.java,
--- a/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Thu Apr 19 07:15:25 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Thu Apr 19 07:34:50 2012 +0000
@@ -56,6 +56,9 @@
     public static final String SKIP_FLOW_VELOCITY =
         "flys.backend.importer.skip.flow.velocity";
 
+    public static final String SKIP_SEDIMENT_YIELD =
+        "flys.backend.importer.skip.sediment.yield";
+
 
     public static final Config INSTANCE = new Config();
 
@@ -133,5 +136,9 @@
     public boolean skipFlowVelocity() {
         return Boolean.getBoolean(SKIP_FLOW_VELOCITY);
     }
+
+    public boolean skipSedimentYield() {
+        return Boolean.getBoolean(SKIP_SEDIMENT_YIELD);
+    }
 }
 // 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 19 07:15:25 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Thu Apr 19 07:34:50 2012 +0000
@@ -81,6 +81,12 @@
 
     public static final String FLOW_VELOCITY_MEASUREMENTS = "v-Messungen";
 
+    public static final String SEDIMENT_YIELD_DIR = "Fracht";
+
+    public static final String SEDIMENT_YIELD_SINGLE_DIR = "Einzeljahre";
+
+    public static final String SEDIMENT_YIELD_EPOCH_DIR = "Epochen";
+
 
     protected String name;
 
@@ -118,6 +124,8 @@
 
     protected List<ImportFlowVelocityMeasurement> flowVelocityMeasurements;
 
+    protected List<ImportSedimentYield> sedimentYields;
+
     protected ImportWst wst;
 
     protected ImportUnit wstUnit;
@@ -138,6 +146,7 @@
         morphologicalWidths       = new ArrayList<ImportMorphWidth>();
         flowVelocityModels        = new ArrayList<ImportFlowVelocityModel>();
         flowVelocityMeasurements  = new ArrayList<ImportFlowVelocityMeasurement>();
+        sedimentYields            = new ArrayList<ImportSedimentYield>();
     }
 
     public ImportRiver(
@@ -205,6 +214,7 @@
         parseSedimentDensity();
         parseMorphologicalWidth();
         parseFlowVelocity();
+        parseSedimentYield();
     }
 
     public void parseFloodProtection() throws IOException {
@@ -383,6 +393,39 @@
     }
 
 
+    protected void parseSedimentYield() throws IOException {
+        log.debug("Parse sediment yield data");
+
+        if (Config.INSTANCE.skipSedimentYield()) {
+            log.info("skip parsing sediment yield data");
+            return;
+        }
+
+        File minfoDir         = getMinfoDir();
+        File sedimentYieldDir = new File(minfoDir, SEDIMENT_YIELD_DIR);
+
+        File singleDir = new File(sedimentYieldDir, SEDIMENT_YIELD_SINGLE_DIR);
+        File epochDir  = new File(sedimentYieldDir, SEDIMENT_YIELD_EPOCH_DIR);
+
+        File[] singles = singleDir.listFiles();
+        File[] epochs  = epochDir.listFiles();
+
+        if (singles == null || singles.length == 0) {
+            log.warn("Cannot parse directory '" + singleDir + "'");
+        }
+        else {
+            // TODO
+        }
+
+        if (epochs == null || epochs.length == 0) {
+            log.warn("Cannot parse directory '" + epochDir + "'");
+        }
+        else {
+            // TODO
+        }
+    }
+
+
     protected void parseBedHeightSingles(File dir) throws IOException {
         log.debug("Parse bed height singles");
 
@@ -751,6 +794,7 @@
         storeSedimentDensity();
         storeMorphologicalWidth();
         storeFlowVelocity();
+        storeSedimentYield();
     }
 
     public void storeWstUnit() {
@@ -989,6 +1033,27 @@
         }
     }
 
+
+    public void storeSedimentYield() {
+        if (!Config.INSTANCE.skipSedimentYield()) {
+            log.info("store sediment yield data");
+
+            River river = getPeer();
+
+            for (ImportSedimentYield sedimentYield: sedimentYields) {
+                try {
+                    sedimentYield.storeDependencies(river);
+                }
+                catch (SQLException sqle) {
+                    log.error("Error while storing sediment yield.", sqle);
+                }
+                catch (ConstraintViolationException cve) {
+                    log.error("Error while storing sediment yield.", cve);
+                }
+            }
+        }
+    }
+
     public void storeAnnotations() {
         if (!Config.INSTANCE.skipAnnotations()) {
             River river = getPeer();
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.java	Thu Apr 19 07:15:25 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.java	Thu Apr 19 07:34:50 2012 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.importer;
 
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -7,6 +8,7 @@
 
 import org.hibernate.Session;
 import org.hibernate.Query;
+import org.hibernate.exception.ConstraintViolationException;
 
 import de.intevation.flys.model.GrainFraction;
 import de.intevation.flys.model.River;
@@ -55,7 +57,9 @@
     }
 
 
-    public void storeDependencies(River river) {
+    public void storeDependencies(River river)
+    throws SQLException, ConstraintViolationException
+    {
         log.debug("store dependencies");
 
         if (grainFraction != null) {

http://dive4elements.wald.intevation.org