From 6f7a9da1800e5a2535f9aac45f0a4db17f4930b5 Mon Sep 17 00:00:00 2001 From: EtienneLt <32468651+EtienneLt@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:34:15 +0200 Subject: [PATCH] add checks on active power control creation (#545) Signed-off-by: Etienne LESOT --- .../byfilter/equipmentfield/BatteryField.java | 9 +++-- .../equipmentfield/GeneratorField.java | 6 ++- .../server/modifications/BatteryCreation.java | 5 +++ .../modifications/BatteryModification.java | 4 +- .../modifications/GeneratorCreation.java | 6 ++- .../modifications/GeneratorModification.java | 6 ++- .../modifications/ModificationUtils.java | 37 ++++++++++++------- 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java index 117db9718..f2688faca 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/BatteryField.java @@ -16,8 +16,7 @@ import org.gridsuite.modification.server.modifications.ModificationUtils; import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_BATTERY_ERROR; -import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatteryActiveLimitsAttributes; -import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatterySetpointsAttributes; +import static org.gridsuite.modification.server.modifications.BatteryModification.*; /** * @author Seddik Yengui @@ -44,6 +43,7 @@ public static String getReferenceValue(Battery battery, String batteryField) { public static void setNewValue(Battery battery, String batteryField, @NotNull String newValue) { BatteryField field = BatteryField.valueOf(batteryField); + String errorMessage = String.format(ERROR_MESSAGE, battery.getId()); final AttributeModification attributeModification = new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET); switch (field) { case MINIMUM_ACTIVE_POWER -> @@ -53,7 +53,7 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St case ACTIVE_POWER_SET_POINT -> { ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( attributeModification, null, null, battery.getMinP(), - battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : " + battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, errorMessage ); modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null); } @@ -64,7 +64,8 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St ActivePowerControlAdder activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); ModificationUtils.getInstance().modifyActivePowerControlAttributes( activePowerControl, activePowerControlAdder, null, - new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null); + new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, + null, MODIFY_BATTERY_ERROR, errorMessage); } } } diff --git a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java index 028c313f4..d0bafe1f4 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/byfilter/equipmentfield/GeneratorField.java @@ -65,6 +65,7 @@ public static String getReferenceValue(Generator generator, String generatorFiel public static void setNewValue(Generator generator, String generatorField, @NotNull String newValue) { GeneratorField field = GeneratorField.valueOf(generatorField); + String errorMessage = String.format(ERROR_MESSAGE, generator.getId()); switch (field) { case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes( new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), @@ -75,7 +76,7 @@ public static void setNewValue(Generator generator, String generatorField, @NotN ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower( new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), null, null, generator.getMinP(), generator.getMaxP(), generator.getTargetP(), - MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : " + MODIFY_GENERATOR_ERROR, errorMessage ); generator.setTargetP(Double.parseDouble(newValue)); } @@ -98,7 +99,8 @@ public static void setNewValue(Generator generator, String generatorField, @NotN ActivePowerControl activePowerControl = generator.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class); ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null, - new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null); + new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null, + MODIFY_GENERATOR_ERROR, errorMessage); } case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes( new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java index 10345a8e2..655949b30 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java @@ -18,6 +18,8 @@ import java.util.List; import static org.gridsuite.modification.server.NetworkModificationException.Type.BATTERY_ALREADY_EXISTS; +import static org.gridsuite.modification.server.NetworkModificationException.Type.CREATE_BATTERY_ERROR; +import static org.gridsuite.modification.server.modifications.BatteryModification.ERROR_MESSAGE; import static org.gridsuite.modification.server.modifications.ModificationUtils.*; /** @@ -49,6 +51,9 @@ public void check(Network network) throws NetworkModificationException { modificationInfos.getErrorType(), modificationInfos.getEquipmentId(), "Battery"); + + ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(), + modificationInfos.getDroop(), CREATE_BATTERY_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId())); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java index 15d9bd3ad..1cc5e234e 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryModification.java @@ -38,6 +38,7 @@ public class BatteryModification extends AbstractModification { private static final String LIMITS = "Limits"; private static final String ACTIVE_LIMITS = "Active limits"; private static final String SETPOINTS = "Setpoints"; + public static final String ERROR_MESSAGE = "Battery '%s' : "; public BatteryModification(BatteryModificationInfos modificationInfos) { this.modificationInfos = modificationInfos; @@ -171,7 +172,8 @@ public static ReportNode modifyBatteryActivePowerControlAttributes(AttributeModi ReportNode subReportNodeSetpoints) { ActivePowerControl activePowerControl = battery.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class); - return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, participate, droop, subReportNode, subReportNodeSetpoints); + return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, + participate, droop, subReportNode, subReportNodeSetpoints, MODIFY_BATTERY_ERROR, String.format(ERROR_MESSAGE, battery.getId())); } private ReportNode modifyBatteryConnectivityAttributes(BatteryModificationInfos modificationInfos, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java index 8931f4a3d..9599abe89 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java @@ -20,7 +20,8 @@ import java.util.ArrayList; import java.util.List; -import static org.gridsuite.modification.server.NetworkModificationException.Type.GENERATOR_ALREADY_EXISTS; +import static org.gridsuite.modification.server.NetworkModificationException.Type.*; +import static org.gridsuite.modification.server.modifications.GeneratorModification.ERROR_MESSAGE; import static org.gridsuite.modification.server.modifications.ModificationUtils.*; /** @@ -58,6 +59,9 @@ public void check(Network network) throws NetworkModificationException { modificationInfos.getRegulatingTerminalId(), modificationInfos.getRegulatingTerminalType(), modificationInfos.getRegulatingTerminalVlId()); + + ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(), + modificationInfos.getDroop(), CREATE_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId())); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java index 71a4508b9..72b4c41d6 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorModification.java @@ -29,6 +29,7 @@ public class GeneratorModification extends AbstractModification { private static final String LIMITS = "Limits"; private static final String ACTIVE_LIMITS = "Active limits"; private static final String SETPOINTS = "Setpoints"; + public static final String ERROR_MESSAGE = "Generator '%s' : "; private final GeneratorModificationInfos modificationInfos; @@ -210,7 +211,10 @@ private ReportNode modifyGeneratorActivePowerControlAttributes(GeneratorModifica Generator generator, ReportNode subReportNode, ReportNode subReportNodeSetpoints) { ActivePowerControl activePowerControl = generator.getExtension(ActivePowerControl.class); ActivePowerControlAdder activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class); - return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints); + + return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, + modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints, + MODIFY_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId())); } private void modifyGeneratorStartUpAttributes(GeneratorModificationInfos modificationInfos, Generator generator, diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index ed69f35ae..534d31b5b 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -1184,18 +1184,27 @@ private void modifyExistingActivePowerControl(ActivePowerControl activePowerC private void createNewActivePowerControl(ActivePowerControlAdder adder, AttributeModification participateInfo, AttributeModification droopInfo, - List reports) { - boolean participate = participateInfo != null ? participateInfo.getValue() : false; - adder.withParticipate(participate); - if (participateInfo != null && reports != null) { - reports.add(buildModificationReport(null, participate, "Participate")); + List reports, + NetworkModificationException.Type exceptionType, + String errorMessage) { + Boolean participate = Optional.ofNullable(participateInfo).map(AttributeModification::getValue).orElse(null); + Float droop = Optional.ofNullable(droopInfo).map(AttributeModification::getValue).orElse(null); + checkActivePowerControl(participate, droop, exceptionType, errorMessage); + if (participate != null && droop != null) { + adder.withParticipate(participate) + .withDroop(droop) + .add(); + if (reports != null) { + reports.add(buildModificationReport(null, participate, "Participate")); + reports.add(buildModificationReport(Double.NaN, droop, "Droop")); + } } - double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN; - adder.withDroop(droop); - if (droopInfo != null && reports != null) { - reports.add(buildModificationReport(Double.NaN, droop, "Droop")); + } + + public void checkActivePowerControl(Boolean participate, Float droop, NetworkModificationException.Type exceptionType, String errorMessage) { + if (Boolean.TRUE.equals(participate) && droop == null) { + throw new NetworkModificationException(exceptionType, String.format("%s Active power regulation on : missing required droop value", errorMessage)); } - adder.add(); } public ReportNode modifyActivePowerControlAttributes(ActivePowerControl activePowerControl, @@ -1203,19 +1212,21 @@ public ReportNode modifyActivePowerControlAttributes(ActivePowerControl activ AttributeModification participateInfo, AttributeModification droopInfo, ReportNode subReportNode, - ReportNode subReporterSetpoints) { + ReportNode subReporterSetpoints, + NetworkModificationException.Type exceptionType, + String errorMessage) { List reports = new ArrayList<>(); if (activePowerControl != null) { modifyExistingActivePowerControl(activePowerControl, participateInfo, droopInfo, reports); } else { - createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports); + createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports, exceptionType, errorMessage); } if (subReportNode != null) { ReportNode subReportNodeSetpoints2 = subReporterSetpoints; if (subReporterSetpoints == null && !reports.isEmpty()) { subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add(); } - reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation"); + reportModifications(subReportNodeSetpoints2, reports, "activePowerControlModified", "Active power control"); return subReportNodeSetpoints2; } return null;