Skip to content

Commit

Permalink
feat(#378): code review
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 Feb 26, 2024
1 parent e230c11 commit 7529951
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public class DataTypeTemplatesService {
* @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 -> lNodeType.getId().equals(lNodeTypeId))
.map(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(MOD_DO_NAME))
.map(tdo -> doTypeService.findDoType(dtt, doType -> doType.getId().equals(tdo.getType()))
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(unNaming -> unNaming.getClass().equals(TDA.class))
.filter(sdoOrDa -> sdoOrDa.getClass().equals(TDA.class))
.map(TDA.class::cast)
.anyMatch(tda -> tda.getName().equals(STVAL_DA_NAME)))
.anyMatch(tda -> STVAL_DA_NAME.equals(tda.getName())))
.orElse(false))
.orElse(false))
.orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ExtRefEditorService implements ExtRefEditor {
"7", "THT"
);

private final IedService iedService;
private final LdeviceService ldeviceService;
private final ExtRefService extRefService;
private final DataTypeTemplatesService dataTypeTemplatesService;
Expand Down Expand Up @@ -87,25 +88,25 @@ private static List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBa
* @param sclReportItems List of SclReportItem
* @return list of ExtRef and associated Bay
*/
private List<ExtRefInfo.ExtRefWithBayReference> getExtRefWithBayReferenceInLDEPF(final LDeviceAdapter lDeviceAdapter, final List<SclReportItem> sclReportItems) {
private List<ExtRefInfo.ExtRefWithBayReference> getExtRefWithBayReferenceInLDEPF(TDataTypeTemplates dataTypeTemplates, TIED tied, final TLDevice tlDevice, final List<SclReportItem> sclReportItems) {
List<ExtRefInfo.ExtRefWithBayReference> extRefBayReferenceList = new ArrayList<>();
IEDAdapter iedAdapter = lDeviceAdapter.getParentAdapter();
if (iedAdapter.getPrivateCompasBay().isEmpty()) {
sclReportItems.add(SclReportItem.error(lDeviceAdapter.getXPath(), "The IED has no Private Bay"));
if (iedAdapter.getCompasICDHeader().isEmpty()) {
sclReportItems.add(SclReportItem.error(lDeviceAdapter.getXPath(), "The IED has no Private compas:ICDHeader"));
String lDevicePath = "SCL/IED[@name=\""+ tied.getName() + "\"]/AccessPoint/Server/LDevice[@inst=\"" + tlDevice.getInst() + "\"]";
Optional<TCompasBay> 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(iedAdapter.getParentAdapter().getDataTypeTemplateAdapter().getCurrentElem(),
lDeviceAdapter.getLN0Adapter().getLnType())) {
extRefBayReferenceList.addAll(lDeviceAdapter.getLN0Adapter()
.getInputsAdapter().getCurrentElem()
if (dataTypeTemplatesService.isDoModAndDaStValExist(dataTypeTemplates, tlDevice.getLN0().getLnType())) {
extRefBayReferenceList.addAll(tlDevice.getLN0()
.getInputs()
.getExtRef().stream()
.map(extRef -> new ExtRefInfo.ExtRefWithBayReference(iedAdapter.getName(), iedAdapter.getPrivateCompasBay().get(), extRef)).toList());
.map(extRef -> new ExtRefInfo.ExtRefWithBayReference(tied.getName(), tCompasBay.get(), extRef)).toList());
} else {
sclReportItems.add(SclReportItem.error(lDeviceAdapter.getXPath(), "DO@name=Mod/DA@name=stVal not found in DataTypeTemplate"));
sclReportItems.add(SclReportItem.error(lDevicePath, "DO@name=Mod/DA@name=stVal not found in DataTypeTemplate"));
}
return extRefBayReferenceList;
}
Expand Down Expand Up @@ -298,29 +299,27 @@ public List<SclReportItem> updateAllExtRefIedNames(SCL scd) {
@Override
public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
List<SclReportItem> 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 -> getExtRefWithBayReferenceInLDEPF(lDeviceAdapter, sclReportItems)
.forEach(extRefBayRef -> epf.getChannels().getChannel().stream().filter(tChannel -> doesExtRefMatchLDEPFChannel(extRefBayRef.extRef(), tChannel))
.findFirst().ifPresent(channel -> {
List<TIED> 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<TIED> 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;
}

Expand Down Expand Up @@ -436,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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ExtRefEditorServiceTest {

@BeforeEach
void init() {
extRefEditorService = new ExtRefEditorService(new LdeviceService(), new ExtRefService(), new DataTypeTemplatesService());
extRefEditorService = new ExtRefEditorService(new IedService(), new LdeviceService(), new ExtRefService(), new DataTypeTemplatesService());
}

@Test
Expand Down Expand Up @@ -500,7 +500,7 @@ void manageBindingForLDEPF_when_extRefMatchFlowKindInternalOrExternal_should_upd
}

@Test
void getExtRefBayReferenceForActifLDEPF_when_DOI_Mod_and_DAI_stVal_notExists_should_precede() {
void manageBindingForLDEPF_when_DOI_Mod_and_DAI_stVal_notExists_should_precede() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_withoutModStValInLN0.xml");
// When
Expand Down Expand Up @@ -582,7 +582,7 @@ void manageBindingForLDEPF_when_LDEPF_NotActive_should_precede() {
}

@Test
void getExtRefBayReferenceForActifLDEPF_when_DO_Mod_and_DA_stVal_NotFoundInDataTypeTemplate_should_return_error() {
void manageBindingForLDEPF_when_DO_Mod_and_DA_stVal_NotFoundInDataTypeTemplate_should_return_error() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ldepf/scd_ldepf_withoutModStValInDataTypeTemplate.xml");
// When
Expand All @@ -595,11 +595,11 @@ void getExtRefBayReferenceForActifLDEPF_when_DO_Mod_and_DA_stVal_NotFoundInDataT
.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\"]"),
"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\"]"),
"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\"]")
"SCL/IED[@name=\"IED_NAME3\"]/AccessPoint/Server/LDevice[@inst=\"LDEPF\"]")
);
}

Expand Down

0 comments on commit 7529951

Please sign in to comment.