changeset 1223:268f8da412e3

Importer: Added a central configuration to allow skipping of parsing/storing individual sub systems. flys-backend/trunk@2354 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Jul 2011 15:52:42 +0000
parents 1f21f162bcf3
children ca7d461a53f1
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/Importer.java
diffstat 4 files changed, 257 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Mon Jul 18 09:06:40 2011 +0000
+++ b/flys-backend/ChangeLog	Mon Jul 18 15:52:42 2011 +0000
@@ -1,3 +1,45 @@
+2011-07-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/Config.java: New.
+	  Central singleton to configure the Importer.
+	  Uses system properties by now:
+
+	  flys.backend.importer.dry.run: boolean
+	      default false. true: don't write to database.
+
+	  flys.backend.importer.annotation.types: String
+	      default unset. Filename of annotation type classifications.
+
+	  flys.backend.importer.skip.gauges: boolean
+	      default: false. true: don't parse/store *.glt, *.sta files
+
+	  flys.backend.importer.skip.annotations: boolean
+	      default: false. true: don't parse/store *.km files
+
+	  flys.backend.importer.skip.prfs: boolean
+	      default: false. true: don't parse/store *.prf files
+
+	  flys.backend.importer.skip.hyks: boolean
+	      default: false. true: don't parse/store *.hyk files
+
+	  flys.backend.importer.skip.wst: boolean
+	      default: false. true: don't parse/store river wst files
+
+	  flys.backend.importer.skip.extra.wsts: boolean
+	      default: false. true: don't parse/store extra *.zus, *.wst files
+
+	  flys.backend.importer.skip.fixations: boolean
+	      default: false. true: don't parse/store fixation *.wst files
+
+	  flys.backend.importer.skip.official.lines: boolean
+	      default: false. true: don't parse/store 'amtliche Linien' *.wst files
+
+	  flys.backend.importer.skip.flood.water: boolean
+	      default: false. true: don't parse/store 'HW-Marken' *.wst files
+
+	  flys.backend.importer.skip.flood.protection: boolean
+	      default: false. true: don't parse/store 'HW-Schutzanlagen' *.wst files
+
 2011-07-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/HYKEntry.java: Fixed OrderBy
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/Config.java	Mon Jul 18 15:52:42 2011 +0000
@@ -0,0 +1,94 @@
+package de.intevation.flys.importer;
+
+public class Config
+{
+    public static final String DRY_RUN =
+        "flys.backend.importer.dry.run";
+
+    public static final String ANNOTATION_TYPES =
+        "flys.backend.importer.annotation.types";
+
+    public static final String SKIP_GAUGES =
+        "flys.backend.importer.skip.gauges";
+
+    public static final String SKIP_ANNOTATIONS =
+        "flys.backend.importer.skip.annotations";
+
+    public static final String SKIP_PRFS =
+        "flys.backend.importer.skip.prfs";
+
+    public static final String SKIP_HYKS =
+        "flys.backend.importer.skip.hyks";
+
+    public static final String SKIP_WST =
+        "flys.backend.importer.skip.wst";
+
+    public static final String SKIP_EXTRA_WSTS =
+        "flys.backend.importer.skip.extra.wsts";
+
+    public static final String SKIP_FIXATIONS =
+        "flys.backend.importer.skip.fixations";
+
+    public static final String SKIP_OFFICIAL_LINES =
+        "flys.backend.importer.skip.official.lines";
+
+    public static final String SKIP_FLOOD_WATER =
+        "flys.backend.importer.skip.flood.water";
+
+    public static final String SKIP_FLOOD_PROTECTION =
+        "flys.backend.importer.skip.flood.protection";
+
+    public static final Config INSTANCE = new Config();
+
+    private Config () {
+    }
+
+    public boolean dryRun() {
+        return Boolean.getBoolean(DRY_RUN);
+    }
+
+    public String getAnnotationTypes() {
+        return System.getProperty(ANNOTATION_TYPES);
+    }
+
+    public boolean skipGauges() {
+        return Boolean.getBoolean(SKIP_GAUGES);
+    }
+
+    public boolean skipAnnotations() {
+        return Boolean.getBoolean(SKIP_ANNOTATIONS);
+    }
+
+    public boolean skipPRFs() {
+        return Boolean.getBoolean(SKIP_PRFS);
+    }
+
+    public boolean skipHYKs() {
+        return Boolean.getBoolean(SKIP_HYKS);
+    }
+
+    public boolean skipWst() {
+        return Boolean.getBoolean(SKIP_WST);
+    }
+
+    public boolean skipExtraWsts() {
+        return Boolean.getBoolean(SKIP_EXTRA_WSTS);
+    }
+
+    public boolean skipFixations() {
+        return Boolean.getBoolean(SKIP_FIXATIONS);
+    }
+
+    public boolean skipOfficialLines() {
+        return Boolean.getBoolean(SKIP_OFFICIAL_LINES);
+    }
+
+    public boolean skipFloodWater() {
+        return Boolean.getBoolean(SKIP_FLOOD_WATER);
+    }
+
+    public boolean skipFloodProtection() {
+        return Boolean.getBoolean(SKIP_FLOOD_PROTECTION);
+    }
+}
+// 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	Mon Jul 18 09:06:40 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Mon Jul 18 15:52:42 2011 +0000
@@ -152,6 +152,11 @@
     }
 
     public void parseFloodProtection() throws IOException {
+        if (Config.INSTANCE.skipFloodProtection()) {
+            log.info("skip parsing flood protection");
+            return;
+        }
+
         log.info("Parse flood protection wst file");
 
         File riverDir = wstFile.getParentFile().getParentFile();
@@ -189,6 +194,11 @@
     }
 
     public void parseFloodWater() throws IOException {
+        if (Config.INSTANCE.skipFloodWater()) {
+            log.info("skip parsing flod water");
+            return;
+        }
+
         log.info("Parse flood water wst file");
 
         File riverDir = wstFile.getParentFile().getParentFile();
@@ -226,6 +236,11 @@
     }
 
     public void parseOfficialLines() throws IOException {
+        if (Config.INSTANCE.skipOfficialLines()) {
+            log.info("skip parsing official lines");
+            return;
+        }
+
         log.info("Parse official wst files");
 
         File riverDir = wstFile.getParentFile().getParentFile();
@@ -256,6 +271,11 @@
     }
 
     public void parseFixations() throws IOException {
+        if (Config.INSTANCE.skipFixations()) {
+            log.info("skip parsing fixations");
+            return;
+        }
+
         log.info("Parse fixation wst files");
 
         File riverDir = wstFile.getParentFile().getParentFile();
@@ -295,6 +315,11 @@
     }
 
     public void parseExtraWsts() throws IOException {
+        if (Config.INSTANCE.skipExtraWsts()) {
+            log.info("skip parsing extra WST files");
+            return;
+        }
+
         log.info("Parse extra longitudinal wst files");
 
         File riverDir = wstFile.getParentFile().getParentFile();
@@ -335,12 +360,22 @@
     }
 
     public void parseWst() throws IOException {
+        if (Config.INSTANCE.skipWst()) {
+            log.info("skip parsing WST file");
+            return;
+        }
+
         WstParser wstParser = new WstParser();
         wstParser.parse(wstFile);
         wst = wstParser.getWst();
     }
 
     public void parseGauges() throws IOException {
+        if (Config.INSTANCE.skipGauges()) {
+            log.info("skip parsing gauges");
+            return;
+        }
+
         File gltFile = new File(wstFile.getParentFile(), PEGEL_GLT);
         gltFile = FileTools.repair(gltFile);
 
@@ -360,6 +395,11 @@
     }
 
     public void parseAnnotations() throws IOException {
+        if (Config.INSTANCE.skipAnnotations()) {
+            log.info("skip parsing annotations");
+            return;
+        }
+
         File riverDir = wstFile.getParentFile().getParentFile();
         AnnotationsParser aparser =
             new AnnotationsParser(annotationClassifier);
@@ -369,6 +409,11 @@
     }
 
     public void parseHYKs() {
+        if (Config.INSTANCE.skipHYKs()) {
+            log.info("skip parsing HYK files");
+            return;
+        }
+
         log.info("looking for HYK files");
         HYKParser parser = new HYKParser();
         File riverDir = wstFile
@@ -401,6 +446,11 @@
     }
 
     public void parsePRFs() {
+        if (Config.INSTANCE.skipPRFs()) {
+            log.info("skip parsing PRFs");
+            return;
+        }
+
         log.info("looking for PRF files");
         PRFParser parser = new PRFParser();
         File riverDir = wstFile
@@ -469,86 +519,108 @@
     }
 
     public void storeHYKs() {
-        log.info("store HYKs");
-        getPeer();
-        for (ImportHYK hyk: hyks) {
-            hyk.storeDependencies();
+        if (!Config.INSTANCE.skipHYKs()) {
+            log.info("store HYKs");
+            getPeer();
+            for (ImportHYK hyk: hyks) {
+                hyk.storeDependencies();
+            }
         }
     }
 
     public void storeCrossSections() {
-        log.info("store cross sections");
-        for (ImportCrossSection crossSection: crossSections) {
-            crossSection.storeDependencies();
+        if (!Config.INSTANCE.skipPRFs()) {
+            log.info("store cross sections");
+            getPeer();
+            for (ImportCrossSection crossSection: crossSections) {
+                crossSection.storeDependencies();
+            }
         }
     }
 
     public void storeWst() {
-        River river = getPeer();
-        wst.storeDependencies(river);
-    }
-
-    public void storeFixations() {
-        log.info("store fixation wsts");
-        River river = getPeer();
-        for (ImportWst wst: fixations) {
-            log.debug("name: " + wst.getDescription());
+        if (!Config.INSTANCE.skipWst()) {
+            River river = getPeer();
             wst.storeDependencies(river);
         }
     }
 
+    public void storeFixations() {
+        if (!Config.INSTANCE.skipFixations()) {
+            log.info("store fixation wsts");
+            River river = getPeer();
+            for (ImportWst wst: fixations) {
+                log.debug("name: " + wst.getDescription());
+                wst.storeDependencies(river);
+            }
+        }
+    }
+
     public void storeExtraWsts() {
-        log.info("store extra wsts");
-        River river = getPeer();
-        for (ImportWst wst: extraWsts) {
-            log.debug("name: " + wst.getDescription());
-            wst.storeDependencies(river);
+        if (!Config.INSTANCE.skipExtraWsts()) {
+            log.info("store extra wsts");
+            River river = getPeer();
+            for (ImportWst wst: extraWsts) {
+                log.debug("name: " + wst.getDescription());
+                wst.storeDependencies(river);
+            }
         }
     }
 
     public void storeOfficialLines() {
-        log.info("store official lines wsts");
-        River river = getPeer();
-        for (ImportWst wst: officialLines) {
-            log.debug("name: " + wst.getDescription());
-            wst.storeDependencies(river);
+        if (!Config.INSTANCE.skipOfficialLines()) {
+            log.info("store official lines wsts");
+            River river = getPeer();
+            for (ImportWst wst: officialLines) {
+                log.debug("name: " + wst.getDescription());
+                wst.storeDependencies(river);
+            }
         }
     }
 
     public void storeFloodWater() {
-        log.info("store flood water wsts");
-        River river = getPeer();
-        for (ImportWst wst: floodWater) {
-            log.debug("name: " + wst.getDescription());
-            wst.storeDependencies(river);
+        if (!Config.INSTANCE.skipFloodWater()) {
+            log.info("store flood water wsts");
+            River river = getPeer();
+            for (ImportWst wst: floodWater) {
+                log.debug("name: " + wst.getDescription());
+                wst.storeDependencies(river);
+            }
         }
     }
 
     public void storeFloodProtection() {
-        log.info("store flood protection wsts");
-        River river = getPeer();
-        for (ImportWst wst: floodProtection) {
-            log.debug("name: " + wst.getDescription());
-            wst.storeDependencies(river);
+        if (!Config.INSTANCE.skipFloodProtection()) {
+            log.info("store flood protection wsts");
+            River river = getPeer();
+            for (ImportWst wst: floodProtection) {
+                log.debug("name: " + wst.getDescription());
+                wst.storeDependencies(river);
+            }
         }
     }
 
     public void storeAnnotations() {
-        River river = getPeer();
-        for (ImportAnnotation annotation: annotations) {
-            annotation.getPeer(river);
+        if (!Config.INSTANCE.skipAnnotations()) {
+            River river = getPeer();
+            for (ImportAnnotation annotation: annotations) {
+                annotation.getPeer(river);
+            }
         }
     }
 
     public void storeGauges() {
-        log.info("store gauges:");
-        River river = getPeer();
-        Session session = ImporterSession.getInstance().getDatabaseSession();
-        for (ImportGauge gauge: gauges) {
-            log.info("\tgauge: " + gauge.getName());
-            gauge.storeDependencies(river);
-            ImporterSession.getInstance().getDatabaseSession();
-            session.flush();
+        if (!Config.INSTANCE.skipGauges()) {
+            log.info("store gauges:");
+            River river = getPeer();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
+            for (ImportGauge gauge: gauges) {
+                log.info("\tgauge: " + gauge.getName());
+                gauge.storeDependencies(river);
+                ImporterSession.getInstance().getDatabaseSession();
+                session.flush();
+            }
         }
     }
 
--- a/flys-backend/src/main/java/de/intevation/flys/importer/Importer.java	Mon Jul 18 09:06:40 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/Importer.java	Mon Jul 18 15:52:42 2011 +0000
@@ -23,12 +23,6 @@
 {
     private static Logger log = Logger.getLogger(Importer.class);
 
-    public static final boolean DRY_RUN =
-        Boolean.getBoolean("flys.backend.importer.dry.run");
-
-    public static final String ANNOTATION_TYPES =
-        "flys.backend.importer.annotation.types";
-
     protected List<ImportRiver> rivers;
 
     public Importer() {
@@ -90,7 +84,7 @@
     }
 
     public static AnnotationClassifier getAnnotationClassifier() {
-        String annotationTypes = System.getProperty(ANNOTATION_TYPES);
+        String annotationTypes = Config.INSTANCE.getAnnotationTypes();
 
         if (annotationTypes == null) {
             log.info("no annotation types file configured.");
@@ -131,7 +125,7 @@
             }
         }
 
-        if (!DRY_RUN) {
+        if (!Config.INSTANCE.dryRun()) {
             new Importer(infoGewParser.getRivers()).writeToDatabase();
         }
     }

http://dive4elements.wald.intevation.org