Skip to content

Commit 64fbacb

Browse files
committed
fix: Processing LDEPF, closes #498, RSR-1237
Signed-off-by: Samir Romdhani <[email protected]>
1 parent 562662a commit 64fbacb

10 files changed

+408
-74
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.lfenergy.compas.sct.commons.model.epf.TCBScopeType;
1616
import org.lfenergy.compas.sct.commons.model.epf.TChannel;
1717
import org.lfenergy.compas.sct.commons.model.epf.TChannelType;
18+
import org.lfenergy.compas.sct.commons.model.epf.TChannelLevMod;
1819
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
1920
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
2021
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
@@ -34,6 +35,12 @@
3435
@RequiredArgsConstructor
3536
public class ExtRefEditorService implements ExtRefEditor {
3637
private static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info";
38+
private static final List<DoNameAndDaName> DO_DA_MAPPINGS = List.of(
39+
new DoNameAndDaName(CHNUM1_DO_NAME, DU_DA_NAME),
40+
new DoNameAndDaName(LEVMOD_DO_NAME, SETVAL_DA_NAME),
41+
new DoNameAndDaName(MOD_DO_NAME, STVAL_DA_NAME),
42+
new DoNameAndDaName(SRCREF_DO_NAME, SETSRCREF_DA_NAME)
43+
);
3744

3845
private final IedService iedService;
3946
private final LdeviceService ldeviceService;
@@ -114,7 +121,7 @@ private static Boolean doesExtRefMatchLDEPFChannel(TExtRef extRef, TChannel tCha
114121
&& extRef.getDesc().startsWith("DYN_LDEPF_ANALOG CHANNEL " + tChannel.getChannelNum() + "_1_AnalogueValue")
115122
&& extRef.getDesc().endsWith("_" + tChannel.getDAName() + "_1");
116123
Boolean doesExtRefDescMatchDigitalChannel = tChannel.getChannelType().equals(TChannelType.DIGITAL)
117-
&& extRef.getDesc().startsWith("DYN_LDEPF_DIGITAL CHANNEL " + tChannel.getChannelNum() + "_1_BOOLEEN")
124+
&& extRef.getDesc().startsWith("DYN_LDEPF_DIGITAL CHANNEL " + tChannel.getChannelNum() + "_1_BOOLEAN")
118125
&& extRef.getDesc().endsWith("_" + tChannel.getDAName() + "_1");
119126
return extRef.isSetDesc() && (doesExtRefDescMatchAnalogChannel || doesExtRefDescMatchDigitalChannel)
120127
&& extRef.isSetPLN() && Utils.lnClassEquals(extRef.getPLN(), tChannel.getLNClass())
@@ -334,38 +341,38 @@ private void updateLDEPFExtRefBinding(TExtRef extRef, TIED iedSource, TChannel s
334341

335342
private List<SclReportItem> updateLDEPFDos(LDeviceAdapter lDeviceAdapter, TExtRef extRef, TChannel setting) {
336343
List<SclReportItem> sclReportItems = new ArrayList<>();
337-
List<DoNameAndDaName> doNameAndDaNameList = List.of(
338-
new DoNameAndDaName(CHNUM1_DO_NAME, DU_DA_NAME),
339-
new DoNameAndDaName(LEVMOD_DO_NAME, SETVAL_DA_NAME),
340-
new DoNameAndDaName(MOD_DO_NAME, STVAL_DA_NAME),
341-
new DoNameAndDaName(SRCREF_DO_NAME, SETSRCREF_DA_NAME)
342-
);
343344
if (setting.getChannelType().equals(TChannelType.DIGITAL)) {
344345
//digital
345346
lDeviceAdapter.findLnAdapter(LN_RBDR, setting.getChannelNum(), null)
346-
.ifPresent(lnAdapter -> doNameAndDaNameList.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
347+
.ifPresent(lnAdapter -> DO_DA_MAPPINGS.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
347348
lDeviceAdapter.findLnAdapter(LN_RBDR, setting.getChannelNum(), LN_PREFIX_B)
348-
.ifPresent(lnAdapter -> doNameAndDaNameList.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
349+
.ifPresent(lnAdapter -> DO_DA_MAPPINGS.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
349350
}
350351
if (setting.getChannelType().equals(TChannelType.ANALOG)) {
351352
//analog
352353
lDeviceAdapter.findLnAdapter(LN_RADR, setting.getChannelNum(), null)
353-
.ifPresent(lnAdapter -> doNameAndDaNameList.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
354+
.ifPresent(lnAdapter -> DO_DA_MAPPINGS.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
354355
lDeviceAdapter.findLnAdapter(LN_RADR, setting.getChannelNum(), LN_PREFIX_A)
355-
.ifPresent(lnAdapter -> doNameAndDaNameList.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
356+
.ifPresent(lnAdapter -> DO_DA_MAPPINGS.forEach(doNameAndDaName -> updateVal(lnAdapter, doNameAndDaName.doName, doNameAndDaName.daName, extRef, setting).ifPresent(sclReportItems::add)));
356357
}
357358
return sclReportItems;
358359
}
359360

360361
private Optional<SclReportItem> updateVal(AbstractLNAdapter<?> lnAdapter, String doName, String daName, TExtRef extRef, TChannel setting) {
361362
String value = switch (daName) {
362-
case DU_DA_NAME -> setting.getChannelShortLabel();
363-
case SETVAL_DA_NAME -> LN_PREFIX_B.equals(lnAdapter.getPrefix()) || LN_PREFIX_A.equals(lnAdapter.getPrefix()) ? setting.getChannelLevModQ().value() : setting.getChannelLevMod().value();
363+
case DU_DA_NAME -> setting.isSetChannelShortLabel() ? setting.getChannelShortLabel(): null;
364+
case SETVAL_DA_NAME -> {
365+
if(LN_PREFIX_B.equals(lnAdapter.getPrefix()) || LN_PREFIX_A.equals(lnAdapter.getPrefix())){
366+
yield setting.isSetChannelLevModQ() && !setting.getChannelLevModQ().equals(TChannelLevMod.NA) ? setting.getChannelLevModQ().value(): null;
367+
} else {
368+
yield setting.isSetChannelLevMod() && !setting.getChannelLevMod().equals(TChannelLevMod.NA) ? setting.getChannelLevMod().value(): null;
369+
}
370+
}
364371
case STVAL_DA_NAME -> ActiveStatus.ON.getValue();
365372
case SETSRCREF_DA_NAME -> computeDaiValue(lnAdapter, extRef, setting.getDAName());
366373
default -> null;
367374
};
368-
return lnAdapter.getDOIAdapterByName(doName).updateDAI(daName, value);
375+
return Optional.ofNullable(value).flatMap(newDaiValue -> lnAdapter.getDOIAdapterByName(doName).updateDAI(daName, newDaiValue));
369376
}
370377

371378
private String computeDaiValue(AbstractLNAdapter<?> lnAdapter, TExtRef extRef, String daName) {

0 commit comments

Comments
 (0)