Skip to content

Commit

Permalink
refactor hvdc logs for creation and modification (#498)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt authored Jul 19, 2024
1 parent 7fc7663 commit 0377cd6
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void apply(Network network, ReportNode subReportNode) {
}
// properties
Battery battery = network.getBattery(modificationInfos.getEquipmentId());
PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties(), "BatteryProperties");
}

private void createBatteryInNodeBreaker(VoltageLevel voltageLevel, BatteryCreationInfos batteryCreationInfos, Network network, ReportNode subReportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void modifyBattery(Battery battery, BatteryModificationInfos modificatio
modifyBatteryLimitsAttributes(modificationInfos, battery, subReportNode);
modifyBatterySetpointsAttributes(modificationInfos, battery, subReportNode);
ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, battery);
PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(battery, subReportNode, modificationInfos.getProperties(), "BatteryProperties");
}

private void modifyBatterySetpointsAttributes(BatteryModificationInfos modificationInfos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void apply(Network network, ReportNode subReportNode) {
}
// apply the properties
Generator generator = network.getGenerator(modificationInfos.getEquipmentId());
PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties(), "GeneratorProperties");
}

private void createGeneratorInNodeBreaker(VoltageLevel voltageLevel, GeneratorCreationInfos generatorCreationInfos, Network network, ReportNode subReportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void modifyGenerator(Generator generator, GeneratorModificationInfos mod
modifyGeneratorStartUpAttributes(modificationInfos, generator, subReportNode);

ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, generator);
PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(generator, subReportNode, modificationInfos.getProperties(), "GeneratorProperties");
}

private void modifyGeneratorShortCircuitAttributes(GeneratorModificationInfos modificationInfos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void apply(Network network, ReportNode subReportNode) {
ModificationUtils.getInstance().disconnectBranch(modificationInfos, network.getLine(modificationInfos.getEquipmentId()), subReportNode);
// properties
Line line = network.getLine(modificationInfos.getEquipmentId());
PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties(), "LineProperties");
}

private void addLine(Network network, VoltageLevel voltageLevel1, VoltageLevel voltageLevel2, LineCreationInfos lineCreationInfos, boolean withSwitch1, boolean withSwitch2, ReportNode subReportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void apply(Network network, ReportNode subReportNode) {

private void modifyLine(Line line, BranchModificationInfos lineModificationInfos, ReportNode subReportNode) {
modifyBranch(line, lineModificationInfos, subReportNode, "lineModification", "Line with id=${id} modified :");
PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties(), "LineProperties");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void apply(Network network, ReportNode subReporter) {

// properties
Load load = network.getLoad(modificationInfos.getEquipmentId());
PropertiesUtils.applyProperties(load, subReporter, modificationInfos.getProperties());
PropertiesUtils.applyProperties(load, subReporter, modificationInfos.getProperties(), "LoadProperties");
}

private void reportElementaryCreations(ReportNode subReportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void modifyLoad(Load load, ReportNode subReportNode) {
ModificationUtils.getInstance().applyElementaryModifications(load::setQ0, load::getQ0, modificationInfos.getQ0(), subReportNode, "Constant reactive power");

// properties
PropertiesUtils.applyProperties(load, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(load, subReportNode, modificationInfos.getProperties(), "LoadProperties");

ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, load);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,70 @@
package org.gridsuite.modification.server.modifications;

import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.report.TypedValue;
import com.powsybl.commons.report.*;
import com.powsybl.iidm.network.Identifiable;
import org.gridsuite.modification.server.dto.FreePropertyInfos;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;
import java.util.*;

public final class PropertiesUtils {
public static final String PROPERTIES = "Properties";

private PropertiesUtils() {
// Should not be instantiated
}

public static void applyProperties(Identifiable<?> identifiable, ReportNode subReportNode, @Nullable List<FreePropertyInfos> properties) {
public static void applyProperties(Identifiable<?> identifiable, ReportNode subReportNode, @Nullable List<FreePropertyInfos> properties, String propertiesLabelKey) {
List<ReportNode> reportNodes = new ArrayList<>();
ReportNode propertiesReporter = subReportNode.newReportNode().withMessageTemplate(PROPERTIES, PROPERTIES).add();
Optional.ofNullable(properties).ifPresent(props ->
props.forEach(prop -> PropertiesUtils.applyProperty(identifiable, prop, subReportNode)));
props.forEach(prop ->
Optional.ofNullable(PropertiesUtils.applyProperty(identifiable, prop))
.ifPresent(reportNodes::add)
)
);
ModificationUtils.getInstance().reportModifications(propertiesReporter, reportNodes,
propertiesLabelKey, PROPERTIES, Map.of());
}

private static void applyProperty(Identifiable<?> identifiable, FreePropertyInfos prop, ReportNode subReportNode) {
private static ReportNode applyProperty(Identifiable<?> identifiable, FreePropertyInfos prop) {
ReportNodeBuilder builder = ReportNode.newRootReportNode();
if (prop.isDeletionMark()) {
if (identifiable.removeProperty(prop.getName())) {
subReportNode.newReportNode()
.withMessageTemplate("propertyDeleted", " Property ${name} deleted")
.withUntypedValue("name", prop.getName())
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
reportPropertyDeletion(builder, prop);
return builder.build();
}
} else {
String oldValue = identifiable.setProperty(prop.getName(), prop.getValue());
if (oldValue != null) { // update
subReportNode.newReportNode()
.withMessageTemplate("propertyChanged", " Property ${name} changed : ${from} -> ${to}")
.withUntypedValue("name", prop.getName())
.withUntypedValue("from", oldValue)
.withUntypedValue("to", prop.getValue())
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
reportPropertyModification(builder, prop);
return builder.build();
} else { // insert
subReportNode.newReportNode()
.withMessageTemplate("propertyAdded", " Property ${name} added with value ${value}")
.withUntypedValue("name", prop.getName())
.withUntypedValue("value", prop.getValue())
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
reportPropertyCreation(builder, prop);
return builder.build();
}
}
return null;
}

private static void reportPropertyCreation(ReportNodeAdderOrBuilder<?> adderOrBuilder, FreePropertyInfos prop) {
adderOrBuilder.withMessageTemplate("propertyAdded", " Property ${name} added with value ${value}")
.withUntypedValue("name", prop.getName())
.withUntypedValue("value", prop.getValue())
.withSeverity(TypedValue.INFO_SEVERITY);
}

private static void reportPropertyModification(ReportNodeAdderOrBuilder<?> adderOrBuilder, FreePropertyInfos prop) {
adderOrBuilder.withMessageTemplate("propertyChanged", " Property ${name} changed : ${from} -> ${to}")
.withUntypedValue("name", prop.getName())
.withUntypedValue("to", prop.getValue())
.withUntypedValue("from", prop.getPreviousValue() == null ? "null" : prop.getPreviousValue())
.withSeverity(TypedValue.INFO_SEVERITY);
}

private static void reportPropertyDeletion(ReportNodeAdderOrBuilder<?> adderOrBuilder, FreePropertyInfos prop) {
adderOrBuilder.withMessageTemplate("propertyDeleted", " Property ${name} deleted")
.withUntypedValue("name", prop.getName())
.withSeverity(TypedValue.INFO_SEVERITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void apply(Network network, ReportNode subReportNode) {
ModificationUtils.getInstance().disconnectCreatedInjection(modificationInfos, network.getShuntCompensator(modificationInfos.getEquipmentId()), subReportNode);
// properties
ShuntCompensator shuntCompensator = network.getShuntCompensator(modificationInfos.getEquipmentId());
PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties(), "ShuntCompensatorProperties");
}

private ShuntCompensatorAdder createShuntAdderInNodeBreaker(VoltageLevel voltageLevel, ShuntCompensatorCreationInfos shuntCompensatorInfos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void apply(Network network, ReportNode subReportNode) {
}

ModificationUtils.getInstance().modifyInjectionConnection(modificationInfos, shuntCompensator);
PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(shuntCompensator, subReportNode, modificationInfos.getProperties(), "ShuntCompensatorProperties");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public void apply(Network network, ReportNode subReportNode) {
.reportElementaryCreation(subReportNode, modificationInfos.getCountry(), "Country");
}
// properties
PropertiesUtils.applyProperties(substation, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(substation, subReportNode, modificationInfos.getProperties(), "SubstationProperties");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public void apply(Network network, ReportNode subReportNode) {
ModificationUtils.getInstance().applyElementaryModifications(station::setName, () -> station.getOptionalName().orElse("No value"), modificationInfos.getEquipmentName(), subReportNode, "Name");
ModificationUtils.getInstance().applyElementaryModifications(station::setCountry, station::getNullableCountry, modificationInfos.getCountry(), subReportNode, "Country");
// properties
PropertiesUtils.applyProperties(station, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(station, subReportNode, modificationInfos.getProperties(), "SubstationProperties");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void apply(Network network, ReportNode subReportNode) {

ModificationUtils.getInstance().disconnectBranch(modificationInfos, network.getTwoWindingsTransformer(modificationInfos.getEquipmentId()), subReportNode);
// properties
PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties(), "TwoWindingsTransformerProperties");
}

private TwoWindingsTransformer create2WTInNodeBreaker(Network network, VoltageLevel voltageLevel1, VoltageLevel voltageLevel2, ReportNode subReportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void apply(Network network, ReportNode subReportNode) {
private void modifyTwoWindingsTransformer(TwoWindingsTransformer twoWindingsTransformer, BranchModificationInfos twoWindingsTransformerModificationInfos, ReportNode subReportNode, Network network) {
modifyBranch(twoWindingsTransformer, twoWindingsTransformerModificationInfos, subReportNode, "twoWindingsTransformerModification", "TwoWindingsTransformer with id=${id} modified :");
addTapChangersToTwoWindingsTransformer(network, (TwoWindingsTransformerModificationInfos) modificationInfos, twoWindingsTransformer, subReportNode);
PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(twoWindingsTransformer, subReportNode, modificationInfos.getProperties(), "TwoWindingsTransformerProperties");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public void apply(Network network, ReportNode subReportNode) {
ModificationUtils.getInstance().createVoltageLevel(modificationInfos, subReportNode, network);
// properties
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getEquipmentId());
PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties(), "VlProperties");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void apply(Network network, ReportNode subReportNode) {
ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setHighVoltageLimit, voltageLevel::getHighVoltageLimit, modificationInfos.getHighVoltageLimit(), subReportNode, "High voltage limit");

modifyVoltageLevelShortCircuit(subReportNode, voltageLevel);
PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties(), "VlProperties");
}

private void modifyVoltageLevelShortCircuit(ReportNode subReportNode, VoltageLevel voltageLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void apply(Network network, ReportNode subReportNode) {
.reportElementaryCreation(subReportNode, modificationInfos.getEquipmentName(), "Name");
}

PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties(), "VscProperties");
}

private void reportHvdcLineInfos(ReportNode subReportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void modifyVsc(@NonNull Network network, @NonNull HvdcLine hvdcLine, Vsc
modifyConverterStation(network, modificationInfos.getConverterStation1(), subReportNode);
modifyConverterStation(network, modificationInfos.getConverterStation2(), subReportNode);

PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties());
PropertiesUtils.applyProperties(hvdcLine, subReportNode, modificationInfos.getProperties(), "VscProperties");
}

private static void operatorActivePowerLimit(HvdcLine hvdcLine, VscModificationInfos modificationInfos, ReportNode subReportNode) {
Expand Down

0 comments on commit 0377cd6

Please sign in to comment.