Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Oct 23, 2024
1 parent 46dcd2f commit 283eda1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Seddik.yengui at rte-france.com>
Expand All @@ -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<Double> attributeModification = new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET);
switch (field) {
case MINIMUM_ACTIVE_POWER ->
Expand All @@ -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);
}
Expand All @@ -65,7 +65,7 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St
ModificationUtils.getInstance().modifyActivePowerControlAttributes(
activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null,
null, MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : ");
null, MODIFY_BATTERY_ERROR, errorMessage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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));
}
Expand All @@ -99,7 +100,7 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null,
MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : ");
MODIFY_GENERATOR_ERROR, errorMessage);
}
case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Collection;
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.CREATE_BATTERY_ERROR;
import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_BATTERY_ERROR;
import static org.gridsuite.modification.server.modifications.ModificationUtils.insertReportNode;

Expand All @@ -39,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;
Expand Down Expand Up @@ -173,7 +173,7 @@ public static ReportNode modifyBatteryActivePowerControlAttributes(AttributeModi
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder,
participate, droop, subReportNode, subReportNodeSetpoints, CREATE_BATTERY_ERROR, "Battery '" + battery.getId() + "' : ");
participate, droop, subReportNode, subReportNodeSetpoints, MODIFY_BATTERY_ERROR, String.format(ERROR_MESSAGE, battery.getId()));
}

private ReportNode modifyBatteryConnectivityAttributes(BatteryModificationInfos modificationInfos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -210,9 +211,10 @@ private ReportNode modifyGeneratorActivePowerControlAttributes(GeneratorModifica
Generator generator, ReportNode subReportNode, ReportNode subReportNodeSetpoints) {
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);

return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder,
modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints,
MODIFY_GENERATOR_ERROR, "Generator '" + modificationInfos.getEquipmentId() + "' : ");
MODIFY_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId()));
}

private void modifyGeneratorStartUpAttributes(GeneratorModificationInfos modificationInfos, Generator generator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,25 +1187,23 @@ private void createNewActivePowerControl(ActivePowerControlAdder<?> adder,
List<ReportNode> reports,
NetworkModificationException.Type exceptionType,
String errorMessage) {
Boolean participate = participateInfo == null ? null : participateInfo.getValue();
Float droop = droopInfo == null ? null : droopInfo.getValue();
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);
adder.withParticipate(participate)
.withDroop(droop)
.add();
if (reports != null) {
reports.add(buildModificationReport(null, participate, "Participate"));
}
adder.withDroop(droop);
if (reports != null) {
reports.add(buildModificationReport(Double.NaN, droop, "Droop"));
}
adder.add();
}
}

public void checkActivePowerControl(Boolean participate, Float droop, NetworkModificationException.Type exceptionType, String errorMessage) {
if (Boolean.TRUE.equals(participate) && droop == null) {
throw new NetworkModificationException(exceptionType, errorMessage + "for creation if participate is true, droop can not be null");
throw new NetworkModificationException(exceptionType, String.format("%s Active power regulation on : missing required droop value", errorMessage));
}
}

Expand Down

0 comments on commit 283eda1

Please sign in to comment.