# HG changeset patch # User Ingo Weinzierl # Date 1335433729 0 # Node ID acb8d08f59a26862b3bfaa3c80907f3dcb96e546 # Parent a1402c16152f795c845d91c1429503cd7c084ba1 Parse and store MINFO waterlevel differences; added config option to skip this process. flys-backend/trunk@4305 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a1402c16152f -r acb8d08f59a2 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Thu Apr 26 09:46:32 2012 +0000 +++ b/flys-backend/ChangeLog Thu Apr 26 09:48:49 2012 +0000 @@ -1,3 +1,13 @@ +2012-04-26 Ingo Weinzierl + + * src/main/java/de/intevation/flys/importer/Config.java: Added a config + option to skip parsing MINFO waterlevel differences: + + -Dflys.backend.importer.skip.waterlevel.differences=True + + * src/main/java/de/intevation/flys/importer/ImportRiver.java: Parse and + store MINFO specific waterlevel differences. + 2012-04-26 Ingo Weinzierl * src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java: diff -r a1402c16152f -r acb8d08f59a2 flys-backend/src/main/java/de/intevation/flys/importer/Config.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/Config.java Thu Apr 26 09:46:32 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/Config.java Thu Apr 26 09:48:49 2012 +0000 @@ -62,6 +62,9 @@ public static final String SKIP_WATERLEVELS = "flys.backend.importer.skip.waterlevels"; + public static final String SKIP_WATERLEVEL_DIFFERENCES = + "flys.backend.importer.skip.waterlevel.differences"; + public static final Config INSTANCE = new Config(); @@ -147,5 +150,9 @@ public boolean skipWaterlevels() { return Boolean.getBoolean(SKIP_WATERLEVELS); } + + public boolean skipWaterlevelDifferences() { + return Boolean.getBoolean(SKIP_WATERLEVEL_DIFFERENCES); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a1402c16152f -r acb8d08f59a2 flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Thu Apr 26 09:46:32 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Thu Apr 26 09:48:49 2012 +0000 @@ -36,6 +36,7 @@ import de.intevation.flys.importer.parsers.SedimentDensityParser; import de.intevation.flys.importer.parsers.SedimentYieldParser; import de.intevation.flys.importer.parsers.WstParser; +import de.intevation.flys.importer.parsers.WaterlevelDifferencesParser; import de.intevation.flys.importer.parsers.WaterlevelParser; import org.hibernate.Session; @@ -93,6 +94,8 @@ public static final String MINFO_WATERLEVELS_DIR = "Wasserspiegellagen"; + public static final String MINFO_WATERLEVEL_DIFF_DIR = "Wasserspiegeldifferenzen"; + protected String name; @@ -134,6 +137,8 @@ protected List waterlevels; + protected List waterlevelDiffs; + protected ImportWst wst; protected ImportUnit wstUnit; @@ -156,6 +161,7 @@ flowVelocityMeasurements = new ArrayList(); sedimentYields = new ArrayList(); waterlevels = new ArrayList(); + waterlevelDiffs = new ArrayList(); } public ImportRiver( @@ -225,6 +231,7 @@ parseFlowVelocity(); parseSedimentYield(); parseWaterlevels(); + parseWaterlevelDifferences(); } public void parseFloodProtection() throws IOException { @@ -462,6 +469,8 @@ return; } + log.info("Parse waterlevels"); + File minfo = getMinfoDir(); File fixDir = new File(minfo, MINFO_FIXATIONS_DIR); File wspDir = new File(fixDir, MINFO_WATERLEVELS_DIR); @@ -479,9 +488,36 @@ parser.parse(file); } - log.info("Parse waterlevels"); + waterlevels = parser.getWaterlevels(); + } - waterlevels = parser.getWaterlevels(); + + protected void parseWaterlevelDifferences() throws IOException { + if (Config.INSTANCE.skipWaterlevelDifferences()) { + log.info("skip parsing waterlevel differences"); + return; + } + + log.info("Parse waterlevel differences"); + + File minfo = getMinfoDir(); + File fixDir = new File(minfo, MINFO_FIXATIONS_DIR); + File diffDir = new File(fixDir, MINFO_WATERLEVEL_DIFF_DIR); + + File[] files = diffDir.listFiles(); + + if (files == null) { + log.warn("Cannot read directory '" + diffDir + "'"); + return; + } + + WaterlevelDifferencesParser parser = new WaterlevelDifferencesParser(); + + for (File file: files) { + parser.parse(file); + } + + waterlevelDiffs = parser.getDifferences(); } @@ -855,6 +891,7 @@ storeFlowVelocity(); storeSedimentYield(); storeWaterlevels(); + storeWaterlevelDifferences(); } public void storeWstUnit() { @@ -1128,6 +1165,27 @@ } + public void storeWaterlevelDifferences() { + if (!Config.INSTANCE.skipWaterlevelDifferences()) { + log.info("store waterlevel differences"); + + River river = getPeer(); + + for (ImportWaterlevelDifference diff: waterlevelDiffs) { + try { + diff.storeDependencies(river); + } + catch (SQLException sqle) { + log.error("Error while storing waterlevel diff.", sqle); + } + catch (ConstraintViolationException cve) { + log.error("Error while storing waterlevel diff.", cve); + } + } + } + } + + public void storeAnnotations() { if (!Config.INSTANCE.skipAnnotations()) { River river = getPeer();