From 227dbd76da1b324f986fb68e28e0948a6d5a759a Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Wed, 20 Nov 2024 11:20:26 +0100 Subject: [PATCH] =?UTF-8?q?=20Handle=20the=20case=20where=20the=20feeder?= =?UTF-8?q?=20for=20one=20of=20the=20branch=20sides=20is=20not=20=E2=80=A6?= =?UTF-8?q?=20(#128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rehili Ghazwa --- .../server/PositionDiagramLabelProvider.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java b/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java index 851e8ac..c9462af 100644 --- a/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java +++ b/src/main/java/com/powsybl/sld/server/PositionDiagramLabelProvider.java @@ -16,7 +16,9 @@ import com.powsybl.sld.model.nodes.EquipmentNode; import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; -import com.powsybl.sld.svg.*; +import com.powsybl.sld.svg.LabelPosition; +import com.powsybl.sld.svg.LabelProviderFactory; +import com.powsybl.sld.svg.SvgParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,35 +94,35 @@ static Integer getInjectionOrder(ConnectablePosition position) { } static Integer getBranchOrder(ConnectablePosition position, VoltageLevel voltageLevel, Branch branch, boolean throwException) { - Integer order = null; - if (branch.getTerminal1().getVoltageLevel() == voltageLevel) { - order = position.getFeeder1().getOrder().orElse(null); - } else if (branch.getTerminal2().getVoltageLevel() == voltageLevel) { - order = position.getFeeder2().getOrder().orElse(null); + Optional feeder = Optional.empty(); + if (branch.getTerminal1().getVoltageLevel().getId().equals(voltageLevel.getId())) { + feeder = Optional.ofNullable(position.getFeeder1()); + } else if (branch.getTerminal2().getVoltageLevel().getId().equals(voltageLevel.getId())) { + feeder = Optional.ofNullable(position.getFeeder2()); } else { LOGGER.error("Given voltageLevel {} not found in terminal 1 and terminal 2 of branch", voltageLevel.getId()); if (throwException) { throw new PowsyblException(String.format("Given voltageLevel %s not found in terminal 1 and terminal 2 of branch", voltageLevel.getId())); } } - return order; + return feeder.flatMap(ConnectablePosition.Feeder::getOrder).orElse(null); } static Integer get3wtOrder(ConnectablePosition position, VoltageLevel voltageLevel, ThreeWindingsTransformer twt, boolean throwException) { - Integer order = null; - if (twt.getLeg1().getTerminal().getVoltageLevel() == voltageLevel) { - order = position.getFeeder1().getOrder().orElse(null); - } else if (twt.getLeg2().getTerminal().getVoltageLevel() == voltageLevel) { - order = position.getFeeder2().getOrder().orElse(null); - } else if (twt.getLeg3().getTerminal().getVoltageLevel() == voltageLevel) { - order = position.getFeeder3().getOrder().orElse(null); + Optional feeder = Optional.empty(); + if (twt.getLeg1().getTerminal().getVoltageLevel().getId().equals(voltageLevel.getId())) { + feeder = Optional.ofNullable(position.getFeeder1()); + } else if (twt.getLeg2().getTerminal().getVoltageLevel().getId().equals(voltageLevel.getId())) { + feeder = Optional.ofNullable(position.getFeeder2()); + } else if (twt.getLeg3().getTerminal().getVoltageLevel().getId().equals(voltageLevel.getId())) { + feeder = Optional.ofNullable(position.getFeeder3()); } else { LOGGER.error("Given voltageLevel {} not found in leg 1, leg 2 and leg 3 of ThreeWindingsTransformer", voltageLevel.getId()); if (throwException) { throw new PowsyblException(String.format("Given voltageLevel %s not found in leg 1, leg 2 and leg 3 of ThreeWindingsTransformer", voltageLevel.getId())); } } - return order; + return feeder.flatMap(ConnectablePosition.Feeder::getOrder).orElse(null); } static Integer getOrderPositions(ConnectablePosition position, VoltageLevel voltageLevel, Identifiable identifiable, boolean throwException) {