Skip to content

Commit

Permalink
feat: remove LD LDevice Status verification
Browse files Browse the repository at this point in the history
Signed-off-by: Samir Romdhani <[email protected]>
  • Loading branch information
samirromdhani committed Jan 24, 2025
1 parent e28e8e1 commit af2b751
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 681 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import org.lfenergy.compas.sct.commons.api.LnEditor;
import org.lfenergy.compas.sct.commons.domain.*;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation;
import org.lfenergy.compas.sct.commons.scl.ln.LnId;
import org.lfenergy.compas.sct.commons.util.ActiveStatus;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -23,7 +21,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation.LNODE_STATUS_PRIVATE_TYPE;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal;

Expand Down Expand Up @@ -160,7 +157,6 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT
*/
public List<SclReportItem> updateLDeviceStatus(SCL scd, SubstationService substationService, LdeviceService ldeviceService, DataTypeTemplatesService dataTypeTemplatesService) {
List<SclReportItem> sclReportItems = new ArrayList<>();
LDeviceActivation lDeviceActivation = new LDeviceActivation(substationService.getLNodes(scd));
scd.getIED().forEach(tied -> ldeviceService.getLdevices(tied)
.forEach(tlDevice -> getAnylns(tlDevice)
.forEach(tln -> {
Expand All @@ -178,17 +174,20 @@ public List<SclReportItem> updateLDeviceStatus(SCL scd, SubstationService substa
return;
}

Optional<String> lNodeStatus = PrivateUtils.extractStringPrivate(tln, LNODE_STATUS_PRIVATE_TYPE);
if (lNodeStatus.isEmpty()) {
sclReportItems.add(SclReportItem.error(xpath, "The LN doesn't have a Private "+LNODE_STATUS_PRIVATE_TYPE));
return;
}

Set<String> enumValues = dataTypeTemplatesService.getEnumValues(scd.getDataTypeTemplates(), tln.getLnType(), doLinkedToDaFilter).collect(Collectors.toSet());
lDeviceActivation.checkLDeviceActivationStatus(tied.getName(), tlDevice.getInst(), lNodeStatus.get(), enumValues, sclReportItems);
if(lDeviceActivation.isUpdatable()){
update(tln, optionalModStVal.get().getValue(), lDeviceActivation.getNewVal());
if (!enumValues.contains(ActiveStatus.ON.getValue()) && !enumValues.contains(ActiveStatus.OFF.getValue())) {
sclReportItems.add(SclReportItem.error(xpath, "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'."));
}
substationService.getLNodes(scd).stream().filter(tlNode1 -> tlNode1.isSetIedName() && tlNode1.isSetLdInst())
.filter(tlNode1 -> tlNode1.getIedName().equals(tied.getName()) && tlNode1.getLdInst().equals(tlDevice.getInst()))
.findFirst()
.ifPresentOrElse(tlNode1 -> {
if(!enumValues.contains(ActiveStatus.ON.getValue())) {
sclReportItems.add(SclReportItem.error(xpath, "The LDevice cannot be set to 'on' but has been selected into SSD."));
}
},
// Deactivate LDevice
() -> update(tln, optionalModStVal.get().getValue(), ActiveStatus.OFF.getValue()));
})));
return sclReportItems;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
import org.lfenergy.compas.sct.commons.scl.ied.InputsAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.util.ActiveStatus;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,95 +697,39 @@ void updateLDeviceStatus_whenMissingDOMod_shouldReturnError() {
}


@Test
void updateLDeviceStatus_whenMissingPrivateLNodeStatus_shouldReturnError() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_NOK_MissingLNodeStatusPrivate.scd");
// When
List<SclReportItem> sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse();
assertThat(sclReportItems)
.hasSize(1)
.extracting(SclReportItem::message, SclReportItem::xpath)
.containsExactly(Tuple.tuple("The LN doesn't have a Private COMPAS-LNodeStatus",
"/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]/LN[class=LLN0]"));
}


@Test
void updateLDeviceStatus_whenEnumNotContainValues_shouldReturnError() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_NOK_MissingEnums.scd");
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
assertThat(getLDeviceStatusValue(scl).get().getValue()).isEqualTo("off");
// When
List<SclReportItem> sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService);
// Then
assertThat(sclReportItems)
.hasSize(1)
.hasSize(2)
.extracting(SclReportItem::message, SclReportItem::xpath)
.containsExactly(Tuple.tuple("The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.",
"/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]"));
}

@Test
void updateLDeviceStatus_whenLDeviceStatusOn_shouldSucceed() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_LD_STATUS_ON.scd");
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
// When
List<SclReportItem> sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService);
// Then
assertThat(sclReportItems).isEmpty();
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("on");
}


@Test
void updateLDeviceStatus_whenLDeviceStatusOnOff_shouldSucceed() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_LD_STATUS_ONOFF.scd");
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
// When
List<SclReportItem> sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService);
// Then
assertThat(sclReportItems).isEmpty();
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("on");
}


@Test
void updateLDeviceStatus_whenLDeviceStatusOff_AndExistINSubstation_shouldReturnError() {
// Given
SCL scl = SclTestMarshaller.getSCLFromFile("/scd-refresh-lnode/Test_LD_STATUS_OFF.scd");
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
// When
List<SclReportItem> sclReportItems = lnService.updateLDeviceStatus(scl, substationService, ldeviceService, dataTypeTemplatesService);
// Then
assertThat(sclReportItems)
.hasSize(1)
.extracting(SclReportItem::message, SclReportItem::xpath)
.containsExactly(Tuple.tuple("The LDevice is not qualified into STD but has been selected into SSD.",
"/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]"));
assertThat(getLDeviceStatusValue(scl, "IedName1", "LDSUIED").get().getValue()).isEqualTo("off");
"/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]/LN[class=LLN0]"),
Tuple.tuple("The LDevice cannot be set to 'on' but has been selected into SSD.",
"/SCL/IED[@name=IedName1]/AccessPoint/Server/LDevice[@inst=LDSUIED]/LN[class=LLN0]"));
}

private Optional<TVal> getLDeviceStatusValue(SCL scl, String iedName, String ldInst) {
return getValFromDaiName(scl, iedName, ldInst, "Mod", "stVal");
private Optional<TVal> getLDeviceStatusValue(SCL scl) {
return getValFromDaiName(scl);
}

private Optional<TVal> getValFromDaiName(SCL scl, String iedName, String ldInst, String doiName, String daiName) {
private Optional<TVal> getValFromDaiName(SCL scl) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scl);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName);
Optional<LDeviceAdapter> lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst(ldInst);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName("IedName1");
Optional<LDeviceAdapter> lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst("LDSUIED");
LN0Adapter ln0Adapter = lDeviceAdapter.get().getLN0Adapter();
Optional<DOIAdapter> doiAdapter = ln0Adapter.getDOIAdapters().stream()
.filter(doiAdapter1 -> doiAdapter1.getCurrentElem().getName().equals(doiName))
.filter(doiAdapter1 -> doiAdapter1.getCurrentElem().getName().equals("Mod"))
.findFirst();
return doiAdapter.flatMap(adapter -> adapter.getCurrentElem().getSDIOrDAI().stream()
.filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class))
.map(TDAI.class::cast)
.filter(tdai -> tdai.getName().equals(daiName) && !tdai.getVal().isEmpty())
.filter(tdai -> tdai.getName().equals("stVal") && !tdai.getVal().isEmpty())
.map(tdai -> tdai.getVal().get(0))
.findFirst());
}
Expand Down

This file was deleted.

Loading

0 comments on commit af2b751

Please sign in to comment.