changeset 7339:40e5ad76103c

WST Import: Added parse error exception to WST parser.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 15 Oct 2013 18:31:59 +0200
parents f37c7e183b5e
children 2ce7bacc940f 42acdab9803a
files backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
diffstat 2 files changed, 70 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Tue Oct 15 17:39:04 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Tue Oct 15 18:31:59 2013 +0200
@@ -356,12 +356,17 @@
                 continue;
             }
             log.info("found file '" + file.getName() + "'");
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(5);
-            iw.setDescription(FLOOD_PROTECTION + "/" + iw.getDescription());
-            floodProtection.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(5);
+                iw.setDescription(FLOOD_PROTECTION + "/" + iw.getDescription());
+                floodProtection.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
     }
 
@@ -768,12 +773,17 @@
                 continue;
             }
             log.info("found file '" + file.getName() + "'");
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(4);
-            iw.setDescription(FLOOD_WATER + "/" + iw.getDescription());
-            floodWater.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(4);
+                iw.setDescription(FLOOD_WATER + "/" + iw.getDescription());
+                floodWater.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
     }
 
@@ -805,7 +815,14 @@
             ImportWst iw = new ImportWst(ImportOfficialWstColumn.COLUMN_FACTORY);
 
             WstParser wstParser = new WstParser(iw);
-            wstParser.parse(file);
+            try {
+                wstParser.parse(file);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+                continue;
+            }
+
             iw.setKind(3);
             iw.setDescription(folder + "/" + iw.getDescription());
 
@@ -878,12 +895,17 @@
             }
             log.debug("Found WST file: " + file);
 
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(2);
-            iw.setDescription(FIXATIONS+ "/" + iw.getDescription());
-            fixations.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(2);
+                iw.setDescription(FIXATIONS+ "/" + iw.getDescription());
+                fixations.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
     }
 
@@ -922,12 +944,17 @@
             }
             log.debug("Found WST file: " + file);
 
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(1);
-            iw.setDescription(EXTRA_LONGITUDINALS + "/" + iw.getDescription());
-            extraWsts.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(1);
+                iw.setDescription(EXTRA_LONGITUDINALS + "/" + iw.getDescription());
+                extraWsts.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
 
     }
@@ -939,9 +966,14 @@
         }
 
         WstParser wstParser = new WstParser();
-        wstParser.parse(wstFile);
-        wst = wstParser.getWst();
-        wst.setKmUp(wst.guessWaterLevelIncreasing());
+        try {
+            wstParser.parse(wstFile);
+            wst = wstParser.getWst();
+            wst.setKmUp(wst.guessWaterLevelIncreasing());
+        }
+        catch (WstParser.ParseException e) {
+            log.error(e);
+        }
     }
 
     public void parseGauges() throws IOException {
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Tue Oct 15 17:39:04 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Tue Oct 15 18:31:59 2013 +0200
@@ -85,6 +85,15 @@
         this.wst = wst;
     }
 
+    public static final class ParseException extends Exception {
+        public ParseException() {
+        }
+
+        public ParseException(String msg) {
+            super(msg);
+        }
+    } // class ParseException
+
     /** Returns a new ImportTimeInterval with a date guessed from string. */
     public static ImportTimeInterval guessDate(String string) {
         try {
@@ -105,7 +114,7 @@
         return null;
     }
 
-    public void parse(File file) throws IOException {
+    public void parse(File file) throws IOException, ParseException {
 
         log.info("Parsing WST file '" + file + "'");
 

http://dive4elements.wald.intevation.org