comparison flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java @ 493:b35c5dc0f8b7

Importer: Make import of historical discharge tables work. flys-backend/trunk@1842 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 06 May 2011 10:27:32 +0000
parents 14de9246b356
children ee693b8fbb55
comparison
equal deleted inserted replaced
492:14de9246b356 493:b35c5dc0f8b7
38 public AtFileParser() { 38 public AtFileParser() {
39 } 39 }
40 40
41 41
42 public ImportDischargeTable parse(File file) throws IOException { 42 public ImportDischargeTable parse(File file) throws IOException {
43 return parse(file, 0); 43 return parse(file, "", 0);
44 } 44 }
45 45
46 public ImportDischargeTable parse(File file, int kind) throws IOException { 46 public ImportDischargeTable parse(
47 File file,
48 String prefix,
49 int kind
50 )
51 throws IOException {
47 52
48 logger.info("parsing AT file: " + file); 53 logger.info("parsing AT file: " + file);
49 54
50 BufferedReader br = null; 55 BufferedReader br = null;
51 56
52 String line = null; 57 String line = null;
53 58
54 boolean beginning = true; 59 boolean beginning = true;
55 60
56 ImportDischargeTable dischargeTable = new ImportDischargeTable(kind); 61 ImportDischargeTable dischargeTable =
62 new ImportDischargeTable(kind, prefix + file.getName());
57 63
58 Date from = null; 64 Date from = null;
59 Date to = null; 65 Date to = null;
60 66
61 try { 67 try {
71 continue; 77 continue;
72 } 78 }
73 79
74 Matcher m = DATE_LINE.matcher(tmp); 80 Matcher m = DATE_LINE.matcher(tmp);
75 if (m.matches()) { 81 if (m.matches()) {
76 from = guessDate(m.group(1), m.group(2), m.group(3)); 82 from = guessDate(m.group(2), m.group(3), m.group(4));
77 to = guessDate(m.group(4), m.group(5), m.group(6)); 83 to = guessDate(m.group(5), m.group(6), m.group(7));
78 if (from == null) { 84 if (from == null) {
79 Date t = from; from = to; to = t; 85 Date t = from; from = to; to = t;
80 } 86 }
81 continue; 87 continue;
82 } 88 }
135 br.close(); 141 br.close();
136 } 142 }
137 } 143 }
138 144
139 if (from != null) { 145 if (from != null) {
146 if (to != null && from.compareTo(to) > 0) {
147 Date t = from; from = to; to = t;
148 }
140 logger.info("from: " + from + " to: " + to); 149 logger.info("from: " + from + " to: " + to);
141 ImportTimeInterval interval = new ImportTimeInterval(from, to); 150 ImportTimeInterval interval = new ImportTimeInterval(from, to);
142 dischargeTable.setTimeInterval(interval); 151 dischargeTable.setTimeInterval(interval);
143 } 152 }
144 153
149 158
150 public static Date guessDate(String day, String month, String year) { 159 public static Date guessDate(String day, String month, String year) {
151 if (day == null && month == null && year == null) { 160 if (day == null && month == null && year == null) {
152 return null; 161 return null;
153 } 162 }
163
164 logger.debug("day: " + day + " month: " + month + " year: " + year);
154 165
155 int dayI = 15; 166 int dayI = 15;
156 if (day != null) { 167 if (day != null) {
157 try { 168 try {
158 dayI = Integer.parseInt(day.trim()); 169 dayI = Integer.parseInt(day.trim());
186 catch (NumberFormatException nfe) { 197 catch (NumberFormatException nfe) {
187 } 198 }
188 } 199 }
189 200
190 Calendar cal = Calendar.getInstance(); 201 Calendar cal = Calendar.getInstance();
191 cal.set(yearI, monthI-1, dayI); 202 cal.set(yearI, monthI-1, dayI, 12, 0, 0);
203 long ms = cal.getTimeInMillis();
204 cal.setTimeInMillis(ms - ms%1000);
192 return cal.getTime(); 205 return cal.getTime();
193 } 206 }
194 } 207 }
195 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 208 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org