use of org.batfish.datamodel.answers.ReportAnswerElement in project batfish by batfish.
the class Batfish method report.
private AnswerElement report() {
ReportAnswerElement answerElement = new ReportAnswerElement();
checkQuestionsDirExists();
Path questionsDir = _settings.getActiveTestrigSettings().getBasePath().resolve(BfConsts.RELPATH_QUESTIONS_DIR);
ConcurrentMap<Path, String> answers = new ConcurrentHashMap<>();
try (DirectoryStream<Path> questions = Files.newDirectoryStream(questionsDir)) {
questions.forEach(questionDirPath -> answers.put(questionDirPath.resolve(BfConsts.RELPATH_ANSWER_JSON), !questionDirPath.getFileName().startsWith(".") && Files.exists(questionDirPath.resolve(BfConsts.RELPATH_ANSWER_JSON)) ? CommonUtil.readFile(questionDirPath.resolve(BfConsts.RELPATH_ANSWER_JSON)) : ""));
} catch (IOException e1) {
throw new BatfishException("Could not create directory stream for '" + questionsDir + "'", e1);
}
ObjectMapper mapper = BatfishObjectMapper.mapper();
for (Entry<Path, String> entry : answers.entrySet()) {
Path answerPath = entry.getKey();
String answerText = entry.getValue();
if (!answerText.equals("")) {
try {
answerElement.getJsonAnswers().add(mapper.readTree(answerText));
} catch (IOException e) {
throw new BatfishException("Error mapping JSON content of '" + answerPath + "' to object", e);
}
}
}
return answerElement;
}
Aggregations