answerElement.getConvertStatus().put(_name, ConvertStatus.PASSED); answerElement.getDefinedStructures().putAll(_answerElement.getDefinedStructures()); answerElement.getUndefinedReferences().putAll(_answerElement.getUndefinedReferences()); answerElement.getReferencedStructures().putAll(_answerElement.getReferencedStructures());
@Override public TableAnswerElement answer() { UnusedStructuresQuestion question = (UnusedStructuresQuestion) _question; // Find all the filenames that produced the queried nodes. This might have false positives if // a file produced multiple nodes, but that was already mis-handled before. Need to rewrite // this question as a TableAnswerElement. Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream() .filter(e -> includeNodes.contains(e.getKey())) .map(Entry::getValue) .collect(Collectors.toSet()); Multiset<Row> rows = LinkedHashMultiset.create(); SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> definedStructures = _batfish.loadConvertConfigurationAnswerElementOrReparse().getDefinedStructures(); definedStructures.entrySet().stream() .filter(e -> includeFiles.contains(e.getKey())) .forEach(e -> rows.addAll(processEntryToRows(e))); TableAnswerElement table = new TableAnswerElement(createMetadata(question)); table.postProcessAnswer(_question, rows); return table; }
@Override protected boolean matchesSafely( ConvertConfigurationAnswerElement item, Description mismatchDescription) { SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> byFile = item.getDefinedStructures(); if (!byFile.containsKey(_filename)) { mismatchDescription.appendText( String.format("File '%s' has no defined structures", _filename)); return false; } SortedMap<String, SortedMap<String, DefinedStructureInfo>> byType = byFile.get(_filename); if (!byType.containsKey(_type)) { mismatchDescription.appendText( String.format("File '%s' has no defined structure of type '%s'", _filename, _type)); return false; } SortedMap<String, DefinedStructureInfo> byStructureName = byType.get(_type); if (!byStructureName.containsKey(_structureName)) { mismatchDescription.appendText( String.format( "File '%s' has no defined structure of type '%s' named '%s'", _filename, _type, _structureName)); return false; } return true; } }
_batfish.loadConvertConfigurationAnswerElementOrReparse(); ccae.getDefinedStructures() .forEach( (filename, byStructType) -> {
ConvertConfigurationAnswerElement item, Description mismatchDescription) { SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> byFile = item.getDefinedStructures(); if (!byFile.containsKey(_filename)) { mismatchDescription.appendText(
ConvertConfigurationAnswerElement item, Description mismatchDescription) { SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> byFile = item.getDefinedStructures(); if (!byFile.containsKey(_filename)) { mismatchDescription.appendText(
public final void setAnswerElement(ConvertConfigurationAnswerElement answerElement) { _answerElement = answerElement; _answerElement.getDefinedStructures().put(getFilename(), _structureDefinitions); _structureReferences.forEach( (structType, byType) -> byType.forEach( (name, byUsage) -> byUsage.forEach( (usage, lines) -> lines.forEach( line -> addStructureReference( _answerElement.getReferencedStructures(), structType, name, usage, line))))); }