diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java new file mode 100644 index 000000000..b08a5fc29 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2024 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.*; + +import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME; +import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME; + +public class DataTypeTemplatesService { + + final LnodeTypeService lnodeTypeService = new LnodeTypeService(); + final DoTypeService doTypeService = new DoTypeService(); + final DoService doService = new DoService(); + + /** + * verify if DO(name=Mod)/DA(name=stVal) exists in DataTypeTemplate + * @param dtt TDataTypeTemplates where Data object and Data attribute exists + * @param lNodeTypeId LNode Type ID where Data object exists + * DataTypeTemplates model : + * + * + * + * + * ... + * + * + * + * + * @return true if the Data Object (Mod) and Data attribute (stVal) present, false otherwise + */ + public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId) { + return lnodeTypeService.findLnodeType(dtt, lNodeType -> lNodeTypeId.equals(lNodeType.getId())) + .map(lNodeType -> doService.findDo(lNodeType, tdo -> MOD_DO_NAME.equals(tdo.getName())) + .map(tdo -> doTypeService.findDoType(dtt, doType -> tdo.getType().equals(doType.getId())) + .map(doType -> doType.getSDOOrDA().stream() + .filter(sdoOrDa -> sdoOrDa.getClass().equals(TDA.class)) + .map(TDA.class::cast) + .anyMatch(tda -> STVAL_DA_NAME.equals(tda.getName()))) + .orElse(false)) + .orElse(false)) + .orElse(false); + } +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java index 266750f3e..d221e4492 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java @@ -44,8 +44,10 @@ public class ExtRefEditorService implements ExtRefEditor { "7", "THT" ); + private final IedService iedService; private final LdeviceService ldeviceService; private final ExtRefService extRefService; + private final DataTypeTemplatesService dataTypeTemplatesService; /** * Provides valid IED sources according to EPF configuration.
@@ -78,6 +80,37 @@ private static List getIedSources(SclRootAdapter sclRootAdapter, TCompasBa .toList(); } + /** + * Provides a list of ExtRef and associated Bay
+ * - The location of ExtRef should be in LDevice (inst=LDEPF)
+ * - ExtRef that lacks Bay or ICDHeader Private is not returned
+ * + * @param sclReportItems List of SclReportItem + * @return list of ExtRef and associated Bay + */ + private List getExtRefWithBayReferenceInLDEPF(TDataTypeTemplates dataTypeTemplates, TIED tied, final TLDevice tlDevice, final List sclReportItems) { + List extRefBayReferenceList = new ArrayList<>(); + String lDevicePath = "SCL/IED[@name=\""+ tied.getName() + "\"]/AccessPoint/Server/LDevice[@inst=\"" + tlDevice.getInst() + "\"]"; + Optional tCompasBay = PrivateUtils.extractCompasPrivate(tied, TCompasBay.class); + if (tCompasBay.isEmpty()) { + sclReportItems.add(SclReportItem.error(lDevicePath, "The IED has no Private Bay")); + if (PrivateUtils.extractCompasPrivate(tied, TCompasICDHeader.class).isEmpty()) { + sclReportItems.add(SclReportItem.error(lDevicePath, "The IED has no Private compas:ICDHeader")); + } + return Collections.emptyList(); + } + + if (dataTypeTemplatesService.isDoModAndDaStValExist(dataTypeTemplates, tlDevice.getLN0().getLnType())) { + extRefBayReferenceList.addAll(tlDevice.getLN0() + .getInputs() + .getExtRef().stream() + .map(extRef -> new ExtRefInfo.ExtRefWithBayReference(tied.getName(), tCompasBay.get(), extRef)).toList()); + } else { + sclReportItems.add(SclReportItem.error(lDevicePath, "DO@name=Mod/DA@name=stVal not found in DataTypeTemplate")); + } + return extRefBayReferenceList; + } + /** * Verify if an Extref matches the EPF Channel or not. * @@ -266,29 +299,27 @@ public List updateAllExtRefIedNames(SCL scd) { @Override public List manageBindingForLDEPF(SCL scd, EPF epf) { List sclReportItems = new ArrayList<>(); - if (!epf.isSetChannels()) return sclReportItems; SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - sclRootAdapter.streamIEDAdapters() - .filter(iedAdapter -> !iedAdapter.getName().contains("TEST")) - .map(iedAdapter -> iedAdapter.findLDeviceAdapterByLdInst(LDEVICE_LDEPF)) - .flatMap(Optional::stream) - .forEach(lDeviceAdapter -> lDeviceAdapter.getExtRefBayReferenceForActifLDEPF(sclReportItems) - .forEach(extRefBayRef -> epf.getChannels().getChannel().stream().filter(tChannel -> doesExtRefMatchLDEPFChannel(extRefBayRef.extRef(), tChannel)) - .findFirst().ifPresent(channel -> { - List iedSources = getIedSources(sclRootAdapter, extRefBayRef.compasBay(), channel); - if (iedSources.size() == 1) { - updateLDEPFExtRefBinding(extRefBayRef.extRef(), iedSources.get(0), channel); - sclReportItems.addAll(updateLDEPFDos(lDeviceAdapter, extRefBayRef.extRef(), channel)); - } else { - if (iedSources.size() > 1) { - sclReportItems.add(SclReportItem.warning(null, "There is more than one IED source to bind the signal " + - "/IED@name=" + extRefBayRef.iedName() + "/LDevice@inst=LDEPF/LN0" + - "/ExtRef@desc=" + extRefBayRef.extRef().getDesc())); - } - // If the source IED is not found, there will be no update or report message. - } - })) - ); + if (!epf.isSetChannels()) return sclReportItems; + iedService.getFilteredIeds(scd, ied -> !ied.getName().contains("TEST")) + .forEach(tied -> ldeviceService.findLdevice(tied, tlDevice -> LDEVICE_LDEPF.equals(tlDevice.getInst())) + .ifPresent(tlDevice -> getExtRefWithBayReferenceInLDEPF(scd.getDataTypeTemplates(), tied, tlDevice, sclReportItems) + .forEach(extRefBayRef -> epf.getChannels().getChannel().stream().filter(tChannel -> doesExtRefMatchLDEPFChannel(extRefBayRef.extRef(), tChannel)) + .findFirst().ifPresent(channel -> { + List iedSources = getIedSources(sclRootAdapter, extRefBayRef.compasBay(), channel); + if (iedSources.size() == 1) { + updateLDEPFExtRefBinding(extRefBayRef.extRef(), iedSources.get(0), channel); + LDeviceAdapter lDeviceAdapter = new LDeviceAdapter(new IEDAdapter(sclRootAdapter, tied.getName()), tlDevice); + sclReportItems.addAll(updateLDEPFDos(lDeviceAdapter, extRefBayRef.extRef(), channel)); + } else { + if (iedSources.size() > 1) { + sclReportItems.add(SclReportItem.warning(null, "There is more than one IED source to bind the signal " + + "/IED@name=" + extRefBayRef.iedName() + "/LDevice@inst=LDEPF/LN0" + + "/ExtRef@desc=" + extRefBayRef.extRef().getDesc())); + } + // If the source IED is not found, there will be no update or report message. + } + })))); return sclReportItems; } @@ -404,7 +435,6 @@ private String computeDaiValue(AbstractLNAdapter lnAdapter, TExtRef extRef, S @Override public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd) { - LdeviceService ldeviceService = new LdeviceService(); scd.getSubstation() .stream() .flatMap(tSubstation -> tSubstation.getVoltageLevel().stream()) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java index fa8b2d300..21c492123 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java @@ -99,6 +99,6 @@ && trimToEmpty(tfcda.getLnInst()).equals(trimToEmpty(bindingInfo.getLnInst())) * @param compasBay The Bay object * @param extRef The ExtRef object */ - public record ExtRefBayReference(String iedName, TCompasBay compasBay, TExtRef extRef){ } + public record ExtRefWithBayReference(String iedName, TCompasBay compasBay, TExtRef extRef){ } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java index 10a49ae39..46ebb27f5 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java @@ -50,7 +50,6 @@ public class InputsAdapter extends SclElementAdapter { private static final String MESSAGE_INVALID_SERVICE_TYPE = "The signal ExtRef ServiceType attribute is unexpected : %s"; private static final String MESSAGE_IED_MISSING_COMPAS_BAY_UUID = "IED is missing Private/compas:Bay@UUID attribute"; private static final String MESSAGE_EXTREF_DESC_MALFORMED = "ExtRef.serviceType=Report but ExtRef.desc attribute is malformed"; - private static final String MESSAGE_LDEVICE_STATUS_UNDEFINED = "The LDevice status is undefined"; private static final String MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID = "The signal ExtRef iedName does not match any " + "IED/Private/compas:ICDHeader@ICDSystemVersionUUID"; private static final String MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED = "The signal ExtRef source LDevice %s status is undefined"; @@ -98,7 +97,7 @@ protected String elementXPath() { public List updateAllExtRefIedNames(Map icdSystemVersionToIed) { Optional optionalLDeviceStatus = getLDeviceAdapter().getLDeviceStatus(); if (optionalLDeviceStatus.isEmpty()) { - return List.of(getLDeviceAdapter().buildFatalReportItem(MESSAGE_LDEVICE_STATUS_UNDEFINED)); + optionalLDeviceStatus = Optional.of(ActiveStatus.ON.getValue()); } try { ActiveStatus lDeviceStatus = ActiveStatus.fromValue(optionalLDeviceStatus.get()); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java index 15d8ae935..26c1361c2 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java @@ -27,8 +27,6 @@ import java.util.*; -import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.MOD_DO_TYPE_NAME; -import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.STVAL_DA_TYPE_NAME; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; import static org.lfenergy.compas.sct.commons.util.Utils.copySclElement; @@ -489,33 +487,6 @@ private String createVal(TExtRef tExtRef) { return sourceLdName + "/" + lnClass + "." + tExtRef.getSrcCBName(); } - /** - * Provides a list of ExtRef and associated Bay
- * - The location of ExtRef should be in an active LDevice (inst=LDEPF)
- * - ExtRef that lacks Bay or ICDHeader Private is not returned
- * - * @param sclReportItems List of SclReportItem - * @return list of ExtRef and associated Bay - */ - public List getExtRefBayReferenceForActifLDEPF(final List sclReportItems) { - List extRefBayReferenceList = new ArrayList<>(); - IEDAdapter parentIedAdapter = getParentAdapter(); - if (parentIedAdapter.getPrivateCompasBay().isEmpty()) { - sclReportItems.add(SclReportItem.error(getXPath(), "The IED has no Private Bay")); - if (parentIedAdapter.getCompasICDHeader().isEmpty()) { - sclReportItems.add(SclReportItem.error(getXPath(), "The IED has no Private compas:ICDHeader")); - } - return Collections.emptyList(); - } - - getLDeviceStatus().map(ActiveStatus::fromValue).ifPresentOrElse(s -> { - if (ActiveStatus.ON.equals(s)) { - extRefBayReferenceList.addAll(getLN0Adapter().getInputsAdapter().getCurrentElem().getExtRef().stream().map(extRef -> new ExtRefInfo.ExtRefBayReference(parentIedAdapter.getName(), parentIedAdapter.getPrivateCompasBay().get(), extRef)).toList()); - } - }, () -> sclReportItems.add(SclReportItem.error(getXPath(), "There is no DOI@name=" + MOD_DO_TYPE_NAME + "/DAI@name=" + STVAL_DA_TYPE_NAME + "/Val for LDevice@inst" + LDEVICE_LDEPF))); - return extRefBayReferenceList; - } - private TFCDA toFCDA(TFCDAFilter tfcdaFilter) { TFCDA tfcda = new TFCDA(); tfcda.setLdInst(tfcdaFilter.getLdInst()); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java new file mode 100644 index 000000000..ee24a4d86 --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java @@ -0,0 +1,140 @@ +// SPDX-FileCopyrightText: 2024 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl2007b4.model.*; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +class DataTypeTemplatesServiceTest { + + @Test + void isDoModAndDaStValExist_when_LNodeType_not_exist_should_return_false() { + //Given + SCL scl = new SCL(); + TDataTypeTemplates dtt = new TDataTypeTemplates(); + scl.setDataTypeTemplates(dtt); + //When + DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); + boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId"); + //Then + assertThat(result).isFalse(); + } + + + @Test + void isDoModAndDaStValExist_when_Do_not_exist_should_return_false() { + //Given + SCL scl = new SCL(); + TDataTypeTemplates dtt = new TDataTypeTemplates(); + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.setId("lnodeTypeId"); + dtt.getLNodeType().add(tlNodeType); + scl.setDataTypeTemplates(dtt); + //When + DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); + boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId"); + //Then + assertThat(result).isFalse(); + } + + @Test + void isDoModAndDaStValExist_when_DoType_not_exist_should_return_false() { + //Given + SCL scl = new SCL(); + TDataTypeTemplates dtt = new TDataTypeTemplates(); + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.setId("lnodeTypeId"); + TDO tdo = new TDO(); + tdo.setType("doTypeId"); + tdo.setName("Mod"); + tlNodeType.getDO().add(tdo); + dtt.getLNodeType().add(tlNodeType); + //When + DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); + boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId"); + //Then + assertThat(result).isFalse(); + } + + + @Test + void isDoModAndDaStValExist_when_Da_Mod_not_exist_should_return_false() { + //Given + SCL scl = new SCL(); + TDataTypeTemplates dtt = new TDataTypeTemplates(); + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.setId("lnodeTypeId"); + TDO tdo = new TDO(); + tdo.setType("doTypeId"); + tdo.setName("Mod"); + tlNodeType.getDO().add(tdo); + dtt.getLNodeType().add(tlNodeType); + TDOType tdoType = new TDOType(); + tdoType.setId("doTypeId"); + dtt.getDOType().add(tdoType); + scl.setDataTypeTemplates(dtt); + //When + DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); + boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId"); + //Then + assertThat(result).isFalse(); + } + + + @Test + void isDoModAndDaStValExist_when_Da_stVal_not_found_should_return_false() { + //Given + SCL scl = new SCL(); + TDataTypeTemplates dtt = new TDataTypeTemplates(); + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.setId("lnodeTypeId"); + TDO tdo = new TDO(); + tdo.setType("doTypeId"); + tdo.setName("Mod"); + tlNodeType.getDO().add(tdo); + dtt.getLNodeType().add(tlNodeType); + TDOType tdoType = new TDOType(); + tdoType.setId("doTypeId"); + TDA tda = new TDA(); + tda.setName("daName"); + tdoType.getSDOOrDA().add(tda); + dtt.getDOType().add(tdoType); + scl.setDataTypeTemplates(dtt); + //When + DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); + boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId"); + //Then + assertThat(result).isFalse(); + } + + + @Test + void isDoModAndDaStValExist_when_DO_Mod_And_DA_stVal_exist_return_true() { + //Given + SCL scl = new SCL(); + TDataTypeTemplates dtt = new TDataTypeTemplates(); + TLNodeType tlNodeType = new TLNodeType(); + tlNodeType.setId("lnodeTypeId"); + TDO tdo = new TDO(); + tdo.setType("doTypeId"); + tdo.setName("Mod"); + tlNodeType.getDO().add(tdo); + dtt.getLNodeType().add(tlNodeType); + TDOType tdoType = new TDOType(); + tdoType.setId("doTypeId"); + TDA tda = new TDA(); + tda.setName("stVal"); + tdoType.getSDOOrDA().add(tda); + dtt.getDOType().add(tdoType); + scl.setDataTypeTemplates(dtt); + //When + DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); + boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId"); + //Then + assertThat(result).isTrue(); + } +} \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java index 5ad2eae78..32dd52463 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefEditorServiceTest.java @@ -39,7 +39,7 @@ class ExtRefEditorServiceTest { @BeforeEach void init() { - extRefEditorService = new ExtRefEditorService(new LdeviceService(), new ExtRefService()); + extRefEditorService = new ExtRefEditorService(new IedService(), new LdeviceService(), new ExtRefService(), new DataTypeTemplatesService()); } @Test @@ -102,9 +102,11 @@ public static Stream updateAllExtRefIedNamesErrors() { SclReportItem.error( "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST13\"]", "The status test does not exist. It should be among [on, off]"), - SclReportItem.error( - "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST14\"]", - "The LDevice status is undefined"), + SclReportItem.warning( + "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/" + + "LDevice[@inst=\"LD_INST14\"]/LN0/Inputs/ExtRef[@desc=\"STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1\"]", + "The signal ExtRef lninst, doName or daName does not match any source " + + "in LDevice /SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST14\"]"), SclReportItem.warning( "/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" + "/LN0/Inputs/ExtRef[@desc=\"ExtRef does not match any ICDSystemVersionUUID\"]", @@ -496,6 +498,112 @@ void manageBindingForLDEPF_when_extRefMatchFlowKindInternalOrExternal_should_upd assertThat(extRefBindExternally.getIedName()).isEqualTo("IED_NAME2"); assertExtRefIsBoundAccordingTOLDEPF(extRefBindExternally, analogueChannel10WithBayExternalBayScope); } + + @Test + void manageBindingForLDEPF_when_DOI_Mod_and_DAI_stVal_notExists_should_precede() { + // Given + SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_withoutModStValInLN0.xml"); + // When + TChannel channel = new TChannel(); + channel.setBayScope(TCBscopeType.BAY_INTERNAL); + channel.setChannelType(TChannelType.DIGITAL); + channel.setChannelNum("1"); + channel.setChannelShortLabel("MR.PX1"); + channel.setChannelLevMod(TChannelLevMod.POSITIVE_OR_RISING); + channel.setChannelLevModQ(TChannelLevMod.OTHER); + channel.setIEDType("BCU"); + channel.setIEDRedundancy(TIEDredundancy.NONE); + channel.setIEDSystemVersionInstance("1"); + channel.setLDInst("LDPX"); + channel.setLNClass("PTRC"); + channel.setLNInst("0"); + channel.setDOName("Str"); + channel.setDOInst("0"); + channel.setDAName("general"); + + EPF epf = new EPF(); + Channels channels = new Channels(); + channels.getChannel().add(channel); + epf.setChannels(channels); + List sclReportItems = extRefEditorService.manageBindingForLDEPF(scd, epf); + // Then + assertThat(sclReportItems).isEmpty(); + TExtRef extRef1 = findExtRef(scd, "IED_NAME1", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"); + assertThat(extRef1.getIedName()).isEqualTo("IED_NAME1"); + TExtRef extRef2 = findExtRef(scd, "IED_NAME2", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"); + assertThat(extRef2.getIedName()).isEqualTo("IED_NAME2"); + TExtRef extRef3 = findExtRef(scd, "IED_NAME3", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"); + assertThat(extRef3.getIedName()).isEqualTo("IED_NAME1"); + + assertExtRefIsBoundAccordingTOLDEPF(extRef1, channel); + assertExtRefIsBoundAccordingTOLDEPF(extRef2, channel); + assertExtRefIsBoundAccordingTOLDEPF(extRef3, channel); + } + + @Test + void manageBindingForLDEPF_when_LDEPF_NotActive_should_precede() { + //Given + SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_with_inactive_ldevice_ldepf.xml"); + TChannel channel = new TChannel(); + channel.setBayScope(TCBscopeType.BAY_INTERNAL); + channel.setChannelType(TChannelType.DIGITAL); + channel.setChannelNum("1"); + channel.setChannelShortLabel("MR.PX1"); + channel.setChannelLevMod(TChannelLevMod.POSITIVE_OR_RISING); + channel.setChannelLevModQ(TChannelLevMod.OTHER); + channel.setIEDType("BCU"); + channel.setIEDRedundancy(TIEDredundancy.NONE); + channel.setIEDSystemVersionInstance("1"); + channel.setLDInst("LDPX"); + channel.setLNClass("PTRC"); + channel.setLNInst("0"); + channel.setDOName("Str"); + channel.setDOInst("0"); + channel.setDAName("general"); + + EPF epf = new EPF(); + Channels channels = new Channels(); + channels.getChannel().add(channel); + epf.setChannels(channels); + // When + List sclReportItems = extRefEditorService.manageBindingForLDEPF(scd, epf); + // Then + assertThat(sclReportItems).isEmpty(); + TExtRef extRef1 = findExtRef(scd, "IED_NAME1", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"); + assertThat(extRef1.getIedName()).isEqualTo("IED_NAME1"); + TExtRef extRef2 = findExtRef(scd, "IED_NAME2", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"); + assertThat(extRef2.getIedName()).isEqualTo("IED_NAME2"); + TExtRef extRef3 = findExtRef(scd, "IED_NAME3", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"); + assertThat(extRef3.getIedName()).isEqualTo("IED_NAME1"); + + assertExtRefIsBoundAccordingTOLDEPF(extRef1, channel); + assertExtRefIsBoundAccordingTOLDEPF(extRef2, channel); + assertExtRefIsBoundAccordingTOLDEPF(extRef3, channel); + } + + @Test + void manageBindingForLDEPF_when_DO_Mod_and_DA_stVal_NotFoundInDataTypeTemplate_should_return_error() { + // Given + SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_withoutModStValInDataTypeTemplate.xml"); + // When + EPF epf = new EPF(); + epf.setChannels(new Channels()); + List sclReportItems = extRefEditorService.manageBindingForLDEPF(scd, epf); + // Then + assertThat(sclReportItems).hasSize(3); + assertThat(sclReportItems) + .extracting(SclReportItem::message, SclReportItem::xpath) + .containsExactly( + Tuple.tuple("DO@name=Mod/DA@name=stVal not found in DataTypeTemplate", + "SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LDEPF\"]"), + Tuple.tuple("DO@name=Mod/DA@name=stVal not found in DataTypeTemplate", + "SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LDEPF\"]"), + Tuple.tuple("DO@name=Mod/DA@name=stVal not found in DataTypeTemplate", + "SCL/IED[@name=\"IED_NAME3\"]/AccessPoint/Server/LDevice[@inst=\"LDEPF\"]") + ); + } + + private void assertExtRefIsBoundAccordingTOLDEPF(TExtRef extRef, TChannel setting) { assertThat(extRef.getLdInst()).isEqualTo(setting.getLDInst()); assertThat(extRef.getLnClass()).contains(setting.getLNClass()); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java index 92a570c6b..9378964a9 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java @@ -23,14 +23,11 @@ import org.opentest4j.AssertionFailedError; import java.nio.charset.StandardCharsets; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Named.named; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; @@ -310,4 +307,15 @@ void filterDuplicatedExtRefs_should_not_remove_not_duplicated_extrefs() { .hasSize(6); } + @Test + void updateAllExtRefIedNames_when_DOI_Mod_and_DAI_stVal_notExists_should_not_produce_error() { + // Given + SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd"); + InputsAdapter inputsAdapter = findInputs(scl, "IedName1", "LDSUIED"); + // When + List sclReportItems = inputsAdapter.updateAllExtRefIedNames(Map.of()); + // Then + assertThat(sclReportItems).isEmpty(); + } + } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java index f97034241..c39113499 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java @@ -33,10 +33,7 @@ import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.MOD_DO_TYPE_NAME; -import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.STVAL_DA_TYPE_NAME; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; -import static org.lfenergy.compas.sct.commons.util.CommonConstants.LDEVICE_LDEPF; import static org.lfenergy.compas.sct.commons.util.ControlBlockEnum.*; import static org.lfenergy.compas.sct.commons.util.Utils.copySclElement; @@ -609,70 +606,6 @@ void manageMonitoringLns_when_2_extRef_and_dai_updatable_should_update_ln(String .containsExactly("LD_Name/LLN0.CB_Name_1", "LD_Name/LLN0.CB_Name_2"); } - @Test - void getExtRefBuyReferenceForActifLDEPF_when_LDEPF_active_and_bay_exists_should_return_existingExtRef() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - LDeviceAdapter lDeviceAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME1").getLDeviceAdapterByLdInst("LDEPF"); - // When - List sclReportItems = new ArrayList<>(); - List extRefBayReferences = lDeviceAdapter.getExtRefBayReferenceForActifLDEPF(sclReportItems); - // Then - assertThat(extRefBayReferences).hasSize(1); - assertThat(sclReportItems).isEmpty(); - } - - @Test - void getExtRefBayReferenceForActifLDEPF_when_NoPrivateBuyNorIcdHeader_should_return_fatal_errors() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME1"); - iedAdapter.getCurrentElem().getPrivate().clear(); - LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst("LDEPF"); - // When - List sclReportItems = new ArrayList<>(); - List extRefBayReferences = lDeviceAdapter.getExtRefBayReferenceForActifLDEPF(sclReportItems); - // Then - assertThat(extRefBayReferences).isEmpty(); - assertThat(sclReportItems).hasSize(2); - assertThat(sclReportItems) - .extracting(SclReportItem::message) - .contains("The IED has no Private Bay", "The IED has no Private compas:ICDHeader"); - } - - @Test - void getExtRefBayReferenceForActifLDEPF_when_DOI_Mod_notExists_should_return_fatal_errors() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - LDeviceAdapter lDeviceAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME3").getLDeviceAdapterByLdInst("LDEPF"); - // When - List sclReportItems = new ArrayList<>(); - List extRefBayReferences = lDeviceAdapter.getExtRefBayReferenceForActifLDEPF(sclReportItems); - // Then - assertThat(extRefBayReferences).isEmpty(); - assertThat(sclReportItems).hasSize(1); - assertThat(sclReportItems) - .extracting(SclReportItem::message) - .containsExactly("There is no DOI@name=" + MOD_DO_TYPE_NAME + "/DAI@name=" + STVAL_DA_TYPE_NAME + "/Val for LDevice@inst" + LDEVICE_LDEPF); - } - - @Test - void getExtRefBayReferenceForActifLDEPF_when_LDEPF_NotActive_should_not_return_existingExtRef() { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_extrefbayRef.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - LDeviceAdapter lDeviceAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME2").getLDeviceAdapterByLdInst("LDEPF"); - // When - List sclReportItems = new ArrayList<>(); - List extRefBayReferences = lDeviceAdapter.getExtRefBayReferenceForActifLDEPF(sclReportItems); - // Then - assertThat(extRefBayReferences).isEmpty(); - assertThat(sclReportItems).isEmpty(); - } - private static Stream provideLnClassAndDoType() { return Stream.of( Arguments.of("Case GOOSE : ln LGOS", MonitoringLnClassEnum.LGOS, DO_GOCBREF, TServiceType.GOOSE), diff --git a/sct-commons/src/test/resources/scd-ldepf/scd_ldepf_withoutModStValInDataTypeTemplate.xml b/sct-commons/src/test/resources/scd-ldepf/scd_ldepf_withoutModStValInDataTypeTemplate.xml new file mode 100644 index 000000000..befdc3bb3 --- /dev/null +++ b/sct-commons/src/test/resources/scd-ldepf/scd_ldepf_withoutModStValInDataTypeTemplate.xml @@ -0,0 +1,189 @@ + + + + + + + SCD + +
+ + + + + + + + + + + + + + + + + + on + + + + + + + + + + + + on + + + + + + + + + off + + + + + + + + + off + + + + + + + + + + + + + + + + + + + + + + + + on + + + + + + + + + + + + on + + + + + + + + + + + + + + + + + + + + + + + + on + + + + + + + + + + + + on + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + off + blocked + test + test/blocked + + + \ No newline at end of file diff --git a/sct-commons/src/test/resources/scd-ldepf/scd_ldepf_withoutModStValInLN0.xml b/sct-commons/src/test/resources/scd-ldepf/scd_ldepf_withoutModStValInLN0.xml new file mode 100644 index 000000000..8913663fb --- /dev/null +++ b/sct-commons/src/test/resources/scd-ldepf/scd_ldepf_withoutModStValInLN0.xml @@ -0,0 +1,174 @@ + + + + + + + SCD + +
+ + + + + + + + + + + + + + + + + + + + + + + + + on + + + + + + + + + off + + + + + + + + + off + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + off + blocked + test + test/blocked + + + \ No newline at end of file diff --git a/sct-commons/src/test/resources/scd-ldepf/scd_with_inactive_ldevice_ldepf.xml b/sct-commons/src/test/resources/scd-ldepf/scd_with_inactive_ldevice_ldepf.xml new file mode 100644 index 000000000..f85ff6180 --- /dev/null +++ b/sct-commons/src/test/resources/scd-ldepf/scd_with_inactive_ldevice_ldepf.xml @@ -0,0 +1,189 @@ + + + + + + + SCD + +
+ + + + + + + + + + + + + + + + + + off + + + + + + + + + + + + on + + + + + + + + + off + + + + + + + + + off + + + + + + + + + + + + + + + + + + + + + + + + off + + + + + + + + + + + + on + + + + + + + + + + + + + + + + + + + + + + + + off + + + + + + + + + + + + on + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + off + blocked + test + test/blocked + + + \ No newline at end of file diff --git a/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd b/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd new file mode 100644 index 000000000..4d99bef72 --- /dev/null +++ b/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd @@ -0,0 +1,124 @@ + + + + + + + SCD + +
+ + + +
+ + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + +
+

00000001

+
+
+
+ + +
+

Adresse IP du serveur Syslog

+
+
+
+
+ + SAMU + SAMU + + + + + + + + + + + + + + + + + 01.00.000 + + + 01.00.000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + blocked + test + test/blocked + off + on + + + +