Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking equipment modifications #397

Merged
merged 8 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public BatteryModification(BatteryModificationInfos modificationInfos) {

@Override
public void check(Network network) throws NetworkModificationException {
if (modificationInfos == null) {
throw new NetworkModificationException(MODIFY_BATTERY_ERROR, "Missing required attributes to modify the equipment");
}
if (network.getBattery(modificationInfos.getEquipmentId()) == null) {
throw new NetworkModificationException(BATTERY_NOT_FOUND, modificationInfos.getEquipmentId());
}
Expand Down Expand Up @@ -74,9 +77,6 @@ private void checkActivePowerZeroOrBetweenMinAndMaxActivePowerBattery(BatteryMod

@Override
public void apply(Network network, Reporter subReporter) {
if (modificationInfos == null) {
throw new NetworkModificationException(MODIFY_BATTERY_ERROR, "Missing required attributes to modify the equipment");
}
Battery battery = ModificationUtils.getInstance().getBattery(network, modificationInfos.getEquipmentId());
// modify the battery in the network
modifyBattery(battery, modificationInfos, subReporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.gridsuite.modification.server.NetworkModificationException.Type.BRANCH_NOT_FOUND;
import static org.gridsuite.modification.server.NetworkModificationException.Type.BRANCH_ACTION_ERROR;
import static org.gridsuite.modification.server.NetworkModificationException.Type.BRANCH_NOT_FOUND;
import static org.gridsuite.modification.server.modifications.ModificationUtils.distinctByKey;

/**
Expand All @@ -40,12 +40,18 @@ public BranchStatusModification(BranchStatusModificationInfos modificationInfos)
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
String branchId = modificationInfos.getEquipmentId();
Branch<?> branch = network.getBranch(branchId);
if (branch == null) {
throw new NetworkModificationException(BRANCH_NOT_FOUND, branchId);
}
}

@Override
public void apply(Network network, Reporter subReporter) {
String branchId = modificationInfos.getEquipmentId();
Branch<?> branch = network.getBranch(branchId);

String branchTypeName = branch.getType() == IdentifiableType.LINE ? "Line" : "2 windings transformer";
switch (modificationInfos.getAction()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ public EquipmentAttributeModification(EquipmentAttributeModificationInfos modifi
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
Identifiable<?> identifiable = network.getIdentifiable(modificationInfos.getEquipmentId());
if (identifiable == null) {
throw new NetworkModificationException(EQUIPMENT_NOT_FOUND, modificationInfos.getEquipmentId());
}
if (identifiable.getType() != modificationInfos.getEquipmentType()) {
throw new NetworkModificationException(WRONG_EQUIPMENT_TYPE, String.format("Type of '%s' is not %s but %s", modificationInfos.getEquipmentId(), modificationInfos.getEquipmentType(), identifiable.getType()));
}
}

@Override
public void apply(Network network, Reporter subReporter) {
Identifiable<?> identifiable = network.getIdentifiable(modificationInfos.getEquipmentId());
if (identifiable instanceof Switch) {
changeSwitchAttribute((Switch) identifiable, modificationInfos.getEquipmentAttributeName(), modificationInfos.getEquipmentAttributeValue(), subReporter);
} else if (identifiable instanceof Injection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ public EquipmentDeletion(EquipmentDeletionInfos modificationInfos) {
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
Identifiable<?> identifiable = ModificationUtils.getInstance().getEquipmentByIdentifiableType(network, modificationInfos.getEquipmentType(), modificationInfos.getEquipmentId());
if (identifiable == null) {
throw new NetworkModificationException(EQUIPMENT_NOT_FOUND, "Equipment with id=" + modificationInfos.getEquipmentId() + " not found or of bad type");
}
}

@Override
public void apply(Network network, Reporter subReporter) {
Identifiable<?> identifiable = ModificationUtils.getInstance().getEquipmentByIdentifiableType(network, modificationInfos.getEquipmentType(), modificationInfos.getEquipmentId());
if (identifiable instanceof Connectable) {
new RemoveFeederBay(modificationInfos.getEquipmentId()).apply(network, true, subReporter);
} else if (identifiable instanceof HvdcLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public GeneratorModification(GeneratorModificationInfos modificationInfos) {

@Override
public void check(Network network) throws NetworkModificationException {
if (modificationInfos == null) {
throw new NetworkModificationException(MODIFY_GENERATOR_ERROR, "Missing required attributes to modify the equipment");
}
if (network.getGenerator(modificationInfos.getEquipmentId()) != null) {
Generator generator = ModificationUtils.getInstance().getGenerator(network, modificationInfos.getEquipmentId());
// check min max reactive limits
Expand Down Expand Up @@ -86,9 +89,6 @@ private void checkActivePowerZeroOrBetweenMinAndMaxActivePowerGenerator(Generato

@Override
public void apply(Network network, Reporter subReporter) {
if (modificationInfos == null) {
throw new NetworkModificationException(MODIFY_GENERATOR_ERROR, "Missing required attributes to modify the equipment");
}
Generator generator = ModificationUtils.getInstance().getGenerator(network, modificationInfos.getEquipmentId());
// modify the generator in the network
modifyGenerator(generator, modificationInfos, subReporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ public GroovyScript(GroovyScriptInfos modificationInfos) {
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
if (StringUtils.isBlank(modificationInfos.getScript())) {
throw new NetworkModificationException(GROOVY_SCRIPT_EMPTY);
}
}

@Override
public void apply(Network network, Reporter subReporter) {
var conf = new CompilerConfiguration();
var binding = new Binding();
binding.setProperty("network", network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ public LineModification(LineModificationInfos modificationInfos) {
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
Line line = network.getLine(modificationInfos.getEquipmentId());
if (line == null) {
throw new NetworkModificationException(LINE_NOT_FOUND,
"Line " + modificationInfos.getEquipmentId() + " does not exist in network");
}
}

@Override
public void apply(Network network, Reporter subReporter) {
Line line = network.getLine(modificationInfos.getEquipmentId());
// modify the line in the network
modifyLine(line, modificationInfos, subReporter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.network.*;
import static org.gridsuite.modification.server.NetworkModificationException.Type.LOAD_NOT_FOUND;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.LoadModificationInfos;

import static org.gridsuite.modification.server.NetworkModificationException.Type.LOAD_NOT_FOUND;

/**
* @author Ayoub Labidi <ayoub.labidi at rte-france.com>
*/
Expand All @@ -26,12 +28,17 @@ public LoadModification(LoadModificationInfos modificationInfos) {
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
Load load = network.getLoad(modificationInfos.getEquipmentId());
if (load == null) {
throw new NetworkModificationException(LOAD_NOT_FOUND,
"Load " + modificationInfos.getEquipmentId() + " does not exist in network");
}
}

@Override
public void apply(Network network, Reporter subReporter) {
Load load = network.getLoad(modificationInfos.getEquipmentId());
// modify the load in the network
modifyLoad(load, modificationInfos, subReporter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ public SubstationModification(SubstationModificationInfos modificationInfos) {
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
Substation station = network.getSubstation(modificationInfos.getEquipmentId());
if (station == null) {
throw new NetworkModificationException(SUBSTATION_NOT_FOUND,
"Substation " + modificationInfos.getEquipmentId() + " does not exist in network");
}
}

@Override
public void apply(Network network, Reporter subReporter) {
Substation station = network.getSubstation(modificationInfos.getEquipmentId());

// modify the substation in the network
subReporter.report(Report.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public void check(Network network) throws NetworkModificationException {
@Override
public void apply(Network network, Reporter subReporter) {
AtomicInteger applicationFailuresCount = new AtomicInteger(0);
modificationInfos.getModifications().forEach(modification -> {
modificationInfos.getModifications().forEach(modificationInfos -> {
flomillot marked this conversation as resolved.
Show resolved Hide resolved
try {
modification.toModification().apply(network);
AbstractModification modification = modificationInfos.toModification();
modification.check(network);
modification.apply(network);
} catch (PowsyblException e) {
applicationFailuresCount.incrementAndGet();
subReporter.report(Report.builder()
.withKey(modification.getType().name() + applicationFailuresCount.get())
.withKey(modificationInfos.getType().name() + applicationFailuresCount.get())
.withDefaultMessage(e.getMessage())
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ public VoltageLevelModification(VoltageLevelModificationInfos voltageLevelModifi
}

@Override
public void apply(Network network, Reporter subReporter) {
public void check(Network network) throws NetworkModificationException {
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getEquipmentId());
if (voltageLevel == null) {
throw new NetworkModificationException(VOLTAGE_LEVEL_NOT_FOUND,
String.format("Voltage level %s does not exist in network", modificationInfos.getEquipmentId()));
}
}

@Override
public void apply(Network network, Reporter subReporter) {
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getEquipmentId());
modifyVoltageLevel(subReporter, voltageLevel);
}

Expand Down
Loading