Skip to content

Commit

Permalink
feat(): remove validation when DOI(Mod) and DAI(stVal) does not exists
Browse files Browse the repository at this point in the history
Signed-off-by: Samir Romdhani <samir.romdhani@rte-france.com>
  • Loading branch information
samirromdhani committed Feb 22, 2024
1 parent a4830ee commit 1f22d0c
Show file tree
Hide file tree
Showing 13 changed files with 1,022 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2024 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.*;

import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME;

public class DataTypeTemplatesService {

final LnodeTypeService lnodeTypeService = new LnodeTypeService();
final DoTypeService doTypeService = new DoTypeService();
final DoService doService = new DoService();

/**
* verify if DO(name=Mod)/DA(name=stVal) exists in DataTypeTemplate
* @param dtt TDataTypeTemplates where Data object and Data attribute exists
* @param lNodeTypeId LNode Type ID where Data object exists
* DataTypeTemplates model :
* <DataTypeTemplates>
* <LNodeType lnClass="LNodeTypeClass" id="LNodeTypeID">
* <DO name="Mod" type="DOModTypeID" ../>
* </LNodeType>
* ...
* <DOType cdc="DOTypeCDC" id="DOModTypeID">
* <DA name="stVal" ../>
* </DOType>
* </DataTypeTemplates>
* @return true if the Data Object (Mod) and Data attribute (stVal) present, false otherwise
*/
public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId) {
return lnodeTypeService.findLnodeType(dtt, lNodeType -> lNodeType.getId().equals(lNodeTypeId))
.map(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(MOD_DO_NAME))
.map(tdo -> doTypeService.findDoType(dtt, doType -> doType.getId().equals(tdo.getType()))
.map(doType -> doType.getSDOOrDA().stream()
.filter(unNaming -> unNaming.getClass().equals(TDA.class))
.map(TDA.class::cast)
.anyMatch(tda -> tda.getName().equals(STVAL_DA_NAME)))
.orElse(false))
.orElse(false))
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ExtRefEditorService implements ExtRefEditor {

private final LdeviceService ldeviceService;
private final ExtRefService extRefService;
private final DataTypeTemplatesService dataTypeTemplatesService;

/**
* Provides valid IED sources according to EPF configuration.<br/>
Expand Down Expand Up @@ -78,6 +79,37 @@ private static List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBa
.toList();
}

/**
* Provides a list of ExtRef and associated Bay <br/>
* - The location of ExtRef should be in LDevice (inst=LDEPF) <br/>
* - ExtRef that lacks Bay or ICDHeader Private is not returned <br/>
*
* @param sclReportItems List of SclReportItem
* @return list of ExtRef and associated Bay
*/
private List<ExtRefInfo.ExtRefWithBayReference> getExtRefWithBayReferenceInLDEPF(final LDeviceAdapter lDeviceAdapter, final List<SclReportItem> sclReportItems) {
List<ExtRefInfo.ExtRefWithBayReference> extRefBayReferenceList = new ArrayList<>();
IEDAdapter iedAdapter = lDeviceAdapter.getParentAdapter();
if (iedAdapter.getPrivateCompasBay().isEmpty()) {
sclReportItems.add(SclReportItem.error(lDeviceAdapter.getXPath(), "The IED has no Private Bay"));
if (iedAdapter.getCompasICDHeader().isEmpty()) {
sclReportItems.add(SclReportItem.error(lDeviceAdapter.getXPath(), "The IED has no Private compas:ICDHeader"));
}
return Collections.emptyList();
}

if(dataTypeTemplatesService.isDoModAndDaStValExist(iedAdapter.getParentAdapter().getDataTypeTemplateAdapter().getCurrentElem(),
lDeviceAdapter.getLN0Adapter().getLnType())) {
extRefBayReferenceList.addAll(lDeviceAdapter.getLN0Adapter()
.getInputsAdapter().getCurrentElem()
.getExtRef().stream()
.map(extRef -> new ExtRefInfo.ExtRefWithBayReference(iedAdapter.getName(), iedAdapter.getPrivateCompasBay().get(), extRef)).toList());
} else {
sclReportItems.add(SclReportItem.error(lDeviceAdapter.getXPath(), "DO@name=Mod/DA@name=stVal not found in DataTypeTemplate"));
}
return extRefBayReferenceList;
}

/**
* Verify if an Extref matches the EPF Channel or not.
*
Expand Down Expand Up @@ -272,7 +304,7 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
.filter(iedAdapter -> !iedAdapter.getName().contains("TEST"))
.map(iedAdapter -> iedAdapter.findLDeviceAdapterByLdInst(LDEVICE_LDEPF))
.flatMap(Optional::stream)
.forEach(lDeviceAdapter -> lDeviceAdapter.getExtRefBayReferenceForActifLDEPF(sclReportItems)
.forEach(lDeviceAdapter -> getExtRefWithBayReferenceInLDEPF(lDeviceAdapter, sclReportItems)
.forEach(extRefBayRef -> epf.getChannels().getChannel().stream().filter(tChannel -> doesExtRefMatchLDEPFChannel(extRefBayRef.extRef(), tChannel))
.findFirst().ifPresent(channel -> {
List<TIED> iedSources = getIedSources(sclRootAdapter, extRefBayRef.compasBay(), channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ && trimToEmpty(tfcda.getLnInst()).equals(trimToEmpty(bindingInfo.getLnInst()))
* @param compasBay The Bay object
* @param extRef The ExtRef object
*/
public record ExtRefBayReference(String iedName, TCompasBay compasBay, TExtRef extRef){ }
public record ExtRefWithBayReference(String iedName, TCompasBay compasBay, TExtRef extRef){ }

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class InputsAdapter extends SclElementAdapter<LN0Adapter, TInputs> {
private static final String MESSAGE_INVALID_SERVICE_TYPE = "The signal ExtRef ServiceType attribute is unexpected : %s";
private static final String MESSAGE_IED_MISSING_COMPAS_BAY_UUID = "IED is missing Private/compas:Bay@UUID attribute";
private static final String MESSAGE_EXTREF_DESC_MALFORMED = "ExtRef.serviceType=Report but ExtRef.desc attribute is malformed";
private static final String MESSAGE_LDEVICE_STATUS_UNDEFINED = "The LDevice status is undefined";
private static final String MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID = "The signal ExtRef iedName does not match any " +
"IED/Private/compas:ICDHeader@ICDSystemVersionUUID";
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED = "The signal ExtRef source LDevice %s status is undefined";
Expand Down Expand Up @@ -98,7 +97,7 @@ protected String elementXPath() {
public List<SclReportItem> updateAllExtRefIedNames(Map<String, IEDAdapter> icdSystemVersionToIed) {
Optional<String> optionalLDeviceStatus = getLDeviceAdapter().getLDeviceStatus();
if (optionalLDeviceStatus.isEmpty()) {
return List.of(getLDeviceAdapter().buildFatalReportItem(MESSAGE_LDEVICE_STATUS_UNDEFINED));
optionalLDeviceStatus = Optional.of(ActiveStatus.ON.getValue());
}
try {
ActiveStatus lDeviceStatus = ActiveStatus.fromValue(optionalLDeviceStatus.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import java.util.*;

import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.MOD_DO_TYPE_NAME;
import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.STVAL_DA_TYPE_NAME;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
import static org.lfenergy.compas.sct.commons.util.Utils.copySclElement;

Expand Down Expand Up @@ -489,33 +487,6 @@ private String createVal(TExtRef tExtRef) {
return sourceLdName + "/" + lnClass + "." + tExtRef.getSrcCBName();
}

/**
* Provides a list of ExtRef and associated Bay <br/>
* - The location of ExtRef should be in an active LDevice (inst=LDEPF) <br/>
* - ExtRef that lacks Bay or ICDHeader Private is not returned <br/>
*
* @param sclReportItems List of SclReportItem
* @return list of ExtRef and associated Bay
*/
public List<ExtRefInfo.ExtRefBayReference> getExtRefBayReferenceForActifLDEPF(final List<SclReportItem> sclReportItems) {
List<ExtRefInfo.ExtRefBayReference> extRefBayReferenceList = new ArrayList<>();
IEDAdapter parentIedAdapter = getParentAdapter();
if (parentIedAdapter.getPrivateCompasBay().isEmpty()) {
sclReportItems.add(SclReportItem.error(getXPath(), "The IED has no Private Bay"));
if (parentIedAdapter.getCompasICDHeader().isEmpty()) {
sclReportItems.add(SclReportItem.error(getXPath(), "The IED has no Private compas:ICDHeader"));
}
return Collections.emptyList();
}

getLDeviceStatus().map(ActiveStatus::fromValue).ifPresentOrElse(s -> {
if (ActiveStatus.ON.equals(s)) {
extRefBayReferenceList.addAll(getLN0Adapter().getInputsAdapter().getCurrentElem().getExtRef().stream().map(extRef -> new ExtRefInfo.ExtRefBayReference(parentIedAdapter.getName(), parentIedAdapter.getPrivateCompasBay().get(), extRef)).toList());
}
}, () -> sclReportItems.add(SclReportItem.error(getXPath(), "There is no DOI@name=" + MOD_DO_TYPE_NAME + "/DAI@name=" + STVAL_DA_TYPE_NAME + "/Val for LDevice@inst" + LDEVICE_LDEPF)));
return extRefBayReferenceList;
}

private TFCDA toFCDA(TFCDAFilter tfcdaFilter) {
TFCDA tfcda = new TFCDA();
tfcda.setLdInst(tfcdaFilter.getLdInst());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// SPDX-FileCopyrightText: 2024 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl2007b4.model.*;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

class DataTypeTemplatesServiceTest {

@Test
void isDoModAndDaStValExist_when_LNodeType_not_exist_should_return_false() {
//Given
SCL scl = new SCL();
TDataTypeTemplates dtt = new TDataTypeTemplates();
scl.setDataTypeTemplates(dtt);
//When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId");
//Then
assertThat(result).isFalse();
}


@Test
void isDoModAndDaStValExist_when_Do_not_exist_should_return_false() {
//Given
SCL scl = new SCL();
TDataTypeTemplates dtt = new TDataTypeTemplates();
TLNodeType tlNodeType = new TLNodeType();
tlNodeType.setId("lnodeTypeId");
dtt.getLNodeType().add(tlNodeType);
scl.setDataTypeTemplates(dtt);
//When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId");
//Then
assertThat(result).isFalse();
}

@Test
void isDoModAndDaStValExist_when_DoType_not_exist_should_return_false() {
//Given
SCL scl = new SCL();
TDataTypeTemplates dtt = new TDataTypeTemplates();
TLNodeType tlNodeType = new TLNodeType();
tlNodeType.setId("lnodeTypeId");
TDO tdo = new TDO();
tdo.setType("doTypeId");
tdo.setName("Mod");
tlNodeType.getDO().add(tdo);
dtt.getLNodeType().add(tlNodeType);
//When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId");
//Then
assertThat(result).isFalse();
}


@Test
void isDoModAndDaStValExist_when_Da_Mod_not_exist_should_return_false() {
//Given
SCL scl = new SCL();
TDataTypeTemplates dtt = new TDataTypeTemplates();
TLNodeType tlNodeType = new TLNodeType();
tlNodeType.setId("lnodeTypeId");
TDO tdo = new TDO();
tdo.setType("doTypeId");
tdo.setName("Mod");
tlNodeType.getDO().add(tdo);
dtt.getLNodeType().add(tlNodeType);
TDOType tdoType = new TDOType();
tdoType.setId("doTypeId");
dtt.getDOType().add(tdoType);
scl.setDataTypeTemplates(dtt);
//When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId");
//Then
assertThat(result).isFalse();
}


@Test
void isDoModAndDaStValExist_when_Da_stVal_not_found_should_return_false() {
//Given
SCL scl = new SCL();
TDataTypeTemplates dtt = new TDataTypeTemplates();
TLNodeType tlNodeType = new TLNodeType();
tlNodeType.setId("lnodeTypeId");
TDO tdo = new TDO();
tdo.setType("doTypeId");
tdo.setName("Mod");
tlNodeType.getDO().add(tdo);
dtt.getLNodeType().add(tlNodeType);
TDOType tdoType = new TDOType();
tdoType.setId("doTypeId");
TDA tda = new TDA();
tda.setName("daName");
tdoType.getSDOOrDA().add(tda);
dtt.getDOType().add(tdoType);
scl.setDataTypeTemplates(dtt);
//When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId");
//Then
assertThat(result).isFalse();
}


@Test
void isDoModAndDaStValExist_when_DO_Mod_And_DA_stVal_exist_return_true() {
//Given
SCL scl = new SCL();
TDataTypeTemplates dtt = new TDataTypeTemplates();
TLNodeType tlNodeType = new TLNodeType();
tlNodeType.setId("lnodeTypeId");
TDO tdo = new TDO();
tdo.setType("doTypeId");
tdo.setName("Mod");
tlNodeType.getDO().add(tdo);
dtt.getLNodeType().add(tlNodeType);
TDOType tdoType = new TDOType();
tdoType.setId("doTypeId");
TDA tda = new TDA();
tda.setName("stVal");
tdoType.getSDOOrDA().add(tda);
dtt.getDOType().add(tdoType);
scl.setDataTypeTemplates(dtt);
//When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
boolean result = dataTypeTemplatesService.isDoModAndDaStValExist(dtt, "lnodeTypeId");
//Then
assertThat(result).isTrue();
}
}
Loading

0 comments on commit 1f22d0c

Please sign in to comment.