diff backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java @ 8056:d86cc6a17b7a

Importer: Import sediment load at measurement stations.
author Tom Gottfried <tom@intevation.de>
date Fri, 18 Jul 2014 15:37:26 +0200
parents fd3a24336e6a
children 3bb1c62ad732
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Fri Jul 18 13:03:28 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Fri Jul 18 15:37:26 2014 +0200
@@ -29,7 +29,9 @@
 import org.dive4elements.river.importer.parsers.PorosityParser;
 import org.dive4elements.river.importer.parsers.SQRelationParser;
 import org.dive4elements.river.importer.parsers.SedimentDensityParser;
+import org.dive4elements.river.importer.parsers.AbstractSedimentLoadParser;
 import org.dive4elements.river.importer.parsers.SedimentLoadLSParser;
+import org.dive4elements.river.importer.parsers.SedimentLoadParser;
 import org.dive4elements.river.importer.parsers.W80Parser;
 import org.dive4elements.river.importer.parsers.W80CSVParser;
 import org.dive4elements.river.importer.parsers.WaterlevelDifferencesParser;
@@ -108,6 +110,8 @@
 
     public static final String SEDIMENT_LOAD_LS_DIR = "Laengsschnitte";
 
+    public static final String SEDIMENT_LOAD_MS_DIR = "Messstellen";
+
     public static final String SEDIMENT_LOAD_SINGLE_DIR = "Einzeljahre";
 
     public static final String SEDIMENT_LOAD_EPOCH_DIR = "Epochen";
@@ -176,6 +180,8 @@
 
     protected List<ImportSedimentLoadLS> sedimentLoadLSs;
 
+    protected List<ImportSedimentLoad> sedimentLoads;
+
     protected List<ImportMeasurementStation> measurementStations;
 
     protected List<ImportSQRelation> sqRelations;
@@ -291,6 +297,7 @@
         flowVelocityModels        = new ArrayList<ImportFlowVelocityModel>();
         flowVelocityMeasurements  = new ArrayList<ImportFlowVelocityMeasurement>();
         sedimentLoadLSs           = new ArrayList<ImportSedimentLoadLS>();
+        sedimentLoads             = new ArrayList<ImportSedimentLoad>();
         measurementStations       = new ArrayList<ImportMeasurementStation>();
         sqRelations               = new ArrayList<ImportSQRelation>();
     }
@@ -378,15 +385,16 @@
         parseOfficialLines();
         parseFloodWater();
         parseFloodProtection();
+        parseMeasurementStations();
         parseBedHeight();
         parseSedimentDensity();
         parsePorosity();
         parseMorphologicalWidth();
         parseFlowVelocity();
         parseSedimentLoadLS();
+        parseSedimentLoad();
         parseWaterlevels();
         parseWaterlevelDifferences();
-        parseMeasurementStations();
         parseSQRelation();
     }
 
@@ -595,9 +603,9 @@
     }
 
 
-    private void parseSedimentLoadLSDir(
+    private void parseSedimentLoadFiles(
         File[] files,
-        SedimentLoadLSParser parser
+        AbstractSedimentLoadParser parser
     ) throws IOException {
        for (File file: files) {
            if (file.isDirectory()) {
@@ -611,6 +619,34 @@
        }
     }
 
+
+    private void parseSedimentLoadDir(
+        File sedimentLoadDir,
+        AbstractSedimentLoadParser parser
+    ) throws IOException {
+
+        File[] sedimentLoadSubDirs = {
+            new File(sedimentLoadDir,
+                     SEDIMENT_LOAD_SINGLE_DIR),
+            new File(sedimentLoadDir,
+                     SEDIMENT_LOAD_EPOCH_DIR),
+            new File(sedimentLoadDir,
+                     SEDIMENT_LOAD_OFF_EPOCH_DIR),
+        };
+
+        for (File subDir : sedimentLoadSubDirs) {
+            File[] files = subDir.listFiles();
+
+            if (files == null || files.length == 0) {
+                log.warn("Cannot read directory '" + subDir + "'");
+            }
+            else {
+                parseSedimentLoadFiles(files, parser);
+            }
+        }
+    }
+
+
     protected void parseSedimentLoadLS() throws IOException {
         if (Config.INSTANCE.skipSedimentLoadLS()) {
             log.info("skip parsing sediment load longitudinal section data");
@@ -619,46 +655,37 @@
 
         log.debug("Parse sediment load longitudinal section data");
 
+        SedimentLoadLSParser parser = new SedimentLoadLSParser();
+
         File minfoDir          = getMinfoDir();
         File sedimentLoadDir   = new File(minfoDir, SEDIMENT_LOAD_DIR);
         File sedimentLoadLSDir = new File(sedimentLoadDir,
                                           SEDIMENT_LOAD_LS_DIR);
 
-        File singleDir   = new File(sedimentLoadLSDir,
-                                    SEDIMENT_LOAD_SINGLE_DIR);
-        File epochDir    = new File(sedimentLoadLSDir,
-                                    SEDIMENT_LOAD_EPOCH_DIR);
-        File offEpochDir = new File(sedimentLoadLSDir,
-                                    SEDIMENT_LOAD_OFF_EPOCH_DIR);
+        parseSedimentLoadDir(sedimentLoadLSDir, parser);
 
-        File[] singles   = singleDir.listFiles();
-        File[] epochs    = epochDir.listFiles();
-        File[] offEpochs = offEpochDir.listFiles();
+        sedimentLoadLSs = parser.getSedimentLoadLSs();
+    }
 
-        SedimentLoadLSParser parser = new SedimentLoadLSParser();
 
-        if (singles == null || singles.length == 0) {
-            log.warn("Cannot read directory '" + singleDir + "'");
-        }
-        else {
-            parseSedimentLoadLSDir(singles, parser);
+    protected void parseSedimentLoad() throws IOException {
+        if (Config.INSTANCE.skipSedimentLoad()) {
+            log.info("skip parsing sediment load data at measurement stations");
+            return;
         }
 
-        if (epochs == null || epochs.length == 0) {
-            log.warn("Cannot read directory '" + epochDir + "'");
-        }
-        else {
-            parseSedimentLoadLSDir(epochs, parser);
-        }
+        log.debug("Parse sediment load data at measurement stations");
 
-        if (offEpochs == null || offEpochs.length == 0) {
-            log.warn("Cannot read directory '" + offEpochDir + "'");
-        }
-        else {
-            parseSedimentLoadLSDir(offEpochs, parser);
-        }
+        SedimentLoadParser parser = new SedimentLoadParser(name);
 
-        sedimentLoadLSs = parser.getSedimentLoadLSs();
+        File minfoDir          = getMinfoDir();
+        File sedimentLoadDir   = new File(minfoDir, SEDIMENT_LOAD_DIR);
+        File sedimentLoadMSDir = new File(sedimentLoadDir,
+                                          SEDIMENT_LOAD_MS_DIR);
+
+        parseSedimentLoadDir(sedimentLoadMSDir, parser);
+
+        sedimentLoads = parser.getSedimentLoads();
     }
 
 
@@ -1257,15 +1284,16 @@
         storeOfficialLines();
         storeFloodWater();
         storeFloodProtection();
+        storeMeasurementStations();
         storeBedHeight();
         storeSedimentDensity();
         storePorosity();
         storeMorphologicalWidth();
         storeFlowVelocity();
         storeSedimentLoadLS();
+        storeSedimentLoad();
         storeWaterlevels();
         storeWaterlevelDifferences();
-        storeMeasurementStations();
         storeSQRelations();
         storeOfficialNumber();
     }
@@ -1515,6 +1543,17 @@
     }
 
 
+    public void storeSedimentLoad() {
+        if (!Config.INSTANCE.skipSedimentLoad()) {
+            log.info("store sediment load data at measurement stations");
+
+            for (ImportSedimentLoad sedimentLoad: sedimentLoads) {
+                sedimentLoad.storeDependencies();
+            }
+        }
+    }
+
+
     public void storeMeasurementStations() {
         if (!Config.INSTANCE.skipMeasurementStations()) {
             log.info("store measurement stations");

http://dive4elements.wald.intevation.org