From af2b751dc1ccb0851ed01cdf3c651f1c4fa38a62 Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Fri, 24 Jan 2025 17:56:12 +0100 Subject: [PATCH] feat: remove LD LDevice Status verification Signed-off-by: Samir Romdhani --- .../compas/sct/commons/LnService.java | 25 ++-- .../scl/ldevice/LDeviceActivation.java | 68 ---------- .../compas/sct/commons/scl/ln/LN0Adapter.java | 2 - .../compas/sct/commons/LnServiceTest.java | 80 ++---------- .../scl/ldevice/LDeviceActivationTest.java | 54 -------- .../scd-refresh-lnode/Test_LD_STATUS_OFF.scd | 119 ------------------ .../scd-refresh-lnode/Test_LD_STATUS_ON.scd | 119 ------------------ .../Test_LD_STATUS_ONOFF.scd | 119 ------------------ .../Test_NOK_MissingLNodeStatusPrivate.scd | 119 ------------------ 9 files changed, 24 insertions(+), 681 deletions(-) delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java delete mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java delete mode 100644 sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_OFF.scd delete mode 100644 sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ON.scd delete mode 100644 sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ONOFF.scd delete mode 100644 sct-commons/src/test/resources/scd-refresh-lnode/Test_NOK_MissingLNodeStatusPrivate.scd diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java index a66782b80..d35090b4d 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java @@ -10,10 +10,8 @@ import org.lfenergy.compas.sct.commons.api.LnEditor; import org.lfenergy.compas.sct.commons.domain.*; import org.lfenergy.compas.sct.commons.dto.SclReportItem; -import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation; import org.lfenergy.compas.sct.commons.scl.ln.LnId; import org.lfenergy.compas.sct.commons.util.ActiveStatus; -import org.lfenergy.compas.sct.commons.util.PrivateUtils; import java.util.ArrayList; import java.util.List; @@ -23,7 +21,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation.LNODE_STATUS_PRIVATE_TYPE; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal; @@ -160,7 +157,6 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT */ public List updateLDeviceStatus(SCL scd, SubstationService substationService, LdeviceService ldeviceService, DataTypeTemplatesService dataTypeTemplatesService) { List sclReportItems = new ArrayList<>(); - LDeviceActivation lDeviceActivation = new LDeviceActivation(substationService.getLNodes(scd)); scd.getIED().forEach(tied -> ldeviceService.getLdevices(tied) .forEach(tlDevice -> getAnylns(tlDevice) .forEach(tln -> { @@ -178,17 +174,20 @@ public List updateLDeviceStatus(SCL scd, SubstationService substa return; } - Optional lNodeStatus = PrivateUtils.extractStringPrivate(tln, LNODE_STATUS_PRIVATE_TYPE); - if (lNodeStatus.isEmpty()) { - sclReportItems.add(SclReportItem.error(xpath, "The LN doesn't have a Private "+LNODE_STATUS_PRIVATE_TYPE)); - return; - } - Set enumValues = dataTypeTemplatesService.getEnumValues(scd.getDataTypeTemplates(), tln.getLnType(), doLinkedToDaFilter).collect(Collectors.toSet()); - lDeviceActivation.checkLDeviceActivationStatus(tied.getName(), tlDevice.getInst(), lNodeStatus.get(), enumValues, sclReportItems); - if(lDeviceActivation.isUpdatable()){ - update(tln, optionalModStVal.get().getValue(), lDeviceActivation.getNewVal()); + if (!enumValues.contains(ActiveStatus.ON.getValue()) && !enumValues.contains(ActiveStatus.OFF.getValue())) { + sclReportItems.add(SclReportItem.error(xpath, "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.")); } + substationService.getLNodes(scd).stream().filter(tlNode1 -> tlNode1.isSetIedName() && tlNode1.isSetLdInst()) + .filter(tlNode1 -> tlNode1.getIedName().equals(tied.getName()) && tlNode1.getLdInst().equals(tlDevice.getInst())) + .findFirst() + .ifPresentOrElse(tlNode1 -> { + if(!enumValues.contains(ActiveStatus.ON.getValue())) { + sclReportItems.add(SclReportItem.error(xpath, "The LDevice cannot be set to 'on' but has been selected into SSD.")); + } + }, + // Deactivate LDevice + () -> update(tln, optionalModStVal.get().getValue(), ActiveStatus.OFF.getValue())); }))); return sclReportItems; } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java deleted file mode 100644 index b524af8f9..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-FileCopyrightText: 2022 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.ldevice; - -import lombok.Getter; -import lombok.Setter; -import org.lfenergy.compas.scl2007b4.model.TLNode; -import org.lfenergy.compas.sct.commons.dto.SclReportItem; -import org.lfenergy.compas.sct.commons.util.ActiveStatus; - -import java.util.List; -import java.util.Set; - -/** - * Common class for all states that define if LDevice should be activated or not - * regardless of the CompasLDeviceStatus Private, Enum Values of DO 'Beh' and if it's referenced in Substation...LNode or not - */ -@Getter -@Setter -public class LDeviceActivation { - - public static final String LNODE_STATUS_PRIVATE_TYPE = "COMPAS-LNodeStatus"; - - private final List tlNodeList; - private boolean isUpdatable; - private String newVal; - - public LDeviceActivation(List tlNodeList) { - this.tlNodeList = tlNodeList; - } - /** - * checks whether LDevice status is authorized to be activated or Not - * @param iedName Ied name value which LDevice appear - * @param ldInst LDevice inst value - * @param enumValues enum values - */ - public void checkLDeviceActivationStatus(String iedName, String ldInst, String lNodeStatus, Set enumValues, List sclReportItems) { - String xpath = "/SCL/IED[@name=%s]/AccessPoint/Server/LDevice[@inst=%s]".formatted(iedName, ldInst); - if (!enumValues.contains(ActiveStatus.ON.getValue()) && !enumValues.contains(ActiveStatus.OFF.getValue())) { - sclReportItems.add(SclReportItem.error(xpath, "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.")); - } else { - tlNodeList.stream().filter(tlNode1 -> tlNode1.isSetIedName() && tlNode1.isSetLdInst()) - .filter(tlNode1 -> tlNode1.getIedName().equals(iedName) && tlNode1.getLdInst().equals(ldInst)) - .findFirst() - .ifPresentOrElse(tlNode1 -> { - if(!enumValues.contains(ActiveStatus.ON.getValue())) { - sclReportItems.add(SclReportItem.error(xpath, "The LDevice cannot be set to 'on' but has been selected into SSD.")); - } else - // Activate LDevice - if(lNodeStatus.equals("on") || lNodeStatus.equals("on;off")|| lNodeStatus.equals("off;on")){ - isUpdatable = true; - newVal = ActiveStatus.ON.getValue(); - } else - // Deactivate LDevice - if(lNodeStatus.equals("off")){ - sclReportItems.add(SclReportItem.error(xpath, "The LDevice is not qualified into STD but has been selected into SSD.")); - } - }, () -> { - // Deactivate LDevice - isUpdatable = true; - newVal = ActiveStatus.OFF.getValue(); - }); - } - } - -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java index 8f275696f..f3f1fc837 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java @@ -10,9 +10,7 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.scl.ObjectReference; import org.lfenergy.compas.sct.commons.scl.ied.InputsAdapter; -import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; -import org.lfenergy.compas.sct.commons.util.ActiveStatus; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import java.util.List; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java index a4f8fe3c6..0046e4050 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java @@ -697,95 +697,39 @@ void updateLDeviceStatus_whenMissingDOMod_shouldReturnError() { } - @Test - void updateLDeviceStatus_whenMissingPrivateLNodeStatus_shouldReturnError() { - // Given - SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_NOK_MissingLNodeStatusPrivate.scd"); - // When - List sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService); - // Then - assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse(); - assertThat(sclReportItems) - .hasSize(1) - .extracting(SclReportItem::message, SclReportItem::xpath) - .containsExactly(Tuple.tuple("The LN doesn't have a Private COMPAS-LNodeStatus", - "/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]/LN[class=LLN0]")); - } - - @Test void updateLDeviceStatus_whenEnumNotContainValues_shouldReturnError() { // Given SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_NOK_MissingEnums.scd"); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); + assertThat(getLDeviceStatusValue(scl).get().getValue()).isEqualTo("off"); // When List sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService); // Then assertThat(sclReportItems) - .hasSize(1) + .hasSize(2) .extracting(SclReportItem::message, SclReportItem::xpath) .containsExactly(Tuple.tuple("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.", - "/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]")); - } - - @Test - void updateLDeviceStatus_whenLDeviceStatusOn_shouldSucceed() { - // Given - SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_LD_STATUS_ON.scd"); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); - // When - List sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService); - // Then - assertThat(sclReportItems).isEmpty(); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("on"); - } - - - @Test - void updateLDeviceStatus_whenLDeviceStatusOnOff_shouldSucceed() { - // Given - SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_LD_STATUS_ONOFF.scd"); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); - // When - List sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService); - // Then - assertThat(sclReportItems).isEmpty(); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("on"); - } - - - @Test - void updateLDeviceStatus_whenLDeviceStatusOff_AndExistINSubstation_shouldReturnError() { - // Given - SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_LD_STATUS_OFF.scd"); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); - // When - List sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService); - // Then - assertThat(sclReportItems) - .hasSize(1) - .extracting(SclReportItem::message, SclReportItem::xpath) - .containsExactly(Tuple.tuple("The LDevice is not qualified into STD but has been selected into SSD.", - "/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]")); - assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off"); + "/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]/LN[class=LLN0]"), + Tuple.tuple("The LDevice cannot be set to 'on' but has been selected into SSD.", + "/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]/LN[class=LLN0]")); } - private Optional getLDeviceStatusValue(SCL scl, String iedName, String ldInst) { - return getValFromDaiName(scl, iedName, ldInst, "Mod", "stVal"); + private Optional getLDeviceStatusValue(SCL scl) { + return getValFromDaiName(scl); } - private Optional getValFromDaiName(SCL scl, String iedName, String ldInst, String doiName, String daiName) { + private Optional getValFromDaiName(SCL scl) { SclRootAdapter sclRootAdapter = new SclRootAdapter(scl); - IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName); - Optional lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst(ldInst); + IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName("IedName1"); + Optional lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst("LDSUIED"); LN0Adapter ln0Adapter = lDeviceAdapter.get().getLN0Adapter(); Optional doiAdapter = ln0Adapter.getDOIAdapters().stream() - .filter(doiAdapter1 -> doiAdapter1.getCurrentElem().getName().equals(doiName)) + .filter(doiAdapter1 -> doiAdapter1.getCurrentElem().getName().equals("Mod")) .findFirst(); return doiAdapter.flatMap(adapter -> adapter.getCurrentElem().getSDIOrDAI().stream() .filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class)) .map(TDAI.class::cast) - .filter(tdai -> tdai.getName().equals(daiName) && !tdai.getVal().isEmpty()) + .filter(tdai -> tdai.getName().equals("stVal") && !tdai.getVal().isEmpty()) .map(tdai -> tdai.getVal().get(0)) .findFirst()); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java deleted file mode 100644 index 10a5a01d5..000000000 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-FileCopyrightText: 2022 2025 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.ldevice; - -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.lfenergy.compas.scl2007b4.model.TLNode; -import org.lfenergy.compas.sct.commons.dto.SclReportItem; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; - -class LDeviceActivationTest { - - - @ParameterizedTest - @ValueSource(strings = {"on", "on;off"}) - void checkLDeviceActivationStatus_shouldReturnNoError_when_LNodeStatusON_Or_ON_OFF(String lNodeStatus) { - // Given - TLNode tlNode = new TLNode(); - tlNode.setIedName("iedName1"); - tlNode.setLdInst("ldInst1"); - List tlNodes = List.of(tlNode); - LDeviceActivation lDeviceActivation = new LDeviceActivation(tlNodes); - List sclReportItems = new ArrayList<>(); - // When - lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst1", lNodeStatus, Set.of("on"), sclReportItems); - // Then - assertThat(lDeviceActivation.isUpdatable()).isTrue(); - assertThat(sclReportItems).isEmpty(); - assertThat(lDeviceActivation.getNewVal()).isEqualTo("on"); - } - - @ParameterizedTest - @ValueSource(strings = {"on", "on;off"}) - void checkLDeviceActivationStatus_shouldDeactivate_when_LDeviceNotReferencedINLNode(String lNodeStatus) { - // Given - List tlNodes = List.of(); - LDeviceActivation lDeviceActivation = new LDeviceActivation(tlNodes); - List sclReportItems = new ArrayList<>(); - // When - lDeviceActivation.checkLDeviceActivationStatus("iedName1", "ldInst2", lNodeStatus, Set.of("on"), sclReportItems); - - // Then - assertThat(lDeviceActivation.isUpdatable()).isTrue(); - assertThat(lDeviceActivation.getNewVal()).isEqualTo("off"); - } - -} \ No newline at end of file diff --git a/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_OFF.scd b/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_OFF.scd deleted file mode 100644 index f21cb6899..000000000 --- a/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_OFF.scd +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - SCD - -
- - - -
- - - 0 - - - - - - - - - - - - - off - - - - - - - - - - - -
-

00000001

-
-
-
- - -
-

Adresse IP du serveur Syslog

-
-
-
-
- - SAMU - SAMU - - - - - - - - - - - - off - - - 01.00.000 - - - 01.00.000 - - - - - off - - - - - - - - - - - - - - - - - - - - - - - on - off - blocked - test - test/blocked - - -
diff --git a/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ON.scd b/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ON.scd deleted file mode 100644 index a4e1e65bb..000000000 --- a/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ON.scd +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - SCD - -
- - - -
- - - 0 - - - - - - - - - - - - - on - - - - - - - - - - - -
-

00000001

-
-
-
- - -
-

Adresse IP du serveur Syslog

-
-
-
-
- - SAMU - SAMU - - - - - - - - - - - - on - - - 01.00.000 - - - 01.00.000 - - - - - off - - - - - - - - - - - - - - - - - - - - - - - on - off - blocked - test - test/blocked - - -
diff --git a/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ONOFF.scd b/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ONOFF.scd deleted file mode 100644 index a11e224ec..000000000 --- a/sct-commons/src/test/resources/scd-refresh-lnode/Test_LD_STATUS_ONOFF.scd +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - SCD - -
- - - -
- - - 0 - - - - - - - - - - - - - on;off - - - - - - - - - - - -
-

00000001

-
-
-
- - -
-

Adresse IP du serveur Syslog

-
-
-
-
- - SAMU - SAMU - - - - - - - - - - - - on;off - - - 01.00.000 - - - 01.00.000 - - - - - off - - - - - - - - - - - - - - - - - - - - - - - on - off - blocked - test - test/blocked - - -
diff --git a/sct-commons/src/test/resources/scd-refresh-lnode/Test_NOK_MissingLNodeStatusPrivate.scd b/sct-commons/src/test/resources/scd-refresh-lnode/Test_NOK_MissingLNodeStatusPrivate.scd deleted file mode 100644 index 823c95d9c..000000000 --- a/sct-commons/src/test/resources/scd-refresh-lnode/Test_NOK_MissingLNodeStatusPrivate.scd +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - SCD - -
- - - -
- - - 0 - - - - - - - - - - - - - on - - - - - - - - - - - -
-

00000001

-
-
-
- - -
-

Adresse IP du serveur Syslog

-
-
-
-
- - SAMU - SAMU - - - - - - - - - - - - - - 01.00.000 - - - 01.00.000 - - - - - off - - - - - - - - - - - - - - - - - - - - - - - blocked - test - test/blocked - off - on - - - -