Skip to content

Commit 6c7e26d

Browse files
committed
feat(#473): RSR-1164 Add findLdevice by ldInst and findAnyLn by lnClass, lnInst and prefx
Signed-off-by: massifben <[email protected]>
1 parent 99a9b0a commit 6c7e26d

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static boolean doesIcdHeaderMatchLDEPFChannel(IEDAdapter iedAdapter, TCh
144144
* @return LDeviceAdapter object that matches the EPF channel
145145
*/
146146
private Optional<LDeviceAdapter> getActiveSourceLDeviceByLDEPFChannel(IEDAdapter iedAdapter, TChannel channel) {
147-
return ldeviceService.findLdevice(iedAdapter.getCurrentElem(), tlDevice -> tlDevice.getInst().equals(channel.getLDInst()))
147+
return ldeviceService.findLdevice(iedAdapter.getCurrentElem(), channel.getLDInst())
148148
.filter(tlDevice -> ldeviceService.getLdeviceStatus(tlDevice).map(ActiveStatus.ON::equals).orElse(false))
149149
.map(tlDevice -> new LDeviceAdapter(iedAdapter, tlDevice));
150150
}
@@ -267,7 +267,7 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
267267
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
268268
if (!epf.isSetChannels()) return sclReportItems;
269269
iedService.getFilteredIeds(scd, ied -> !ied.getName().contains("TEST"))
270-
.forEach(tied -> ldeviceService.findLdevice(tied, tlDevice -> LDEVICE_LDEPF.equals(tlDevice.getInst()))
270+
.forEach(tied -> ldeviceService.findLdevice(tied, LDEVICE_LDEPF)
271271
.ifPresent(tlDevice -> getExtRefWithBayReferenceInLDEPF(scd.getDataTypeTemplates(), tied, tlDevice, sclReportItems)
272272
.forEach(extRefBayRef -> epf.getChannels().getChannel().stream().filter(tChannel -> doesExtRefMatchLDEPFChannel(extRefBayRef.extRef(), tChannel))
273273
.findFirst().ifPresent(channel -> {
@@ -291,7 +291,7 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
291291
@Override
292292
public void epfPostProcessing(SCL scd) {
293293
iedService.getFilteredIeds(scd, ied -> !ied.getName().contains("TEST"))
294-
.forEach(tied -> ldeviceService.findLdevice(tied, tlDevice -> LDEVICE_LDEPF.equals(tlDevice.getInst()))
294+
.forEach(tied -> ldeviceService.findLdevice(tied, LDEVICE_LDEPF)
295295
.ifPresent(tlDevice -> tlDevice.getLN0().getDOI()
296296
.stream().filter(tdoi -> tdoi.getName().startsWith(INREF_PREFIX))
297297
.forEach(tdoi -> {

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

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public Optional<TLDevice> findLdevice(TIED tied, Predicate<TLDevice> ldevicePred
4646
return getFilteredLdevices(tied, ldevicePredicate).findFirst();
4747
}
4848

49+
public Optional<TLDevice> findLdevice(TIED tied, String ldInst) {
50+
return findLdevice(tied, tlDevice -> tlDevice.getInst().equals(ldInst));
51+
}
52+
4953
public Optional<ActiveStatus> getLdeviceStatus(TLDevice tlDevice) {
5054
return lnService.getDaiModStValValue(tlDevice.getLN0());
5155
}

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

+14-10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public Optional<TAnyLN> findAnyLn(TLDevice tlDevice, Predicate<TAnyLN> lnPredica
3838
return getFilteredAnyLns(tlDevice, lnPredicate).findFirst();
3939
}
4040

41+
public Optional<TAnyLN> findAnyLn(TLDevice tlDevice, String lnClass, String lnInst, String lnPrefix) {
42+
return findAnyLn(tlDevice, tAnyLN -> matchesLn(tAnyLN, lnClass, lnInst, lnPrefix));
43+
}
44+
4145
public Stream<TLN> getLns(TLDevice tlDevice) {
4246
return tlDevice.getLN().stream();
4347
}
@@ -50,6 +54,16 @@ public Optional<TLN> findLn(TLDevice tlDevice, Predicate<TLN> lnPredicate) {
5054
return getFilteredLns(tlDevice, lnPredicate).findFirst();
5155
}
5256

57+
public boolean matchesLn(TAnyLN tAnyLN, String lnClass, String lnInst, String lnPrefix) {
58+
return switch (tAnyLN) {
59+
case TLN ln -> lnClass.equals(ln.getLnClass().getFirst())
60+
&& StringUtils.trimToEmpty(lnInst).equals(StringUtils.trimToEmpty(ln.getInst()))
61+
&& (StringUtils.trimToEmpty(lnPrefix).equals(StringUtils.trimToEmpty(ln.getPrefix())));
62+
case LN0 ignored -> lnClass.equals(TLLN0Enum.LLN_0.value());
63+
default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
64+
};
65+
}
66+
5367
/**
5468
* The Lnode status depends on the LN0 status.
5569
* If Ln stVAl = null => we take the LN0 status
@@ -177,16 +191,6 @@ public DoLinkedToDa getDoLinkedToDaCompletedFromDAI(TIED tied, String ldInst, TA
177191
return result;
178192
}
179193

180-
public boolean matchesLn(TAnyLN tAnyLN, String lnClass, String lnInst, String lnPrefix) {
181-
return switch (tAnyLN) {
182-
case TLN ln -> lnClass.equals(ln.getLnClass().getFirst())
183-
&& lnInst.equals(ln.getInst())
184-
&& (StringUtils.trimToEmpty(lnPrefix).equals(StringUtils.trimToEmpty(ln.getPrefix())));
185-
case LN0 ignored -> lnClass.equals(TLLN0Enum.LLN_0.value());
186-
default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
187-
};
188-
}
189-
190194
private boolean hasSettingGroup(TDAI tdai) {
191195
return tdai.isSetVal() && tdai.getVal().stream().anyMatch(tVal -> tVal.isSetSGroup() && tVal.getSGroup() > 0);
192196
}

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void getFilteredLdevices_should_return_ldevices() {
6868
}
6969

7070
@Test
71-
void findLdevice_should_return_ldevice() {
71+
void findLdevice_with_predicate_should_return_ldevice() {
7272
//Given
7373
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
7474
TIED tied = std.getIED().getFirst();
@@ -80,6 +80,19 @@ void findLdevice_should_return_ldevice() {
8080
.containsExactly("LDTM", "VirtualSAMULDTM");
8181
}
8282

83+
@Test
84+
void findLdevice_with_ldInst_should_return_ldevice() {
85+
//Given
86+
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
87+
TIED tied = std.getIED().getFirst();
88+
//When
89+
TLDevice ldevice = ldeviceService.findLdevice(tied, "LDTM").orElseThrow();
90+
//Then
91+
assertThat(ldevice)
92+
.extracting(TLDevice::getInst, TLDevice::getLdName)
93+
.containsExactly("LDTM", "VirtualSAMULDTM");
94+
}
95+
8396
@Test
8497
void getActiveLdevices_should_return_ldevices() {
8598
//Given

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void getAnylns_should_return_lns() {
5050
}
5151

5252
@Test
53-
void findAnyLn_should_return_ln() {
53+
void findAnyLn_with_predicate_should_return_ln() {
5454
//Given
5555
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
5656
TLDevice ldsuied = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().getFirst();
@@ -64,6 +64,36 @@ void findAnyLn_should_return_ln() {
6464
.containsExactly("RTE_080BBB4D93E4E704CF69E8616CAF1A74_LLN0_V1.0.0", LN0.class);
6565
}
6666

67+
@Test
68+
void findAnyLn_with_lnClass_lnInst_lnPrefix_should_return_ln() {
69+
//Given
70+
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
71+
TLDevice ldtm = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().stream().filter(tlDevice -> "LDTM".equals(tlDevice.getInst())).findFirst().orElseThrow();
72+
73+
//When
74+
Optional<TAnyLN> anyLn = lnService.findAnyLn(ldtm, "TCTR", "43", "I04C");
75+
76+
//Then
77+
assertThat(anyLn.orElseThrow())
78+
.extracting(TAnyLN::getLnType, TAnyLN::getClass)
79+
.containsExactly("RTE_336B5093F3DDA93A19E979FB89196E26_TCTR_V1.0.0", TLN.class);
80+
}
81+
82+
@Test
83+
void findAnyLn_with_lnClass_lnInst_lnPrefix_should_return_ln0() {
84+
//Given
85+
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
86+
TLDevice ldsuied = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().getFirst();
87+
88+
//When
89+
Optional<TAnyLN> anyLn = lnService.findAnyLn(ldsuied, "LLN0", "", null);
90+
91+
//Then
92+
assertThat(anyLn.orElseThrow())
93+
.extracting(TAnyLN::getLnType, TAnyLN::getClass)
94+
.containsExactly("RTE_080BBB4D93E4E704CF69E8616CAF1A74_LLN0_V1.0.0", LN0.class);
95+
}
96+
6797
@Test
6898
void getLns_should_return_lns() {
6999
//Given

0 commit comments

Comments
 (0)