From 606abc0e8108b771aec9ae792a595c24d6dd4eb7 Mon Sep 17 00:00:00 2001 From: massifben <105049157+massifben@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:06:53 +0200 Subject: [PATCH] feat(#412): RSR-1048 add special case for InRef binding for LDEPF DIGITAL BOOLEAN channels Signed-off-by: massifben <105049157+massifben@users.noreply.github.com> --- .../compas/sct/commons/scl/ln/LN0Adapter.java | 21 +++++--- .../sct/commons/scl/ln/LN0AdapterTest.java | 48 ++++++++++++++++--- .../scd_update_inref_test.xml | 26 +++++++++- 3 files changed, 82 insertions(+), 13 deletions(-) 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 cab641278..49cbf7ada 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 @@ -8,15 +8,16 @@ import org.apache.commons.lang3.tuple.Pair; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.*; -import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation; 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.PrivateUtils; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; import static org.lfenergy.compas.sct.commons.util.CommonConstants.BEHAVIOUR_DO_NAME; @@ -47,9 +48,6 @@ *
  • {@link LN0Adapter#getDAI Returns the value of the DataAttributeRef containment reference By filter}
  • *
  • {@link LN0Adapter#getDAIValues(DataAttributeRef) Returns DAI (sGroup, value) containment reference list By DataAttributeRef filter}
  • * - *
  • {@link LN0Adapter#getDataSetByName(String) Returns the value of the TDataSet object reference By the value of the name attribute }
  • - * - *
  • {@link LN0Adapter#getControlBlocks(List, TServiceType) Returns the value of the ControlBlock containment reference list that match datSet value of given TDataSet }
  • *
  • {@link LN0Adapter#addPrivate Add TPrivate under this object}
  • *
  • {@link LN0Adapter#removeAllControlBlocksAndDatasets() Remove all ControlBlock}
  • * @@ -75,6 +73,7 @@ public class LN0Adapter extends AbstractLNAdapter { public static final DaTypeName BEHAVIOUR_DA_TYPE_NAME = getDaTypeNameForBeh(); private static final String DAI_NAME_PURPOSE = "purpose"; private static final String INREF_PREFIX = "InRef"; + private static final Pattern LDEFP_DIGITAL_CHANNEL_PATTERN = Pattern.compile("DYN_LDEPF_DIGITAL CHANNEL \\d+_\\d+_BOOLEAN"); /** * Constructor @@ -188,7 +187,7 @@ public Optional updateLDeviceStatus(List> ie if (daiBehList.isEmpty()) { return Optional.of(buildFatalReportItem("The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'")); } - Set enumValues = getEnumValues(daiBehList.get(0).getDaName().getType()); + Set enumValues = getEnumValues(daiBehList.getFirst().getDaName().getType()); Optional optionalTCompasLDevice = PrivateUtils.extractCompasPrivate(getParentAdapter().getCurrentElem(), TCompasLDevice.class); if (optionalTCompasLDevice.isEmpty()) { return Optional.of(buildFatalReportItem("The LDevice doesn't have a Private compas:LDevice.")); @@ -237,13 +236,23 @@ public List updateDoInRef() { && doiAdapter.findDataAdapterByName(DAI_NAME_PURPOSE).isPresent()) .map(doiAdapter -> doiAdapter.getDataAdapterByName(DAI_NAME_PURPOSE).getCurrentElem().getVal().stream() .findFirst() - .map(tVal -> doiAdapter.updateDaiFromExtRef(getBoundExtRefsByDesc(tVal.getValue()))) + .map(tVal -> doiAdapter.updateDaiFromExtRef(getExtRefsBoundToInRef(tVal.getValue()))) .orElse(List.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())))) ) .flatMap(List::stream) .collect(Collectors.toList()); } + private List getExtRefsBoundToInRef(String desc) { + List boundExtRefs = getBoundExtRefsByDesc(desc); + // Special case for LDEPF DIGITAL CHANNEL of type BOOLEAN RSR-1048 + if (boundExtRefs.isEmpty() && LDEFP_DIGITAL_CHANNEL_PATTERN.matcher(desc).matches()) { + String descWithoutType = desc.substring(0, desc.lastIndexOf("_")); + return getBoundExtRefsByDesc(descWithoutType); + } + return boundExtRefs; + } + private List getBoundExtRefsByDesc(String desc) { return getExtRefs().stream() .filter(tExtRef -> tExtRef.isSetIedName() && tExtRef.isSetLdInst() && tExtRef.isSetLnClass() && tExtRef.isSetDoName() && diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java index 10233f345..8de69781a 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java @@ -302,7 +302,7 @@ void getControlBlocksForMatchingFCDA_should_return_expected_Items(LN0 ln0, TServ List controlBlocks = ln0Adapter.getControlBlocksForMatchingFCDA(extRefInfo).toList(); // Then assertThat(controlBlocks).hasSize(1); - assertThat(controlBlocks.get(0).getServiceType()).isEqualTo(serviceType); + assertThat(controlBlocks.getFirst().getServiceType()).isEqualTo(serviceType); } private static Stream provideServiceType() { @@ -335,7 +335,7 @@ void getDOIAdapters_should_return_expected_list_of_DOIAdapter() { LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); // When Then assertThat(ln0Adapter.getDOIAdapters()).isNotEmpty(); - assertThat(ln0Adapter.getDOIAdapters().get(0).getCurrentElem().getName()).isEqualTo("Do"); + assertThat(ln0Adapter.getDOIAdapters().getFirst().getCurrentElem().getName()).isEqualTo("Do"); } @Test @@ -434,7 +434,7 @@ void testFindMatch() { // When Then AbstractDAIAdapter daiAdapter = (AbstractDAIAdapter) assertDoesNotThrow(() -> ln0Adapter.findMatch(doTypeName, daTypeName).get()); assertThat(daiAdapter.getCurrentElem().getName()).isEqualTo("bda3"); - assertThat(daiAdapter.getCurrentElem().getVal().get(0).getValue()).isEqualTo("Completed-diff"); + assertThat(daiAdapter.getCurrentElem().getVal().getFirst().getValue()).isEqualTo("Completed-diff"); DoTypeName doTypeName2 = new DoTypeName("Do.sdo1"); // When Then assertThat(ln0Adapter.findMatch(doTypeName2, daTypeName)).isEmpty(); @@ -540,7 +540,7 @@ void testGetDAI() { var dataAttributeRefs = ln0Adapter.getDAI(filter, false); // Then assertThat(dataAttributeRefs).hasSize(1); - assertThat(dataAttributeRefs.get(0).getDaName().getType()).isEqualTo("BehaviourModeKind"); + assertThat(dataAttributeRefs.getFirst().getDaName().getType()).isEqualTo("BehaviourModeKind"); } @Test @@ -864,7 +864,7 @@ void createControlBlockIfNotExists_should_create_SampledValueControl() { // Then assertThat(sourceLn0.getCurrentElem().getSampledValueControl()) .hasSize(1); - TSampledValueControl tSampledValueControl = sourceLn0.getCurrentElem().getSampledValueControl().get(0); + TSampledValueControl tSampledValueControl = sourceLn0.getCurrentElem().getSampledValueControl().getFirst(); assertThat(tSampledValueControl) .extracting(TControl::getName, TSampledValueControl::getSmvID, TControl::getDatSet, TSampledValueControl::isMulticast, TSampledValueControl::getSmpRate, TSampledValueControl::getNofASDU, TSampledValueControl::getSmpMod, TSampledValueControl::getSecurityEnable, @@ -895,7 +895,7 @@ void createControlBlockIfNotExists_should_create_ReportControl() { // Then assertThat(sourceLn0.getCurrentElem().getReportControl()) .hasSize(1); - TReportControl tReportControl = sourceLn0.getCurrentElem().getReportControl().get(0); + TReportControl tReportControl = sourceLn0.getCurrentElem().getReportControl().getFirst(); assertThat(tReportControl) .extracting(TControl::getName, TReportControl::getRptID, TControl::getDatSet, TReportControl::isBuffered, TReportControl::getBufTime, TReportControl::isIndexed, TControlWithTriggerOpt::getIntgPd, TReportControl::getConfRev) @@ -1140,6 +1140,42 @@ void updateDoInRef_when_ExtRef_desc_matches_should_update_setSrcRef_and_setSrcCB assertThat(sclReportItems).isEmpty(); } + @Test + void updateDoInRef_when_DAI_purpose_of_Ldevice_LDEPF_ends_with_BOOLEAN_should_match_desc_that_ends_with_enum_and_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTstCB() { + // Given + SCL scd = SclTestMarshaller.getSCLFromFile("/scd-test-update-inref/scd_update_inref_test.xml"); + LN0Adapter sourceLn0 = findLn0(scd, "IED_NAME1", "LDEPF"); + String doiNameInRef = "InRef3"; + String originalSetSrcCB = getDaiValue(sourceLn0, doiNameInRef, SETSRCCB_DA_NAME); + String expectedSrcRef = "IED_NAME1LDEPF/PRANCR1.Do11.sdo11"; + String expectedSrcCb = "IED_NAME1LDEPF/prefixANCR1.GSE1"; + String originalSetTstCB = getDaiValue(sourceLn0, doiNameInRef, SETTSTCB_DA_NAME); + String expectedTstRef = "IED_NAME1LDEPF/PRANCR1.Do11.sdo11"; + String expectedTstCB = "IED_NAME1LDEPF/prefixANCR3.GSE3"; + + // When + List sclReportItems = sourceLn0.updateDoInRef(); + // Then + + String finalSetSrcRef = getDaiValue(sourceLn0, doiNameInRef, SETSRCREF_DA_NAME); + String finalSetSrcCB = getDaiValue(sourceLn0, doiNameInRef, SETSRCCB_DA_NAME); + String finalSetTstRef = getDaiValue(sourceLn0, doiNameInRef, SETTSTREF_DA_NAME); + String finalSetTstCB = getDaiValue(sourceLn0, doiNameInRef, SETTSTCB_DA_NAME); + assertThat(finalSetSrcRef) + .isNotBlank() + .isEqualTo(expectedSrcRef); + assertThat(finalSetSrcCB) + .isNotEqualTo(originalSetSrcCB) + .isEqualTo(expectedSrcCb); + assertThat(finalSetTstRef) + .isNotBlank() + .isEqualTo(expectedTstRef); + assertThat(finalSetTstCB) + .isNotEqualTo(originalSetTstCB) + .isEqualTo(expectedTstCB); + assertThat(sclReportItems).isEmpty(); + } + @Test void updateDoInRef_when_ExtRef_desc_matches_and_dais_not_updatable_should_not_update_setSrcRef_and_setSrcCB_and_setTstRef_and_setTstCB() { // Given diff --git a/sct-commons/src/test/resources/scd-test-update-inref/scd_update_inref_test.xml b/sct-commons/src/test/resources/scd-test-update-inref/scd_update_inref_test.xml index 8cc947077..0a3bbea4f 100644 --- a/sct-commons/src/test/resources/scd-test-update-inref/scd_update_inref_test.xml +++ b/sct-commons/src/test/resources/scd-test-update-inref/scd_update_inref_test.xml @@ -67,6 +67,30 @@ + + + + + + DYN_LDEPF_DIGITAL CHANNEL 36_1_BOOLEAN + + + + OLD_VAL + + + + OLD_VAL + + + + + + + + + + @@ -179,4 +203,4 @@ - \ No newline at end of file +