Skip to content

Commit

Permalink
Add indentation on some reports
Browse files Browse the repository at this point in the history
Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
FranckLecuyer committed Sep 11, 2023
1 parent 9c97261 commit df13cca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ public void check(Network network) throws NetworkModificationException {
}

private void report(Reporter reporter, String key, String defaultMessage, Map<String, Object> values, TypedValue severity) {
report(reporter, key, defaultMessage, values, severity, 0);
}

private void report(Reporter reporter, String key, String defaultMessage, Map<String, Object> values, TypedValue severity, int indentationLevel) {
StringBuilder indentation = new StringBuilder();
for (int i = 0; i < indentationLevel; i++) {
indentation.append(" ");
}
ReportBuilder builder = Report.builder()
.withKey(key)
.withDefaultMessage(defaultMessage)
.withDefaultMessage(indentation.toString() + defaultMessage)
.withSeverity(severity);
for (Map.Entry<String, Object> valueEntry : values.entrySet()) {
builder.withValue(valueEntry.getKey(), valueEntry.getValue().toString());
Expand Down Expand Up @@ -201,50 +209,50 @@ private void applyShuntCompensatorModification(Network network, Reporter subRepo
Reporter reporter = subReporter.createSubReporter(SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId(), SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId());
report(reporter, "shuntCompensatorModification", "Shunt compensator with id=${id} modified :", Map.of("id", m.getShuntCompensatorId()), TypedValue.INFO_SEVERITY);

double currentSectionCount = shuntCompensator.getSectionCount();
int currentSectionCount = shuntCompensator.getSectionCount();

Terminal shuntCompensatorTerminal = shuntCompensator.getTerminal();
if (shuntCompensatorTerminal.isConnected()) { // shunt compensator is connected
if (m.getSectionCount() == null) {
report(reporter, "shuntCompensatorSectionCountUndefined", "Section count value is undefined", Map.of(), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorSectionCountUndefined", "Section count value is undefined", Map.of(), TypedValue.WARN_SEVERITY, 1);
} else {
if (currentSectionCount == 0) {
if (m.getSectionCount() == 0) {
shuntCompensatorTerminal.disconnect();
report(reporter, "shuntCompensatorDisconnected", "Shunt compensator disconnected", Map.of(), TypedValue.INFO_SEVERITY);
report(reporter, "shuntCompensatorDisconnected", "Shunt compensator disconnected", Map.of(), TypedValue.INFO_SEVERITY, 1);
} else if (m.getSectionCount() == 1) {
shuntCompensator.setSectionCount(1);
reporter.report(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, shuntCompensator.getSectionCount(), SECTION_COUNT, 1));
} else {
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY, 1);
}
} else if (currentSectionCount == 1) {
if (m.getSectionCount() == 0) {
shuntCompensatorTerminal.disconnect();
report(reporter, "shuntCompensatorDisconnected", "Shunt compensator disconnected", Map.of(), TypedValue.INFO_SEVERITY);
report(reporter, "shuntCompensatorDisconnected", "Shunt compensator disconnected", Map.of(), TypedValue.INFO_SEVERITY, 1);
shuntCompensator.setSectionCount(0);
reporter.report(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, shuntCompensator.getSectionCount(), SECTION_COUNT, 1));
} else if (m.getSectionCount() > 1) {
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY, 1);
}
} else {
report(reporter, "shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of("value", currentSectionCount), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of("value", currentSectionCount), TypedValue.WARN_SEVERITY, 1);
}
}
} else { // shunt compensator is disconnected
if (m.getConnect() == null) {
report(reporter, "shuntCompensatorConnectUndefined", "Connect value is undefined", Map.of(), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorConnectUndefined", "Connect value is undefined", Map.of(), TypedValue.WARN_SEVERITY, 1);
} else {
if (currentSectionCount == 0) {
if (m.getSectionCount() == 1) {
if (Boolean.TRUE.equals(m.getConnect())) {
shuntCompensatorTerminal.connect();
report(reporter, "shuntCompensatorReconnected", "Shunt compensator reconnected", Map.of(), TypedValue.INFO_SEVERITY);
report(reporter, "shuntCompensatorReconnected", "Shunt compensator reconnected", Map.of(), TypedValue.INFO_SEVERITY, 1);
}
shuntCompensator.setSectionCount(1);
reporter.report(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, shuntCompensator.getSectionCount(), SECTION_COUNT, 1));
} else if (m.getSectionCount() > 1) {
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY, 1);
}
} else if (currentSectionCount == 1) {
if (m.getSectionCount() == 0) {
Expand All @@ -253,13 +261,13 @@ private void applyShuntCompensatorModification(Network network, Reporter subRepo
} else if (m.getSectionCount() == 1) {
if (Boolean.TRUE.equals(m.getConnect())) {
shuntCompensatorTerminal.connect();
report(reporter, "shuntCompensatorReconnected", "Shunt compensator reconnected", Map.of(), TypedValue.INFO_SEVERITY);
report(reporter, "shuntCompensatorReconnected", "Shunt compensator reconnected", Map.of(), TypedValue.INFO_SEVERITY, 1);
}
} else if (m.getSectionCount() > 1) {
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorSectionCountValueIgnored", "Section count value ${value} cannot be applied : it should be 0 or 1", Map.of("value", m.getSectionCount()), TypedValue.WARN_SEVERITY, 1);
}
} else {
report(reporter, "shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of("value", currentSectionCount), TypedValue.WARN_SEVERITY);
report(reporter, "shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of("value", currentSectionCount), TypedValue.WARN_SEVERITY, 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void assertLogMessage(String expectedMessage, String reportKey, Re
assertNotNull(reporterCaptor.getValue());
Optional<String> message = getMessageFromReporter(reportKey, reporterCaptor.getValue());
assertTrue(message.isPresent());
assertEquals(expectedMessage, message.get());
assertEquals(expectedMessage, message.get().trim());
}

private static Optional<String> getMessageFromReporter(String reportKey, ReporterModel reporterModel) {
Expand Down

0 comments on commit df13cca

Please sign in to comment.