comparison 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
comparison
equal deleted inserted replaced
1203:3c01bef43a98 1204:22858e7cca79
1 package de.intevation.flys.importer; 1 package de.intevation.flys.importer;
2 2
3 import java.math.BigDecimal;
4
3 import java.util.List; 5 import java.util.List;
6 import java.util.Map;
4 import java.util.ArrayList; 7 import java.util.ArrayList;
8 import java.util.Date;
9 import java.util.Calendar;
5 10
6 import java.io.File; 11 import java.io.File;
7 import java.io.IOException; 12 import java.io.IOException;
8 13
9 import org.apache.log4j.Logger; 14 import org.apache.log4j.Logger;
14 19
15 import org.hibernate.Session; 20 import org.hibernate.Session;
16 import org.hibernate.Query; 21 import org.hibernate.Query;
17 22
18 public class ImportRiver 23 public class ImportRiver
24 implements PRFParser.Callback
19 { 25 {
20 private static Logger log = Logger.getLogger(ImportRiver.class); 26 private static Logger log = Logger.getLogger(ImportRiver.class);
21 27
22 public static final String PEGEL_GLT = "PEGEL.GLT"; 28 public static final String PEGEL_GLT = "PEGEL.GLT";
23 29
46 52
47 protected List<ImportGauge> gauges; 53 protected List<ImportGauge> gauges;
48 54
49 protected List<ImportAnnotation> annotations; 55 protected List<ImportAnnotation> annotations;
50 56
57 protected List<ImportCrossSection> crossSections;
58
51 protected List<ImportWst> extraWsts; 59 protected List<ImportWst> extraWsts;
52 60
53 protected List<ImportWst> fixations; 61 protected List<ImportWst> fixations;
54 62
55 protected List<ImportWst> officialLines; 63 protected List<ImportWst> officialLines;
63 protected AnnotationClassifier annotationClassifier; 71 protected AnnotationClassifier annotationClassifier;
64 72
65 protected River peer; 73 protected River peer;
66 74
67 public ImportRiver() { 75 public ImportRiver() {
76 crossSections = new ArrayList<ImportCrossSection>();
68 extraWsts = new ArrayList<ImportWst>(); 77 extraWsts = new ArrayList<ImportWst>();
69 fixations = new ArrayList<ImportWst>(); 78 fixations = new ArrayList<ImportWst>();
70 officialLines = new ArrayList<ImportWst>(); 79 officialLines = new ArrayList<ImportWst>();
71 floodWater = new ArrayList<ImportWst>(); 80 floodWater = new ArrayList<ImportWst>();
72 floodProtection = new ArrayList<ImportWst>(); 81 floodProtection = new ArrayList<ImportWst>();
118 } 127 }
119 128
120 public void parseDependencies() throws IOException { 129 public void parseDependencies() throws IOException {
121 parseGauges(); 130 parseGauges();
122 parseAnnotations(); 131 parseAnnotations();
132 parsePRFs();
123 parseWst(); 133 parseWst();
124 parseExtraWsts(); 134 parseExtraWsts();
125 parseFixations(); 135 parseFixations();
126 parseOfficialLines(); 136 parseOfficialLines();
127 parseFloodWater(); 137 parseFloodWater();
343 aparser.parse(riverDir); 353 aparser.parse(riverDir);
344 354
345 annotations = aparser.getAnnotations(); 355 annotations = aparser.getAnnotations();
346 } 356 }
347 357
358 public void parsePRFs() {
359 log.info("looking for PRF files");
360 PRFParser parser = new PRFParser();
361 File riverDir = wstFile
362 .getParentFile() // Basisdaten
363 .getParentFile() // Hydrologie
364 .getParentFile(); // <river>
365 parser.parsePRFs(riverDir, this);
366 }
367
368 public static Date yearToDate(int year) {
369 Calendar cal = Calendar.getInstance();
370 cal.set(year, 5, 15, 12, 0, 0);
371 long ms = cal.getTimeInMillis();
372 cal.setTimeInMillis(ms - ms%1000);
373 return cal.getTime();
374 }
375
376 @Override
377 public void prfParsed(PRFParser parser) {
378 log.debug("callback from PRF parser");
379
380 String description = parser.getDescription();
381 Integer year = parser.getYear();
382 ImportTimeInterval ti = year != null
383 ? new ImportTimeInterval(yearToDate(year))
384 : null;
385
386 List<ImportCrossSectionLine> lines =
387 new ArrayList<ImportCrossSectionLine>();
388
389 for (Map.Entry<Double, List<XY>> entry: parser.getData().entrySet()) {
390 BigDecimal km = new BigDecimal(entry.getKey());
391 List<XY> points = entry.getValue();
392 lines.add(new ImportCrossSectionLine(km, points));
393 }
394
395 crossSections.add(new ImportCrossSection(
396 this, description, ti, lines));
397 }
398
348 public void storeDependencies() { 399 public void storeDependencies() {
349 storeAnnotations(); 400 storeAnnotations();
401 storeCrossSections();
350 storeGauges(); 402 storeGauges();
351 storeWst(); 403 storeWst();
352 storeExtraWsts(); 404 storeExtraWsts();
353 storeFixations(); 405 storeFixations();
354 storeOfficialLines(); 406 storeOfficialLines();
355 storeFloodWater(); 407 storeFloodWater();
356 storeFloodProtection(); 408 storeFloodProtection();
409 }
410
411 public void storeCrossSections() {
412 log.info("store cross sections");
413 for (ImportCrossSection crossSection: crossSections) {
414 crossSection.storeDependencies();
415 }
357 } 416 }
358 417
359 public void storeWst() { 418 public void storeWst() {
360 River river = getPeer(); 419 River river = getPeer();
361 wst.storeDependencies(river); 420 wst.storeDependencies(river);

http://dive4elements.wald.intevation.org