-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
328 additions
and
68 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LNodeStatusService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.lfenergy.compas.scl2007b4.model.SCL; | ||
import org.lfenergy.compas.scl2007b4.model.TAnyLN; | ||
import org.lfenergy.compas.scl2007b4.model.TBaseElement; | ||
import org.lfenergy.compas.scl2007b4.model.TPredefinedBasicTypeEnum; | ||
import org.lfenergy.compas.sct.commons.domain.DataAttribute; | ||
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa; | ||
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter; | ||
import org.lfenergy.compas.sct.commons.dto.SclReportItem; | ||
import org.lfenergy.compas.sct.commons.util.CommonConstants; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class LNodeStatusService { | ||
|
||
private final LnService lnService = new LnService(); | ||
private final DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService(); | ||
|
||
public List<SclReportItem> updateLnModStValBasedOnLNodeStatus(SCL scl) { | ||
scl.getSubstation().stream() | ||
.flatMap(tSubstation -> tSubstation.getVoltageLevel().stream()) | ||
.flatMap(tVoltageLevel -> tVoltageLevel.getBay().stream()) | ||
.flatMap(tBay -> tBay.getFunction().stream()) | ||
.flatMap(tFunction -> tFunction.getLNode().stream()) | ||
.map(tlNode -> { | ||
String lNodeLnodeStatus = extractStringPrivate(tlNode, "COMPAS-LNodeStatus") | ||
.orElseThrow(); // FIXME | ||
TAnyLN tAnyLN = findLn(scl, tlNode.getIedName(), tlNode.getLdInst(), tlNode.getLnClass().getFirst(), tlNode.getLnInst(), tlNode.getPrefix()) | ||
.orElseThrow();// FIXME | ||
String lnLNodeStatus = extractStringPrivate(tAnyLN, "COMPAS-LNodeStatus") | ||
.orElseThrow(); | ||
switch (lNodeLnodeStatus) { | ||
case "on" -> { | ||
if (lnLNodeStatus.contains("on")) { | ||
// Met à jour Mod stVal s'il existe | ||
lnService.getDaiModStVal(tAnyLN) | ||
.ifPresent(tdai -> { | ||
|
||
dataTypeTemplatesService.findDoLinkedToDa(scl.getDataTypeTemplates(), tAnyLN.getLnType(), DoLinkedToDaFilter.from(CommonConstants.MOD_DO_NAME, CommonConstants.STVAL_DA_NAME)) | ||
.map(DoLinkedToDa::dataAttribute) | ||
.filter(dataAttribute -> TPredefinedBasicTypeEnum.ENUM.equals(dataAttribute.getBType())) | ||
.map(DataAttribute::getType); | ||
}); | ||
} else { | ||
// erreur // FIXME | ||
} | ||
} | ||
case "of" -> { | ||
if (lnLNodeStatus.contains("off")) { | ||
// Met à jour Mod stVal s'il existe | ||
} else { | ||
// erreur // FIXME | ||
} | ||
} | ||
default -> { | ||
// erreur // FIXME | ||
} | ||
} | ||
return null; | ||
} | ||
); | ||
|
||
return List.of(); | ||
} | ||
|
||
private static Optional<String> extractStringPrivate(TBaseElement tBaseElement, String privateType) { | ||
return tBaseElement.getPrivate().stream() | ||
.filter(tPrivate -> privateType.equals(tPrivate.getType())) | ||
.flatMap(tPrivate -> tPrivate.getContent().stream()) | ||
.filter(String.class::isInstance) | ||
.map(String.class::cast) | ||
.filter(StringUtils::isNotBlank) | ||
.findFirst(); | ||
} | ||
|
||
private Optional<TAnyLN> findLn(SCL scl, String iedName, String ldInst, String lnClass, String lnInst, String prefix) { | ||
return scl.getIED().stream() | ||
.filter(tied -> iedName.equals(tied.getName())) | ||
.findFirst() | ||
.flatMap(tied -> new LdeviceService().findLdevice(tied, tlDevice -> ldInst.equals(tlDevice.getInst()))) | ||
.flatMap(tlDevice -> lnService.findAnyLn(tlDevice, tAnyLN -> lnService.matchesLn(tAnyLN, lnInst, lnClass, prefix))); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LNodeStatusServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.lfenergy.compas.scl2007b4.model.SCL; | ||
import org.lfenergy.compas.sct.commons.dto.SclReportItem; | ||
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; | ||
|
||
class LNodeStatusServiceTest { | ||
|
||
private LNodeStatusService lNodeStatusService; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
lNodeStatusService = new LNodeStatusService(); | ||
} | ||
|
||
@Test | ||
void updateLnStatusBasedOnPrivateLNodeStatus_should_succeed() { | ||
// Given | ||
SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd"); | ||
// When | ||
List<SclReportItem> sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl); | ||
// Then | ||
assertThat(sclReportItems).isEmpty(); | ||
assertThat(getValue(findDai(findLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", ""), "Mod.stVal"))) | ||
.isEqualTo("on"); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.