From d83efeb9e75cb821b7e8feeb41db43987c5d1987 Mon Sep 17 00:00:00 2001 From: Samir Romdhani Date: Mon, 9 Dec 2024 11:30:39 +0100 Subject: [PATCH] feat / review deconstructing compas-flow Signed-off-by: Samir Romdhani --- .../sct/commons/ExtRefEditorService.java | 52 -------- .../sct/commons/ExtRefEditorServiceTest.java | 1 - .../commons/scl/ied/InputsAdapterTest.java | 57 ++------ ...t_Missing_ModstVal_In_LN0_when_binding.scd | 124 ------------------ 4 files changed, 10 insertions(+), 224 deletions(-) delete mode 100644 sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd 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 e68ddd7c8..221b133f5 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 @@ -15,19 +15,15 @@ import org.lfenergy.compas.sct.commons.model.epf.TCBScopeType; import org.lfenergy.compas.sct.commons.model.epf.TChannel; import org.lfenergy.compas.sct.commons.model.epf.TChannelType; -import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.ActiveStatus; -import org.lfenergy.compas.sct.commons.util.PrivateEnum; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import org.lfenergy.compas.sct.commons.util.Utils; -import java.math.BigInteger; import java.util.*; -import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.*; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; @@ -325,48 +321,6 @@ public void epfPostProcessing(SCL scd) { }))); } - private List validateIed(SclRootAdapter sclRootAdapter) { - List iedErrors = new ArrayList<>(checkIedCompasIcdHeaderAttributes(sclRootAdapter)); - iedErrors.addAll(checkIedUnityOfIcdSystemVersionUuid(sclRootAdapter)); - return iedErrors; - } - - private List checkIedCompasIcdHeaderAttributes(SclRootAdapter sclRootAdapter) { - return sclRootAdapter.streamIEDAdapters() - .map(iedAdapter -> { - Optional compasPrivate = iedAdapter.getCompasICDHeader(); - if (compasPrivate.isEmpty()) { - return iedAdapter.buildFatalReportItem(String.format("IED has no Private %s element", PrivateEnum.COMPAS_ICDHEADER.getPrivateType())); - } - if (isBlank(compasPrivate.get().getICDSystemVersionUUID()) - || isBlank(compasPrivate.get().getIEDName())) { - return iedAdapter.buildFatalReportItem(String.format("IED private %s as no icdSystemVersionUUID or iedName attribute", - PrivateEnum.COMPAS_ICDHEADER.getPrivateType())); - } - return null; - } - ).filter(Objects::nonNull) - .toList(); - } - - private List checkIedUnityOfIcdSystemVersionUuid(SclRootAdapter sclRootAdapter) { - Map> systemVersionToIedList = sclRootAdapter.getCurrentElem().getIED().stream() - .collect(Collectors.groupingBy(ied -> PrivateUtils.extractCompasPrivate(ied, TCompasICDHeader.class) - .map(TCompasICDHeader::getICDSystemVersionUUID) - .orElse(""))); - - return systemVersionToIedList.entrySet().stream() - .filter(entry -> isNotBlank(entry.getKey())) - .filter(entry -> entry.getValue().size() > 1) - .map(entry -> SclReportItem.error(entry.getValue().stream() - .map(tied -> new IEDAdapter(sclRootAdapter, tied)) - .map(IEDAdapter::getXPath) - .collect(Collectors.joining(", ")), - "/IED/Private/compas:ICDHeader[@ICDSystemVersionUUID] must be unique" + - " but the same ICDSystemVersionUUID was found on several IED.")) - .toList(); - } - private void updateLDEPFExtRefBinding(TExtRef extRef, TIED iedSource, TChannel setting) { extRef.setIedName(iedSource.getName()); extRef.setLdInst(setting.getLDInst()); @@ -434,12 +388,6 @@ private String computeDaiValue(AbstractLNAdapter lnAdapter, TExtRef extRef, S } } - record TopoKey(String FlowNode, BigInteger FlowNodeOrder) { - } - - record BayTopoKey(TBay bay, TopoKey topoKey) { - } - private record DoNameAndDaName(String doName, String daName) { } 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 6bb6d2332..bdb7547cc 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 @@ -16,7 +16,6 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.model.epf.*; -import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; 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 f1a530199..c464fd56b 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 @@ -153,44 +153,34 @@ void updateAllSourceDataSetsAndControlBlocks_should_create_dataset_and_fcda_for_ public static Stream provideCreateFCDA() { return Stream.of( Arguments.of(named("should include signal internal to a Bay", - "test bay internal"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test bay internal"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))), Arguments.of(named("should include signal external to a Bay", - "test bay external"), - "IED_NAME3/LD_INST31/DS_LD_INST31_GSE", + "test bay external"), "IED_NAME3/LD_INST31/DS_LD_INST31_GSE", List.of(new FCDARecord("LD_INST31", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))), Arguments.of(named("keep source DA with fc = ST", - "test daName ST"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test daName ST"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameST", TFCEnum.ST))), Arguments.of(named("keep source DA with fc = MX", - "test daName MX"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GMI", + "test daName MX"), "IED_NAME2/LD_INST21/DS_LD_INST21_GMI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", "daNameMX", TFCEnum.MX))), Arguments.of(named("for GOOSE, should keep only valid fcda candidates", - "test ServiceType is GOOSE, no daName and DO contains ST and MX, but only ST is FCDA candidate"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test ServiceType is GOOSE, no daName and DO contains ST and MX, but only ST is FCDA candidate"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "OtherDoName", "daNameST", TFCEnum.ST))), Arguments.of(named("for SMV, should keep only valid fcda candidates", - "test ServiceType is SMV, no daName and DO contains ST and MX, but only ST is FCDA candidate"), - "IED_NAME2/LD_INST21/DS_LD_INST21_SVI", + "test ServiceType is SMV, no daName and DO contains ST and MX, but only ST is FCDA candidate"), "IED_NAME2/LD_INST21/DS_LD_INST21_SVI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "OtherDoName", "daNameST", TFCEnum.ST))), Arguments.of(named("for Report, should get source daName from ExtRef.desc to deduce FC ST", - "test ServiceType is Report_daReportST_1"), - "IED_NAME2/LD_INST21/DS_LD_INST21_DQCI", + "test ServiceType is Report_daReportST_1"), "IED_NAME2/LD_INST21/DS_LD_INST21_DQCI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", null, TFCEnum.ST))), Arguments.of(named("for Report, should get source daName from ExtRef.desc to deduce FC MX", - "test ServiceType is Report_daReportMX_1"), - "IED_NAME2/LD_INST21/DS_LD_INST21_CYCI", + "test ServiceType is Report_daReportMX_1"), "IED_NAME2/LD_INST21/DS_LD_INST21_CYCI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoName", null, TFCEnum.MX))), Arguments.of(named("should ignore instance number when checking FCDA Candidate file", - "test no daName and doName with instance number"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test no daName and doName with instance number"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoWithInst1", "daNameST", TFCEnum.ST))), Arguments.of(named("should ignore instance number when checking FCDA Candidate file (DO with SDO)", - "test no daName and doName with instance number and SDO"), - "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", + "test no daName and doName with instance number and SDO"), "IED_NAME2/LD_INST21/DS_LD_INST21_GSI", List.of(new FCDARecord("LD_INST21", "ANCR", "1", "", "DoWithInst2.subDo", "daNameST", TFCEnum.ST))) ); } @@ -214,26 +204,6 @@ void updateAllSourceDataSetsAndControlBlocks_when_no_valid_source_Da_found_shoul .allMatch(ln0Adapter -> !ln0Adapter.getCurrentElem().isSetDataSet()); } - @ParameterizedTest - @MethodSource("provideDoCreateFCDA") - void updateAllSourceDataSetsAndControlBlocks_when_valid_source_Da_found_should_create_FCDA(String extRefDesc, String extRefIedName) { - // Given - SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success.xml"); - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - InputsAdapter inputsAdapter = keepOnlyThisExtRef(sclRootAdapter, extRefDesc); - DACOMM dacomm = DaComTestMarshallerHelper.getDACOMMFromFile("/cb_comm/Template_DA_COMM_v1.xml"); - // When - List sclReportItems = inputsAdapter.updateAllSourceDataSetsAndControlBlocks(dacomm.getFCDAs().getFCDA()); - // Then - assertThat(sclReportItems).isEmpty(); - assertThat(sclRootAdapter.streamIEDAdapters() - .filter(iedAdapter -> iedAdapter.getName().equals(extRefIedName)) - .flatMap(IEDAdapter::streamLDeviceAdapters) - .filter(LDeviceAdapter::hasLN0) - .map(LDeviceAdapter::getLN0Adapter)) - .allMatch(ln0Adapter -> ln0Adapter.getCurrentElem().isSetDataSet()); - } - public static Stream provideDoNotCreateFCDA() { return Stream.of( Arguments.of(named("should not create FCDA for source Da different from MX and ST", @@ -245,13 +215,6 @@ public static Stream provideDoNotCreateFCDA() { ); } - public static Stream provideDoCreateFCDA() { - return Stream.of( - Arguments.of(named("should create FCDA", "test bay internal"), "IED_NAME2"), - Arguments.of(named("should create FCDA", "test bay external"), "IED_NAME3") - ); - } - @Test void updateAllSourceDataSetsAndControlBlocks_when_AccessPoint_does_not_have_dataset_creation_capability_should_report_error() { // Given 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 deleted file mode 100644 index 4d99bef72..000000000 --- a/sct-commons/src/test/resources/scd-refresh-lnode/Test_Missing_ModstVal_In_LN0_when_binding.scd +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - SCD - -
- - - -
- - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - -
-

00000001

-
-
-
- - -
-

Adresse IP du serveur Syslog

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