Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/data/importer/LAFParser.java @ 366:567ce7697fc7 0.5
Code documentation.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 10 Sep 2013 15:55:54 +0200 |
parents | d39d3886b97d |
children | c63281230bc3 |
comparison
equal
deleted
inserted
replaced
365:fab80595ed55 | 366:567ce7697fc7 |
---|---|
8 import javax.inject.Inject; | 8 import javax.inject.Inject; |
9 import javax.inject.Named; | 9 import javax.inject.Named; |
10 | 10 |
11 import de.intevation.lada.auth.AuthenticationResponse; | 11 import de.intevation.lada.auth.AuthenticationResponse; |
12 | 12 |
13 | 13 /** |
14 * This parser is used to read data in LAF based key-value pair structure. | |
15 * | |
16 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> | |
17 */ | |
14 public class LAFParser { | 18 public class LAFParser { |
15 | 19 |
16 private static final String PROBE_NEXT = "\n%PROBE%"; | 20 private static final String PROBE_NEXT = "\n%PROBE%"; |
17 | 21 |
18 private boolean dryRun; | 22 private boolean dryRun; |
26 private Writer writer; | 30 private Writer writer; |
27 | 31 |
28 private Map<String, List<ReportData>> warnings; | 32 private Map<String, List<ReportData>> warnings; |
29 private Map<String, List<ReportData>> errors; | 33 private Map<String, List<ReportData>> errors; |
30 | 34 |
35 /** | |
36 * Default constructor. | |
37 */ | |
31 public LAFParser() { | 38 public LAFParser() { |
32 this.warnings = new HashMap<String, List<ReportData>>(); | 39 this.warnings = new HashMap<String, List<ReportData>>(); |
33 this.errors = new HashMap<String, List<ReportData>>(); | 40 this.errors = new HashMap<String, List<ReportData>>(); |
34 this.setDryRun(false); | 41 this.setDryRun(false); |
35 } | 42 } |
36 | 43 |
44 /** | |
45 * Read and parse the data and write the objects to the database. | |
46 * | |
47 * @param auth Authentication information | |
48 * @param laf The LAF formated data. | |
49 * @return success | |
50 * @throws LAFParserException | |
51 */ | |
37 public boolean parse(AuthenticationResponse auth, String laf) | 52 public boolean parse(AuthenticationResponse auth, String laf) |
38 throws LAFParserException | 53 throws LAFParserException |
39 { | 54 { |
40 if (!laf.startsWith("%PROBE%\n")) { | 55 if (!laf.startsWith("%PROBE%\n")) { |
41 throw new LAFParserException("No %PROBE% at the begining."); | 56 throw new LAFParserException("No %PROBE% at the begining."); |
101 } | 116 } |
102 } | 117 } |
103 return parsed; | 118 return parsed; |
104 } | 119 } |
105 | 120 |
121 /** | |
122 * Write all created objects to the database. | |
123 * | |
124 * @param auth The authentication information. | |
125 */ | |
106 private void writeAll(AuthenticationResponse auth) { | 126 private void writeAll(AuthenticationResponse auth) { |
107 String probeId = producer.getProbe().getProbeId() == null ? "probeId" : producer.getProbe().getProbeId(); | 127 String probeId = producer.getProbe().getProbeId() == null ? "probeId" : producer.getProbe().getProbeId(); |
108 boolean p = writer.writeProbe(auth, producer.getProbe()); | 128 boolean p = writer.writeProbe(auth, producer.getProbe()); |
109 if (!p) { | 129 if (!p) { |
110 this.errors.put(probeId, writer.getErrors()); | 130 this.errors.put(probeId, writer.getErrors()); |
134 else { | 154 else { |
135 warn.addAll(writer.getWarnings()); | 155 warn.addAll(writer.getWarnings()); |
136 } | 156 } |
137 } | 157 } |
138 | 158 |
159 /** | |
160 * Read all attributes from a single probe block and create entity objects. | |
161 * | |
162 * @param content Single probe block enclosed by %PROBE% | |
163 * @throws LAFParserException | |
164 */ | |
139 private void readAll(String content) | 165 private void readAll(String content) |
140 throws LAFParserException | 166 throws LAFParserException |
141 { | 167 { |
142 boolean key = false; | 168 boolean key = false; |
143 boolean value = false; | 169 boolean value = false; |
240 this.producer.newMessung(); | 266 this.producer.newMessung(); |
241 this.producer.newOrt(); | 267 this.producer.newOrt(); |
242 } | 268 } |
243 } | 269 } |
244 | 270 |
271 /** | |
272 * @return if objects are or not. | |
273 */ | |
245 public boolean isDryRun() { | 274 public boolean isDryRun() { |
246 return dryRun; | 275 return dryRun; |
247 } | 276 } |
248 | 277 |
278 /** | |
279 * If set to true, no objects will be created and written to database. | |
280 * | |
281 * @param dryRun | |
282 */ | |
249 public void setDryRun(boolean dryRun) { | 283 public void setDryRun(boolean dryRun) { |
250 this.dryRun = dryRun; | 284 this.dryRun = dryRun; |
251 } | 285 } |
252 | 286 |
253 /** | 287 /** |
262 */ | 296 */ |
263 public Map<String, List<ReportData>> getErrors() { | 297 public Map<String, List<ReportData>> getErrors() { |
264 return errors; | 298 return errors; |
265 } | 299 } |
266 | 300 |
301 /** | |
302 * Reset errors and warnings. | |
303 */ | |
267 public void reset() { | 304 public void reset() { |
268 producer.reset(); | 305 producer.reset(); |
269 this.errors = new HashMap<String, List<ReportData>>(); | 306 this.errors = new HashMap<String, List<ReportData>>(); |
270 this.warnings = new HashMap<String, List<ReportData>>(); | 307 this.warnings = new HashMap<String, List<ReportData>>(); |
271 } | 308 } |