Commit 9b6fa1e8 authored by Andy Wilkinson's avatar Andy Wilkinson

Separate conditions that did and did not match in auto-config endpoint

Closes gh-7122
parent c06dc33b
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.endpoint; package org.springframework.boot.actuate.endpoint;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -66,27 +68,36 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -66,27 +68,36 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
@JsonInclude(Include.NON_EMPTY) @JsonInclude(Include.NON_EMPTY)
public static class Report { public static class Report {
private MultiValueMap<String, MessageAndCondition> positiveMatches; private final MultiValueMap<String, MessageAndCondition> positiveMatches;
private MultiValueMap<String, MessageAndCondition> negativeMatches; private final Map<String, MessageAndConditions> negativeMatches;
private List<String> exclusions; private final List<String> exclusions;
private Report parent; private final Report parent;
public Report(ConditionEvaluationReport report) { public Report(ConditionEvaluationReport report) {
this.positiveMatches = new LinkedMultiValueMap<String, MessageAndCondition>(); this.positiveMatches = new LinkedMultiValueMap<String, MessageAndCondition>();
this.negativeMatches = new LinkedMultiValueMap<String, MessageAndCondition>(); this.negativeMatches = new LinkedHashMap<String, MessageAndConditions>();
this.exclusions = report.getExclusions(); this.exclusions = report.getExclusions();
for (Map.Entry<String, ConditionAndOutcomes> entry : report for (Map.Entry<String, ConditionAndOutcomes> entry : report
.getConditionAndOutcomesBySource().entrySet()) { .getConditionAndOutcomesBySource().entrySet()) {
add(entry.getValue().isFullMatch() ? this.positiveMatches if (entry.getValue().isFullMatch()) {
: this.negativeMatches, entry.getKey(), entry.getValue()); add(this.positiveMatches, entry.getKey(), entry.getValue());
}
} else {
if (report.getParent() != null) { add(this.negativeMatches, entry.getKey(), entry.getValue());
this.parent = new Report(report.getParent()); }
} }
this.parent = report.getParent() != null ? new Report(report.getParent())
: null;
}
private void add(Map<String, MessageAndConditions> map, String source,
ConditionAndOutcomes conditionAndOutcomes) {
String name = ClassUtils.getShortName(source);
map.put(name, new MessageAndConditions(conditionAndOutcomes));
} }
private void add(MultiValueMap<String, MessageAndCondition> map, String source, private void add(MultiValueMap<String, MessageAndCondition> map, String source,
...@@ -101,7 +112,7 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -101,7 +112,7 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
return this.positiveMatches; return this.positiveMatches;
} }
public Map<String, List<MessageAndCondition>> getNegativeMatches() { public Map<String, MessageAndConditions> getNegativeMatches() {
return this.negativeMatches; return this.negativeMatches;
} }
...@@ -115,6 +126,34 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -115,6 +126,34 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
} }
/**
* Adapts {@link ConditionAndOutcomes} to a JSON friendly structure.
*/
@JsonPropertyOrder({ "notMatched", "matched" })
public static class MessageAndConditions {
private final List<MessageAndCondition> notMatched = new ArrayList<MessageAndCondition>();
private final List<MessageAndCondition> matched = new ArrayList<MessageAndCondition>();
public MessageAndConditions(ConditionAndOutcomes conditionAndOutcomes) {
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
List<MessageAndCondition> target = conditionAndOutcome.getOutcome()
.isMatch() ? this.matched : this.notMatched;
target.add(new MessageAndCondition(conditionAndOutcome));
}
}
public List<MessageAndCondition> getNotMatched() {
return this.notMatched;
}
public List<MessageAndCondition> getMatched() {
return this.matched;
}
}
/** /**
* Adapts {@link ConditionAndOutcome} to a JSON friendly structure. * Adapts {@link ConditionAndOutcome} to a JSON friendly structure.
*/ */
...@@ -146,4 +185,5 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> { ...@@ -146,4 +185,5 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment