changeset 2806:33f40b23edd8

Initial checkin for parsing MINFO bed heights. flys-backend/trunk@4211 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 11 Apr 2012 09:30:04 +0000
parents a55b7b35cc3a
children 5ac1db5156be
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/Config.java flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/Importer.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java
diffstat 8 files changed, 323 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Wed Apr 11 09:23:10 2012 +0000
+++ b/flys-backend/ChangeLog	Wed Apr 11 09:30:04 2012 +0000
@@ -1,3 +1,24 @@
+2012-04-11  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/Config.java: Added new command
+	  line option to skip parsing bed heights (german "Sohlhoehen").
+	  Set "-Dflys.backend.importer.skip.bed.height=true" to skip parsing this
+	  file type.
+
+	* src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java,
+	  src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java:
+	  Initial checkin of parsers for bed heights (single and epoch).
+
+	* src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java,
+	  src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java: Temp
+	  storage for bed heights data used during the import.
+
+	* src/main/java/de/intevation/flys/importer/Importer.java: Added an INFO
+	  statement that signals the start of parsing rivers.
+
+	* src/main/java/de/intevation/flys/importer/ImportRiver.java: Collect and
+	  trigger parsing of bed heights files (placed in 'Morphologie/Sohlhoehen').
+
 2012-04-11  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/schema/oracle-minfo.sql,
--- a/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Wed Apr 11 09:23:10 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Wed Apr 11 09:30:04 2012 +0000
@@ -41,6 +41,10 @@
     public static final String SKIP_FLOOD_PROTECTION =
         "flys.backend.importer.skip.flood.protection";
 
+    public static final String SKIP_BED_HEIGHT =
+        "flys.backend.importer.skip.bed.height";
+
+
     public static final Config INSTANCE = new Config();
 
     private Config () {
@@ -97,5 +101,9 @@
     public boolean skipFloodProtection() {
         return Boolean.getBoolean(SKIP_FLOOD_PROTECTION);
     }
+
+    public boolean skipBedHeight() {
+        return Boolean.getBoolean(SKIP_BED_HEIGHT);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java	Wed Apr 11 09:30:04 2012 +0000
@@ -0,0 +1,30 @@
+package de.intevation.flys.importer;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.model.River;
+
+
+public class ImportBedHeightEpoch
+{
+    private static Logger log = Logger.getLogger(ImportBedHeightEpoch.class);
+
+    protected String description;
+
+
+    public ImportBedHeightEpoch(String description) {
+        this.description = description;
+    }
+
+
+    public String getDescription() {
+        return description;
+    }
+
+
+    public void storeDependencies(River river) {
+        log.info("Store dependencies for epoch: '" + getDescription() + "'");
+        log.error("TODO: IMPLEMENT ME!");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java	Wed Apr 11 09:30:04 2012 +0000
@@ -0,0 +1,31 @@
+package de.intevation.flys.importer;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.model.River;
+
+
+public class ImportBedHeightSingle
+{
+    private static Logger log = Logger.getLogger(ImportBedHeightSingle.class);
+
+
+    protected String description;
+
+
+    public ImportBedHeightSingle(String description) {
+        this.description = description;
+    }
+
+
+    public String getDescription() {
+        return description;
+    }
+
+
+    public void storeDependencies(River river) {
+        log.info("Store dependencies for single: '" + getDescription() + "'");
+        log.error("TODO: IMPLEMENT ME!");
+    }
+}
+// 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	Wed Apr 11 09:23:10 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Wed Apr 11 09:30:04 2012 +0000
@@ -21,6 +21,8 @@
 import de.intevation.flys.model.River;
 import de.intevation.flys.model.Unit;
 
+import de.intevation.flys.importer.parsers.BedHeightEpochParser;
+import de.intevation.flys.importer.parsers.BedHeightSingleParser;
 import de.intevation.flys.importer.parsers.PRFParser;
 import de.intevation.flys.importer.parsers.HYKParser;
 import de.intevation.flys.importer.parsers.AnnotationsParser;
@@ -54,6 +56,15 @@
     public static final String FLOOD_PROTECTION =
         "HW-Schutzanlagen";
 
+    public static final String MINFO_DIR = "Morphologie";
+
+    public static final String BED_HEIGHT_DIR = "Sohlhoehen";
+
+    public static final String BED_HEIGHT_SINGLE_DIR = "Einzeljahre";
+
+    public static final String BED_HEIGHT_EPOCH_DIR = "Epochen";
+
+
     protected String name;
 
     protected File   wstFile;
@@ -78,6 +89,10 @@
 
     protected List<ImportWst> floodProtection;
 
+    protected List<ImportBedHeightSingle> bedHeightSingles;
+
+    protected List<ImportBedHeightEpoch> bedHeightEpochs;
+
     protected ImportWst wst;
 
     protected ImportUnit wstUnit;
@@ -141,6 +156,11 @@
         this.wst = wst;
     }
 
+    public File getMinfoDir() {
+        File riverDir  = wstFile.getParentFile().getParentFile().getParentFile();
+        return new File(riverDir, MINFO_DIR);
+    }
+
     public void parseDependencies() throws IOException {
         parseGauges();
         parseAnnotations();
@@ -152,6 +172,7 @@
         parseOfficialLines();
         parseFloodWater();
         parseFloodProtection();
+        parseBedHeight();
     }
 
     public void parseFloodProtection() throws IOException {
@@ -196,6 +217,65 @@
         }
     }
 
+
+    public void parseBedHeight() throws IOException {
+        if (Config.INSTANCE.skipBedHeight()) {
+            log.info("skip parsing bed height.");
+            return;
+        }
+
+        log.info("Parse bed height.");
+
+        File minfoDir     = getMinfoDir();
+        File bedHeightDir = new File(minfoDir, BED_HEIGHT_DIR);
+        File singlesDir   = new File(bedHeightDir, BED_HEIGHT_SINGLE_DIR);
+        File epochDir     = new File(bedHeightDir, BED_HEIGHT_EPOCH_DIR);
+
+        parseBedHeightSingles(singlesDir);
+        parseBedHeightEpochs(epochDir);
+    }
+
+
+    protected void parseBedHeightSingles(File dir) throws IOException {
+        log.debug("Parse bed height singles");
+
+        File[] files = dir.listFiles();
+
+        if (files == null) {
+            log.warn("Cannot parse directory '" + dir + "'");
+            return;
+        }
+
+        BedHeightSingleParser parser = new BedHeightSingleParser();
+
+        for (File file: files) {
+            parser.parse(file);
+        }
+
+        bedHeightSingles = parser.getBedHeights();
+    }
+
+
+    protected void parseBedHeightEpochs(File dir) throws IOException {
+        log.debug("Parse bed height epochs");
+
+        File[] files = dir.listFiles();
+
+        if (files == null) {
+            log.warn("Cannot parse directory '" + dir + "'");
+            return;
+        }
+
+        BedHeightEpochParser parser = new BedHeightEpochParser();
+
+        for (File file: files) {
+            parser.parse(file);
+        }
+
+        bedHeightEpochs = parser.getBedHeights();
+    }
+
+
     public void parseFloodWater() throws IOException {
         if (Config.INSTANCE.skipFloodWater()) {
             log.info("skip parsing flod water");
@@ -520,6 +600,7 @@
         storeOfficialLines();
         storeFloodWater();
         storeFloodProtection();
+        storeBedHeight();
     }
 
     public void storeWstUnit() {
@@ -613,6 +694,28 @@
         }
     }
 
+
+    public void storeBedHeight() {
+        if (!Config.INSTANCE.skipBedHeight()) {
+            log.info("store bed heights");
+            River river = getPeer();
+
+            if (bedHeightSingles != null) {
+                for (ImportBedHeightSingle single: bedHeightSingles) {
+                    log.debug("name: " + single.getDescription());
+                    single.storeDependencies(river);
+                }
+            }
+
+            if (bedHeightEpochs != null) {
+                for (ImportBedHeightEpoch epoch: bedHeightEpochs) {
+                    log.debug("name: " + epoch.getDescription());
+                    epoch.storeDependencies(river);
+                }
+            }
+        }
+    }
+
     public void storeAnnotations() {
         if (!Config.INSTANCE.skipAnnotations()) {
             River river = getPeer();
--- a/flys-backend/src/main/java/de/intevation/flys/importer/Importer.java	Wed Apr 11 09:23:10 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/Importer.java	Wed Apr 11 09:30:04 2012 +0000
@@ -115,6 +115,8 @@
         InfoGewParser infoGewParser = new InfoGewParser(
             getAnnotationClassifier());
 
+        log.info("Start parsing rivers...");
+
         for (String gew: args) {
             log.info("parsing info gew file: " + gew);
             try {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java	Wed Apr 11 09:30:04 2012 +0000
@@ -0,0 +1,64 @@
+package de.intevation.flys.importer.parsers;
+
+import java.io.File;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.importer.ImportBedHeightEpoch;
+
+
+public class BedHeightEpochParser {
+
+    public static final String ENCODING = "ISO-8859-1";
+
+
+    protected List<ImportBedHeightEpoch> bedHeights;
+
+
+    private static final Logger log =
+        Logger.getLogger(BedHeightEpochParser.class);
+
+
+    public BedHeightEpochParser() {
+        bedHeights = new ArrayList<ImportBedHeightEpoch>();
+    }
+
+
+    public List<ImportBedHeightEpoch> getBedHeights() {
+        return bedHeights;
+    }
+
+
+    public void parse(File file) throws IOException {
+        log.info("Parsing bed height epoch file '" + file + "'");
+
+        LineNumberReader in = null;
+        try {
+            in =
+                new LineNumberReader(
+                new InputStreamReader(
+                new FileInputStream(file), ENCODING));
+
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                if ((line = line.trim()).length() == 0) {
+                    continue;
+                }
+            }
+        }
+        finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java	Wed Apr 11 09:30:04 2012 +0000
@@ -0,0 +1,64 @@
+package de.intevation.flys.importer.parsers;
+
+import java.io.File;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.importer.ImportBedHeightSingle;
+
+
+public class BedHeightSingleParser {
+
+    public static final String ENCODING = "ISO-8859-1";
+
+
+    private static final Logger log =
+        Logger.getLogger(BedHeightSingleParser.class);
+
+
+    protected List<ImportBedHeightSingle> bedHeights;
+
+
+    public BedHeightSingleParser() {
+        bedHeights = new ArrayList<ImportBedHeightSingle>();
+    }
+
+
+    public List<ImportBedHeightSingle> getBedHeights() {
+        return bedHeights;
+    }
+
+
+    public void parse(File file) throws IOException {
+        log.info("Parsing bed height single file '" + file + "'");
+
+        LineNumberReader in = null;
+        try {
+            in =
+                new LineNumberReader(
+                new InputStreamReader(
+                new FileInputStream(file), ENCODING));
+
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                if ((line = line.trim()).length() == 0) {
+                    continue;
+                }
+            }
+        }
+        finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org