# HG changeset patch # User Raimund Renkert # Date 1477493565 -7200 # Node ID d9d57a1074781110895c0f79a166390cb7ea8011 # Parent 657f35a7467d0784a8aeeb5c53d068aabfb7424f Fixed error handling for importer. diff -r 657f35a7467d -r d9d57a107478 src/main/java/de/intevation/lada/importer/laf/LafErrorListener.java --- 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 getErrors() { return this.errors; } diff -r 657f35a7467d -r d9d57a107478 src/main/java/de/intevation/lada/importer/laf/LafImporter.java --- 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(); diff -r 657f35a7467d -r d9d57a107478 src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java --- 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 copyErr = new ArrayList(currentErrors); + errors.put(probe.getIdAlt(), copyErr); + } + if (currentWarnings.size() > 0) { + List copyWarn = new ArrayList(currentWarnings); + warnings.put(probe.getIdAlt(), copyWarn); + } return; } @@ -153,6 +161,14 @@ err.setKey("duplicate"); err.setValue(""); currentErrors.add(err); + if (currentErrors.size() > 0) { + List copyErr = new ArrayList(currentErrors); + errors.put(probe.getIdAlt(), copyErr); + } + if (currentWarnings.size() > 0) { + List copyWarn = new ArrayList(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 copyErr = new ArrayList(currentErrors); + errors.put(probe.getIdAlt(), copyErr); + } + if (currentWarnings.size() > 0) { + List copyWarn = new ArrayList(currentWarnings); + warnings.put(probe.getIdAlt(), copyWarn); + } return; } if (newProbe == null) { @@ -211,17 +235,12 @@ } if (currentErrors.size() > 0) { List copyErr = new ArrayList(currentErrors); - System.out.println("errs for probe: " + probe.getIdAlt()); errors.put(probe.getIdAlt(), copyErr); } if (currentWarnings.size() > 0) { List copyWarn = new ArrayList(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> getWarnings() { - System.out.println(warnings.size()); return warnings; }