Skip to content

Commit

Permalink
take comments into account
Browse files Browse the repository at this point in the history
  • Loading branch information
massifben committed Dec 20, 2024
1 parent dd3367d commit 08400a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
public class LNodeStatusService {

private static final String LNODE_STATUS_PRIVATE_TYPE = "COMPAS-LNodeStatus";
private static final List<String> LN_LNS_POSSIBLE_VALUES = List.of("off;on", "on;off", "on", "off");
private static final List<String> LNODE_LNS_POSSIBLE_VALUES = List.of("on", "off");
private final LdeviceService ldeviceService;
private final LnService lnService;
private final DataTypeTemplatesService dataTypeTemplatesService;
Expand All @@ -40,16 +42,17 @@ public List<SclReportItem> updateLnModStValBasedOnLNodeStatus(SCL scl) {

private SclReportItem updateSingleLnModStValBasedOnLNodeStatus(SCL scl, TLNode tlNode) {
String lNodeLNS = PrivateUtils.extractStringPrivate(tlNode, LNODE_STATUS_PRIVATE_TYPE).orElse(null);
if (!"on".equals(lNodeLNS) && !"off".equals(lNodeLNS)) {
if (lNodeLNS == null || !LNODE_LNS_POSSIBLE_VALUES.contains(lNodeLNS)) {
return SclReportItem.error(lNodePath(tlNode), "The private %s of the LNode has invalid value. Expecting one of [on, off] but got : %s".formatted(LNODE_STATUS_PRIVATE_TYPE, lNodeLNS));
}
TAnyLN anyLn = findLn(scl, tlNode.getIedName(), tlNode.getLdInst(), tlNode.getLnClass().getFirst(), tlNode.getLnInst(), tlNode.getPrefix()).orElse(null);
if (anyLn == null) {
return SclReportItem.error(lNodePath(tlNode), "LNode in Substation section does not have a matching LN in IED section");
}
String anyLnLNS = PrivateUtils.extractStringPrivate(anyLn, LNODE_STATUS_PRIVATE_TYPE).orElse(null);
if (anyLnLNS == null) {
return SclReportItem.error(lnPath(tlNode), "LN does not have a private %s".formatted(LNODE_STATUS_PRIVATE_TYPE));
if (anyLnLNS == null || !LN_LNS_POSSIBLE_VALUES.contains(anyLnLNS)) {
return SclReportItem.error(lnPath(tlNode), "The private %s of the LN has invalid value. Expecting one of %s but got : %s".formatted(LNODE_STATUS_PRIVATE_TYPE, LN_LNS_POSSIBLE_VALUES, anyLnLNS));

}
if (!anyLnLNS.contains(lNodeLNS)) {
return SclReportItem.error(lnPath(tlNode), "Cannot set DAI Mod.stVal to %s, because LN private %s is set to %s".formatted(lNodeLNS, LNODE_STATUS_PRIVATE_TYPE, anyLnLNS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void updateLnStatusBasedOnPrivateLNodeStatus_when_invalid_compasLNodeStatus_valu
void updateLnStatusBasedOnPrivateLNodeStatus_when_LNode_does_not_match_any_LN_should_return_error() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
((TLN) findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", ""))
((TLN) findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", ""))
.setPrefix("helloworld");
// When
List<SclReportItem> sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
Expand All @@ -129,17 +129,17 @@ void updateLnStatusBasedOnPrivateLNodeStatus_when_no_compasLNodeStatus_in_LN_sho
// Then
assertThat(sclReportItems).containsExactly(
SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_1)/LN[PDIS,1,]",
"LN does not have a private COMPAS-LNodeStatus")
"The private COMPAS-LNodeStatus of the LN has invalid value. Expecting one of [off;on, on;off, on, off] but got : null")
);
}

@Test
void updateLnStatusBasedOnPrivateLNodeStatus_when_compasLNodeStatus_is_on_in_LNode_but_off_in_LN_should_return_error() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "LLN0", "", "")
findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "LLN0", "", "")
.getPrivate().getFirst().getContent().set(0, "off");
findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", "")
findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", "")
.getPrivate().getFirst().getContent().set(0, "off");
// When
List<SclReportItem> sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
Expand All @@ -156,9 +156,9 @@ void updateLnStatusBasedOnPrivateLNodeStatus_when_compasLNodeStatus_is_on_in_LNo
void updateLnStatusBasedOnPrivateLNodeStatus_when_compasLNodeStatus_is_off_in_LNode_but_on_in_LN_should_return_error() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
findAnyLn(scl, "IED_NAME_1", "LDEVICE_4", "LLN0", "", "")
findAnyLn(scl, "IED_NAME_1", "LDEVICE_4", "LLN0", "", "")
.getPrivate().getFirst().getContent().set(0, "on");
findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "4", "")
findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "4", "")
.getPrivate().getFirst().getContent().set(0, "on");
// When
List<SclReportItem> sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
Expand Down

0 comments on commit 08400a1

Please sign in to comment.