Search in sources :

Example 1 with ReportAnswerElement

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;
}
Also used : Path(java.nio.file.Path) CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) ReportAnswerElement(org.batfish.datamodel.answers.ReportAnswerElement) IOException(java.io.IOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BatfishException (org.batfish.common.BatfishException)1 CleanBatfishException (org.batfish.common.CleanBatfishException)1 BatfishObjectMapper (org.batfish.common.util.BatfishObjectMapper)1 ReportAnswerElement (org.batfish.datamodel.answers.ReportAnswerElement)1