comparison src/main/java/de/intevation/lada/data/importer/LAFProducer.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 3d2c53a10ee6
comparison
equal deleted inserted replaced
365:fab80595ed55 366:567ce7697fc7
1 package de.intevation.lada.data.importer; 1 package de.intevation.lada.data.importer;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.HashMap; 4 import java.util.HashMap;
5 import java.util.LinkedList;
6 import java.util.List; 5 import java.util.List;
7 import java.util.Map; 6 import java.util.Map;
8 7
9 import javax.inject.Inject; 8 import javax.inject.Inject;
10 import javax.inject.Named; 9 import javax.inject.Named;
11 10
12 import de.intevation.lada.data.QueryBuilder;
13 import de.intevation.lada.data.Repository; 11 import de.intevation.lada.data.Repository;
14 import de.intevation.lada.model.LKommentarM; 12 import de.intevation.lada.model.LKommentarM;
15 import de.intevation.lada.model.LKommentarMId; 13 import de.intevation.lada.model.LKommentarMId;
16 import de.intevation.lada.model.LKommentarP; 14 import de.intevation.lada.model.LKommentarP;
17 import de.intevation.lada.model.LMessung; 15 import de.intevation.lada.model.LMessung;
18 import de.intevation.lada.model.LMessungId; 16 import de.intevation.lada.model.LMessungId;
19 import de.intevation.lada.model.LMesswert; 17 import de.intevation.lada.model.LMesswert;
20 import de.intevation.lada.model.LMesswertId; 18 import de.intevation.lada.model.LMesswertId;
21 import de.intevation.lada.model.LOrt; 19 import de.intevation.lada.model.LOrt;
22 import de.intevation.lada.model.LProbe; 20 import de.intevation.lada.model.LProbe;
23 import de.intevation.lada.model.LProbe;
24 import de.intevation.lada.model.LZusatzWert; 21 import de.intevation.lada.model.LZusatzWert;
25 import de.intevation.lada.model.LZusatzWertId; 22 import de.intevation.lada.model.LZusatzWertId;
26 import de.intevation.lada.model.Ort; 23 import de.intevation.lada.model.Ort;
27 import de.intevation.lada.model.SProbenZusatz; 24
28 25 /**
26 * The LAFProducer creates entity objects form key-value pairs using the
27 * AttributeMapper.
28 *
29 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
30 */
29 @Named("lafproducer") 31 @Named("lafproducer")
30 public class LAFProducer 32 public class LAFProducer
31 implements Producer 33 implements Producer
32 { 34 {
33 35
55 private Map<String, List<ReportData>> errors; 57 private Map<String, List<ReportData>> errors;
56 58
57 @Inject 59 @Inject
58 private AttributeMapper mapper; 60 private AttributeMapper mapper;
59 61
62 /**
63 * Default contructor. Initializes the producer and reads the config file
64 * using the systemproperty "de.intevation.lada.importconfig".
65 */
60 public LAFProducer() { 66 public LAFProducer() {
61 this.warnings = new HashMap<String, List<ReportData>>(); 67 this.warnings = new HashMap<String, List<ReportData>>();
62 this.errors = new HashMap<String, List<ReportData>>(); 68 this.errors = new HashMap<String, List<ReportData>>();
63 this.probe = new LProbe(); 69 this.probe = new LProbe();
64 this.pKommentare = new ArrayList<LKommentarP>(); 70 this.pKommentare = new ArrayList<LKommentarP>();
72 probenFormat = format.getFormat("probe"); 78 probenFormat = format.getFormat("probe");
73 messungFormat = format.getFormat("messung"); 79 messungFormat = format.getFormat("messung");
74 ortFormat = format.getFormat("ort"); 80 ortFormat = format.getFormat("ort");
75 } 81 }
76 82
83 /**
84 * Add data to the producer.
85 * This triggers the producer to create a new object or add data to
86 * existing objects.
87 *
88 * @param key The key.
89 * @param values The value
90 */
77 @Override 91 @Override
78 public void addData(String key, Object values) 92 public void addData(String key, Object values)
79 throws LAFParserException { 93 throws LAFParserException {
80 String lKey = key.toLowerCase(); 94 String lKey = key.toLowerCase();
81 if(lKey.equals("probenkommentar")) { 95 if(lKey.equals("probenkommentar")) {
171 else if (isValidOrt(lKey, values.toString())) { 185 else if (isValidOrt(lKey, values.toString())) {
172 this.ort = mapper.addAttribute(lKey, values, this.ort); 186 this.ort = mapper.addAttribute(lKey, values, this.ort);
173 } 187 }
174 } 188 }
175 189
190 /**
191 * Check if the key is defined in the config file and validate the value
192 * using the pattern defined for this key.
193 *
194 * @param key The key.
195 * @param value The value.
196 * @return valid or not.
197 */
176 private boolean isValidOrt(String key, String value) { 198 private boolean isValidOrt(String key, String value) {
177 for (EntryFormat ef: ortFormat) { 199 for (EntryFormat ef: ortFormat) {
178 if (ef.getKey().equals(key.toLowerCase())) { 200 if (ef.getKey().equals(key.toLowerCase())) {
179 if (ef.getPattern().matcher(value).matches()) { 201 if (ef.getPattern().matcher(value).matches()) {
180 return true; 202 return true;
182 } 204 }
183 } 205 }
184 return false; 206 return false;
185 } 207 }
186 208
209 /**
210 * Check if the key is defined in the config file and validate the value
211 * using the pattern defined for this key.
212 *
213 * @param key The key.
214 * @param value The value.
215 * @return valid or not.
216 */
187 private boolean isValidMessung(String key, String value) { 217 private boolean isValidMessung(String key, String value) {
188 for (EntryFormat ef: messungFormat) { 218 for (EntryFormat ef: messungFormat) {
189 if (ef.getKey().equals(key.toLowerCase())) { 219 if (ef.getKey().equals(key.toLowerCase())) {
190 if (ef.getPattern().matcher(value).matches()) { 220 if (ef.getPattern().matcher(value).matches()) {
191 return true; 221 return true;
193 } 223 }
194 } 224 }
195 return false; 225 return false;
196 } 226 }
197 227
228 /**
229 * Check if the key is defined in the config file and validate the value
230 * using the pattern defined for this key.
231 *
232 * @param key The key.
233 * @param value The value.
234 * @return valid or not.
235 */
198 private boolean isValidProbe(String key, String value) { 236 private boolean isValidProbe(String key, String value) {
199 for (EntryFormat ef: probenFormat) { 237 for (EntryFormat ef: probenFormat) {
200 if (ef.getKey().equals(key.toLowerCase())) { 238 if (ef.getKey().equals(key.toLowerCase())) {
201 if (ef.getPattern().matcher(value).matches()) { 239 if (ef.getPattern().matcher(value).matches()) {
202 return true; 240 return true;
204 } 242 }
205 } 243 }
206 return false; 244 return false;
207 } 245 }
208 246
247 /**
248 * @return the {@link LProbe} entity.
249 */
209 @Override 250 @Override
210 public LProbe getProbe() { 251 public LProbe getProbe() {
211 return this.probe; 252 return this.probe;
212 } 253 }
213 254
255 /**
256 * @return List of {@link LMessung} entities.
257 */
214 @Override 258 @Override
215 public List<LMessung> getMessungen() { 259 public List<LMessung> getMessungen() {
216 return this.messungen; 260 return this.messungen;
217 } 261 }
218 262
263 /**
264 * @return List of {@link Ort} entities.
265 */
219 @Override 266 @Override
220 public List<Ort> getOrte() { 267 public List<Ort> getOrte() {
221 return this.orte; 268 return this.orte;
222 } 269 }
223 270
271 /**
272 * @return List of {@link LOrt} entities.
273 */
224 @Override 274 @Override
225 public List<LOrt> getLOrte() { 275 public List<LOrt> getLOrte() {
226 return this.lorte; 276 return this.lorte;
227 } 277 }
278
279 /**
280 * @return List of {@link LKommentarP} entities.
281 */
228 @Override 282 @Override
229 public List<LKommentarP> getProbenKommentare() { 283 public List<LKommentarP> getProbenKommentare() {
230 return this.pKommentare; 284 return this.pKommentare;
231 } 285 }
232 286
287 /**
288 * @return List of {@link LKommentarM} entities.
289 */
233 @Override 290 @Override
234 public List<LKommentarM> getMessungsKommentare() { 291 public List<LKommentarM> getMessungsKommentare() {
235 return this.mKommentare; 292 return this.mKommentare;
236 } 293 }
237 294
295 /**
296 * @return List of {@link LMesswert} entities.
297 */
238 @Override 298 @Override
239 public List<LMesswert> getMesswerte() { 299 public List<LMesswert> getMesswerte() {
240 return this.messwerte; 300 return this.messwerte;
241 } 301 }
242 302
303 /**
304 * @return List of {@link LZusatzWert} entities.
305 */
243 @Override 306 @Override
244 public List<LZusatzWert> getZusatzwerte() { 307 public List<LZusatzWert> getZusatzwerte() {
245 return this.zusatzwerte; 308 return this.zusatzwerte;
246 } 309 }
247 310
311 /**
312 * Reset errors and warnings.
313 */
248 @Override 314 @Override
249 public void reset() { 315 public void reset() {
250 this.errors = new HashMap<String, List<ReportData>>(); 316 this.errors = new HashMap<String, List<ReportData>>();
251 this.warnings = new HashMap<String, List<ReportData>>(); 317 this.warnings = new HashMap<String, List<ReportData>>();
252 this.probe = new LProbe(); 318 this.probe = new LProbe();
259 this.mKommentare = new ArrayList<LKommentarM>(); 325 this.mKommentare = new ArrayList<LKommentarM>();
260 this.pKommentare = new ArrayList<LKommentarP>(); 326 this.pKommentare = new ArrayList<LKommentarP>();
261 mapper.reset(); 327 mapper.reset();
262 } 328 }
263 329
330 /**
331 * Add the current {@link LMessung} entity to the List and create a new one.
332 */
264 public void newMessung() { 333 public void newMessung() {
265 if (this.messung != null) { 334 if (this.messung != null) {
266 this.messungen.add(this.messung); 335 this.messungen.add(this.messung);
267 } 336 }
268 LMessungId id = new LMessungId(); 337 LMessungId id = new LMessungId();
270 this.messung = new LMessung(); 339 this.messung = new LMessung();
271 this.messung.setProbeId(this.probe.getProbeId()); 340 this.messung.setProbeId(this.probe.getProbeId());
272 this.messung.setId(id); 341 this.messung.setId(id);
273 } 342 }
274 343
344 /**
345 * Add the {@link Ort} and {@link LOrt} entities to the lists and create
346 * a new {@link OrtCreator}.
347 */
275 public void newOrt() { 348 public void newOrt() {
276 if (this.ort != null) { 349 if (this.ort != null) {
277 Ort o = this.ort.toOrt(); 350 Ort o = this.ort.toOrt();
278 if (o != null) { 351 if (o != null) {
279 this.orte.add(o); 352 this.orte.add(o);
326 @Override 399 @Override
327 public void finishOrt() { 400 public void finishOrt() {
328 if (orte.isEmpty()) { 401 if (orte.isEmpty()) {
329 return; 402 return;
330 } 403 }
331
332 } 404 }
333 } 405 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)