Skip to content

Commit

Permalink
feat / review deconstructing compas-flow
Browse files Browse the repository at this point in the history
Signed-off-by: Samir Romdhani <samir.romdhani@rte-france.com>
  • Loading branch information
samirromdhani committed Dec 9, 2024
1 parent 66c01ca commit d83efeb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -325,48 +321,6 @@ public void epfPostProcessing(SCL scd) {
})));
}

private List<SclReportItem> validateIed(SclRootAdapter sclRootAdapter) {
List<SclReportItem> iedErrors = new ArrayList<>(checkIedCompasIcdHeaderAttributes(sclRootAdapter));
iedErrors.addAll(checkIedUnityOfIcdSystemVersionUuid(sclRootAdapter));
return iedErrors;
}

private List<SclReportItem> checkIedCompasIcdHeaderAttributes(SclRootAdapter sclRootAdapter) {
return sclRootAdapter.streamIEDAdapters()
.map(iedAdapter -> {
Optional<TCompasICDHeader> 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<SclReportItem> checkIedUnityOfIcdSystemVersionUuid(SclRootAdapter sclRootAdapter) {
Map<String, List<TIED>> 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());
Expand Down Expand Up @@ -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) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,44 +153,34 @@ void updateAllSourceDataSetsAndControlBlocks_should_create_dataset_and_fcda_for_
public static Stream<Arguments> 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)))
);
}
Expand All @@ -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<SclReportItem> 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<Arguments> provideDoNotCreateFCDA() {
return Stream.of(
Arguments.of(named("should not create FCDA for source Da different from MX and ST",
Expand All @@ -245,13 +215,6 @@ public static Stream<Arguments> provideDoNotCreateFCDA() {
);
}

public static Stream<Arguments> 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
Expand Down

This file was deleted.

0 comments on commit d83efeb

Please sign in to comment.