diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java
index b72c0b4b2..3e6c643ab 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesService.java
@@ -12,7 +12,9 @@
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa;
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -30,18 +32,19 @@ public class DataTypeTemplatesService implements DataTypeTemplateReader {
/**
* verify if DO(name=Mod)/DA(name=stVal) exists in DataTypeTemplate
- * @param dtt TDataTypeTemplates where Data object and Data attribute exists
+ *
+ * @param dtt TDataTypeTemplates where Data object and Data attribute exists
* @param lNodeTypeId LNode Type ID where Data object exists
- * DataTypeTemplates model :
- *
- *
- *
- *
- * ...
- *
- *
- *
- *
+ * DataTypeTemplates model :
+ *
+ *
+ *
+ *
+ * ...
+ *
+ *
+ *
+ *
* @return true if the Data Object (Mod) and Data attribute (stVal) present, false otherwise
*/
public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId) {
@@ -54,16 +57,14 @@ public boolean isDoModAndDaStValExist(TDataTypeTemplates dtt, String lNodeTypeId
@Override
public Stream getAllDoLinkedToDa(TDataTypeTemplates dtt) {
- return lnodeTypeService.getLnodeTypes(dtt)
+ return lnodeTypeService.getLnodeTypes(dtt)
.flatMap(tlNodeType -> {
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(new DataObject());
- doLinkedToDa.setDataAttribute(new DataAttribute());
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(new DataObject(), new DataAttribute());
return tlNodeType.getDO()
.stream()
.map(tdo -> doTypeService.findDoType(dtt, tdoType -> tdoType.getId().equals(tdo.getType()))
.map(doType -> {
- doLinkedToDa.getDataObject().setDoName(tdo.getName());
+ doLinkedToDa.dataObject().setDoName(tdo.getName());
return doTypeService.getAllSDOLinkedToDa(dtt, doType, doLinkedToDa).stream();
}))
.filter(Optional::isPresent)
@@ -78,41 +79,49 @@ public Stream getFilteredDoLinkedToDa(TDataTypeTemplates dtt, Stri
.flatMap(tlNodeType -> doService.getFilteredDos(tlNodeType, tdo -> StringUtils.isBlank(doLinkedToDaFilter.doName())
|| doLinkedToDaFilter.doName().equals(tdo.getName()))
.flatMap(tdo -> {
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName(tdo.getName());
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(new DataAttribute());
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, new DataAttribute());
return doTypeService.findDoType(dtt, tdoType -> tdoType.getId().equals(tdo.getType()))
.stream()
.flatMap(tdoType -> {
- doLinkedToDa.getDataObject().setCdc(tdoType.getCdc());
+ doLinkedToDa.dataObject().setCdc(tdoType.getCdc());
return doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa).stream()
.filter(doLinkedToDa1 -> StringUtils.isBlank(doLinkedToDaFilter.doName())
|| (doLinkedToDa1.getDoRef().startsWith(doLinkedToDaFilter.getDoRef()) && StringUtils.isBlank(doLinkedToDaFilter.daName()))
|| doLinkedToDa1.getDaRef().startsWith(doLinkedToDaFilter.getDaRef()));
});
- }));
+ }));
}
@Override
- public Optional findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDa doLinkedToDa) {
- List dataRefList = new ArrayList<>(doLinkedToDa.getDataObject().getSdoNames());
- dataRefList.addAll(doLinkedToDa.getDataAttribute().getBdaNames());
+ public Optional findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter) {
+ List dataRefList = new ArrayList<>(doLinkedToDaFilter.sdoNames());
+ dataRefList.addAll(doLinkedToDaFilter.bdaNames());
return lnodeTypeService.findLnodeType(dtt, lNodeType -> lNodeTypeId.equals(lNodeType.getId()))
- .flatMap(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(doLinkedToDa.getDataObject().getDoName()))
+ .flatMap(lNodeType -> doService.findDo(lNodeType, tdo -> tdo.getName().equals(doLinkedToDaFilter.doName()))
// Search DoType for each DO
.flatMap(tdo -> doTypeService.findDoType(dtt, doType -> doType.getId().equals(tdo.getType()))
.flatMap(tdoType -> {
// Search last DoType from DOType (SDO) > DOType (SDO)
TDOType lastDoType = findDOTypeBySdoName(dtt, tdoType, dataRefList);
+ // Prepare DataObject
+ DataObject dataObject = new DataObject(tdo.getName(), tdoType.getCdc(), doLinkedToDaFilter.sdoNames());
// Search first DA from last DoType
- return sdoOrDAService.findDA(lastDoType, tda1 -> tda1.getName().equals(doLinkedToDa.getDataAttribute().getDaName()))
+ return sdoOrDAService.findDA(lastDoType, tda -> tda.getName().equals(doLinkedToDaFilter.daName()))
.flatMap(tda -> {
+ // Prepare DataAttribute
+ DataAttribute dataAttribute = new DataAttribute();
+ dataAttribute.setDaName(tda.getName());
+ dataAttribute.setFc(tda.getFc());
// Check if first DA is STRUCT or not
- if(!tda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT)) {
- return Optional.of(doLinkedToDa);
+ if (!tda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT)) {
+ dataAttribute.addDaVal(tda.getVal());
+ dataAttribute.setBType(tda.getBType());
+ dataAttribute.setType(tda.getType());
+ dataAttribute.setValImport(tda.isValImport());
+ return Optional.of(new DoLinkedToDa(dataObject, dataAttribute));
}
// Search first DaType from DOType (from last DOType where DA is STRUCT)
return getDATypeByDaName(dtt, lastDoType, tda.getName())
@@ -122,11 +131,18 @@ public Optional findDoLinkedToDa(TDataTypeTemplates dtt, String lN
&& tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT), dataRefList);
// last DAType should contain BDA not STRUCT
- if(dataRefList.size() != 1) return Optional.empty();
+ if (dataRefList.size() != 1) return Optional.empty();
String lastBdaName = dataRefList.getFirst();
return bdaService.findBDA(lastDAType, tbda -> tbda.getName().equals(lastBdaName)
&& !tbda.getBType().equals(TPredefinedBasicTypeEnum.STRUCT))
- .flatMap(tbda -> Optional.of(doLinkedToDa));
+ .flatMap(tbda -> {
+ dataAttribute.getBdaNames().addAll(doLinkedToDaFilter.bdaNames());
+ dataAttribute.setBType(tbda.getBType());
+ dataAttribute.setType(tbda.getType());
+ dataAttribute.setValImport(tbda.isValImport());
+ dataAttribute.addDaVal(tbda.getVal());
+ return Optional.of(new DoLinkedToDa(dataObject, dataAttribute));
+ });
});
});
})
@@ -139,7 +155,7 @@ private Optional getDATypeByDaName(TDataTypeTemplates dtt, TDOType tdoT
}
private TDOType findDOTypeBySdoName(TDataTypeTemplates dtt, TDOType tdoType, List sdoNames) {
- if(sdoNames.isEmpty()) return tdoType;
+ if (sdoNames.isEmpty()) return tdoType;
return sdoOrDAService.findSDO(tdoType, tsdo -> tsdo.getName().equals(sdoNames.getFirst()))
.flatMap(tsdo -> doTypeService.findDoType(dtt, tdoType2 -> tdoType2.getId().equals(tsdo.getType())))
.map(tdoType2 -> {
@@ -149,7 +165,7 @@ private TDOType findDOTypeBySdoName(TDataTypeTemplates dtt, TDOType tdoType, Lis
}
private TDAType findDATypeByBdaName(TDataTypeTemplates dtt, TDAType tdaType, Predicate tbdaPredicate, List bdaNames) {
- if(bdaNames.isEmpty()) return tdaType;
+ if (bdaNames.isEmpty()) return tdaType;
return bdaService.getFilteredBDAs(tdaType, tbdaPredicate)
.findFirst()
.flatMap(tbda -> daTypeService.findDaType(dtt, tbda.getType()))
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoTypeService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoTypeService.java
index 17cf62278..5b53aa546 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoTypeService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoTypeService.java
@@ -16,9 +16,9 @@
public class DoTypeService {
- final DaTypeService daTypeService = new DaTypeService();
- final SDOOrDAService sdoOrDAService = new SDOOrDAService();
- final BDAService bdaService = new BDAService();
+ final DaTypeService daTypeService = new DaTypeService();
+ final SDOOrDAService sdoOrDAService = new SDOOrDAService();
+ final BDAService bdaService = new BDAService();
public Stream getDoTypes(TDataTypeTemplates tDataTypeTemplates) {
return tDataTypeTemplates.getDOType().stream();
@@ -37,53 +37,54 @@ public List getAllSDOLinkedToDa(TDataTypeTemplates dtt, TDOType td
// DA -> BDA -> BDA..
sdoOrDAService.getDAs(tdoType).forEach(tda -> {
DoLinkedToDa doLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
- doLinkedToDa.getDataAttribute().setDaName(tda.getName());
- if(tda.isSetFc()) {
- doLinkedToDa.getDataAttribute().setFc(tda.getFc());
+ doLinkedToDa.dataAttribute().setDaName(tda.getName());
+ if (tda.isSetFc()) {
+ doLinkedToDa.dataAttribute().setFc(tda.getFc());
}
// STRUCT type (BType=STRUCT) refer to BDA, otherwise it is DA
- if(TPredefinedBasicTypeEnum.STRUCT.equals(tda.getBType())) {
+ if (TPredefinedBasicTypeEnum.STRUCT.equals(tda.getBType())) {
daTypeService.findDaType(dtt, tda.getType())
.ifPresent(nextDaType -> result.addAll(getDaLinkedToBDA(dtt, nextDaType, doLinkedToDa).toList()));
} else {
- doLinkedToDa.setDataAttribute(updateDataAttributeFromDaOrBda(tda, doLinkedToDa.getDataAttribute()));
- result.add(doLinkedToDa);
+ DataAttribute dataAttribute = updateDataAttributeFromDaOrBda(tda, doLinkedToDa.dataAttribute());
+ result.add(new DoLinkedToDa(doLinkedToDa.dataObject(), dataAttribute));
}
});
// SDO -> SDO -> SDO..
sdoOrDAService.getSDOs(tdoType)
.forEach(tsdo -> {
- if(tsdo.isSetType()){
- findDoType(dtt, tdoType1 -> tdoType1.getId().equals(tsdo.getType()))
- .ifPresent(nextDoType -> {
- DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
- newDoLinkedToDa.getDataObject().getSdoNames().add(tsdo.getName());
- if(nextDoType.isSetCdc()) {
- newDoLinkedToDa.getDataObject().setCdc(nextDoType.getCdc());
- }
- result.addAll(getAllSDOLinkedToDa(dtt, nextDoType, newDoLinkedToDa));
- });
+ if (tsdo.isSetType()) {
+ findDoType(dtt, tdoType1 -> tdoType1.getId().equals(tsdo.getType()))
+ .ifPresent(nextDoType -> {
+ DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
+ newDoLinkedToDa.dataObject().getSdoNames().add(tsdo.getName());
+ if (nextDoType.isSetCdc()) {
+ newDoLinkedToDa.dataObject().setCdc(nextDoType.getCdc());
+ }
+ result.addAll(getAllSDOLinkedToDa(dtt, nextDoType, newDoLinkedToDa));
+ });
}
});
return result;
}
+
private Stream getDaLinkedToBDA(TDataTypeTemplates dtt, TDAType tdaType1, DoLinkedToDa doLinkedToDaTemplate) {
// BDA -> BDA -> BDA..
return bdaService.getBDAs(tdaType1)
.flatMap(tbda -> {
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDaTemplate);
- newDoLinkedToDa.getDataAttribute().getBdaNames().add(tbda.getName());
+ newDoLinkedToDa.dataAttribute().getBdaNames().add(tbda.getName());
// STRUCT type (BType=STRUCT) refer to complex BDA object, otherwise it is kind of DA object
- if(TPredefinedBasicTypeEnum.STRUCT.equals(tbda.getBType())){
- return daTypeService.findDaType(dtt, tbda.getType())
+ if (TPredefinedBasicTypeEnum.STRUCT.equals(tbda.getBType())) {
+ return daTypeService.findDaType(dtt, tbda.getType())
.stream().flatMap(nextDaType -> getDaLinkedToBDA(dtt, nextDaType, newDoLinkedToDa));
} else {
- newDoLinkedToDa.setDataAttribute(updateDataAttributeFromDaOrBda(tbda, newDoLinkedToDa.getDataAttribute()));
- return Stream.of(newDoLinkedToDa);
+ DataAttribute dataAttribute = updateDataAttributeFromDaOrBda(tbda, newDoLinkedToDa.dataAttribute());
+ return Stream.of(new DoLinkedToDa(newDoLinkedToDa.dataObject(), dataAttribute));
}
- });
+ });
}
private DataAttribute updateDataAttributeFromDaOrBda(TAbstractDataAttribute daOrBda, DataAttribute dataAttribute) {
@@ -94,4 +95,4 @@ private DataAttribute updateDataAttributeFromDaOrBda(TAbstractDataAttribute daOr
return dataAttribute;
}
-}
\ No newline at end of file
+}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java
index 221b133f5..e9ddd2e92 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefEditorService.java
@@ -307,15 +307,12 @@ public void epfPostProcessing(SCL scd) {
&& (purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_DIGITAL CHANNEL")
|| purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_ANALOG CHANNEL"));
if(isSetSrcRefExistAndEmpty && isPurposeExistAndMatchChannel) {
-
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName(tdoi.getName());
- doLinkedToDa.setDataObject(dataObject);
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName(SETSRCREF_DA_NAME);
dataAttribute.setDaiValues(List.of(new DaVal(null, tied.getName()+tlDevice.getInst()+"/LPHD0.Proxy")));
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
lnEditor.updateOrCreateDOAndDAInstances(tlDevice.getLN0(), doLinkedToDa);
}
})));
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LNodeStatusService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LNodeStatusService.java
new file mode 100644
index 000000000..af902ca3a
--- /dev/null
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LNodeStatusService.java
@@ -0,0 +1,103 @@
+// SPDX-FileCopyrightText: 2024 RTE FRANCE
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package org.lfenergy.compas.sct.commons;
+
+import lombok.RequiredArgsConstructor;
+import org.lfenergy.compas.scl2007b4.model.*;
+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 org.lfenergy.compas.sct.commons.util.PrivateUtils;
+import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+@RequiredArgsConstructor
+public class LNodeStatusService {
+
+ private static final String LNODE_STATUS_PRIVATE_TYPE = "COMPAS-LNodeStatus";
+ private static final List LN_LNS_POSSIBLE_VALUES = List.of("off;on", "on;off", "on", "off");
+ private static final List LNODE_LNS_POSSIBLE_VALUES = List.of("on", "off");
+ private final LdeviceService ldeviceService;
+ private final LnService lnService;
+ private final DataTypeTemplatesService dataTypeTemplatesService;
+
+ public List updateLnModStValBasedOnLNodeStatus(SCL scl) {
+ return 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 -> updateSingleLnModStValBasedOnLNodeStatus(scl, tlNode))
+ .filter(Objects::nonNull)
+ .toList();
+ }
+
+ private SclReportItem updateSingleLnModStValBasedOnLNodeStatus(SCL scl, TLNode tlNode) {
+ String lNodeLNS = PrivateUtils.extractStringPrivate(tlNode, LNODE_STATUS_PRIVATE_TYPE).orElse(null);
+ 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 || !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));
+ }
+ TDAI daiModStVal = lnService.getDaiModStVal(anyLn).orElse(null);
+ if (daiModStVal == null) {
+ return null; // do nothing if DAI Mod.stVal is missing
+ }
+ List modStValEnumValues = getModStValEnumValues(scl.getDataTypeTemplates(), anyLn.getLnType()).toList();
+ if (!modStValEnumValues.contains(lNodeLNS)) {
+ return SclReportItem.error(lnPath(tlNode), "Cannot set DAI Mod.stVal to '%s' because value is not in EnumType %s".formatted(lNodeLNS, modStValEnumValues));
+ }
+ daiModStVal.getVal().clear();
+ daiModStVal.getVal().add(SclConstructorHelper.newVal(lNodeLNS));
+ return null; // no error
+ }
+
+ private static String lnPath(TLNode tlNode) {
+ return "IED(%s)/LD(%s)/LN[%s,%s,%s]".formatted(tlNode.getIedName(), tlNode.getLdInst(), tlNode.getLnClass().getFirst(), tlNode.getLnInst(), tlNode.getPrefix());
+ }
+
+ private static String lNodePath(TLNode tlNode) {
+ return "LNode(iedName=%s, ldInst=%s, lnClass=%s, lnInst=%s, prefix=%s)".formatted(tlNode.getIedName(), tlNode.getLdInst(), tlNode.getLnClass().getFirst(), tlNode.getLnInst(), tlNode.getPrefix());
+ }
+
+ private Stream getModStValEnumValues(TDataTypeTemplates dataTypeTemplates, String lnType) {
+ return dataTypeTemplatesService.findDoLinkedToDa(dataTypeTemplates, lnType, DoLinkedToDaFilter.from(CommonConstants.MOD_DO_NAME, CommonConstants.STVAL_DA_NAME))
+ .map(DoLinkedToDa::dataAttribute)
+ .filter(dataAttribute -> TPredefinedBasicTypeEnum.ENUM.equals(dataAttribute.getBType()))
+ .map(DataAttribute::getType)
+ .flatMap(enumId ->
+ dataTypeTemplates.getEnumType().stream()
+ .filter(tEnumType -> tEnumType.getId().equals(enumId))
+ .findFirst())
+ .stream()
+ .flatMap(tEnumType -> tEnumType.getEnumVal().stream())
+ .map(TEnumVal::getValue);
+ }
+
+ private Optional 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 -> ldeviceService.findLdevice(tied, tlDevice -> ldInst.equals(tlDevice.getInst())))
+ .flatMap(tlDevice -> lnService.findAnyLn(tlDevice, tAnyLN -> lnService.matchesLn(tAnyLN, lnClass, lnInst, prefix)));
+
+ }
+}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java
index 008aad426..f607b0d20 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java
@@ -41,6 +41,6 @@ public Optional findLdevice(TIED tied, Predicate ldevicePred
public Optional getLdeviceStatus(TLDevice tlDevice) {
LnService lnService = new LnService();
- return lnService.getDaiModStval(tlDevice.getLN0());
+ return lnService.getDaiModStValValue(tlDevice.getLN0());
}
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java
index 2ccad6508..50d55c585 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java
@@ -12,7 +12,6 @@
import org.lfenergy.compas.sct.commons.util.ActiveStatus;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
@@ -60,33 +59,37 @@ public Optional findLn(TLDevice tlDevice, Predicate lnPredicate) {
* @return the Lnode Status
*/
public ActiveStatus getLnStatus(TAnyLN tAnyLN, LN0 ln0) {
- Optional ln0Status = getDaiModStval(ln0);
- return getDaiModStval(tAnyLN).filter(ActiveStatus.OFF::equals).orElseGet(() -> ln0Status.orElse(ActiveStatus.OFF));
+ Optional ln0Status = getDaiModStValValue(ln0);
+ return getDaiModStValValue(tAnyLN).filter(ActiveStatus.OFF::equals).orElseGet(() -> ln0Status.orElse(ActiveStatus.OFF));
}
- public Optional getDaiModStval(TAnyLN tAnyLN) {
+ public Optional getDaiModStValValue(TAnyLN tAnyLN) {
+ return getDaiModStVal(tAnyLN)
+ .stream()
+ .flatMap(tdai -> tdai.getVal().stream())
+ .map(TVal::getValue)
+ .findFirst()
+ .map(ActiveStatus::fromValue);
+ }
+
+ public Optional getDaiModStVal(TAnyLN tAnyLN) {
return tAnyLN
.getDOI()
.stream()
.filter(tdoi -> MOD_DO_NAME.equals(tdoi.getName()))
- .findFirst()
- .flatMap(tdoi -> tdoi.getSDIOrDAI()
- .stream()
- .filter(dai -> dai.getClass().equals(TDAI.class))
- .map(TDAI.class::cast)
- .filter(tdai -> STVAL_DA_NAME.equals(tdai.getName()))
- .map(TDAI::getVal)
- .flatMap(Collection::stream)
- .findFirst()
- .map(TVal::getValue))
- .map(ActiveStatus::fromValue);
+ .flatMap(tdoi -> tdoi.getSDIOrDAI().stream())
+ .filter(TDAI.class::isInstance)
+ .map(TDAI.class::cast)
+ .filter(tdai -> STVAL_DA_NAME.equals(tdai.getName()))
+ .findFirst();
}
+
public Stream getActiveLns(TLDevice tlDevice) {
LN0 ln0 = tlDevice.getLN0();
Stream tlnStream = tlDevice.getLN()
.stream()
.filter(tln -> ActiveStatus.ON.equals(getLnStatus(tln, ln0)));
- Stream ln0Stream = Stream.of(ln0).filter(ln02 -> getDaiModStval(ln02).map(ActiveStatus.ON::equals).orElse(false));
+ Stream ln0Stream = Stream.of(ln0).filter(ln02 -> getDaiModStValValue(ln02).map(ActiveStatus.ON::equals).orElse(false));
return Stream.concat(ln0Stream, tlnStream);
}
@@ -99,7 +102,7 @@ public Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLi
return tAnyLN.getDOI().stream().filter(doi -> doi.getName().equals(doLinkedToDaFilter.doName()))
.findFirst()
.flatMap(doi -> {
- if(structNamesList.size() > 1) {
+ if (structNamesList.size() > 1) {
String firstSDIName = structNamesList.removeFirst();
return this.getSdiByName(doi, firstSDIName)
.map(intermediateSdi -> findSDIByStructName(intermediateSdi, structNamesList))
@@ -116,7 +119,7 @@ public Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLi
return Optional.empty();
})
.stream().findFirst();
- } else if(structNamesList.size() == 1){
+ } else if (structNamesList.size() == 1) {
return doi.getSDIOrDAI().stream()
.filter(unNaming -> unNaming.getClass().equals(TDAI.class))
.map(TDAI.class::cast)
@@ -129,16 +132,16 @@ public Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLi
@Override
public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedToDa) {
- createDoiSdiDaiChainIfNotExists(tAnyLN, doLinkedToDa.getDataObject(), doLinkedToDa.getDataAttribute())
+ createDoiSdiDaiChainIfNotExists(tAnyLN, doLinkedToDa.dataObject(), doLinkedToDa.dataAttribute())
.ifPresent(tdai -> {
- List daiVals = doLinkedToDa.getDataAttribute().getDaiValues();
- if(!hasSettingGroup(tdai) && daiVals.size() == 1 && daiVals.getFirst().settingGroup() == null) {
+ List daiVals = doLinkedToDa.dataAttribute().getDaiValues();
+ if (!hasSettingGroup(tdai) && daiVals.size() == 1 && daiVals.getFirst().settingGroup() == null) {
String value = daiVals.getFirst().val();
tdai.getVal().stream().findFirst()
.ifPresentOrElse(tVal -> tVal.setValue(value),
() -> tdai.getVal().add(newVal(value)));
} else {
- for (DaVal daVal: daiVals) {
+ for (DaVal daVal : daiVals) {
tdai.getVal().stream()
.filter(tValElem -> tValElem.isSetSGroup() && tValElem.getSGroup() == daVal.settingGroup())
.findFirst()
@@ -152,11 +155,11 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT
public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLinkedToDa doLinkedToDa) {
getDOAndDAInstances(anyLN, doLinkedToDa.toFilter())
.ifPresent(tdai -> {
- if(tdai.isSetVal()) {
- doLinkedToDa.getDataAttribute().addDaVal(tdai.getVal());
+ if (tdai.isSetVal()) {
+ doLinkedToDa.dataAttribute().addDaVal(tdai.getVal());
}
- if(doLinkedToDa.getDataAttribute().getFc() == TFCEnum.SG || doLinkedToDa.getDataAttribute().getFc() == TFCEnum.SE) {
- if(hasSettingGroup(tdai)) {
+ if (doLinkedToDa.dataAttribute().getFc() == TFCEnum.SG || doLinkedToDa.dataAttribute().getFc() == TFCEnum.SE) {
+ if (hasSettingGroup(tdai)) {
boolean isIedHasConfSG = tied.isSetAccessPoint() &&
tied.getAccessPoint().stream()
.filter(tAccessPoint -> tAccessPoint.getServer() != null
@@ -166,13 +169,13 @@ public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLin
&& tAccessPoint.getServices() != null
&& tAccessPoint.getServices().getSettingGroups() != null
&& tAccessPoint.getServices().getSettingGroups().getConfSG() != null);
- doLinkedToDa.getDataAttribute().setValImport((!tdai.isSetValImport() || tdai.isValImport()) && isIedHasConfSG);
+ doLinkedToDa.dataAttribute().setValImport((!tdai.isSetValImport() || tdai.isValImport()) && isIedHasConfSG);
} else {
- log.warn(String.format("Inconsistency in the SCD file - DAI= %s with fc= %s must have a sGroup attribute", tdai.getName(), doLinkedToDa.getDataAttribute().getFc()));
- doLinkedToDa.getDataAttribute().setValImport(false);
- }
- } else if(tdai.isSetValImport()) {
- doLinkedToDa.getDataAttribute().setValImport(tdai.isValImport());
+ log.warn(String.format("Inconsistency in the SCD file - DAI= %s with fc= %s must have a sGroup attribute", tdai.getName(), doLinkedToDa.dataAttribute().getFc()));
+ doLinkedToDa.dataAttribute().setValImport(false);
+ }
+ } else if (tdai.isSetValImport()) {
+ doLinkedToDa.dataAttribute().setValImport(tdai.isValImport());
}
});
}
@@ -198,22 +201,22 @@ private Optional createDoiSdiDaiChainIfNotExists(TAnyLN tAnyLN, DataObject
TDOI doi = tAnyLN.getDOI().stream().filter(doi1 -> doi1.getName().equals(dataObject.getDoName()))
.findFirst()
- .orElseGet(()-> {
+ .orElseGet(() -> {
TDOI newDOI = new TDOI();
newDOI.setName(dataObject.getDoName());
tAnyLN.getDOI().add(newDOI);
return newDOI;
});
- if(structInstances.size() > 1){
+ if (structInstances.size() > 1) {
TSDI firstSDI = findOrCreateSDIFromDOI(doi, structInstances.getFirst());
TSDI lastSDI = findOrCreateSDIByStructName(firstSDI, structInstances);
- if(structInstances.size() == 1){
+ if (structInstances.size() == 1) {
return lastSDI.getSDIOrDAI().stream()
.filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class))
.map(TDAI.class::cast)
.filter(tdai -> tdai.getName().equals(structInstances.getFirst()))
.map(tdai -> {
- if(tdai.isSetValImport()) {
+ if (tdai.isSetValImport()) {
tdai.setValImport(dataAttribute.isValImport());
}
return tdai;
@@ -226,13 +229,13 @@ private Optional createDoiSdiDaiChainIfNotExists(TAnyLN tAnyLN, DataObject
return Optional.of(newDAI);
});
}
- } else if(structInstances.size() == 1){
+ } else if (structInstances.size() == 1) {
return doi.getSDIOrDAI().stream()
.filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class))
.map(TDAI.class::cast)
.filter(tdai -> tdai.getName().equals(structInstances.getFirst()))
.map(tdai -> {
- if(tdai.isSetValImport()) tdai.setValImport(dataAttribute.isValImport());
+ if (tdai.isSetValImport()) tdai.setValImport(dataAttribute.isValImport());
return tdai;
})
.findFirst()
@@ -247,7 +250,7 @@ private Optional createDoiSdiDaiChainIfNotExists(TAnyLN tAnyLN, DataObject
}
private TSDI findSDIByStructName(TSDI tsdi, List sdiNames) {
- if(sdiNames.isEmpty()) return tsdi;
+ if (sdiNames.isEmpty()) return tsdi;
return this.getSdiByName(tsdi, sdiNames.getFirst())
.map(sdi1 -> {
sdiNames.removeFirst();
@@ -294,14 +297,13 @@ private Optional getSdiByName(TSDI sdi, String sdiName) {
}
/**
- *
- * @param sdi TSDI
+ * @param sdi TSDI
* @param structName list start with sdi name
* @return already existing TSDI or newly created TSDI from given TSDI
*/
private TSDI findOrCreateSDIByStructName(TSDI sdi, List structName) {
structName.removeFirst();
- if(structName.isEmpty() || structName.size() == 1) return sdi;
+ if (structName.isEmpty() || structName.size() == 1) return sdi;
return findOrCreateSDIByStructName(findOrCreateSDIFromSDI(sdi, structName.getFirst()), structName);
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataTypeTemplateReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataTypeTemplateReader.java
index 63640ec7f..572391f71 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataTypeTemplateReader.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataTypeTemplateReader.java
@@ -19,6 +19,6 @@ public interface DataTypeTemplateReader {
Stream getFilteredDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter);
- Optional findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDa doLinkedToDa);
+ Optional findDoLinkedToDa(TDataTypeTemplates dtt, String lNodeTypeId, DoLinkedToDaFilter doLinkedToDaFilter);
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataObject.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataObject.java
index e8119345b..b18a06820 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataObject.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DataObject.java
@@ -13,18 +13,21 @@
@Getter
@Setter
+@NoArgsConstructor
public class DataObject {
private String doName;
private TPredefinedCDCEnum cdc;
private List sdoNames = new ArrayList<>();
+ public DataObject(String doName, TPredefinedCDCEnum cdc, List sdoNames) {
+ this.doName = doName;
+ this.cdc = cdc;
+ this.sdoNames.addAll(sdoNames);
+ }
+
public static DataObject copyFrom(DataObject dataObject) {
- DataObject dataObject1 = new DataObject();
- dataObject1.setDoName(dataObject.getDoName());
- dataObject1.setCdc(dataObject.getCdc());
- dataObject1.getSdoNames().addAll(dataObject.getSdoNames());
- return dataObject1;
+ return new DataObject(dataObject.getDoName(), dataObject.getCdc(), dataObject.getSdoNames());
}
@Override
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java
index 7a1d86a48..92e34de9f 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDa.java
@@ -5,25 +5,16 @@
package org.lfenergy.compas.sct.commons.domain;
-import lombok.Getter;
-import lombok.Setter;
-
import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME;
-@Getter
-@Setter
-public class DoLinkedToDa {
-
- private DataObject dataObject;
- private DataAttribute dataAttribute;
+public record DoLinkedToDa(DataObject dataObject, DataAttribute dataAttribute) {
public static DoLinkedToDa copyFrom(DoLinkedToDa doLinkedToDa) {
- DoLinkedToDa newDoLinkedToDa = new DoLinkedToDa();
- newDoLinkedToDa.setDataObject(DataObject.copyFrom(doLinkedToDa.getDataObject()));
- newDoLinkedToDa.setDataAttribute(DataAttribute.copyFrom(doLinkedToDa.getDataAttribute()));
- return newDoLinkedToDa;
+ return new DoLinkedToDa(
+ DataObject.copyFrom(doLinkedToDa.dataObject()),
+ DataAttribute.copyFrom(doLinkedToDa.dataAttribute()));
}
public String getDoRef() {
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java
index ecc3986cf..3912eb323 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java
@@ -18,7 +18,7 @@
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter;
-import org.lfenergy.compas.sct.commons.scl.ln.LnKey;
+import org.lfenergy.compas.sct.commons.scl.ln.LnId;
import org.lfenergy.compas.sct.commons.util.Utils;
import java.util.HashSet;
@@ -152,14 +152,10 @@ public static LNodeDTO from(AbstractLNAdapter nodeAdapter,
public static LNodeDTO from(TAnyLN tAnyLN, LogicalNodeOptions options, String iedName, String ldInst, SCL scl) {
log.info(Utils.entering());
- LnKey lnKey = switch (tAnyLN) {
- case LN0 ln0 -> new LnKey(ln0);
- case TLN tln -> new LnKey(tln);
- default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
- };
- String inst = lnKey.getInst();
- String lnClass = lnKey.getLnClass();
- String prefix = lnKey.getPrefix();
+ LnId lnId = LnId.from(tAnyLN);
+ String inst = lnId.lnInst();
+ String lnClass = lnId.lnClass();
+ String prefix = lnId.prefix();
String lnType = tAnyLN.getLnType();
LNodeDTO lNodeDTO = new LNodeDTO(inst, lnClass, prefix, lnType);
if (options.isWithExtRef()) {
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnId.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnId.java
new file mode 100644
index 000000000..af80a0eb3
--- /dev/null
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnId.java
@@ -0,0 +1,82 @@
+// SPDX-FileCopyrightText: 2021 RTE FRANCE
+//
+// SPDX-License-Identifier: Apache-2.0
+package org.lfenergy.compas.sct.commons.scl.ln;
+
+import org.apache.commons.lang3.StringUtils;
+import org.lfenergy.compas.scl2007b4.model.*;
+import org.lfenergy.compas.sct.commons.exception.ScdException;
+
+import java.util.List;
+import java.util.Objects;
+
+public record LnId(String lnClass, String lnInst, String prefix) {
+ private static final String LN0_LNCLASS = TLLN0Enum.LLN_0.value();
+
+ /**
+ * Id of LN0. All LN0 have the same lnClass, lnInst and prefix in SCD
+ */
+ public static final LnId LN0_ID = new LnId(LN0_LNCLASS, "", "");
+
+ /**
+ * Constructor
+ *
+ * @param lnClass always required
+ * @param lnInst optional. It should be empty for LN0, and should be filled for LN. No verification is done because some Lnode GAPC do not have a lninst.
+ * @param prefix optional. Is set to empty if null because empty is the default value on LN and the majority of the JAXB Element (LN, LNode, FCDA, ClientLN, but not on ExtRef and IEDName unfortunately)
+ */
+ public LnId(String lnClass, String lnInst, String prefix) {
+ if (StringUtils.isBlank(lnClass)) {
+ throw new ScdException("lnClass is required");
+ }
+ this.lnClass = lnClass;
+ this.lnInst = Objects.requireNonNullElse(lnInst, "");
+ this.prefix = Objects.requireNonNullElse(prefix, "");
+ }
+
+ /**
+ * Alternative constructor with lnClass as a List instead of a String.
+ * JAXB classes lnClass attribute are List, even though it can only contain one element.
+ * This constructor makes it easier to create LnId from JAXB classes
+ *
+ * @param lnClass one element list containing the lnClass value of the LN
+ * @param lnInst LN lnInst
+ * @param prefix LN prefix
+ */
+ public LnId(List lnClass, String lnInst, String prefix) {
+ this(lnClass == null || lnClass.isEmpty() ? null : lnClass.getFirst(), lnInst, prefix);
+ }
+
+ /**
+ * Extract id from LN element
+ *
+ * @param tAnyLN LN element
+ * @return id
+ */
+ public static LnId from(TAnyLN tAnyLN) {
+ if (tAnyLN instanceof TLN0) {
+ return LN0_ID;
+ } else if (tAnyLN instanceof TLN tln) {
+ return new LnId(tln.getLnClass(), tln.getInst(), tln.getPrefix());
+ } else {
+ throw new ScdException("Unexpected class : " + (tAnyLN != null ? tAnyLN.getClass() : null));
+ }
+ }
+
+ /**
+ * Extract id from LNode element
+ *
+ * @param tlNode LNode element
+ * @return id
+ */
+ public static LnId from(TLNode tlNode) {
+ if (tlNode.getLnClass().contains(LN0_LNCLASS)) {
+ return LN0_ID;
+ } else {
+ return new LnId(tlNode.getLnClass(), tlNode.getLnInst(), tlNode.getPrefix());
+ }
+ }
+
+
+
+}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java
deleted file mode 100644
index 3f37c514f..000000000
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// SPDX-FileCopyrightText: 2021 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.sct.commons.scl.ln;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
-import org.lfenergy.compas.scl2007b4.model.*;
-
-@Getter
-@EqualsAndHashCode
-public class LnKey {
-
- private final String inst;
- @EqualsAndHashCode.Exclude
- private final String lnType;
- private final String lnClass;
- /** empty for LN0 */
- private final String prefix;
-
- public LnKey(LN0 ln0) {
- this.inst = ln0.getInst();
- this.lnType = ln0.getLnType();
- this.lnClass = ln0.getLnClass().get(0);
- this.prefix = StringUtils.EMPTY;
- }
-
- public LnKey(TLN tln) {
- this.inst = tln.getInst();
- this.lnType = tln.getLnType();
- this.lnClass = tln.getLnClass().get(0);
- this.prefix = tln.getPrefix();
- }
-
-}
-
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/PrivateUtils.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/PrivateUtils.java
index 049f1e48a..8d9cbfde1 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/PrivateUtils.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/PrivateUtils.java
@@ -7,6 +7,7 @@
import jakarta.xml.bind.JAXBElement;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
+import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.PrivateLinkedToStds;
import org.lfenergy.compas.sct.commons.exception.ScdException;
@@ -320,4 +321,13 @@ public static void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(TPrivate st
}
+ public static Optional 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();
}
+}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java
index f9d5898d1..54b837884 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataTypeTemplatesServiceTest.java
@@ -17,7 +17,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.tuple;
-import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.*;
+import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.initDttFromFile;
+import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal;
class DataTypeTemplatesServiceTest {
@@ -151,12 +152,12 @@ void getFilteredDoLinkedToDa_should_return_expected_items() {
List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList();
//Then
assertThat(result).hasSize(9)
- .extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ .extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactlyInAnyOrder(
tuple("FirstDoName", List.of(),
"sampleDaName1", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null),
@@ -191,12 +192,12 @@ void getFilteredDOAndDA_when_given_DoName_should_return_expected_dataReference()
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList();
//Then
- assertThat(result).hasSize(1).extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ assertThat(result).hasSize(1).extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactly(tuple("SecondDoName", List.of(), "sampleDaName41", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null));
}
@@ -212,12 +213,12 @@ void getFilteredDOAndDA_when_given_DO_with_one_structName_should_return_expected
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList();
//Then
- assertThat(result).hasSize(3).extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ assertThat(result).hasSize(3).extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactlyInAnyOrder(tuple("FirstDoName", List.of("sdoName1"), "sampleDaName21", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null),
tuple("FirstDoName", List.of("sdoName1", "sdoName21"), "sampleDaName31", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null),
tuple("FirstDoName", List.of("sdoName1", "sdoName21", "sdoName31"), "sampleDaName41", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null));
@@ -234,12 +235,12 @@ void getFilteredDOAndDA_when_given_DO_with_many_structName_should_return_expecte
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList();
//Then
- assertThat(result).hasSize(2).extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ assertThat(result).hasSize(2).extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactlyInAnyOrder(tuple("FirstDoName", List.of("sdoName1", "sdoName21"), "sampleDaName31", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null),
tuple("FirstDoName", List.of("sdoName1", "sdoName21", "sdoName31"), "sampleDaName41", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null));
}
@@ -256,12 +257,12 @@ void getFilteredDOAndDA_when_given_DO_and_DA_with_structNames_should_return_expe
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
List result = dataTypeTemplatesService.getFilteredDoLinkedToDa(dtt, lNodeTypeId, doLinkedToDaFilter).toList();
//Then
- assertThat(result).hasSize(1).extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ assertThat(result).hasSize(1).extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactlyInAnyOrder(tuple("FirstDoName", List.of("sdoName2"), "structDaName1", List.of("structBdaName1", "enumBdaName22"), TPredefinedBasicTypeEnum.ENUM, "EnumType1"));
}
@@ -270,58 +271,66 @@ void findDoLinkedToDa_should_find_DO_SDO_DA_and_all_BDA() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/ied-test-schema-conf/ied_unit_test.xml");
TDataTypeTemplates dtt = scd.getDataTypeTemplates();
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName("Do");
dataObject.setSdoNames(List.of("sdo1", "d"));
- doLinkedToDa.setDataObject(dataObject);
+ dataObject.setCdc(TPredefinedCDCEnum.WYE);
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("antRef");
dataAttribute.setBdaNames(List.of("bda1", "bda2", "bda3"));
- doLinkedToDa.setDataAttribute(dataAttribute);
+ dataAttribute.setFc(TFCEnum.ST);
+ dataAttribute.setBType(TPredefinedBasicTypeEnum.ENUM);
+ dataAttribute.setType("RecCycModKind");
+ dataAttribute.setValImport(true);
+ dataAttribute.addDaVal(List.of(newVal("myValue")));
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
+ DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter("Do", List.of("sdo1", "d"), "antRef", List.of("bda1", "bda2", "bda3"));
// When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
- Optional result = dataTypeTemplatesService.findDoLinkedToDa(dtt, "LNO1", doLinkedToDa);
+ Optional result = dataTypeTemplatesService.findDoLinkedToDa(dtt, "LNO1", doLinkedToDaFilter);
// Then
- assertThat(result).contains(doLinkedToDa);
+ assertThat(result).get().usingRecursiveComparison().isEqualTo(doLinkedToDa);
}
@Test
void findDoLinkedToDa_should_find_DO_SDO_DA_and_partial_BDA_list() {
// Given
TDataTypeTemplates dtt = initDttFromFile("/dtt-test-schema-conf/scd_dtt_do_sdo_da_bda.xml");
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName("Do1");
+ dataObject.setCdc(TPredefinedCDCEnum.WYE);
dataObject.setSdoNames(List.of("sdo1", "sdo2"));
- doLinkedToDa.setDataObject(dataObject);
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("da2");
+ dataAttribute.setFc(TFCEnum.ST);
dataAttribute.setBdaNames(List.of("bda1", "bda2"));
- doLinkedToDa.setDataAttribute(dataAttribute);
+ dataAttribute.setBType(TPredefinedBasicTypeEnum.ENUM);
+ dataAttribute.setType("EnumType1");
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
// When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
- Optional result = dataTypeTemplatesService.findDoLinkedToDa(dtt, "LN1", doLinkedToDa);
+ Optional result = dataTypeTemplatesService.findDoLinkedToDa(dtt, "LN1", new DoLinkedToDaFilter("Do1", List.of("sdo1", "sdo2"), "da2", List.of("bda1", "bda2")));
// Then
- assertThat(result).contains(doLinkedToDa);
+ assertThat(result).get().usingRecursiveComparison().isEqualTo(doLinkedToDa);
}
@Test
void findDoLinkedToDa_should_find_DO_DA() {
// Given
TDataTypeTemplates dtt = initDttFromFile("/dtt-test-schema-conf/scd_dtt_do_sdo_da_bda.xml");
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName("Do1");
- doLinkedToDa.setDataObject(dataObject);
+ dataObject.setCdc(TPredefinedCDCEnum.WYE);
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("da1");
- doLinkedToDa.setDataAttribute(dataAttribute);
+ dataAttribute.setBType(TPredefinedBasicTypeEnum.BOOLEAN);
+ dataAttribute.setFc(TFCEnum.ST);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
// When
DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService();
- Optional result = dataTypeTemplatesService.findDoLinkedToDa(dtt, "LN1", doLinkedToDa);
+ Optional result = dataTypeTemplatesService.findDoLinkedToDa(dtt, "LN1", new DoLinkedToDaFilter("Do1", List.of(), "da1", List.of()));
// Then
- assertThat(result).contains(doLinkedToDa);
+ assertThat(result).get().usingRecursiveComparison().isEqualTo(doLinkedToDa);
}
@Test
@@ -415,10 +424,10 @@ void getAllDOAndDA_when_1DO_linked_to_1DA_should_return_expectedItems() {
//Then
assertThat(result).hasSize(1);
assertThat(result.getFirst())
- .extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames())
+ .extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames())
.containsExactly("doName", List.of(), "daName", List.of());
}
@@ -432,12 +441,12 @@ void getAllDOAndDA_should_return_all_dataReference() {
List result = dataTypeTemplatesService.getAllDoLinkedToDa(dtt).toList();
// Then
assertThat(result).hasSize(34)
- .extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ .extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactlyInAnyOrder(
// -> Do11
tuple("Do11", List.of(), "sampleDa11", List.of(), TPredefinedBasicTypeEnum.ENUM, "RecCycModKind"),
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DoTypeServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DoTypeServiceTest.java
index df023a117..0d5511d73 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DoTypeServiceTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DoTypeServiceTest.java
@@ -11,16 +11,13 @@
import org.lfenergy.compas.sct.commons.domain.DataAttribute;
import org.lfenergy.compas.sct.commons.domain.DataObject;
import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa;
-import org.lfenergy.compas.sct.commons.dto.DaTypeName;
-import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
-import org.lfenergy.compas.sct.commons.dto.DoTypeName;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
import java.util.List;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
-import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.*;
+import static org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateTestUtils.initDttFromFile;
class DoTypeServiceTest {
@@ -85,23 +82,20 @@ void getAllSDOLinkedToDa_should_return_expected_dataReference() {
TDOType tdoType = doTypeService.findDoType(dtt, tdoType1 -> tdoType1.getId()
.equals("DOType0")).orElseThrow();
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName("FirstDoName");
- doLinkedToDa.setDataObject(dataObject);
DataAttribute dataAttribute = new DataAttribute();
- doLinkedToDa.setDataAttribute(dataAttribute);
-
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
List result = doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa);
//Then
assertThat(result).hasSize(8)
- .extracting(doLinkedToDa1 -> doLinkedToDa1.getDataObject().getDoName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataObject().getSdoNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getDaName(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBdaNames(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getBType(),
- doLinkedToDa1 -> doLinkedToDa1.getDataAttribute().getType())
+ .extracting(doLinkedToDa1 -> doLinkedToDa1.dataObject().getDoName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataObject().getSdoNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getDaName(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBdaNames(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getBType(),
+ doLinkedToDa1 -> doLinkedToDa1.dataAttribute().getType())
.containsExactlyInAnyOrder(
tuple("FirstDoName", List.of(),
"sampleDaName1", List.of(), TPredefinedBasicTypeEnum.BOOLEAN, null),
@@ -131,22 +125,19 @@ void getAllSDOLinkedToDa_should_return_all_dai() {
DoTypeService doTypeService = new DoTypeService();
TDOType tdoType = doTypeService.findDoType(dtt, tdoType1 -> tdoType1.getId()
.equals("DO11")).orElseThrow();
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName("firstDONAME");
- doLinkedToDa.setDataObject(dataObject);
DataAttribute dataAttribute = new DataAttribute();
- doLinkedToDa.setDataAttribute(dataAttribute);
- // When
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute); // When
List list = doTypeService.getAllSDOLinkedToDa(dtt, tdoType, doLinkedToDa);
// Then
assertThat(list)
.hasSize(811)
- .allMatch(dataAttributeRef -> StringUtils.startsWith(dataAttributeRef.getDataObject().getDoName(), "firstDONAME"))
- .areExactly(1, new Condition<>(dataAttributeRef -> dataAttributeRef.getDataAttribute().getDaName().equals("da1"), "Il n'y a que certaines réponses contenant da1"))
- .areExactly(270, new Condition<>(dataAttributeRef -> dataAttributeRef.getDataAttribute().getDaName().equals("da11"), "Il n'y a que certaines réponses contenant da11"))
- .areExactly(270, new Condition<>(dataAttributeRef -> dataAttributeRef.getDataAttribute().getDaName().equals("da22"), "Il n'y a que certaines réponses contenant da22"))
- .areExactly(270, new Condition<>(dataAttributeRef -> dataAttributeRef.getDataAttribute().getDaName().equals("da32"), "Il n'y a que certaines réponses contenant da32"));
+ .allMatch(dataAttributeRef -> StringUtils.startsWith(dataAttributeRef.dataObject().getDoName(), "firstDONAME"))
+ .areExactly(1, new Condition<>(dataAttributeRef -> dataAttributeRef.dataAttribute().getDaName().equals("da1"), "Il n'y a que certaines réponses contenant da1"))
+ .areExactly(270, new Condition<>(dataAttributeRef -> dataAttributeRef.dataAttribute().getDaName().equals("da11"), "Il n'y a que certaines réponses contenant da11"))
+ .areExactly(270, new Condition<>(dataAttributeRef -> dataAttributeRef.dataAttribute().getDaName().equals("da22"), "Il n'y a que certaines réponses contenant da22"))
+ .areExactly(270, new Condition<>(dataAttributeRef -> dataAttributeRef.dataAttribute().getDaName().equals("da32"), "Il n'y a que certaines réponses contenant da32"));
}
}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LNodeStatusServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LNodeStatusServiceTest.java
new file mode 100644
index 000000000..d988862f1
--- /dev/null
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LNodeStatusServiceTest.java
@@ -0,0 +1,188 @@
+// 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.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.lfenergy.compas.scl2007b4.model.SCL;
+import org.lfenergy.compas.scl2007b4.model.TAnyLN;
+import org.lfenergy.compas.scl2007b4.model.TLN;
+import org.lfenergy.compas.sct.commons.dto.SclReportItem;
+import org.lfenergy.compas.sct.commons.testhelpers.SclHelper;
+import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Named.named;
+import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*;
+
+class LNodeStatusServiceTest {
+
+ private LNodeStatusService lNodeStatusService;
+
+ @BeforeEach
+ void setUp() {
+ lNodeStatusService = new LNodeStatusService(new LdeviceService(), new LnService(), new DataTypeTemplatesService());
+ }
+
+ @ParameterizedTest
+ @MethodSource("provideUpdateModStVal")
+ void updateLnStatusBasedOnPrivateLNodeStatus_should_update_Mod_stVal(String ldInst, String lnClass, String lnInst, String expected) {
+ // Given
+ SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).isEmpty();
+ assertThat(findDai(scl, "IED_NAME_1", ldInst, lnClass, lnInst, "", "Mod", "stVal"))
+ .map(SclHelper::getValue)
+ .hasValue(expected);
+ }
+
+ public static Stream provideUpdateModStVal() {
+ return Stream.of(
+ Arguments.of(named("LN 'on' à mettre à 'on'", "LDEVICE_1"), "PDIS", "1", "on"),
+ Arguments.of(named("LN 'off;on' à mettre à 'on'", "LDEVICE_1"), "PDIS", "2", "on"),
+ Arguments.of(named("LN 'off' à mettre à 'off'", "LDEVICE_1"), "PDIS", "3", "off"),
+ Arguments.of(named("LN 'off;on' à mettre à 'off'", "LDEVICE_1"), "PDIS", "3", "off"),
+ Arguments.of(named("LN0 'on' à mettre à 'on'", "LDEVICE_1"), "LLN0", "", "on"),
+ Arguments.of(named("LN0 'off;on' à mettre à 'on'", "LDEVICE_2"), "LLN0", "", "on"),
+ Arguments.of(named("LN0 'off' à mettre à 'off'", "LDEVICE_3"), "LLN0", "", "off"),
+ Arguments.of(named("LN0 'off;on' à mettre à 'off'", "LDEVICE_4"), "LLN0", "", "off")
+ );
+ }
+
+ @Test
+ void updateLnStatusBasedOnPrivateLNodeStatus_do_nothing_if_DAI_Mod_stVal_is_missing() {
+ // Given
+ SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus_without_mod_stval.scd");
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).isEmpty();
+ assertThat(getLDevices(scl.getIED().getFirst())
+ .flatMap(tlDevice -> Stream.concat(Stream.of(tlDevice.getLN0()), tlDevice.getLN().stream())))
+ .flatMap(TAnyLN::getDOI)
+ .isEmpty();
+ }
+
+ @Test
+ void updateLnStatusBasedOnPrivateLNodeStatus_when_no_compasLNodeStatus_in_LNode_should_return_error() {
+ // Given
+ SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
+ scl.getSubstation().getFirst().getVoltageLevel().getFirst().getBay().getFirst().getFunction().getFirst().getLNode().getFirst()
+ .getPrivate().clear();
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).containsExactly(
+ SclReportItem.error("LNode(iedName=IED_NAME_1, ldInst=LDEVICE_1, lnClass=PDIS, lnInst=1, prefix=)",
+ "The private COMPAS-LNodeStatus of the LNode has invalid value. Expecting one of [on, off] but got : null")
+ );
+ }
+
+ @Test
+ void updateLnStatusBasedOnPrivateLNodeStatus_when_invalid_compasLNodeStatus_value_in_LNode_should_return_error() {
+ // Given
+ SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
+ scl.getSubstation().getFirst().getVoltageLevel().getFirst().getBay().getFirst().getFunction().getFirst().getLNode().getFirst()
+ .getPrivate().getFirst().getContent().set(0, "helloworld");
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).containsExactly(
+ SclReportItem.error("LNode(iedName=IED_NAME_1, ldInst=LDEVICE_1, lnClass=PDIS, lnInst=1, prefix=)",
+ "The private COMPAS-LNodeStatus of the LNode has invalid value. Expecting one of [on, off] but got : helloworld")
+ );
+ }
+
+ @Test
+ 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", ""))
+ .setPrefix("helloworld");
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).containsExactly(
+ SclReportItem.error("LNode(iedName=IED_NAME_1, ldInst=LDEVICE_1, lnClass=PDIS, lnInst=1, prefix=)",
+ "LNode in Substation section does not have a matching LN in IED section")
+ );
+ }
+
+ @Test
+ void updateLnStatusBasedOnPrivateLNodeStatus_when_no_compasLNodeStatus_in_LN_should_return_error() {
+ // Given
+ SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
+ findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", "")
+ .getPrivate().clear();
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).containsExactly(
+ SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_1)/LN[PDIS,1,]",
+ "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", "", "")
+ .getPrivate().getFirst().getContent().set(0, "off");
+ findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", "")
+ .getPrivate().getFirst().getContent().set(0, "off");
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).containsExactlyInAnyOrder(
+ SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_1)/LN[LLN0,,]",
+ "Cannot set DAI Mod.stVal to on, because LN private COMPAS-LNodeStatus is set to off"),
+ SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_1)/LN[PDIS,1,]",
+ "Cannot set DAI Mod.stVal to on, because LN private COMPAS-LNodeStatus is set to off")
+ );
+ }
+
+ @Test
+ 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", "", "")
+ .getPrivate().getFirst().getContent().set(0, "on");
+ findAnyLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "4", "")
+ .getPrivate().getFirst().getContent().set(0, "on");
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).containsExactlyInAnyOrder(
+ SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_4)/LN[LLN0,,]",
+ "Cannot set DAI Mod.stVal to off, because LN private COMPAS-LNodeStatus is set to on"),
+ SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_1)/LN[PDIS,4,]",
+ "Cannot set DAI Mod.stVal to off, because LN private COMPAS-LNodeStatus is set to on")
+ );
+ }
+
+ @Test
+ void updateLnStatusBasedOnPrivateLNodeStatus_when_Mod_stVal_enumType_does_not_contains_value_should_return_error() {
+ // Given
+ SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd");
+ scl.getDataTypeTemplates().getEnumType().getFirst().getEnumVal().removeIf(tEnumVal -> tEnumVal.getValue().equals("on"));
+ // When
+ List sclReportItems = lNodeStatusService.updateLnModStValBasedOnLNodeStatus(scl);
+ // Then
+ assertThat(sclReportItems).contains(
+ SclReportItem.error("IED(IED_NAME_1)/LD(LDEVICE_1)/LN[PDIS,1,]",
+ "Cannot set DAI Mod.stVal to 'on' because value is not in EnumType [off, test]")
+ );
+ }
+
+}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java
index 8daa222d7..38260e960 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java
@@ -121,13 +121,13 @@ void getFilteredAnyLns_should_return_lns() {
}
@Test
- void getDaiModStval_should_return_status() {
+ void getDaiModStValValue_should_return_status() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLDevice tlDevice = std.getIED().getFirst().getAccessPoint().getFirst().getServer().getLDevice().getFirst();
//When
- Optional daiModStval = lnService.getDaiModStval(tlDevice.getLN0());
+ Optional daiModStval = lnService.getDaiModStValValue(tlDevice.getLN0());
//Then
assertThat(daiModStval).contains(ActiveStatus.ON);
@@ -212,9 +212,7 @@ void completeFromDataAttributeInstance_should_complete_when_valImport_set_or_not
dataObject.setDoName("Do");
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("Da");
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
lnService.completeFromDAInstance(tied, "ldInst", tAnyLN, doLinkedToDa);
@@ -272,15 +270,13 @@ void completeFromDataAttributeInstance_should_complete_when_settingGroup_set_or_
dataAttribute.setDaName("Da");
dataAttribute.setFc(givenFc);
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
lnService.completeFromDAInstance(tied, "ldInst", tAnyLN, doLinkedToDa);
//Then
- assertThat(doLinkedToDa.getDataAttribute().isValImport()).isEqualTo(expectedValImport);
+ assertThat(doLinkedToDa.dataAttribute().isValImport()).isEqualTo(expectedValImport);
}
@@ -294,14 +290,12 @@ void completeFromDataAttributeInstance__should_not_complete_when_not_found() {
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("Da");
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
lnService.completeFromDAInstance(tied, "ldInst", tAnyLN, doLinkedToDa);
//Then
- assertThat(doLinkedToDa.getDataAttribute().isValImport()).isFalse();//initialValue
+ assertThat(doLinkedToDa.dataAttribute().isValImport()).isFalse();//initialValue
}
@ParameterizedTest
@@ -321,15 +315,13 @@ void completeFromDataAttributeInstance_should_complete_when_struct(Boolean input
dataAttribute.setDaName("antRef");
dataAttribute.setBdaNames(List.of("bda1","bda2","bda3"));
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
lnService.completeFromDAInstance(tied, "ldInst", tAnyLN, doLinkedToDa);
//Then
- assertThat(doLinkedToDa.getDataAttribute().isValImport()).isEqualTo(expected);
+ assertThat(doLinkedToDa.dataAttribute().isValImport()).isEqualTo(expected);
}
@Test
@@ -343,9 +335,7 @@ void updateOrCreateDOAndDAInstance_should_create_given_DO_and_DA_instances_when_
dataAttribute.setDaName("stVal");
dataAttribute.getDaiValues().add(new DaVal(1L, "new value"));
dataAttribute.getDaiValues().add(new DaVal(2L, "new value 2"));
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
lnService.updateOrCreateDOAndDAInstances(tAnyLN, doLinkedToDa);
@@ -375,9 +365,7 @@ void updateOrCreateDOAndDAInstance_should_create_given_DO_and_DA_instances_when_
dataAttribute.setDaName("antRef");
dataAttribute.setBdaNames(List.of("bda1"));
dataAttribute.getDaiValues().add(new DaVal(null, "new value"));
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
@@ -440,9 +428,7 @@ void updateOrCreateDOAndDAInstance_should_complete_DO_and_DA_instances_modificat
dataAttribute.setBdaNames(List.of("BdaName1"));
dataAttribute.getDaiValues().add(new DaVal(null, "new dai value"));
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
//When
LnService lnService = new LnService();
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java
index a3a6aaaaf..2691f0783 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/domain/DoLinkedToDaTest.java
@@ -18,25 +18,23 @@ class DoLinkedToDaTest {
@Test
void test_copyFrom() {
// Given
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
DataObject dataObject = new DataObject();
dataObject.setDoName("doName");
dataObject.setSdoNames(List.of("sdoName1"));
dataObject.setCdc(TPredefinedCDCEnum.CST);
- doLinkedToDa.setDataObject(dataObject);
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("daName");
dataAttribute.setBdaNames(List.of("bdaName1"));
dataAttribute.setFc(TFCEnum.BL);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
// When
DoLinkedToDa newDoLinkedToDa = DoLinkedToDa.copyFrom(doLinkedToDa);
// Then
assertAll("Copy From",
- () -> assertThat(newDoLinkedToDa.getDataObject().getCdc()).isEqualTo(doLinkedToDa.getDataObject().getCdc()),
- () -> assertThat(newDoLinkedToDa.getDataAttribute().getBType()).isEqualTo(doLinkedToDa.getDataAttribute().getBType()),
- () -> assertThat(newDoLinkedToDa.getDataAttribute().getType()).isEqualTo(doLinkedToDa.getDataAttribute().getType()),
- () -> assertThat(newDoLinkedToDa.getDataAttribute().getFc()).isEqualTo(doLinkedToDa.getDataAttribute().getFc()),
+ () -> assertThat(newDoLinkedToDa.dataObject().getCdc()).isEqualTo(doLinkedToDa.dataObject().getCdc()),
+ () -> assertThat(newDoLinkedToDa.dataAttribute().getBType()).isEqualTo(doLinkedToDa.dataAttribute().getBType()),
+ () -> assertThat(newDoLinkedToDa.dataAttribute().getType()).isEqualTo(doLinkedToDa.dataAttribute().getType()),
+ () -> assertThat(newDoLinkedToDa.dataAttribute().getFc()).isEqualTo(doLinkedToDa.dataAttribute().getFc()),
() -> assertThat(newDoLinkedToDa.getDoRef()).isEqualTo(doLinkedToDa.getDoRef()),
() -> assertThat(newDoLinkedToDa.getDaRef()).isEqualTo(doLinkedToDa.getDaRef()));
}
@@ -49,8 +47,7 @@ void test_getDoRef() {
dataObject.setSdoNames(List.of("sdoName1"));
dataObject.setCdc(TPredefinedCDCEnum.CST);
// When Then
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, new DataAttribute());
assertThat(doLinkedToDa.getDoRef()).isEqualTo("doName.sdoName1");
}
@@ -61,9 +58,10 @@ void test_getDaRef() {
dataAttribute.setDaName("daName");
dataAttribute.setBdaNames(List.of("bdaName1"));
dataAttribute.setFc(TFCEnum.BL);
- // When Then
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataAttribute(dataAttribute);
+ // When
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(new DataObject(), dataAttribute);
+
+ // Then
assertThat(doLinkedToDa.getDaRef()).isEqualTo("daName.bdaName1");
}
@@ -75,9 +73,7 @@ void isUpdatable_should_return_true_whenIsDOModDAstVal() {
DataAttribute dataAttribute = new DataAttribute();
dataAttribute.setDaName("stVal");
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
// When Then
assertThat(doLinkedToDa.isUpdatable()).isTrue();
}
@@ -94,9 +90,7 @@ void isUpdatable_should_return_true_whenValImportIsTrue() {
dataAttribute.setValImport(true);
dataAttribute.setFc(TFCEnum.SE);
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
// When Then
assertThat(doLinkedToDa.isUpdatable()).isTrue();
}
@@ -113,11 +107,9 @@ void isUpdatable_should_return_false_whenValImportIsFalse() {
dataAttribute.setValImport(false);
dataAttribute.setFc(TFCEnum.SE);
- DoLinkedToDa doLinkedToDa = new DoLinkedToDa();
- doLinkedToDa.setDataObject(dataObject);
- doLinkedToDa.setDataAttribute(dataAttribute);
+ DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
// When Then
assertThat(doLinkedToDa.isUpdatable()).isFalse();
}
-}
\ No newline at end of file
+}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnKeyTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnIdTest.java
similarity index 62%
rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnKeyTest.java
rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnIdTest.java
index 4501f79d4..bdbff7a3b 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnKeyTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnIdTest.java
@@ -14,7 +14,7 @@
import static org.assertj.core.api.Assertions.assertThat;
-class LnKeyTest {
+class LnIdTest {
@Test
void test_LnKey_withLN() {
@@ -24,12 +24,11 @@ void test_LnKey_withLN() {
ln.setInst("1");
ln.getLnClass().add(TSystemLNGroupEnum.LGOS.value());
// When
- LnKey lnKey = new LnKey(ln);
+ LnId lnId = LnId.from(ln);
// Then
- assertThat(lnKey.getLnType()).isEqualTo("LnTypeAny");
- assertThat(lnKey.getLnClass()).isEqualTo("LGOS");
- assertThat(lnKey.getInst()).isEqualTo("1");
- assertThat(lnKey.getPrefix()).isEqualTo(StringUtils.EMPTY);
+ assertThat(lnId.lnClass()).isEqualTo("LGOS");
+ assertThat(lnId.lnInst()).isEqualTo("1");
+ assertThat(lnId.prefix()).isEqualTo(StringUtils.EMPTY);
}
@Test
@@ -39,12 +38,11 @@ void test_LnKey_withLN0() {
ln0.setLnType("LnType0");
ln0.getLnClass().add(TLLN0Enum.LLN_0.value());
// When
- LnKey lnKey = new LnKey(ln0);
+ LnId lnId = LnId.from(ln0);
// Then
- assertThat(lnKey.getLnType()).isEqualTo("LnType0");
- assertThat(lnKey.getLnClass()).isEqualTo("LLN0");
- assertThat(lnKey.getInst()).isEqualTo("");
- assertThat(lnKey.getPrefix()).isEqualTo(StringUtils.EMPTY);
+ assertThat(lnId.lnClass()).isEqualTo("LLN0");
+ assertThat(lnId.lnInst()).isEqualTo("");
+ assertThat(lnId.prefix()).isEqualTo(StringUtils.EMPTY);
}
-}
\ No newline at end of file
+}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclHelper.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclHelper.java
index 0d843c335..eb24171e4 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclHelper.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/testhelpers/SclHelper.java
@@ -21,6 +21,7 @@
import java.util.Optional;
import java.util.stream.Stream;
+import static org.apache.commons.lang3.StringUtils.trimToEmpty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newConnectedAp;
import static org.lfenergy.compas.sct.commons.util.Utils.lnClassEquals;
@@ -99,257 +100,279 @@ public static LNAdapter findLn(SCL scl, String iedName, String ldInst, String ln
);
}
- public static IDataParentAdapter findDoiOrSdi(AbstractLNAdapter> lnAdapter, String dataTypeRef) {
- if (dataTypeRef.length() < 1) {
- Assertions.fail("dataTypeRef must at least contain a DO, but got: " + dataTypeRef);
+ public static TAnyLN findAnyLn(SCL scl, String iedName, String ldInst, String lnClass, String lnInst, String prefix) {
+ TIED ied = scl.getIED().stream().filter(tied -> tied.getName().equals(iedName))
+ .findFirst().orElseThrow(() -> new AssertionFailedError("IED with name=%s not found".formatted(iedName)));
+ TLDevice tlDevice = getLDevices(ied)
+ .filter(tlDevice1 -> tlDevice1.getInst().equals(ldInst))
+ .findFirst().orElseThrow(() -> new AssertionFailedError("LDevice with inst=%s not found".formatted(ldInst)));
+ if (lnClass.equals(TLLN0Enum.LLN_0.value()) && tlDevice.isSetLN0()) {
+ return tlDevice.getLN0();
}
- String[] names = dataTypeRef.split("\\.");
- IDataParentAdapter parentAdapter = lnAdapter.getDOIAdapterByName(names[0]);
- for (int i = 1; i < names.length; i++) {
- parentAdapter = parentAdapter.getStructuredDataAdapterByName(names[i]);
- }
- return parentAdapter;
+ return tlDevice.getLN().stream()
+ .filter(tln -> Utils.lnClassEquals(tln.getLnClass(), lnClass) && trimToEmpty(tln.getInst()).equals(trimToEmpty(lnInst)) && trimToEmpty(tln.getPrefix()).equals(trimToEmpty(prefix)))
+ .findFirst()
+ .orElseThrow(() -> new AssertionFailedError("LN (lnClass=%s, lnInst=%s, lnPrefix=%s) not found".formatted(lnClass, lnInst, prefix)));
}
- public static Optional findDai(SCL scl, String iedName, String ldInst, String doiName, String daiName) {
- return scl.getIED().stream().filter(tied -> tied.getName().equals(iedName))
- .flatMap(tied -> tied.getAccessPoint().stream())
- .flatMap(tAccessPoint -> tAccessPoint.getServer().getLDevice().stream())
- .filter(tlDevice -> tlDevice.getInst().equals(ldInst))
- .flatMap(tlDevice -> tlDevice.getLN0().getDOI().stream())
- .filter(tdoi -> tdoi.getName().equals(doiName))
- .flatMap(tdoi -> tdoi.getSDIOrDAI().stream().map(tUnNaming -> (TDAI)tUnNaming))
- .filter(tdai -> tdai.getName().equals(daiName))
- .findFirst();
+ public static Stream getLDevices(TIED tied){
+ return tied.getAccessPoint().stream()
+ .filter(TAccessPoint::isSetServer)
+ .flatMap(tAccessPoint -> tAccessPoint.getServer().getLDevice().stream());
}
- public static AbstractDAIAdapter> findDai(AbstractLNAdapter> lnAdapter, String dataTypeRef) {
- String[] names = dataTypeRef.split("\\.");
- if (names.length < 2) {
- Assertions.fail("dataTypeRef must at least contain a DO and a DA name, but got: " + dataTypeRef);
- }
-
- IDataParentAdapter parentAdapter = findDoiOrSdi(lnAdapter, String.join(".", Arrays.asList(names).subList(0, names.length - 1)));
- return parentAdapter.getDataAdapterByName(names[names.length - 1]);
+public static IDataParentAdapter findDoiOrSdi(AbstractLNAdapter> lnAdapter, String dataTypeRef) {
+ if (dataTypeRef.length() < 1) {
+ Assertions.fail("dataTypeRef must at least contain a DO, but got: " + dataTypeRef);
}
-
- public static String getValue(AbstractDAIAdapter> daiAdapter) {
- return getValue(daiAdapter.getCurrentElem());
+ String[] names = dataTypeRef.split("\\.");
+ IDataParentAdapter parentAdapter = lnAdapter.getDOIAdapterByName(names[0]);
+ for (int i = 1; i < names.length; i++) {
+ parentAdapter = parentAdapter.getStructuredDataAdapterByName(names[i]);
}
+ return parentAdapter;
+}
- public static String getValue(TDAI tdai) {
- if (!tdai.isSetVal()) {
- Assertions.fail("No value found for DAI " + tdai.getName());
- } else if (tdai.getVal().size() > 1) {
- Assertions.fail("Expecting a single value for for DAI " + tdai.getName());
- }
- return tdai.getVal().get(0).getValue();
- }
+public static Optional findDai(SCL scl, String iedName, String ldInst, String doiName, String daiName) {
+ return findDai( scl, iedName, ldInst, "LLN0", "", "", doiName, daiName);
+}
+public static Optional findDai(SCL scl, String iedName, String ldInst, String lnClass, String lnInst, String lnPrefix, String doiName, String daiName) {
+ return findAnyLn(scl, iedName, ldInst, lnClass, lnInst, lnPrefix)
+ .getDOI().stream()
+ .filter(tdoi -> tdoi.getName().equals(doiName))
+ .flatMap(tdoi -> tdoi.getSDIOrDAI().stream().map(tUnNaming -> (TDAI) tUnNaming))
+ .filter(tdai -> tdai.getName().equals(daiName))
+ .findFirst();
+}
- public static LDeviceAdapter findLDeviceByLdName(SCL scl, String ldName) {
- return new SclRootAdapter(scl).streamIEDAdapters()
- .flatMap(IEDAdapter::streamLDeviceAdapters)
- .filter(lDeviceAdapter -> ldName.equals(lDeviceAdapter.getLdName()))
- .findFirst()
- .orElseThrow(() -> new AssertionFailedError("LDevice with ldName=%s not found in SCD".formatted(ldName)));
+public static AbstractDAIAdapter> findDai(AbstractLNAdapter> lnAdapter, String dataTypeRef) {
+ String[] names = dataTypeRef.split("\\.");
+ if (names.length < 2) {
+ Assertions.fail("dataTypeRef must at least contain a DO and a DA name, but got: " + dataTypeRef);
}
- public static DataSetAdapter findDataSet(SCL scl, String iedName, String ldInst, String dataSetName) {
- LN0Adapter ln0 = findLn0(scl, iedName, ldInst);
- return ln0.findDataSetByName(dataSetName)
- .orElseThrow(() -> new AssertionFailedError(String.format("DataSet.name=%s not found in IED.name=%s,LDevice.inst=%s,LN0",
- dataSetName, iedName, ldInst)));
- }
+ IDataParentAdapter parentAdapter = findDoiOrSdi(lnAdapter, String.join(".", Arrays.asList(names).subList(0, names.length - 1)));
+ return parentAdapter.getDataAdapterByName(names[names.length - 1]);
+}
- public static T findControlBlock(SCL scl, String iedName, String ldInst, String cbName, Class controlBlockClass) {
- LN0Adapter ln0 = findLn0(scl, iedName, ldInst);
- return ln0.getTControlsByType(controlBlockClass).stream()
- .filter(t -> cbName.equals(t.getName()))
- .findFirst()
- .orElseThrow(() -> new AssertionFailedError(String.format("%s name=%s not found in IED.name=%s,LDevice.inst=%s,LN0",
- controlBlockClass.getSimpleName(), cbName, iedName, ldInst)));
- }
+public static String getValue(AbstractDAIAdapter> daiAdapter) {
+ return getValue(daiAdapter.getCurrentElem());
+}
- public static void assertControlBlockExists(SCL scd, String iedName, String ldInst, String cbName,
- String datSet, String id, ControlBlockEnum controlBlockEnum) {
- TControl controlBlock = findControlBlock(scd, iedName, ldInst, cbName, controlBlockEnum.getControlBlockClass());
- assertThat(controlBlock.getDatSet()).isEqualTo(datSet);
- assertThat(getControlBlockId(controlBlock)).isEqualTo(id);
+public static String getValue(TDAI tdai) {
+ if (!tdai.isSetVal()) {
+ Assertions.fail("No value found for DAI " + tdai.getName());
+ } else if (tdai.getVal().size() > 1) {
+ Assertions.fail("Expecting a single value for for DAI " + tdai.getName());
}
+ return tdai.getVal().get(0).getValue();
+}
- private static String getControlBlockId(TControl tControl) {
- if (tControl instanceof TGSEControl tgseControl) {
- return tgseControl.getAppID();
- }
- if (tControl instanceof TSampledValueControl tSampledValueControl) {
- return tSampledValueControl.getSmvID();
- }
- if (tControl instanceof TReportControl tReportControl) {
- return tReportControl.getRptID();
- }
- throw new AssertionFailedError("Cannot get Id for ControlBlock of type " + tControl.getClass().getSimpleName());
- }
- public static Stream streamAllDataSets(SCL scl) {
- return streamAllLn0Adapters(scl)
- .map(ln0Adapter -> ln0Adapter.getCurrentElem().getDataSet())
- .flatMap(List::stream);
- }
+public static LDeviceAdapter findLDeviceByLdName(SCL scl, String ldName) {
+ return new SclRootAdapter(scl).streamIEDAdapters()
+ .flatMap(IEDAdapter::streamLDeviceAdapters)
+ .filter(lDeviceAdapter -> ldName.equals(lDeviceAdapter.getLdName()))
+ .findFirst()
+ .orElseThrow(() -> new AssertionFailedError("LDevice with ldName=%s not found in SCD".formatted(ldName)));
+}
- public static Stream streamAllLn0Adapters(SCL scl) {
- return new SclRootAdapter(scl)
- .streamIEDAdapters()
- .flatMap(IEDAdapter::streamLDeviceAdapters)
- .filter(LDeviceAdapter::hasLN0)
- .map(LDeviceAdapter::getLN0Adapter);
- }
+public static DataSetAdapter findDataSet(SCL scl, String iedName, String ldInst, String dataSetName) {
+ LN0Adapter ln0 = findLn0(scl, iedName, ldInst);
+ return ln0.findDataSetByName(dataSetName)
+ .orElseThrow(() -> new AssertionFailedError(String.format("DataSet.name=%s not found in IED.name=%s,LDevice.inst=%s,LN0",
+ dataSetName, iedName, ldInst)));
+}
- public static Stream streamAllExtRef(SCL scl) {
- return streamAllLn0Adapters(scl)
- .filter(AbstractLNAdapter::hasInputs)
- .map(LN0Adapter::getInputsAdapter)
- .map(InputsAdapter::getCurrentElem)
- .map(TInputs::getExtRef)
- .flatMap(List::stream);
- }
+public static T findControlBlock(SCL scl, String iedName, String ldInst, String cbName, Class controlBlockClass) {
+ LN0Adapter ln0 = findLn0(scl, iedName, ldInst);
+ return ln0.getTControlsByType(controlBlockClass).stream()
+ .filter(t -> cbName.equals(t.getName()))
+ .findFirst()
+ .orElseThrow(() -> new AssertionFailedError(String.format("%s name=%s not found in IED.name=%s,LDevice.inst=%s,LN0",
+ controlBlockClass.getSimpleName(), cbName, iedName, ldInst)));
+}
- public static String getDaiValue(AbstractLNAdapter> ln, String doiName, String daiName) {
- return ln.getDOIAdapterByName(doiName).getDataAdapterByName(daiName).getCurrentElem().getVal().get(0).getValue();
- }
+public static void assertControlBlockExists(SCL scd, String iedName, String ldInst, String cbName,
+ String datSet, String id, ControlBlockEnum controlBlockEnum) {
+ TControl controlBlock = findControlBlock(scd, iedName, ldInst, cbName, controlBlockEnum.getControlBlockClass());
+ assertThat(controlBlock.getDatSet()).isEqualTo(datSet);
+ assertThat(getControlBlockId(controlBlock)).isEqualTo(id);
+}
- public static Stream streamAllConnectedApGseP(SCL scd, String pType) {
- return scd.getCommunication().getSubNetwork().stream()
- .map(TSubNetwork::getConnectedAP)
- .flatMap(List::stream)
- .map(TConnectedAP::getGSE)
- .flatMap(List::stream)
- .map(TControlBlock::getAddress)
- .map(TAddress::getP)
- .flatMap(List::stream)
- .filter(tp -> pType.equals(tp.getType()))
- .map(TP::getValue);
+private static String getControlBlockId(TControl tControl) {
+ if (tControl instanceof TGSEControl tgseControl) {
+ return tgseControl.getAppID();
}
-
- public static SclRootAdapter createSclRootAdapterWithIed(String iedName) {
- SCL scl = new SCL();
- scl.setHeader(new THeader());
- TIED ied = new TIED();
- ied.setName(iedName);
- scl.getIED().add(ied);
- return new SclRootAdapter(scl);
+ if (tControl instanceof TSampledValueControl tSampledValueControl) {
+ return tSampledValueControl.getSmvID();
}
-
- public static SclRootAdapter createSclRootWithConnectedAp(String iedName, String apName) {
- SclRootAdapter sclRootAdapter = createSclRootAdapterWithIed(iedName);
- SCL scl = sclRootAdapter.getCurrentElem();
- scl.setCommunication(new TCommunication());
- TSubNetwork subNetwork = new TSubNetwork();
- scl.getCommunication().getSubNetwork().add(subNetwork);
- subNetwork.getConnectedAP().add(newConnectedAp(iedName, apName));
- return sclRootAdapter;
+ if (tControl instanceof TReportControl tReportControl) {
+ return tReportControl.getRptID();
}
+ throw new AssertionFailedError("Cannot get Id for ControlBlock of type " + tControl.getClass().getSimpleName());
+}
- public static TExtRef createExtRefExample(String cbName, TServiceType tServiceType) {
- TExtRef tExtRef = new TExtRef();
- tExtRef.setIedName("IED_NAME_2");
- tExtRef.setServiceType(tServiceType);
- tExtRef.setSrcLDInst("Inst_2");
- tExtRef.setSrcLNInst("LN");
- tExtRef.setSrcPrefix("Prefix");
- tExtRef.setSrcCBName(cbName);
- return tExtRef;
- }
+public static Stream streamAllDataSets(SCL scl) {
+ return streamAllLn0Adapters(scl)
+ .map(ln0Adapter -> ln0Adapter.getCurrentElem().getDataSet())
+ .flatMap(List::stream);
+}
- public static SclRootAdapter createIedsInScl(String lnClass, String doName) {
- // DataTypeTemplate
- TDO tdo = new TDO();
- tdo.setName(doName);
- tdo.setType("REF");
- TLNodeType tlNodeType = new TLNodeType();
- tlNodeType.setId("T1");
- tlNodeType.getLnClass().add(lnClass);
- tlNodeType.getDO().add(tdo);
-
- TDA tda = new TDA();
- tda.setName("setSrcRef");
- tda.setValImport(true);
- tda.setBType(TPredefinedBasicTypeEnum.OBJ_REF);
- tda.setFc(TFCEnum.SP);
-
- TDOType tdoType = new TDOType();
- tdoType.setId("REF");
- tdoType.getSDOOrDA().add(tda);
-
- TDataTypeTemplates tDataTypeTemplates = new TDataTypeTemplates();
- tDataTypeTemplates.getLNodeType().add(tlNodeType);
- tDataTypeTemplates.getDOType().add(tdoType);
-
-
- //ied Client
- TDOI tdoi = new TDOI();
- tdoi.setName(doName);
- TLDevice tlDevice = new TLDevice();
- tlDevice.setInst("LD_ADD");
- TInputs tInputs = new TInputs();
- LN0 ln0 = new LN0();
- ln0.setInputs(tInputs);
- tlDevice.setLN0(ln0);
-
- TLDevice tlDevice1 = new TLDevice();
- tlDevice1.setLN0(new LN0());
- tlDevice1.setInst(LD_SUIED);
- TLN tln1 = new TLN();
- tln1.getLnClass().add(lnClass);
- tln1.setLnType("T1");
- tln1.getDOI().add(tdoi);
- tlDevice1.getLN().add(tln1);
- TServer tServer1 = new TServer();
- tServer1.getLDevice().add(tlDevice1);
- tServer1.getLDevice().add(tlDevice);
- TAccessPoint tAccessPoint1 = new TAccessPoint();
- tAccessPoint1.setName("AP_NAME");
- tAccessPoint1.setServer(tServer1);
- TIED tied1 = new TIED();
- tied1.setName(IED_NAME_1);
- tied1.getAccessPoint().add(tAccessPoint1);
-
- //ied Source
- TLDevice tlDevice2 = new TLDevice();
- tlDevice2.setInst("Inst_2");
- tlDevice2.setLdName("LD_Name");
- tlDevice2.setLN0(new LN0());
- TServer tServer2 = new TServer();
- tServer2.getLDevice().add(tlDevice2);
- TAccessPoint tAccessPoint2 = new TAccessPoint();
- tAccessPoint2.setName("AP_NAME");
- tAccessPoint2.setServer(tServer2);
- TIED tied2 = new TIED();
- tied2.setName(IED_NAME_2);
- tied2.getAccessPoint().add(tAccessPoint2);
- //SCL file
- SCL scd = new SCL();
- scd.getIED().add(tied1);
- scd.getIED().add(tied2);
- THeader tHeader = new THeader();
- tHeader.setRevision("1");
- scd.setHeader(tHeader);
- scd.setDataTypeTemplates(tDataTypeTemplates);
-
- return new SclRootAdapter(scd);
- }
+public static Stream streamAllLn0Adapters(SCL scl) {
+ return new SclRootAdapter(scl)
+ .streamIEDAdapters()
+ .flatMap(IEDAdapter::streamLDeviceAdapters)
+ .filter(LDeviceAdapter::hasLN0)
+ .map(LDeviceAdapter::getLN0Adapter);
+}
- public static List getDaiValues(LDeviceAdapter lDeviceAdapter, String lnClass, String doName, String daName) {
- return getDAIAdapters(lDeviceAdapter, lnClass, doName, daName)
- .map(daiAdapter -> daiAdapter.getCurrentElem().getVal())
- .flatMap(List::stream)
- .toList();
- }
+public static Stream streamAllExtRef(SCL scl) {
+ return streamAllLn0Adapters(scl)
+ .filter(AbstractLNAdapter::hasInputs)
+ .map(LN0Adapter::getInputsAdapter)
+ .map(InputsAdapter::getCurrentElem)
+ .map(TInputs::getExtRef)
+ .flatMap(List::stream);
+}
- public static Stream getDAIAdapters(LDeviceAdapter lDeviceAdapter, String lnClass, String doName, String daName) {
- return lDeviceAdapter.getLNAdapters().stream()
- .filter(lnAdapter -> lnClassEquals(lnAdapter.getCurrentElem().getLnClass(), lnClass))
- .map(lnAdapter -> lnAdapter.getDOIAdapterByName(doName))
- .map(doiAdapter -> (DOIAdapter.DAIAdapter) doiAdapter.getDataAdapterByName(daName));
- }
+public static String getDaiValue(AbstractLNAdapter> ln, String doiName, String daiName) {
+ return ln.getDOIAdapterByName(doiName).getDataAdapterByName(daiName).getCurrentElem().getVal().get(0).getValue();
+}
+
+public static Stream streamAllConnectedApGseP(SCL scd, String pType) {
+ return scd.getCommunication().getSubNetwork().stream()
+ .map(TSubNetwork::getConnectedAP)
+ .flatMap(List::stream)
+ .map(TConnectedAP::getGSE)
+ .flatMap(List::stream)
+ .map(TControlBlock::getAddress)
+ .map(TAddress::getP)
+ .flatMap(List::stream)
+ .filter(tp -> pType.equals(tp.getType()))
+ .map(TP::getValue);
+}
+
+public static SclRootAdapter createSclRootAdapterWithIed(String iedName) {
+ SCL scl = new SCL();
+ scl.setHeader(new THeader());
+ TIED ied = new TIED();
+ ied.setName(iedName);
+ scl.getIED().add(ied);
+ return new SclRootAdapter(scl);
+}
+
+public static SclRootAdapter createSclRootWithConnectedAp(String iedName, String apName) {
+ SclRootAdapter sclRootAdapter = createSclRootAdapterWithIed(iedName);
+ SCL scl = sclRootAdapter.getCurrentElem();
+ scl.setCommunication(new TCommunication());
+ TSubNetwork subNetwork = new TSubNetwork();
+ scl.getCommunication().getSubNetwork().add(subNetwork);
+ subNetwork.getConnectedAP().add(newConnectedAp(iedName, apName));
+ return sclRootAdapter;
+}
+
+public static TExtRef createExtRefExample(String cbName, TServiceType tServiceType) {
+ TExtRef tExtRef = new TExtRef();
+ tExtRef.setIedName("IED_NAME_2");
+ tExtRef.setServiceType(tServiceType);
+ tExtRef.setSrcLDInst("Inst_2");
+ tExtRef.setSrcLNInst("LN");
+ tExtRef.setSrcPrefix("Prefix");
+ tExtRef.setSrcCBName(cbName);
+ return tExtRef;
+}
+
+public static SclRootAdapter createIedsInScl(String lnClass, String doName) {
+ // DataTypeTemplate
+ TDO tdo = new TDO();
+ tdo.setName(doName);
+ tdo.setType("REF");
+ TLNodeType tlNodeType = new TLNodeType();
+ tlNodeType.setId("T1");
+ tlNodeType.getLnClass().add(lnClass);
+ tlNodeType.getDO().add(tdo);
+
+ TDA tda = new TDA();
+ tda.setName("setSrcRef");
+ tda.setValImport(true);
+ tda.setBType(TPredefinedBasicTypeEnum.OBJ_REF);
+ tda.setFc(TFCEnum.SP);
+
+ TDOType tdoType = new TDOType();
+ tdoType.setId("REF");
+ tdoType.getSDOOrDA().add(tda);
+
+ TDataTypeTemplates tDataTypeTemplates = new TDataTypeTemplates();
+ tDataTypeTemplates.getLNodeType().add(tlNodeType);
+ tDataTypeTemplates.getDOType().add(tdoType);
+
+
+ //ied Client
+ TDOI tdoi = new TDOI();
+ tdoi.setName(doName);
+ TLDevice tlDevice = new TLDevice();
+ tlDevice.setInst("LD_ADD");
+ TInputs tInputs = new TInputs();
+ LN0 ln0 = new LN0();
+ ln0.setInputs(tInputs);
+ tlDevice.setLN0(ln0);
+
+ TLDevice tlDevice1 = new TLDevice();
+ tlDevice1.setLN0(new LN0());
+ tlDevice1.setInst(LD_SUIED);
+ TLN tln1 = new TLN();
+ tln1.getLnClass().add(lnClass);
+ tln1.setLnType("T1");
+ tln1.getDOI().add(tdoi);
+ tlDevice1.getLN().add(tln1);
+ TServer tServer1 = new TServer();
+ tServer1.getLDevice().add(tlDevice1);
+ tServer1.getLDevice().add(tlDevice);
+ TAccessPoint tAccessPoint1 = new TAccessPoint();
+ tAccessPoint1.setName("AP_NAME");
+ tAccessPoint1.setServer(tServer1);
+ TIED tied1 = new TIED();
+ tied1.setName(IED_NAME_1);
+ tied1.getAccessPoint().add(tAccessPoint1);
+
+ //ied Source
+ TLDevice tlDevice2 = new TLDevice();
+ tlDevice2.setInst("Inst_2");
+ tlDevice2.setLdName("LD_Name");
+ tlDevice2.setLN0(new LN0());
+ TServer tServer2 = new TServer();
+ tServer2.getLDevice().add(tlDevice2);
+ TAccessPoint tAccessPoint2 = new TAccessPoint();
+ tAccessPoint2.setName("AP_NAME");
+ tAccessPoint2.setServer(tServer2);
+ TIED tied2 = new TIED();
+ tied2.setName(IED_NAME_2);
+ tied2.getAccessPoint().add(tAccessPoint2);
+ //SCL file
+ SCL scd = new SCL();
+ scd.getIED().add(tied1);
+ scd.getIED().add(tied2);
+ THeader tHeader = new THeader();
+ tHeader.setRevision("1");
+ scd.setHeader(tHeader);
+ scd.setDataTypeTemplates(tDataTypeTemplates);
+
+ return new SclRootAdapter(scd);
+}
+
+public static List getDaiValues(LDeviceAdapter lDeviceAdapter, String lnClass, String doName, String daName) {
+ return getDAIAdapters(lDeviceAdapter, lnClass, doName, daName)
+ .map(daiAdapter -> daiAdapter.getCurrentElem().getVal())
+ .flatMap(List::stream)
+ .toList();
+}
+
+public static Stream getDAIAdapters(LDeviceAdapter lDeviceAdapter, String lnClass, String doName, String daName) {
+ return lDeviceAdapter.getLNAdapters().stream()
+ .filter(lnAdapter -> lnClassEquals(lnAdapter.getCurrentElem().getLnClass(), lnClass))
+ .map(lnAdapter -> lnAdapter.getDOIAdapterByName(doName))
+ .map(doiAdapter -> (DOIAdapter.DAIAdapter) doiAdapter.getDataAdapterByName(daName));
+}
}
diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java
index 5a9b20954..6b8ab3469 100644
--- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java
+++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/util/PrivateUtilsTest.java
@@ -630,4 +630,18 @@ void createPrivate_compas_Topo_should_succeed(){
.map(JAXBElement::getValue)
.containsExactly(tCompasTopo1, tCompasTopo2);
}
+
+ @Test
+ void extractStringPrivate_should_succeed(){
+ // Given
+ TIED tied = new TIED();
+ TPrivate tPrivate = new TPrivate();
+ tPrivate.setType("MyCustomType");
+ tPrivate.getContent().add("hello World");
+ tied.getPrivate().add(tPrivate);
+ // When
+ Optional result = PrivateUtils.extractStringPrivate(tied, "MyCustomType");
+ // Then
+ assertThat(result).hasValue("hello World");
+ }
}
diff --git a/sct-commons/src/test/resources/ied-test-schema-conf/ied_unit_test.xml b/sct-commons/src/test/resources/ied-test-schema-conf/ied_unit_test.xml
index 212d76299..c15f75606 100644
--- a/sct-commons/src/test/resources/ied-test-schema-conf/ied_unit_test.xml
+++ b/sct-commons/src/test/resources/ied-test-schema-conf/ied_unit_test.xml
@@ -113,7 +113,9 @@
-
+
+ myValue
+
diff --git a/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus.scd b/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus.scd
new file mode 100644
index 000000000..120833d95
--- /dev/null
+++ b/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus.scd
@@ -0,0 +1,125 @@
+
+
+
+
+
+
+
+ SCD
+
+
+
+
+ 90
+
+
+
+ on
+
+
+ on
+
+
+ off
+
+
+ off
+
+
+
+
+ on
+
+
+ on
+
+
+ off
+
+
+ off
+
+
+
+
+
+
+
+
+
+
+
+ on
+
+
+
+
+
+ on;off
+
+
+
+
+
+ on
+
+
+
+
+
+ on;off
+
+
+
+
+
+ off
+
+
+
+
+
+
+
+ on
+
+
+
+
+
+
+
+ on;off
+
+
+
+
+
+
+
+ off
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ on
+ off
+ test
+
+
+
diff --git a/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus_without_mod_stval.scd b/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus_without_mod_stval.scd
new file mode 100644
index 000000000..da7204fdc
--- /dev/null
+++ b/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus_without_mod_stval.scd
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+ SCD
+
+
+
+
+ 90
+
+
+
+ on
+
+
+ on
+
+
+ off
+
+
+ off
+
+
+
+
+ on
+
+
+ on
+
+
+ off
+
+
+ off
+
+
+
+
+
+
+
+
+
+
+
+ on
+
+
+ on;off
+
+
+ on
+
+
+ on;off
+
+
+ off
+
+
+
+
+ on
+
+
+
+
+ on;off
+
+
+
+
+ off
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ on
+ off
+ test
+
+
+