Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java @ 1204:22858e7cca79
Integrated PRF parsing into importer. Needs testing!
flys-backend/trunk@2309 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 07 Jul 2011 22:25:38 +0000 |
parents | aa9e3da95c31 |
children | c7370734b872 |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Thu Jul 07 15:59:24 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Thu Jul 07 22:25:38 2011 +0000 @@ -1,7 +1,12 @@ package de.intevation.flys.importer; +import java.math.BigDecimal; + import java.util.List; +import java.util.Map; import java.util.ArrayList; +import java.util.Date; +import java.util.Calendar; import java.io.File; import java.io.IOException; @@ -16,6 +21,7 @@ import org.hibernate.Query; public class ImportRiver +implements PRFParser.Callback { private static Logger log = Logger.getLogger(ImportRiver.class); @@ -48,6 +54,8 @@ protected List<ImportAnnotation> annotations; + protected List<ImportCrossSection> crossSections; + protected List<ImportWst> extraWsts; protected List<ImportWst> fixations; @@ -65,6 +73,7 @@ protected River peer; public ImportRiver() { + crossSections = new ArrayList<ImportCrossSection>(); extraWsts = new ArrayList<ImportWst>(); fixations = new ArrayList<ImportWst>(); officialLines = new ArrayList<ImportWst>(); @@ -120,6 +129,7 @@ public void parseDependencies() throws IOException { parseGauges(); parseAnnotations(); + parsePRFs(); parseWst(); parseExtraWsts(); parseFixations(); @@ -345,8 +355,50 @@ annotations = aparser.getAnnotations(); } + public void parsePRFs() { + log.info("looking for PRF files"); + PRFParser parser = new PRFParser(); + File riverDir = wstFile + .getParentFile() // Basisdaten + .getParentFile() // Hydrologie + .getParentFile(); // <river> + parser.parsePRFs(riverDir, this); + } + + public static Date yearToDate(int year) { + Calendar cal = Calendar.getInstance(); + cal.set(year, 5, 15, 12, 0, 0); + long ms = cal.getTimeInMillis(); + cal.setTimeInMillis(ms - ms%1000); + return cal.getTime(); + } + + @Override + public void prfParsed(PRFParser parser) { + log.debug("callback from PRF parser"); + + String description = parser.getDescription(); + Integer year = parser.getYear(); + ImportTimeInterval ti = year != null + ? new ImportTimeInterval(yearToDate(year)) + : null; + + List<ImportCrossSectionLine> lines = + new ArrayList<ImportCrossSectionLine>(); + + for (Map.Entry<Double, List<XY>> entry: parser.getData().entrySet()) { + BigDecimal km = new BigDecimal(entry.getKey()); + List<XY> points = entry.getValue(); + lines.add(new ImportCrossSectionLine(km, points)); + } + + crossSections.add(new ImportCrossSection( + this, description, ti, lines)); + } + public void storeDependencies() { storeAnnotations(); + storeCrossSections(); storeGauges(); storeWst(); storeExtraWsts(); @@ -356,6 +408,13 @@ storeFloodProtection(); } + public void storeCrossSections() { + log.info("store cross sections"); + for (ImportCrossSection crossSection: crossSections) { + crossSection.storeDependencies(); + } + } + public void storeWst() { River river = getPeer(); wst.storeDependencies(river);