Mercurial > lada > lada-server
changeset 1105:d9d57a107478
Fixed error handling for importer.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 26 Oct 2016 16:52:45 +0200 |
parents | 657f35a7467d |
children | 7ea01e09dff4 de7184e1370d |
files | src/main/java/de/intevation/lada/importer/laf/LafErrorListener.java src/main/java/de/intevation/lada/importer/laf/LafImporter.java src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java |
diffstat | 3 files changed, 44 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/importer/laf/LafErrorListener.java Mon Oct 24 11:56:54 2016 +0200 +++ b/src/main/java/de/intevation/lada/importer/laf/LafErrorListener.java Wed Oct 26 16:52:45 2016 +0200 @@ -20,18 +20,26 @@ int line, int charPositionInLine, String msg, RecognitionException e) { - String sourceName = "Parser"; - if (e != null && e.getCtx() != null) { - sourceName = e.getCtx().getText(); - } + String sourceName = "Parser"; + if (e != null && e.getCtx() != null) { + sourceName = e.getCtx().getText(); + } + String token = "Token"; + if (e != null && e.getOffendingToken() != null) { + e.getOffendingToken().getText(); + } ReportItem err = new ReportItem(); err.setKey(sourceName); - err.setValue(line + ":" + charPositionInLine + " - " + e.getOffendingToken().getText()); + err.setValue(line + ":" + charPositionInLine + " - " + token); err.setCode(670); this.errors.add(err); System.err.println(err.getKey() + " - " +err.getValue() + " - " + err.getCode()); } + public void reset() { + this.errors.clear(); + } + public List<ReportItem> getErrors() { return this.errors; }
--- a/src/main/java/de/intevation/lada/importer/laf/LafImporter.java Mon Oct 24 11:56:54 2016 +0200 +++ b/src/main/java/de/intevation/lada/importer/laf/LafImporter.java Wed Oct 26 16:52:45 2016 +0200 @@ -47,6 +47,7 @@ CommonTokenStream cts = new CommonTokenStream(lexer); LafParser parser = new LafParser(cts); LafErrorListener errorListener = LafErrorListener.INSTANCE; + errorListener.reset(); parser.addErrorListener(errorListener); ParseTree tree = parser.probendatei(); LafObjectListener listener = new LafObjectListener();
--- a/src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java Mon Oct 24 11:56:54 2016 +0200 +++ b/src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java Wed Oct 26 16:52:45 2016 +0200 @@ -122,9 +122,17 @@ if (!isAuthorized) { ReportItem err = new ReportItem(); err.setCode(699); - err.setKey("auth"); - err.setValue("not authorized"); + err.setKey(userInfo.getName()); + err.setValue(probe.getMstId()); currentErrors.add(err); + if (currentErrors.size() > 0) { + List<ReportItem> copyErr = new ArrayList<ReportItem>(currentErrors); + errors.put(probe.getIdAlt(), copyErr); + } + if (currentWarnings.size() > 0) { + List<ReportItem> copyWarn = new ArrayList<ReportItem>(currentWarnings); + warnings.put(probe.getIdAlt(), copyWarn); + } return; } @@ -153,6 +161,14 @@ err.setKey("duplicate"); err.setValue(""); currentErrors.add(err); + if (currentErrors.size() > 0) { + List<ReportItem> copyErr = new ArrayList<ReportItem>(currentErrors); + errors.put(probe.getIdAlt(), copyErr); + } + if (currentWarnings.size() > 0) { + List<ReportItem> copyWarn = new ArrayList<ReportItem>(currentWarnings); + warnings.put(probe.getIdAlt(), copyWarn); + } return; } // It is a brand new probe! @@ -177,6 +193,14 @@ err.setKey("not known"); err.setValue("No valid Probe Object"); currentErrors.add(err); + if (currentErrors.size() > 0) { + List<ReportItem> copyErr = new ArrayList<ReportItem>(currentErrors); + errors.put(probe.getIdAlt(), copyErr); + } + if (currentWarnings.size() > 0) { + List<ReportItem> copyWarn = new ArrayList<ReportItem>(currentWarnings); + warnings.put(probe.getIdAlt(), copyWarn); + } return; } if (newProbe == null) { @@ -211,17 +235,12 @@ } if (currentErrors.size() > 0) { List<ReportItem> copyErr = new ArrayList<ReportItem>(currentErrors); - System.out.println("errs for probe: " + probe.getIdAlt()); errors.put(probe.getIdAlt(), copyErr); } if (currentWarnings.size() > 0) { List<ReportItem> copyWarn = new ArrayList<ReportItem>(currentWarnings); warnings.put(probe.getIdAlt(), copyWarn); - System.out.println("warn: " + warnings.size()); } - currentErrors.clear(); - currentWarnings.clear(); - logger.debug("probe written to database."); } private void create(LafRawData.Messung object, int probeId, String mstId) { @@ -237,7 +256,7 @@ if (!authorizer.isAuthorizedOnNew(userInfo, messung, Messung.class)) { ReportItem warn = new ReportItem(); warn.setCode(699); - warn.setKey("auth"); + warn.setKey(userInfo.getName()); warn.setValue("Messung: " + messung.getNebenprobenNr()); currentErrors.add(warn); return; @@ -342,8 +361,8 @@ if (!userInfo.getMessstellen().contains(kommentar.getMstId())) { ReportItem warn = new ReportItem(); warn.setCode(699); - warn.setKey("auth"); - warn.setValue(kommentar.getMstId()); + warn.setKey(userInfo.getName()); + warn.setValue("Kommentar: " + kommentar.getMstId()); currentWarnings.add(warn); return null; } @@ -870,10 +889,9 @@ } /** - * @return the warnings + * @return the errors */ public Map<String, List<ReportItem>> getWarnings() { - System.out.println(warnings.size()); return warnings; }