Skip to content

Commit

Permalink
Fix reports post processing (#113)
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
  • Loading branch information
ayolab authored Sep 27, 2024
1 parent e065d8b commit 1eeae3f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* <br/>
* The start tree structure returned by short-circuit is:
* <pre>
* 00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis or ShortCircuitAnalysis
* 00000000-0000-0000-0000-000000000000
* \-- ShortCircuitAnalysis -> "ShortCircuitAnalysis (${providerToUse})"
* +-- [...]
* \-- [...]
Expand All @@ -43,9 +43,9 @@ public abstract class AbstractReportMapper {
*/
public ReportNode processReporter(@NonNull final ReportNode reportNode, ShortCircuitRunContext runContext) {
if (reportNode.getMessageKey() != null && reportNode.getMessageKey()
.matches("^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}@)?.*ShortCircuitAnalysis$")) {
.matches("^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})")) {
log.debug("ShortCircuitAnalysis root node found, will modify it!");
return forUuidAtShortCircuitAnalysis(reportNode, runContext);
return forRootReport(reportNode, runContext);
} else {
log.trace("Unrecognized ReportNode: {}", reportNode);
return reportNode;
Expand All @@ -66,11 +66,11 @@ public static ReportNode insertReportNode(ReportNode parent, ReportNode child) {
}

/**
* Modify node with key {@code ********-****-****-****-************@ShortCircuitAnalysis} or {@code ShortCircuitAnalysis}
* Modify node with key {@code ********-****-****-****-************}
*
* @implNote we assume there will always be at least one modification
*/
protected ReportNode forUuidAtShortCircuitAnalysis(@NonNull final ReportNode reportNode, ShortCircuitRunContext runContext) {
protected ReportNode forRootReport(@NonNull final ReportNode reportNode, ShortCircuitRunContext runContext) {
ReportNodeBuilder builder = ReportNode.newRootReportNode()
.withMessageTemplate(reportNode.getMessageKey(), reportNode.getMessageTemplate());
reportNode.getValues().forEach((key, value) -> builder.withTypedValue(key, value.getValue().toString(), value.getType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* <br/>
* The tree structure returned by short-circuit is:
* <pre>
* 00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis or ShortCircuitAnalysis
* 00000000-0000-0000-0000-000000000000
* \-- ShortCircuitAnalysis -> "ShortCircuitAnalysis (${providerToUse})"
* +-- generatorConversion -> "Conversion of generators"
* +-- batteryConversion -> "Conversion of the batteries"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

@Slf4j
class ReportMapperAbstractModelTest extends AbstractReportMapperTest {
static final String ROOT_REPORTER_ID = "00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis";
static final String ROOT_REPORTER_NO_ID = "ShortCircuitAnalysis";
static final String ROOT_REPORTER_ID = "00000000-0000-0000-0000-000000000000";
static final String SHORTCIRCUIT_TYPE_REPORT = "ShortCircuitAnalysis";

private final AbstractReportMapper reportMapper = new AbstractReportMapper() {
Expand All @@ -40,7 +39,7 @@ void testIgnoreOthersReportModels() {
}

@ParameterizedTest
@ValueSource(strings = {ROOT_REPORTER_ID, ROOT_REPORTER_NO_ID})
@ValueSource(strings = {ROOT_REPORTER_ID})
void testModifyRootNode(final String rootId) {
final ReportNode reportNode = ReportNode.newRootReportNode().withMessageTemplate(rootId, rootId).build();
final ReportNode subReportNode = reportNode.newReportNode()
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/reporter_shortcircuit_modified.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.1",
"dictionaries": {
"default": {
"00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis": "00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis",
"00000000-0000-0000-0000-000000000000": "00000000-0000-0000-0000-000000000000",
"ShortCircuitAnalysis": "ShortCircuitAnalysis (${providerToUse})",
"TestReporter": "Test Reporter",
"testReportLine": "Test log line",
Expand All @@ -27,7 +27,7 @@
}
},
"reportRoot": {
"messageKey": "00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis",
"messageKey": "00000000-0000-0000-0000-000000000000",
"children": [
{
"messageKey": "TestReporter"
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/reporter_shortcircuit_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.1",
"dictionaries": {
"default": {
"00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis": "00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis",
"00000000-0000-0000-0000-000000000000": "00000000-0000-0000-0000-000000000000",
"ShortCircuitAnalysis": "ShortCircuitAnalysis (${providerToUse})",
"TestReporter": "Test Reporter",
"testReportLine": "Test log line",
Expand All @@ -24,7 +24,7 @@
}
},
"reportRoot": {
"messageKey": "00000000-0000-0000-0000-000000000000@ShortCircuitAnalysis",
"messageKey": "00000000-0000-0000-0000-000000000000",
"children": [
{
"messageKey": "TestReporter"
Expand Down

0 comments on commit 1eeae3f

Please sign in to comment.