Mercurial > lada > lada-server
diff src/main/java/de/intevation/lada/data/importer/LAFProducer.java @ 331:5d11428e6a09
Made the importer a little more robust and introduced a better warning/error reporting.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 27 Aug 2013 15:28:21 +0200 |
parents | 5844d7457dde |
children | cb47c33b119d |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/importer/LAFProducer.java Tue Aug 27 15:26:46 2013 +0200 +++ b/src/main/java/de/intevation/lada/data/importer/LAFProducer.java Tue Aug 27 15:28:21 2013 +0200 @@ -1,7 +1,10 @@ package de.intevation.lada.data.importer; import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import javax.inject.Inject; import javax.inject.Named; @@ -36,10 +39,15 @@ private List<EntryFormat> messungFormat; private List<EntryFormat> ortFormat; + private Map<String, List<ReportData>> warnings; + private Map<String, List<ReportData>> errors; + @Inject private AttributeMapper mapper; public LAFProducer() { + this.warnings = new HashMap<String, List<ReportData>>(); + this.errors = new HashMap<String, List<ReportData>>(); this.probe = new LProbe(); this.pKommentare = new ArrayList<LKommentarP>(); this.mKommentare = new ArrayList<LKommentarM>(); @@ -55,7 +63,8 @@ } @Override - public void addData(String key, Object values) { + public void addData(String key, Object values) + throws LAFParserException { String lKey = key.toLowerCase(); if(lKey.equals("probenkommentar")) { LKommentarP kommentar = new LKommentarP(); @@ -98,6 +107,10 @@ } else if (isValidProbe(lKey, values.toString())) { this.probe = mapper.addAttribute(lKey, values, this.probe); + if (this.probe == null) { + this.errors.put(values.toString(), mapper.getErrors()); + throw new LAFParserException(values.toString() + " exists"); + } } else if (isValidOrt(lKey, values.toString())) { this.ort = mapper.addAttribute(lKey, values, this.ort); @@ -169,6 +182,8 @@ @Override public void reset() { + this.errors.clear(); + this.warnings.clear(); this.probe = new LProbe(); this.messungen.clear(); this.messung = null; @@ -177,6 +192,7 @@ this.messwerte.clear(); this.mKommentare.clear(); this.pKommentare.clear(); + mapper.reset(); } public void newMessung() { @@ -197,4 +213,18 @@ this.ort = new LOrt(); this.ort.setProbeId(this.probe.getProbeId()); } + + /** + * @return the warnings + */ + public Map<String, List<ReportData>> getWarnings() { + return this.warnings; + } + + /** + * @return the errors + */ + public Map<String, List<ReportData>> getErrors() { + return this.errors; + } }