@Nonnull @VisibleForTesting // triplet -> filename -> lines static Map<WarningTriplet, Map<String, SortedSet<Integer>>> aggregateDuplicateWarnings( Map<String, Warnings> fileWarnings) { Map<WarningTriplet, Map<String, SortedSet<Integer>>> map = new HashMap<>(); fileWarnings.forEach( (filename, warnings) -> { for (ParseWarning w : warnings.getParseWarnings()) { WarningTriplet triplet = new WarningTriplet(w); map.computeIfAbsent(triplet, k -> new HashMap<>()) .computeIfAbsent(filename, k -> new TreeSet<>()) .add(w.getLine()); } }); return map; }
@Override public void visitErrorNode(ErrorNode errorNode) { Token token = errorNode.getSymbol(); String lineText = errorNode.getText().replace("\n", "").replace("\r", "").trim(); int line = getLine(token); _configuration.setUnrecognized(true); if (token instanceof UnrecognizedLineToken) { UnrecognizedLineToken unrecToken = (UnrecognizedLineToken) token; _w.getParseWarnings() .add( new ParseWarning( line, lineText, unrecToken.getParserContext(), "This syntax is unrecognized")); } else { String msg = String.format("Unrecognized Line: %d: %s", line, lineText); _w.redFlag(msg + " SUBSEQUENT LINES MAY NOT BE PROCESSED CORRECTLY"); } } }
@Override public void visitErrorNode(ErrorNode errorNode) { Token token = errorNode.getSymbol(); String lineText = errorNode.getText().replace("\n", "").replace("\r", "").trim(); int line = getLine(token); _configuration.setUnrecognized(true); if (token instanceof UnrecognizedLineToken) { UnrecognizedLineToken unrecToken = (UnrecognizedLineToken) token; _w.getParseWarnings() .add( new ParseWarning( line, lineText, unrecToken.getParserContext(), "This syntax is unrecognized")); } else { String msg = String.format("Unrecognized Line: %d: %s", line, lineText); _w.redFlag(msg + " SUBSEQUENT LINES MAY NOT BE PROCESSED CORRECTLY"); } } }
@Override public void visitErrorNode(ErrorNode errorNode) { Token token = errorNode.getSymbol(); int line = token.getLine(); String lineText = errorNode.getText().replace("\n", "").replace("\r", "").trim(); _configuration.setUnrecognized(true); if (token instanceof UnrecognizedLineToken) { UnrecognizedLineToken unrecToken = (UnrecognizedLineToken) token; _w.getParseWarnings() .add( new ParseWarning( line, lineText, unrecToken.getParserContext(), "This syntax is unrecognized")); } else { String msg = String.format("Unrecognized Line: %d: %s", line, lineText); _w.redFlag(msg + " SUBSEQUENT LINES MAY NOT BE PROCESSED CORRECTLY"); } } }
private void mergeInitStepAnswer( InitInfoAnswerElement initInfoAnswerElement, InitStepAnswerElement initStepAnswerElement, boolean summary, boolean verboseError) { if (!summary) { if (verboseError) { SortedMap<String, List<BatfishStackTrace>> errors = initInfoAnswerElement.getErrors(); initStepAnswerElement .getErrors() .forEach( (hostname, initStepErrors) -> errors.computeIfAbsent(hostname, k -> new ArrayList<>()).add(initStepErrors)); } SortedMap<String, Warnings> warnings = initInfoAnswerElement.getWarnings(); initStepAnswerElement .getWarnings() .forEach( (hostname, initStepWarnings) -> { Warnings combined = warnings.computeIfAbsent(hostname, h -> buildWarnings(_settings)); combined.getParseWarnings().addAll(initStepWarnings.getParseWarnings()); combined.getPedanticWarnings().addAll(initStepWarnings.getPedanticWarnings()); combined.getRedFlagWarnings().addAll(initStepWarnings.getRedFlagWarnings()); combined .getUnimplementedWarnings() .addAll(initStepWarnings.getUnimplementedWarnings()); }); } }
@Test public void testAggregateDuplicateWarnings() { Warnings f1Warnings = new Warnings(); f1Warnings .getParseWarnings() .addAll( ImmutableList.of( new ParseWarning(3, "dup", "[configuration]", null), new ParseWarning(4, "dup", "[configuration]", null), new ParseWarning(5, "unique", "[configuration]", null))); Warnings f2Warnings = new Warnings(); f2Warnings .getParseWarnings() .addAll(ImmutableList.of(new ParseWarning(23, "dup", "[configuration]", null))); Map<String, Warnings> fileWarnings = ImmutableMap.of("f1", f1Warnings, "f2", f2Warnings); assertThat( aggregateDuplicateWarnings(fileWarnings), equalTo( ImmutableMap.of( new WarningTriplet("dup", "[configuration]", null), ImmutableMap.of("f1", ImmutableSortedSet.of(3, 4), "f2", ImmutableSortedSet.of(23)), new WarningTriplet("unique", "[configuration]", null), ImmutableMap.of("f1", ImmutableSortedSet.of(5))))); }
@Override public ParseVendorConfigurationAnswerElement loadParseVendorConfigurationAnswerElement() { ParseVendorConfigurationAnswerElement pvcae = new ParseVendorConfigurationAnswerElement(); Warnings warnings = new Warnings(); warnings.getParseWarnings().add(new ParseWarning(3, "text", "ctx", "comment")); pvcae.setWarnings(ImmutableSortedMap.of("nowarnings", new Warnings(), "f", warnings)); return pvcae; } }
@Override public TableAnswerElement answer() { ParseWarningQuestion question = (ParseWarningQuestion) _question; TableMetadata metadata = createMetadata(question); Map<String, ColumnMetadata> columnMetadataMap = metadata.toColumnMap(); ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(); Map<String, Warnings> fileWarnings = pvcae.getWarnings(); Rows rows = new Rows(); if (question.getAggregateDuplicates()) { aggregateDuplicateWarnings(fileWarnings) .forEach( (triplet, filelines) -> rows.add(getAggregateRow(triplet, filelines, columnMetadataMap))); } else { fileWarnings.forEach( (filename, warnings) -> { for (ParseWarning w : warnings.getParseWarnings()) { rows.add(getRow(filename, w, columnMetadataMap)); } }); } TableAnswerElement answerElement = new TableAnswerElement(createMetadata(question)); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; }