Mercurial > lada > lada-server
diff src/main/java/de/intevation/lada/data/importer/AttributeMapper.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/AttributeMapper.java Tue Aug 27 15:26:46 2013 +0200 +++ b/src/main/java/de/intevation/lada/data/importer/AttributeMapper.java Tue Aug 27 15:28:21 2013 +0200 @@ -3,8 +3,12 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -21,6 +25,7 @@ import de.intevation.lada.model.LMesswert; import de.intevation.lada.model.LOrt; import de.intevation.lada.model.LProbe; +import de.intevation.lada.model.LProbeInfo; import de.intevation.lada.model.SMessEinheit; import de.intevation.lada.model.SMessgroesse; import de.intevation.lada.rest.Response; @@ -32,9 +37,20 @@ private EntityManager em; @Inject + @Named("lproberepository") + private Repository probeRepo; + + @Inject @Named("readonlyrepository") private Repository sRepository; + private List<ReportData> warnings; + private List<ReportData> errors; + + public AttributeMapper() { + this.warnings = new ArrayList<ReportData>(); + this.errors = new ArrayList<ReportData>(); + } public LProbe addAttribute(String key, Object value, LProbe probe) { DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm"); if ("datenbasis_s".equals(key)) { @@ -42,6 +58,10 @@ probe.setDatenbasisId(v); } else if ("probe_id".equals(key)) { + if (probeRepo.findById(LProbeInfo.class, value.toString()) != null) { + errors.add(new ReportData("probe_id", value.toString(), 662)); + return null; + } probe.setProbeId(value.toString()); } else if ("hauptprobennummer".equals(key)) { @@ -281,4 +301,23 @@ } return ort; } + + /** + * @return the warnings + */ + public List<ReportData> getWarnings() { + return warnings; + } + + /** + * @return the errors + */ + public List<ReportData> getErrors() { + return errors; + } + + public void reset() { + errors.clear(); + warnings.clear(); + } }