@Override protected String featureValueOf(Issue actual) { return actual.getType().getMajor(); } }
@Override protected String featureValueOf(Issue actual) { return actual.getType().getMinor(); } }
@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())); }
MajorIssueConfig config = issueConfigs.get(oldIssue.getType().getMajor()); Issue newIssue; if (config == null) { newIssue = oldIssue; } else { String minorIssue = oldIssue.getType().getMinor(); Optional<MinorIssueConfig> optionalMinorConfig = config.getMinorIssueConfig(minorIssue); oldIssue.getExplanation(), minorConfig.getSeverity(), oldIssue.getType(), minorConfig.getUrl()); } else {
/** 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")); } }
@Test public void testApplyRowIssuesConfigurationMatch() { String col = "col"; String major = "major"; String minor = "minor"; Issue oldIssue = new Issue("explanation", 5, new Issue.Type(major, minor)); Row oldRow = Row.of(col, oldIssue); int newSeverity = 6; String newUrl = "example.com"; Issue newIssue = new Issue(oldIssue.getExplanation(), newSeverity, oldIssue.getType(), newUrl); Set<String> issueColumns = ImmutableSet.of(col); Map<String, MajorIssueConfig> issueConfigs = ImmutableMap.of( major, new MajorIssueConfig(major, ImmutableList.of(new MinorIssueConfig(minor, 6, newUrl)))); assertThat( _manager.applyRowIssuesConfiguration(oldRow, issueColumns, issueConfigs), equalTo(Row.of(col, newIssue))); }