@VisibleForTesting static @Nonnull Map<String, MajorIssueConfig> computeMajorIssueConfigs(TableAnswerElement table) { Map<String, ImmutableList.Builder<MinorIssueConfig>> majorIssueConfigs = new HashMap<>(); // For every issue column of every row, extract the issue and use it to update the map table.getMetadata().getColumnMetadata().stream() .filter(c -> c.getSchema().equals(Schema.ISSUE)) .map(ColumnMetadata::getName) .flatMap( column -> table.getRowsList().stream() .filter(row -> row.hasNonNull(column)) .map(row -> row.getIssue(column))) .forEach( issue -> majorIssueConfigs .computeIfAbsent(issue.getType().getMajor(), m -> ImmutableList.builder()) .add( new MinorIssueConfig( issue.getType().getMinor(), issue.getSeverity(), issue.getUrl()))); return CommonUtil.toImmutableMap( majorIssueConfigs, Entry::getKey, // major issue type e -> new MajorIssueConfig(e.getKey(), e.getValue().build())); }
/** Test if Issues are (De)serialiazed properly */ @Test public void testSerDeser() throws IOException { String issueStr = "{\"explanation\" : \"myex\", \"type\" : { \"major\" : \"maj\", \"minor\": \"min\" }, \"severity\" : 75, \"url\": \"www.cnn.com\"}"; Issue issue = BatfishObjectMapper.mapper().readValue(issueStr, Issue.class); // check if the issue is properly deserialized assertThat(issue.getExplanation(), equalTo("myex")); assertThat(issue.getType().getMajor(), equalTo("maj")); assertThat(issue.getType().getMinor(), equalTo("min")); assertThat(issue.getSeverity(), equalTo(75)); assertThat(issue.getUrl(), equalTo("www.cnn.com")); String issueSer = BatfishObjectMapper.mapper().writeValueAsString(issue); ObjectNode issueObj = (ObjectNode) BatfishObjectMapper.mapper().readTree(issueSer); // check serialization assertThat(issueObj.get("explanation").asText(), equalTo("myex")); assertThat(issueObj.get("severity").asInt(), equalTo(75)); assertThat(issueObj.get("url").asText(), equalTo("www.cnn.com")); assertThat(issueObj.get("type").get("major").asText(), equalTo("maj")); assertThat(issueObj.get("type").get("minor").asText(), equalTo("min")); } }
newIssue = oldIssue; } else { String minorIssue = oldIssue.getType().getMinor(); Optional<MinorIssueConfig> optionalMinorConfig = config.getMinorIssueConfig(minorIssue);
@Override protected String featureValueOf(Issue actual) { return actual.getType().getMinor(); } }