Skip to content

Commit

Permalink
Merge pull request #474 from com-pas/feat/473-RSR-1164-add-findldevic…
Browse files Browse the repository at this point in the history
…e-by-ldinst-and-findanyln-by-lnclass-lninst-and-prefx

feat(#473): RSR-1164 Add findLdevice by ldInst and findAnyLn by lnClass, lnInst and prefix
  • Loading branch information
massifben authored Feb 17, 2025
2 parents 99a9b0a + 6c7e26d commit 7d87177
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static boolean doesIcdHeaderMatchLDEPFChannel(IEDAdapter iedAdapter, TCh
* @return LDeviceAdapter object that matches the EPF channel
*/
private Optional<LDeviceAdapter> getActiveSourceLDeviceByLDEPFChannel(IEDAdapter iedAdapter, TChannel channel) {
return ldeviceService.findLdevice(iedAdapter.getCurrentElem(), tlDevice -> tlDevice.getInst().equals(channel.getLDInst()))
return ldeviceService.findLdevice(iedAdapter.getCurrentElem(), channel.getLDInst())
.filter(tlDevice -> ldeviceService.getLdeviceStatus(tlDevice).map(ActiveStatus.ON::equals).orElse(false))
.map(tlDevice -> new LDeviceAdapter(iedAdapter, tlDevice));
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
if (!epf.isSetChannels()) return sclReportItems;
iedService.getFilteredIeds(scd, ied -> !ied.getName().contains("TEST"))
.forEach(tied -> ldeviceService.findLdevice(tied, tlDevice -> LDEVICE_LDEPF.equals(tlDevice.getInst()))
.forEach(tied -> ldeviceService.findLdevice(tied, LDEVICE_LDEPF)
.ifPresent(tlDevice -> getExtRefWithBayReferenceInLDEPF(scd.getDataTypeTemplates(), tied, tlDevice, sclReportItems)
.forEach(extRefBayRef -> epf.getChannels().getChannel().stream().filter(tChannel -> doesExtRefMatchLDEPFChannel(extRefBayRef.extRef(), tChannel))
.findFirst().ifPresent(channel -> {
Expand All @@ -291,7 +291,7 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
@Override
public void epfPostProcessing(SCL scd) {
iedService.getFilteredIeds(scd, ied -> !ied.getName().contains("TEST"))
.forEach(tied -> ldeviceService.findLdevice(tied, tlDevice -> LDEVICE_LDEPF.equals(tlDevice.getInst()))
.forEach(tied -> ldeviceService.findLdevice(tied, LDEVICE_LDEPF)
.ifPresent(tlDevice -> tlDevice.getLN0().getDOI()
.stream().filter(tdoi -> tdoi.getName().startsWith(INREF_PREFIX))
.forEach(tdoi -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public Optional<TLDevice> findLdevice(TIED tied, Predicate<TLDevice> ldevicePred
return getFilteredLdevices(tied, ldevicePredicate).findFirst();
}

public Optional<TLDevice> findLdevice(TIED tied, String ldInst) {
return findLdevice(tied, tlDevice -> tlDevice.getInst().equals(ldInst));
}

public Optional<ActiveStatus> getLdeviceStatus(TLDevice tlDevice) {
return lnService.getDaiModStValValue(tlDevice.getLN0());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public Optional<TAnyLN> findAnyLn(TLDevice tlDevice, Predicate<TAnyLN> lnPredica
return getFilteredAnyLns(tlDevice, lnPredicate).findFirst();
}

public Optional<TAnyLN> findAnyLn(TLDevice tlDevice, String lnClass, String lnInst, String lnPrefix) {
return findAnyLn(tlDevice, tAnyLN -> matchesLn(tAnyLN, lnClass, lnInst, lnPrefix));
}

public Stream<TLN> getLns(TLDevice tlDevice) {
return tlDevice.getLN().stream();
}
Expand All @@ -50,6 +54,16 @@ public Optional<TLN> findLn(TLDevice tlDevice, Predicate<TLN> lnPredicate) {
return getFilteredLns(tlDevice, lnPredicate).findFirst();
}

public boolean matchesLn(TAnyLN tAnyLN, String lnClass, String lnInst, String lnPrefix) {
return switch (tAnyLN) {
case TLN ln -> lnClass.equals(ln.getLnClass().getFirst())
&& StringUtils.trimToEmpty(lnInst).equals(StringUtils.trimToEmpty(ln.getInst()))
&& (StringUtils.trimToEmpty(lnPrefix).equals(StringUtils.trimToEmpty(ln.getPrefix())));
case LN0 ignored -> lnClass.equals(TLLN0Enum.LLN_0.value());
default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
};
}

/**
* The Lnode status depends on the LN0 status.
* If Ln stVAl = null => we take the LN0 status
Expand Down Expand Up @@ -177,16 +191,6 @@ public DoLinkedToDa getDoLinkedToDaCompletedFromDAI(TIED tied, String ldInst, TA
return result;
}

public boolean matchesLn(TAnyLN tAnyLN, String lnClass, String lnInst, String lnPrefix) {
return switch (tAnyLN) {
case TLN ln -> lnClass.equals(ln.getLnClass().getFirst())
&& lnInst.equals(ln.getInst())
&& (StringUtils.trimToEmpty(lnPrefix).equals(StringUtils.trimToEmpty(ln.getPrefix())));
case LN0 ignored -> lnClass.equals(TLLN0Enum.LLN_0.value());
default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
};
}

private boolean hasSettingGroup(TDAI tdai) {
return tdai.isSetVal() && tdai.getVal().stream().anyMatch(tVal -> tVal.isSetSGroup() && tVal.getSGroup() > 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void getFilteredLdevices_should_return_ldevices() {
}

@Test
void findLdevice_should_return_ldevice() {
void findLdevice_with_predicate_should_return_ldevice() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().getFirst();
Expand All @@ -80,6 +80,19 @@ void findLdevice_should_return_ldevice() {
.containsExactly("LDTM", "VirtualSAMULDTM");
}

@Test
void findLdevice_with_ldInst_should_return_ldevice() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TIED tied = std.getIED().getFirst();
//When
TLDevice ldevice = ldeviceService.findLdevice(tied, "LDTM").orElseThrow();
//Then
assertThat(ldevice)
.extracting(TLDevice::getInst, TLDevice::getLdName)
.containsExactly("LDTM", "VirtualSAMULDTM");
}

@Test
void getActiveLdevices_should_return_ldevices() {
//Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void getAnylns_should_return_lns() {
}

@Test
void findAnyLn_should_return_ln() {
void findAnyLn_with_predicate_should_return_ln() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLDevice ldsuied = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().getFirst();
Expand All @@ -64,6 +64,36 @@ void findAnyLn_should_return_ln() {
.containsExactly("RTE_080BBB4D93E4E704CF69E8616CAF1A74_LLN0_V1.0.0", LN0.class);
}

@Test
void findAnyLn_with_lnClass_lnInst_lnPrefix_should_return_ln() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLDevice ldtm = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().stream().filter(tlDevice -> "LDTM".equals(tlDevice.getInst())).findFirst().orElseThrow();

//When
Optional<TAnyLN> anyLn = lnService.findAnyLn(ldtm, "TCTR", "43", "I04C");

//Then
assertThat(anyLn.orElseThrow())
.extracting(TAnyLN::getLnType, TAnyLN::getClass)
.containsExactly("RTE_336B5093F3DDA93A19E979FB89196E26_TCTR_V1.0.0", TLN.class);
}

@Test
void findAnyLn_with_lnClass_lnInst_lnPrefix_should_return_ln0() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLDevice ldsuied = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().getFirst();

//When
Optional<TAnyLN> anyLn = lnService.findAnyLn(ldsuied, "LLN0", "", null);

//Then
assertThat(anyLn.orElseThrow())
.extracting(TAnyLN::getLnType, TAnyLN::getClass)
.containsExactly("RTE_080BBB4D93E4E704CF69E8616CAF1A74_LLN0_V1.0.0", LN0.class);
}

@Test
void getLns_should_return_lns() {
//Given
Expand Down

0 comments on commit 7d87177

Please sign in to comment.