From 242eb28d414e158bb970c865298860f7c0bb7910 Mon Sep 17 00:00:00 2001 From: gleizesDor <115622893+gleizesDor@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:07:03 +0100 Subject: [PATCH] =?UTF-8?q?feat(#341):=20Cr=C3=A9ation=20Lnode,=20DOI=20et?= =?UTF-8?q?=20Private=20domain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com> --- pom.xml | 6 + .../SclAutomationServiceIntegrationTest.java | 2 +- .../sct/commons/ControlBlockService.java | 14 +- .../compas/sct/commons/DataSetService.java | 34 ++++ .../compas/sct/commons/DoService.java | 29 ++++ .../compas/sct/commons/DoTypeService.java | 29 ++++ .../sct/commons/ExtRefReaderService.java | 24 +++ .../compas/sct/commons/ExtRefService.java | 17 +- .../compas/sct/commons/IedService.java | 24 +++ .../compas/sct/commons/LdeviceService.java | 59 +++++++ .../compas/sct/commons/LnService.java | 17 ++ .../compas/sct/commons/LnodeTypeService.java | 29 ++++ .../commons/SclElementsProviderService.java | 20 ++- .../compas/sct/commons/SclService.java | 8 +- .../compas/sct/commons/api/DataSetReader.java | 15 ++ .../compas/sct/commons/api/DoReader.java | 21 +++ .../compas/sct/commons/api/DoTypeReader.java | 21 +++ .../compas/sct/commons/api/ExtRefReader.java | 15 ++ .../compas/sct/commons/api/IedReader.java | 19 +++ .../compas/sct/commons/api/LdeviceReader.java | 24 +++ .../compas/sct/commons/api/LnReader.java | 15 ++ .../sct/commons/api/LnodeTypeReader.java | 21 +++ .../sct/commons/dto/DataAttributeRef.java | 2 +- .../compas/sct/commons/dto/DataSetInfo.java | 76 ++------- .../compas/sct/commons/dto/ExtRefInfo.java | 31 ++-- .../compas/sct/commons/dto/FCDAInfo.java | 75 --------- .../sct/commons/dto/GooseControlBlock.java | 1 + .../compas/sct/commons/dto/LDeviceDTO.java | 4 +- .../compas/sct/commons/dto/LNodeDTO.java | 73 +++++++-- .../compas/sct/commons/dto/LNodeMetaData.java | 4 +- .../sct/commons/dto/ReportControlBlock.java | 2 +- .../sct/commons/dto/SMVControlBlock.java | 4 +- .../sct/commons/scl/ObjectReference.java | 6 +- .../sct/commons/scl/dtt/DOTypeAdapter.java | 13 +- .../sct/commons/scl/dtt/LNodeTypeAdapter.java | 100 +++++------- .../commons/scl/ied/AccessPointAdapter.java | 2 + .../commons/scl/ied/ControlBlockAdapter.java | 2 + .../sct/commons/scl/ied/DAITracker.java | 1 + .../sct/commons/scl/ied/DOIAdapter.java | 3 +- .../sct/commons/scl/ied/DataSetAdapter.java | 1 + .../sct/commons/scl/ied/IEDAdapter.java | 7 +- .../sct/commons/scl/ied/InputsAdapter.java | 6 +- .../compas/sct/commons/scl/ied/Ldevice.java | 52 ------- .../scl/{ => ldevice}/LDeviceActivation.java | 2 +- .../scl/{ied => ldevice}/LDeviceAdapter.java | 26 ++-- .../scl/{ied => ln}/AbstractLNAdapter.java | 129 +++++++-------- .../commons/scl/{ied => ln}/LN0Adapter.java | 10 +- .../commons/scl/{ied => ln}/LNAdapter.java | 9 +- .../scl/{ied => ln}/LNAdapterBuilder.java | 5 +- .../compas/sct/commons/scl/ln/LnKey.java | 38 +++++ .../compas/sct/commons/util/Utils.java | 6 +- .../sct/commons/ControlBlockServiceTest.java | 14 +- .../sct/commons/DataSetServiceTest.java | 49 ++++++ .../compas/sct/commons/ExtRefServiceTest.java | 11 +- .../compas/sct/commons/HmiServiceTest.java | 4 +- ...eviceTest.java => LdeviceServiceTest.java} | 15 +- .../SclElementsProviderServiceTest.java | 2 + .../compas/sct/commons/SclServiceTest.java | 10 +- .../sct/commons/dto/DataAttributeRefTest.java | 2 +- .../sct/commons/dto/DataSetInfoTest.java | 87 +++-------- .../compas/sct/commons/dto/FCDAInfoTest.java | 110 ++----------- .../sct/commons/dto/LDeviceDTOTest.java | 2 +- .../compas/sct/commons/dto/LNodeDTOTest.java | 4 +- .../commons/scl/dtt/DOTypeAdapterTest.java | 15 +- .../commons/scl/dtt/LNodeTypeAdapterTest.java | 10 +- .../scl/ied/ControlBlockAdapterTest.java | 2 + .../sct/commons/scl/ied/DAITrackerTest.java | 3 + .../sct/commons/scl/ied/DOIAdapterTest.java | 2 + .../commons/scl/ied/DataSetAdapterTest.java | 1 + .../sct/commons/scl/ied/IEDAdapterTest.java | 2 + .../commons/scl/ied/InputsAdapterTest.java | 3 + .../{ => ldevice}/LDeviceActivationTest.java | 2 +- .../{ied => ldevice}/LDeviceAdapterTest.java | 10 +- .../scl/{ied => ln}/LN0AdapterTest.java | 147 ++++++++++-------- .../scl/{ied => ln}/LNAdapterTest.java | 21 ++- .../sct/commons/testhelpers/SclHelper.java | 4 + 76 files changed, 988 insertions(+), 697 deletions(-) create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataSetService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoTypeService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/IedService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnodeTypeService.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataSetReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoTypeReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/IedReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LdeviceReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnReader.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnodeTypeReader.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ldevice.java rename sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/{ => ldevice}/LDeviceActivation.java (99%) rename sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/{ied => ldevice}/LDeviceAdapter.java (95%) rename sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/{ied => ln}/AbstractLNAdapter.java (91%) rename sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/{ied => ln}/LN0Adapter.java (97%) rename sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/{ied => ln}/LNAdapter.java (95%) rename sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/{ied => ln}/LNAdapterBuilder.java (90%) create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java create mode 100644 sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataSetServiceTest.java rename sct-commons/src/test/java/org/lfenergy/compas/sct/commons/{scl/ied/LdeviceTest.java => LdeviceServiceTest.java} (58%) rename sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/{ => ldevice}/LDeviceActivationTest.java (99%) rename sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/{ied => ldevice}/LDeviceAdapterTest.java (98%) rename sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/{ied => ln}/LN0AdapterTest.java (94%) rename sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/{ied => ln}/LNAdapterTest.java (97%) diff --git a/pom.xml b/pom.xml index b31c36062..17e482332 100644 --- a/pom.xml +++ b/pom.xml @@ -134,6 +134,7 @@ ${java.version} ${java.version} + --enable-preview @@ -145,6 +146,11 @@ org.apache.maven.plugins maven-surefire-plugin 2.22.2 + + + + @{argLine} --enable-preview + org.apache.maven.plugins diff --git a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java index 5ccc21468..d4aaea1ca 100644 --- a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java +++ b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java @@ -18,7 +18,7 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import java.util.Arrays; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockService.java index eafecb9ea..5f28d9e61 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockService.java @@ -5,17 +5,23 @@ package org.lfenergy.compas.sct.commons; import org.apache.commons.lang3.StringUtils; -import org.lfenergy.compas.scl2007b4.model.*; +import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.sct.commons.api.ControlBlockEditor; -import org.lfenergy.compas.sct.commons.dto.*; +import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings; import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.NetworkRanges; import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.RangesPerCbType; import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.Settings; import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.SettingsOrError; +import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation; +import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.*; -import org.lfenergy.compas.sct.commons.util.*; +import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; +import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; +import org.lfenergy.compas.sct.commons.util.Utils; import java.util.*; import java.util.stream.Stream; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataSetService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataSetService.java new file mode 100644 index 000000000..6443f3f37 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataSetService.java @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.LN0; +import org.lfenergy.compas.scl2007b4.model.TAnyLN; +import org.lfenergy.compas.scl2007b4.model.TDataSet; +import org.lfenergy.compas.scl2007b4.model.TLN; +import org.lfenergy.compas.sct.commons.api.DataSetReader; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class DataSetService implements DataSetReader { + + public Stream getDataSets(TAnyLN tAnyLN) { + return switch (tAnyLN) { + case LN0 ln0 -> ln0.isSetDataSet() ? ln0.getDataSet().stream() : Stream.empty(); + case TLN tln -> tln.isSetDataSet() ? tln.getDataSet().stream() : Stream.empty(); + default -> throw new IllegalStateException("Unexpected value: " + tAnyLN); + }; + } + + public Stream getFilteredDataSets(TAnyLN tAnyLN, Predicate dataSetPredicate) { + return getDataSets(tAnyLN).filter(dataSetPredicate); + } + + public Optional findDataSet(TAnyLN tAnyLN, Predicate dataSetPredicate) { + return getFilteredDataSets(tAnyLN, dataSetPredicate).findFirst(); + } +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoService.java new file mode 100644 index 000000000..1e2f0dc1c --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoService.java @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2022 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.TDO; +import org.lfenergy.compas.scl2007b4.model.TLNodeType; +import org.lfenergy.compas.sct.commons.api.DoReader; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class DoService implements DoReader { + + public Stream getDos(TLNodeType tlNodeType) { + return tlNodeType.getDO().stream(); + } + + public Stream getFilteredDos(TLNodeType tlNodeType, Predicate tdoPredicate) { + return getDos(tlNodeType).filter(tdoPredicate); + } + + public Optional findDo(TLNodeType tlNodeType, Predicate tdoPredicate) { + return getFilteredDos(tlNodeType, tdoPredicate).findFirst(); + } + +} 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 new file mode 100644 index 000000000..be83d6576 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoTypeService.java @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2022 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates; +import org.lfenergy.compas.scl2007b4.model.TDOType; +import org.lfenergy.compas.sct.commons.api.DoTypeReader; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class DoTypeService implements DoTypeReader { + + public Stream getDoTypes(TDataTypeTemplates tDataTypeTemplates) { + return tDataTypeTemplates.getDOType().stream(); + } + + public Stream getFilteredDoTypes(TDataTypeTemplates tDataTypeTemplates, Predicate tdoTypePredicate) { + return getDoTypes(tDataTypeTemplates).filter(tdoTypePredicate); + } + + public Optional findDoType(TDataTypeTemplates tDataTypeTemplates, Predicate tdoTypePredicate) { + return getFilteredDoTypes(tDataTypeTemplates, tdoTypePredicate).findFirst(); + } + +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java new file mode 100644 index 000000000..380a2d75f --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.LN0; +import org.lfenergy.compas.scl2007b4.model.TAnyLN; +import org.lfenergy.compas.scl2007b4.model.TExtRef; +import org.lfenergy.compas.scl2007b4.model.TLN; +import org.lfenergy.compas.sct.commons.api.ExtRefReader; + +import java.util.stream.Stream; + +public class ExtRefReaderService implements ExtRefReader { + + public Stream getExtRefs(TAnyLN tAnyLN) { + return switch (tAnyLN) { + case LN0 ln0 -> ln0.isSetInputs() ? ln0.getInputs().getExtRef().stream() : Stream.empty(); + case TLN tln -> tln.isSetInputs() ? tln.getInputs().getExtRef().stream() : Stream.empty(); + default -> throw new IllegalStateException("Unexpected value: " + tAnyLN); + }; + } +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefService.java index 4252bc4b3..12a827328 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefService.java @@ -6,21 +6,22 @@ import org.apache.commons.lang3.StringUtils; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.api.ExtRefEditor; import org.lfenergy.compas.sct.commons.dto.*; -import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.NetworkRanges; -import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.RangesPerCbType; -import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.Settings; -import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.SettingsOrError; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.*; -import org.lfenergy.compas.sct.commons.util.*; +import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.util.ILDEPFSettings; +import org.lfenergy.compas.sct.commons.util.LdeviceStatus; +import org.lfenergy.compas.sct.commons.util.PrivateEnum; +import org.lfenergy.compas.sct.commons.util.PrivateUtils; +import org.lfenergy.compas.sct.commons.api.ExtRefEditor; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; import static org.lfenergy.compas.sct.commons.util.Utils.isExtRefFeedBySameControlBlock; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/IedService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/IedService.java new file mode 100644 index 000000000..b429337e4 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/IedService.java @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2022 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.SCL; +import org.lfenergy.compas.scl2007b4.model.TIED; +import org.lfenergy.compas.sct.commons.api.IedReader; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class IedService implements IedReader { + + public Stream getFilteredIeds(SCL scd, Predicate iedPredicate) { + return scd.getIED().stream().filter(iedPredicate); + } + + public Optional findIed(SCL scd, Predicate iedPredicate) { + return getFilteredIeds(scd, iedPredicate).findFirst(); + } +} 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 new file mode 100644 index 000000000..324239c1f --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: 2022 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.*; +import org.lfenergy.compas.sct.commons.api.LdeviceReader; +import org.lfenergy.compas.sct.commons.util.LdeviceStatus; + +import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME; +import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME; + +public class LdeviceService implements LdeviceReader { + + public Stream getLdevices(TIED tied) { + if (!tied.isSetAccessPoint()) { + return Stream.empty(); + } + return tied.getAccessPoint() + .stream() + .map(TAccessPoint::getServer) + .filter(Objects::nonNull) + .filter(TServer::isSetLDevice) + .flatMap(tServer -> tServer.getLDevice().stream()); + } + + public Stream getFilteredLdevices(TIED tied, Predicate ldevicePredicate) { + return getLdevices(tied).filter(ldevicePredicate); + } + + public Optional findLdevice(TIED tied, Predicate ldevicePredicate) { + return getFilteredLdevices(tied, ldevicePredicate).findFirst(); + } + + public Optional getLdeviceStatus(TLDevice tlDevice) { + return tlDevice.getLN0() + .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(LdeviceStatus::fromValue); + } +} 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 new file mode 100644 index 000000000..602b47498 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2022 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.*; +import org.lfenergy.compas.sct.commons.api.LnReader; + +import java.util.stream.Stream; + +public class LnService implements LnReader { + + public Stream getAnylns(TLDevice tlDevice) { + return Stream.concat(Stream.of(tlDevice.getLN0()), tlDevice.getLN().stream()); + } +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnodeTypeService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnodeTypeService.java new file mode 100644 index 000000000..34b6a14db --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnodeTypeService.java @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2022 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates; +import org.lfenergy.compas.scl2007b4.model.TLNodeType; +import org.lfenergy.compas.sct.commons.api.LnodeTypeReader; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class LnodeTypeService implements LnodeTypeReader { + + public Stream getLnodeTypes(TDataTypeTemplates tDataTypeTemplates) { + return tDataTypeTemplates.getLNodeType().stream(); + } + + public Stream getFilteredLnodeTypes(TDataTypeTemplates tDataTypeTemplates, Predicate tlNodeTypePredicate) { + return getLnodeTypes(tDataTypeTemplates).filter(tlNodeTypePredicate); + } + + public Optional findLnodeType(TDataTypeTemplates tDataTypeTemplates, Predicate tlNodeTypePredicate) { + return getFilteredLnodeTypes(tDataTypeTemplates, tlNodeTypePredicate).findFirst(); + } + +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclElementsProviderService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclElementsProviderService.java index 51c9f46d4..77303b8ae 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclElementsProviderService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclElementsProviderService.java @@ -13,6 +13,8 @@ import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.EnumTypeAdapter; import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import java.util.*; import java.util.stream.Collectors; @@ -78,18 +80,14 @@ public List getExtRefSourceInfo(SCL scd, ExtRefInfo extRefInfo) th throw new ScdException("Internal binding can't have control block"); } - SclRootAdapter sclRootAdapter = new SclRootAdapter(scd); - // Get CBs - IEDAdapter srcIEDAdapter = sclRootAdapter.getIEDAdapterByName(bindingInfo.getIedName()); - LDeviceAdapter srcLDeviceAdapter = srcIEDAdapter.findLDeviceAdapterByLdInst(extRefInfo.getBindingInfo().getLdInst()) - .orElseThrow(); - - List> aLNAdapters = srcLDeviceAdapter.getLNAdaptersIncludingLN0(); - - return aLNAdapters.stream() - .map(abstractLNAdapter1 -> abstractLNAdapter1.getControlBlocksForMatchingFCDA(extRefInfo)) - .flatMap(Collection::stream) + return new SclRootAdapter(scd) + .getIEDAdapterByName(bindingInfo.getIedName()) + .findLDeviceAdapterByLdInst(extRefInfo.getBindingInfo().getLdInst()) + .orElseThrow() + .getLNAdaptersIncludingLN0() + .stream() + .flatMap(lnAdapter -> lnAdapter.getControlBlocksForMatchingFCDA(extRefInfo)) .toList(); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclService.java index 3364bdf52..9019c8dbe 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclService.java @@ -19,7 +19,11 @@ import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter; import org.lfenergy.compas.sct.commons.scl.header.HeaderAdapter; import org.lfenergy.compas.sct.commons.scl.icd.IcdHeader; -import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ied.DAITracker; +import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.scl.sstation.SubstationAdapter; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import org.lfenergy.compas.sct.commons.util.Utils; @@ -107,7 +111,7 @@ public void updateDAI(SCL scd, String iedName, String ldInst, DataAttributeRef d DataTypeTemplateAdapter dttAdapter = sclRootAdapter.getDataTypeTemplateAdapter(); LNodeTypeAdapter lNodeTypeAdapter = dttAdapter.getLNodeTypeAdapterById(dataAttributeRef.getLnType()) .orElseThrow(() -> new ScdException("Unknown LNodeType : " + dataAttributeRef.getLnType())); - lNodeTypeAdapter.check(dataAttributeRef.getDoName(), dataAttributeRef.getDaName()); + lNodeTypeAdapter.checkDoAndDaTypeName(dataAttributeRef.getDoName(), dataAttributeRef.getDaName()); if (TPredefinedBasicTypeEnum.OBJ_REF == dataAttributeRef.getBType()) { Long sGroup = dataAttributeRef.getDaName().getDaiValues().keySet().stream().findFirst().orElse(-1L); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataSetReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataSetReader.java new file mode 100644 index 000000000..766add5c8 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DataSetReader.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TAnyLN; +import org.lfenergy.compas.scl2007b4.model.TDataSet; + +import java.util.stream.Stream; + +public interface DataSetReader { + + Stream getDataSets(TAnyLN tAnyLN); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoReader.java new file mode 100644 index 000000000..105f58429 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoReader.java @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TDO; +import org.lfenergy.compas.scl2007b4.model.TLNodeType; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public interface DoReader { + + Stream getDos(TLNodeType tlNodeType); + + Stream getFilteredDos(TLNodeType tlNodeType, Predicate tdoPredicate); + + Optional findDo(TLNodeType tlNodeType, Predicate tdoPredicate); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoTypeReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoTypeReader.java new file mode 100644 index 000000000..c946a1e39 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/DoTypeReader.java @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TDOType; +import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public interface DoTypeReader { + + Stream getDoTypes(TDataTypeTemplates tDataTypeTemplates); + + Stream getFilteredDoTypes(TDataTypeTemplates tDataTypeTemplates, Predicate tlNodeTypePredicate); + + Optional findDoType(TDataTypeTemplates tDataTypeTemplates, Predicate tlNodeTypePredicate); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefReader.java new file mode 100644 index 000000000..68853e5ec --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefReader.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TAnyLN; +import org.lfenergy.compas.scl2007b4.model.TExtRef; + +import java.util.stream.Stream; + +public interface ExtRefReader { + + Stream getExtRefs(TAnyLN tAnyLN); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/IedReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/IedReader.java new file mode 100644 index 000000000..7c166567d --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/IedReader.java @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.SCL; +import org.lfenergy.compas.scl2007b4.model.TIED; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public interface IedReader { + + Stream getFilteredIeds(SCL scd, Predicate iedPredicate); + + Optional findIed(SCL scd, Predicate iedPredicate); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LdeviceReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LdeviceReader.java new file mode 100644 index 000000000..888a8cb9a --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LdeviceReader.java @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TIED; +import org.lfenergy.compas.scl2007b4.model.TLDevice; +import org.lfenergy.compas.sct.commons.util.LdeviceStatus; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public interface LdeviceReader { + + Stream getLdevices(TIED tied); + + Stream getFilteredLdevices(TIED tied, Predicate ldevicePredicate); + + Optional findLdevice(TIED tied, Predicate ldevicePredicate); + + Optional getLdeviceStatus(TLDevice tlDevice); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnReader.java new file mode 100644 index 000000000..6905d2f00 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnReader.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TAnyLN; +import org.lfenergy.compas.scl2007b4.model.TLDevice; + +import java.util.stream.Stream; + +public interface LnReader { + + Stream getAnylns(TLDevice tlDevice); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnodeTypeReader.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnodeTypeReader.java new file mode 100644 index 000000000..f35729c27 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnodeTypeReader.java @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons.api; + +import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates; +import org.lfenergy.compas.scl2007b4.model.TLNodeType; + +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public interface LnodeTypeReader { + + Stream getLnodeTypes(TDataTypeTemplates tDataTypeTemplates); + + Stream getFilteredLnodeTypes(TDataTypeTemplates tDataTypeTemplates, Predicate tlNodeTypePredicate); + + Optional findLnodeType(TDataTypeTemplates tDataTypeTemplates, Predicate tlNodeTypePredicate); +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRef.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRef.java index e373f2871..ce1403818 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRef.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRef.java @@ -8,7 +8,7 @@ import lombok.*; import org.apache.commons.lang3.StringUtils; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.SclConstructorHelper; import java.util.ArrayList; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataSetInfo.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataSetInfo.java index 8ef98c1b1..02ad929a1 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataSetInfo.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataSetInfo.java @@ -5,15 +5,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import org.lfenergy.compas.scl2007b4.model.TAnyLN; import org.lfenergy.compas.scl2007b4.model.TDataSet; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; /** * A representation of the model object Data Set. @@ -23,82 +18,33 @@ *

*
    *
  • {@link DataSetInfo#getName() Name}
  • - *
  • {@link DataSetInfo#getFCDAInfos() Refers to FCDA infos}
  • + *
  • {@link DataSetInfo#getFcdaInfos()} Refers to FCDA infos}
  • *
* * @see org.lfenergy.compas.scl2007b4.model.TDataSet */ @Getter @NoArgsConstructor -public class DataSetInfo extends LNodeMetaDataEmbedder{ +public class DataSetInfo extends LNodeMetaDataEmbedder { + //TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info private String name; private List fcdaInfos = new ArrayList<>(); - /** - * Constructor - * @param name input - */ - public DataSetInfo(String name){ + public DataSetInfo(TDataSet tDataSet) { super(); - this.name = name; - } - - /** - * Convert DataSet object to DataSetInfo object - * @param tDataSet object - * @return DataSetInfo object value - */ - public static DataSetInfo from(TDataSet tDataSet) { - DataSetInfo dataSetInfo = new DataSetInfo(); - dataSetInfo.name = tDataSet.getName(); - dataSetInfo.fcdaInfos.addAll( - tDataSet.getFCDA().stream() - .map(tfcda -> new FCDAInfo(dataSetInfo.name, tfcda)) - .collect(Collectors.toList()) - ); - return dataSetInfo; - } - - /** - * Get Set of DataSet from LnAdapter - * @param lnAdapter object LnAdapter - * @return Set of DataSetInfo - */ - public static Set getDataSets(AbstractLNAdapter lnAdapter){ - return lnAdapter.getDataSetMatchingExtRefInfo(null) - .stream().map(DataSetInfo::from).collect(Collectors.toSet()); - } - - /** - * Add FCDA to FCDA list - * @param fcdaInfo object FCDAInfo containing FCDA datas - */ - public void addFCDAInfo(FCDAInfo fcdaInfo){ - fcdaInfos.add(fcdaInfo); - } - - /** - * Get FCDA list from DtaSetInfo - * @return FCDA list - */ - public List getFCDAInfos(){ - return Collections.unmodifiableList(fcdaInfos); - } - - /** - * Set DataSet name - * @param name string DataSet name - */ - public void setName(String name){ - this.name = name; + this.name = tDataSet.getName(); + this.fcdaInfos = tDataSet.getFCDA() + .stream() + .map(fcda -> new FCDAInfo(name, fcda.getFc(), fcda.getLdInst(), fcda.getPrefix(), fcda.getLnClass().get(0), fcda.getLnInst(), new DoTypeName(fcda.getDoName()), new DaTypeName(fcda.getDaName()), fcda.getIx())) + .toList(); } /** * Check DataSet validity * @return validity state */ - public boolean isValid(){ - if(name.length() > 32 || fcdaInfos.isEmpty()){ + public boolean isValid() { + if (name.length() > 32 || fcdaInfos.isEmpty()) { return false; } return fcdaInfos.stream().allMatch(FCDAInfo::isValid); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java index 1ed007267..fa8b2d300 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ExtRefInfo.java @@ -9,6 +9,11 @@ import org.lfenergy.compas.scl2007b4.model.TCompasBay; import org.lfenergy.compas.scl2007b4.model.TExtRef; import org.lfenergy.compas.scl2007b4.model.TFCDA; + +import java.util.Objects; + +import static org.apache.commons.lang3.StringUtils.trimToEmpty; + /** * A representation of the model object ExtRef. * @@ -33,7 +38,7 @@ @NoArgsConstructor @AllArgsConstructor public class ExtRefInfo extends LNodeMetaDataEmbedder{ - + //TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info private ExtRefSignalInfo signalInfo; private ExtRefBindingInfo bindingInfo; private ExtRefSourceInfo sourceInfo; @@ -59,8 +64,7 @@ public ExtRefInfo(TExtRef tExtRef) { * @param prefix input * @return ExtRefInfo object */ - public static ExtRefInfo from(TExtRef tExtRef, String iedName, String ldInst, - String lnClass, String lnInst, String prefix){ + public static ExtRefInfo from(TExtRef tExtRef, String iedName, String ldInst, String lnClass, String lnInst, String prefix) { ExtRefInfo extRefInfo = new ExtRefInfo(tExtRef); extRefInfo.setHolderLDInst(ldInst); extRefInfo.setHolderIEDName(iedName); @@ -78,18 +82,15 @@ public static ExtRefInfo from(TExtRef tExtRef, String iedName, String ldInst, * @param tfcda FCDA data to check compatibilities with ExtRef * @return true if ExtRef matches FCDA for parameters ahead false otherwise */ - public boolean checkMatchingFCDA(@NonNull TFCDA tfcda){ - if(bindingInfo == null || signalInfo == null) return false; - FCDAInfo fcdaInfo = new FCDAInfo(tfcda); - FCDAInfo fcdaOfBinding = FCDAInfo.builder() - .ldInst(bindingInfo.getLdInst()) - .lnClass(bindingInfo.getLnClass()) - .lnInst(bindingInfo.getLnInst()) - .prefix(bindingInfo.getPrefix()) - .doName(new DoTypeName(signalInfo.getPDO())) - .daName(new DaTypeName(signalInfo.getPDA())) - .build(); - return fcdaInfo.checkFCDACompatibilitiesForBinding(fcdaOfBinding); + public boolean checkMatchingFCDA(@NonNull TFCDA tfcda) { + if (bindingInfo == null || signalInfo == null) return false; + + return trimToEmpty(tfcda.getLdInst()).equals(trimToEmpty(bindingInfo.getLdInst())) + && trimToEmpty(tfcda.getPrefix()).equals(trimToEmpty(bindingInfo.getPrefix())) + && trimToEmpty(tfcda.getLnClass().get(0)).equals(trimToEmpty(bindingInfo.getLnClass())) + && trimToEmpty(tfcda.getLnInst()).equals(trimToEmpty(bindingInfo.getLnInst())) + && Objects.equals(tfcda.getDoName(), signalInfo.getPDO()) + && Objects.equals(tfcda.getDaName(), signalInfo.getPDA()); } /** diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java index 453f5b590..341c1d935 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java @@ -10,10 +10,6 @@ import org.lfenergy.compas.scl2007b4.model.TFCDA; import org.lfenergy.compas.scl2007b4.model.TFCEnum; -import java.util.Objects; - -import static org.lfenergy.compas.sct.commons.util.Utils.equalsOrBothBlank; - /** * A representation of the model object FCDA. * @@ -34,10 +30,8 @@ * @see org.lfenergy.compas.scl2007b4.model.TFCDA */ @Getter -@Setter @AllArgsConstructor @NoArgsConstructor -@Builder public class FCDAInfo { private String dataSet; @@ -51,62 +45,6 @@ public class FCDAInfo { private DaTypeName daName; //daName.[...bdaNames] private Long ix; - /** - * Constructor - * @param dataSet input - * @param tfcda input - */ - public FCDAInfo(String dataSet, TFCDA tfcda) { - this(tfcda); - this.dataSet = dataSet; - } - - public FCDAInfo(TFCDA tfcda) { - fc = tfcda.getFc(); - ldInst = tfcda.getLdInst(); - prefix = tfcda.getPrefix(); - if (!tfcda.getLnClass().isEmpty()) { - this.lnClass = tfcda.getLnClass().get(0); - } - lnInst = tfcda.getLnInst(); - doName = new DoTypeName(tfcda.getDoName()); - daName = new DaTypeName(tfcda.getDaName()); - ix = tfcda.isSetIx() ? tfcda.getIx() : null; - } - - /** - * Gets FCDA - * @return FCDA object - */ - @JsonIgnore - public TFCDA getFCDA(){ - TFCDA tfcda = new TFCDA(); - tfcda.setLdInst(ldInst); - tfcda.setFc(fc); - if(!StringUtils.isBlank(lnClass)){ - tfcda.getLnClass().add(lnClass); - if(!StringUtils.isBlank(lnInst)){ - tfcda.setLnInst(lnInst); - } - if(!StringUtils.isBlank(prefix)){ - tfcda.setPrefix(prefix); - } - } - - if(doName != null && doName.isDefined()){ - tfcda.setDoName(doName.toString()); - } - - if(daName != null && daName.isDefined()){ - tfcda.setDaName(daName.toString()); - } - - if(ix != null){ - tfcda.setIx(ix); - } - return tfcda; - } - /** * Checks FCDAInfo validity * @return validity state @@ -115,17 +53,4 @@ public boolean isValid() { return doName != null && doName.isDefined(); } - /** - * Checks if two FCDAInfo object match for ldInst, lnInst, lnClass, lnPrefix doName and daName for search of binding control blocks - * @param fcdaInfo FCDA to copare with - * @return true if FCDAs match for binding, otherwise false - */ - public boolean checkFCDACompatibilitiesForBinding(FCDAInfo fcdaInfo) { - return equalsOrBothBlank(getLdInst(), fcdaInfo.getLdInst()) - && equalsOrBothBlank(getPrefix(), fcdaInfo.getPrefix()) - && equalsOrBothBlank(getLnClass(), fcdaInfo.getLnClass()) - && equalsOrBothBlank(getLnInst(), fcdaInfo.getLnInst()) - && Objects.equals(getDoName(), fcdaInfo.getDoName()) - && Objects.equals(getDaName(), fcdaInfo.getDaName()); - } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java index 25c2fa3bf..652ef691f 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java @@ -36,6 +36,7 @@ @Getter @Setter public class GooseControlBlock extends ControlBlock { + //TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info private boolean fixedOffs = false; private TProtocol protocol; private TGSEControlTypeEnum type = TGSEControlTypeEnum.GOOSE; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java index b9aa8c641..479e887c6 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java @@ -7,8 +7,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.HashSet; 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 adba8b9f2..c9c3b5cbb 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 @@ -7,13 +7,17 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.lfenergy.compas.scl2007b4.model.TAnyLN; -import org.lfenergy.compas.scl2007b4.model.TExtRef; +import org.lfenergy.compas.scl2007b4.model.*; +import org.lfenergy.compas.sct.commons.DataSetService; +import org.lfenergy.compas.sct.commons.ExtRefReaderService; +import org.lfenergy.compas.sct.commons.LnodeTypeService; +import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; +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.util.Utils; import java.util.HashSet; @@ -41,21 +45,21 @@ * * @see org.lfenergy.compas.scl2007b4.model.TLNode */ - @Slf4j @Getter @NoArgsConstructor public class LNodeDTO { + //TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info private String inst; private String nodeClass; private String nodeType; private String prefix; - private Set extRefs = new HashSet<>(); - private Set gooseControlBlocks = new HashSet<>(); - private Set smvControlBlocks = new HashSet<>(); - private Set reportControlBlocks = new HashSet<>(); + private final Set extRefs = new HashSet<>(); + private final Set gooseControlBlocks = new HashSet<>(); + private final Set smvControlBlocks = new HashSet<>(); + private final Set reportControlBlocks = new HashSet<>(); private Set datSets = new HashSet<>(); - private Set dataAttributeRefs = new HashSet<>(); + private final Set dataAttributeRefs = new HashSet<>(); /** * Constructor @@ -110,7 +114,8 @@ public static LNodeDTO from(AbstractLNAdapter nodeAdapter, } if(options.isWithDatSet()) { - lNodeDTO.datSets = DataSetInfo.getDataSets(nodeAdapter); + DataSetService dataSetService = new DataSetService(); + lNodeDTO.datSets = dataSetService.getDataSets(nodeAdapter.getCurrentElem()).map(DataSetInfo::new).collect(Collectors.toSet()); } if(options.isWithDataAttributeRef()) { @@ -140,6 +145,50 @@ public static LNodeDTO from(AbstractLNAdapter nodeAdapter, return lNodeDTO; } + 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().orElse(""); + String lnType = tAnyLN.getLnType(); + LNodeDTO lNodeDTO = new LNodeDTO(inst, lnClass, prefix, lnType); + if (options.isWithExtRef()) { + List extRefInfos = new ExtRefReaderService().getExtRefs(tAnyLN) + .map(extRef -> ExtRefInfo.from(extRef, iedName, ldInst, lnClass, inst, prefix)) + .toList(); + lNodeDTO.addAllExtRefInfo(extRefInfos); + } + if (options.isWithDatSet()) { + List dataSetInfos = new DataSetService().getDataSets(tAnyLN) + .map(DataSetInfo::new) + .distinct() + .toList(); + lNodeDTO.addAllDatSets(dataSetInfos); + } + + if (options.isWithDataAttributeRef()) { + DataAttributeRef filter = DataAttributeRef.builder() + .lnInst(inst) + .lnClass(lnClass) + .prefix(prefix) + .lnType(lnType) + .build(); + + TLNodeType lnodeType = new LnodeTypeService().findLnodeType(scl.getDataTypeTemplates(), lnodeType1 -> lnodeType1.getId().equals(lnType)) + .orElseThrow(() -> new IllegalArgumentException("Corrupted SCD file: reference to unknown lnType(" + lnType + ")")); + List dataAttributeRefList = new LNodeTypeAdapter(new DataTypeTemplateAdapter(new SclRootAdapter(scl), scl.getDataTypeTemplates()), lnodeType) + .getDataAttributeRefs(filter); + lNodeDTO.addAllDataAttributeRef(dataAttributeRefList); + } + log.info(Utils.leaving()); + return lNodeDTO; + } + /** * Sets LNode Inst value * @param inst input diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeMetaData.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeMetaData.java index c59cc0227..b739ab12e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeMetaData.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeMetaData.java @@ -8,8 +8,8 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; /** * A representation of common attributes that defines LDName, LNName. diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlock.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlock.java index 27353cfa9..eec1d8b6f 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlock.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ReportControlBlock.java @@ -40,7 +40,7 @@ @Getter @Setter public class ReportControlBlock extends ControlBlock { - + //TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info private TReportControl.OptFields optFields = newDefaultOptFields(); protected TTrgOps trgOps = newDefaultTrgOps(); protected long intgPd = 60000L; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java index defd366fd..5bcc74452 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java @@ -39,8 +39,8 @@ */ @Getter @Setter -public class SMVControlBlock extends ControlBlock{ - +public class SMVControlBlock extends ControlBlock { + //TODO this is a DTO object; it's meant to be used for carry information; he must be created be the one responsible for carying the info private TSampledValueControl.SmvOpts smvOpts = newDefaultSmvOpts(); private TProtocol protocol; private boolean multicast = true; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ObjectReference.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ObjectReference.java index 9f1c02d31..e7539addf 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ObjectReference.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ObjectReference.java @@ -9,6 +9,8 @@ import org.lfenergy.compas.scl2007b4.model.TExtRef; import org.lfenergy.compas.scl2007b4.model.TLLN0Enum; import org.lfenergy.compas.sct.commons.dto.ExtrefTarget; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; /** * A representation of the model object @@ -31,8 +33,8 @@ * LDName = "name" attribute of IEDName element + "inst" attribute of LDevice element * LNName = "prefix" + "lnClass" + "lnInst" * - * @see org.lfenergy.compas.sct.commons.scl.ied.LNAdapter - * @see org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter + * @see LNAdapter + * @see LN0Adapter * @see org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter */ @Getter diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapter.java index 50577f3ae..32195a88c 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapter.java @@ -466,9 +466,8 @@ public List getDataAttributeRefs(DataAttributeRef rootDataAttr } DataAttributeRef currentDataAttributeRef = DataAttributeRef.copyFrom(rootDataAttributeRef); currentDataAttributeRef.addDoStructName(tsdo.getName()); - parentAdapter.getDOTypeAdapterById(tsdo.getType()).ifPresent( - doTypeAdapter -> - resultDataAttributeRefs.addAll(doTypeAdapter.getDataAttributeRefs(currentDataAttributeRef, filter))); + parentAdapter.getDOTypeAdapterById(tsdo.getType()) + .ifPresent(doTypeAdapter -> resultDataAttributeRefs.addAll(doTypeAdapter.getDataAttributeRefs(currentDataAttributeRef, filter))); } } return resultDataAttributeRefs; @@ -486,8 +485,8 @@ public List getDataAttributeRefs(DataAttributeRef rootDataAttr * @param da DA containing information to summarize * @return list of completed Data Attribute References beginning from this DoType. */ - private List getDataAttributeRefsOfDA(DataAttributeRef rootDataAttributeRef, DataAttributeRef filter, TDA da){ - if(excludedByFilter(filter, da)){ + private List getDataAttributeRefsOfDA(DataAttributeRef rootDataAttributeRef, DataAttributeRef filter, TDA da) { + if (excludedByFilter(filter, da)) { return Collections.emptyList(); } DataAttributeRef currentDataAttributeRef = DataAttributeRef.copyFrom(rootDataAttributeRef); @@ -496,8 +495,8 @@ private List getDataAttributeRefsOfDA(DataAttributeRef rootDat currentDataAttributeRef.getDaName().setBType(da.getBType()); if(da.getBType() == TPredefinedBasicTypeEnum.STRUCT){ return parentAdapter.getDATypeAdapterById(da.getType()) - .map(daTypeAdapter -> daTypeAdapter.getDataAttributeRefs(currentDataAttributeRef, filter)) - .orElse(Collections.emptyList()); + .map(daTypeAdapter -> daTypeAdapter.getDataAttributeRefs(currentDataAttributeRef, filter)) + .orElse(Collections.emptyList()); } else { currentDataAttributeRef.getDaName().setType(da.getType()); currentDataAttributeRef.getDaName().setValImport(da.isValImport()); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java index ae3f530af..78b312f61 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapter.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; import org.lfenergy.compas.scl2007b4.model.TDO; +import org.lfenergy.compas.scl2007b4.model.TDOType; import org.lfenergy.compas.scl2007b4.model.TLNodeType; import org.lfenergy.compas.scl2007b4.model.TPredefinedBasicTypeEnum; import org.lfenergy.compas.sct.commons.dto.DaTypeName; @@ -166,37 +167,31 @@ public Optional getDOTypeId(String doName) { */ public List getDataAttributeRefs(@NonNull DataAttributeRef filter) { - List dataAttributeRefs = new ArrayList<>(); - if (filter.isDaNameDefined()) { + if (filter.getDaName().isDefined()) { try { - check(filter.getDoName(), filter.getDaName()); + checkDoAndDaTypeName(filter.getDoName(), filter.getDaName()); } catch (ScdException e) { log.error(e.getMessage()); - return dataAttributeRefs; + return new ArrayList<>(); } } - DataAttributeRef rootDataAttributeRef = new DataAttributeRef(); - rootDataAttributeRef.setLnType(currentElem.getId()); - rootDataAttributeRef.setLnClass(filter.getLnClass()); - rootDataAttributeRef.setLnInst(filter.getLnInst()); - rootDataAttributeRef.setPrefix(filter.getPrefix()); - - for (TDO tdo : currentElem.getDO()) { - if (filter.isDoNameDefined() && - !filter.getDoName().getName().equals(tdo.getName())) { - continue; - } - parentAdapter.getDOTypeAdapterById(tdo.getType()).ifPresent( - doTypeAdapter -> { - DataAttributeRef currentDataAttributeRef = DataAttributeRef.copyFrom(rootDataAttributeRef); - currentDataAttributeRef.getDoName().setName(tdo.getName()); - currentDataAttributeRef.getDoName().setCdc(doTypeAdapter.getCdc()); - dataAttributeRefs.addAll(doTypeAdapter.getDataAttributeRefs(currentDataAttributeRef, filter)); - } - ); // else this should never happen or the scd won't be built in the first place and we'd never be here - } - return dataAttributeRefs; + return currentElem.getDO() + .stream() + .filter(tdo -> !filter.isDoNameDefined() || filter.getDoName().getName().equals(tdo.getName())) + .flatMap(tdo -> { + TDOType tdoType = parentAdapter.getCurrentElem().getDOType().stream().filter(tdoTypeLambda -> tdoTypeLambda.getId().equals(tdo.getType())).findFirst().orElseThrow(); + DataAttributeRef dataAttributeRef = new DataAttributeRef(); + dataAttributeRef.setPrefix(filter.getPrefix()); + dataAttributeRef.setLnClass(filter.getLnClass()); + dataAttributeRef.setLnInst(filter.getLnInst()); + dataAttributeRef.setLnType(currentElem.getId()); + dataAttributeRef.getDoName().setName(tdo.getName()); + dataAttributeRef.getDoName().setCdc(tdoType.getCdc()); + + return new DOTypeAdapter(parentAdapter, tdoType).getDataAttributeRefs(dataAttributeRef, filter).stream(); + }) + .toList(); } /** @@ -321,44 +316,31 @@ Pair findPathFromDo2DA(String doName, String daName) thro * @throws ScdException when inconsistency are found in th SCL's * DataTypeTemplate (unknown reference for example). Which should normally not happens. */ - public void check(@NonNull DoTypeName doTypeName, @NonNull DaTypeName daTypeName) throws ScdException { + public void checkDoAndDaTypeName(@NonNull DoTypeName doTypeName, @NonNull DaTypeName daTypeName) throws ScdException { if (!doTypeName.isDefined() || !daTypeName.isDefined()) { throw new ScdException("Invalid Data: data attributes information are missing"); } // check Data Object information - DOAdapter doAdapter = this.getDOAdapterByName(doTypeName.getName()).orElseThrow( - () -> new ScdException( - String.format("Unknown DO(%s) in LNodeType(%s)", doTypeName.getName(), currentElem.getId()) - ) - ); - - DOTypeAdapter doTypeAdapter = doAdapter.getDoTypeAdapter().orElseThrow( - () -> new ScdException("Corrupted SCL DataTypeTemplate, Unknown DOType id: " + doAdapter.getType()) - ); + DOAdapter doAdapter = getDOAdapterByName(doTypeName.getName()) + .orElseThrow(() -> new ScdException(String.format("Unknown DO(%s) in LNodeType(%s)", doTypeName.getName(), currentElem.getId()))); - Pair adapterPair = doTypeAdapter.checkAndCompleteStructData(doTypeName) - .orElse(null); + Optional> adapterPairOptional = doAdapter.getDoTypeAdapter() + .orElseThrow(() -> new ScdException("Corrupted SCL DataTypeTemplate, Unknown DOType id: " + doAdapter.getType())) + .checkAndCompleteStructData(doTypeName); // check coherence between Data Object and Data Attributes information - DOTypeAdapter lastDoTypeAdapter; - if (adapterPair == null) { - adapterPair = findPathFromDo2DA(doTypeName.getName(), daTypeName.getName()); - lastDoTypeAdapter = adapterPair.getValue(); - } else { - if (adapterPair.getRight().containsDAWithDAName(daTypeName.getName())) { - lastDoTypeAdapter = adapterPair.getValue(); - } else { - adapterPair = adapterPair.getRight().findPathDoTypeToDA(daTypeName.getName()); - lastDoTypeAdapter = adapterPair.getValue(); - } - } - - DAAdapter daAdapter = lastDoTypeAdapter.getDAAdapterByName(daTypeName.getName()) - .orElseThrow( - () -> new ScdException( - String.format("Unknown DA (%s) in DOType (%s) ", daTypeName.getName(), "leafSdoId") - ) - ); + DAAdapter daAdapter = adapterPairOptional + .map(Pair::getValue) + .map(doTypeAdapter -> { + if (doTypeAdapter.containsDAWithDAName(daTypeName.getName())) { + return doTypeAdapter; + } else { + return doTypeAdapter.findPathDoTypeToDA(daTypeName.getName()).getValue(); + } + }) + .orElseGet(() -> findPathFromDo2DA(doTypeName.getName(), daTypeName.getName()).getValue()) + .getDAAdapterByName(daTypeName.getName()) + .orElseThrow(() -> new ScdException(String.format("Unknown DA (%s) in DOType (%s) ", daTypeName.getName(), "leafSdoId"))); // check Data Attributes if (!daTypeName.getStructNames().isEmpty() && daAdapter.getBType() != TPredefinedBasicTypeEnum.STRUCT) { @@ -369,10 +351,8 @@ public void check(@NonNull DoTypeName doTypeName, @NonNull DaTypeName daTypeName daAdapter.check(daTypeName); } else { daTypeName.setFc(daAdapter.getCurrentElem().getFc()); - DATypeAdapter daTypeAdapter = parentAdapter.getDATypeAdapterById(daAdapter.getType()).orElseThrow( - () -> new ScdException( - String.format("Unknown DAType (%s) referenced by DA(%s)", daAdapter.getType(), daAdapter.getName()) - ) + DATypeAdapter daTypeAdapter = parentAdapter.getDATypeAdapterById(daAdapter.getType()) + .orElseThrow(() -> new ScdException(String.format("Unknown DAType (%s) referenced by DA(%s)", daAdapter.getType(), daAdapter.getName())) ); daTypeAdapter.check(daTypeName); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java index 07b6167cd..9c64f66da 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AccessPointAdapter.java @@ -10,6 +10,8 @@ import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.ServicesConfigEnum; import org.lfenergy.compas.sct.commons.util.Utils; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapter.java index a2a887624..6902f2f5e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapter.java @@ -11,6 +11,8 @@ import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import org.lfenergy.compas.sct.commons.util.Utils; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DAITracker.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DAITracker.java index 40ee993c7..d3a522a8d 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DAITracker.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DAITracker.java @@ -14,6 +14,7 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import java.util.List; import java.util.Map; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java index 29ab05073..5f46b012e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapter.java @@ -8,6 +8,7 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.scl.ObjectReference; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.*; @@ -51,7 +52,7 @@ public class DOIAdapter extends SclElementAdapter parentAdapter, TDOI currentElem) { + public DOIAdapter(AbstractLNAdapter parentAdapter, TDOI currentElem) { super(parentAdapter, currentElem); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapter.java index b51440f2a..4f442c13f 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapter.java @@ -11,6 +11,7 @@ import org.lfenergy.compas.scl2007b4.model.TFCDA; import org.lfenergy.compas.scl2007b4.model.TFCEnum; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.Comparator; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapter.java index 9d2d5e104..30f1b5095 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapter.java @@ -12,6 +12,9 @@ import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.ObjectReference; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; @@ -51,8 +54,8 @@ * * * - * @see org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter - * @see org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter + * @see LDeviceAdapter + * @see AbstractLNAdapter * @see org.lfenergy.compas.sct.commons.scl.ied.AbstractDAIAdapter * @see org.lfenergy.compas.scl2007b4.model.TSettingGroups * @see Issue !3 (Add new IEDs) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java index 8f1a76823..3249c77b8 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java @@ -15,6 +15,9 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import org.lfenergy.compas.sct.commons.util.LdeviceStatus; import org.lfenergy.compas.sct.commons.util.PrivateUtils; @@ -100,8 +103,7 @@ public List updateAllExtRefIedNames(Map icdSy return switch (lDeviceStatus) { case ON -> getExtRefs().stream() .filter(tExtRef -> StringUtils.isNotBlank(tExtRef.getIedName()) && StringUtils.isNotBlank(tExtRef.getDesc())) - .map(extRef -> - updateExtRefIedName(extRef, icdSystemVersionToIed.get(extRef.getIedName()))) + .map(extRef -> updateExtRefIedName(extRef, icdSystemVersionToIed.get(extRef.getIedName()))) .flatMap(Optional::stream) .toList(); case OFF -> { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ldevice.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ldevice.java deleted file mode 100644 index 4dcfa5dfa..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ldevice.java +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.ied; - -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.TDAI; -import org.lfenergy.compas.scl2007b4.model.TLDevice; -import org.lfenergy.compas.scl2007b4.model.TVal; -import org.lfenergy.compas.sct.commons.util.LdeviceStatus; - -import java.util.Collection; -import java.util.Optional; - -import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME; -import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME; - -/** - * Object representing '' , but with utility methods to manipulate the business - * Do not include "currentElements" and so on inside this class - */ -@Getter -public class Ldevice { - - //Object is supposed to grow by the needs we have - private final String inst; - private final String ldName; - private final String description; - private final Optional ldeviceStatus; - - public Ldevice(TLDevice tlDevice) { - inst = tlDevice.getInst(); - ldName = tlDevice.getLdName(); - description = tlDevice.getDesc(); - ldeviceStatus = tlDevice.getLN0() - .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(LdeviceStatus::fromValue); - } -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java similarity index 99% rename from sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java rename to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java index cd1d995ce..58abfa71b 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivation.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivation.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl; +package org.lfenergy.compas.sct.commons.scl.ldevice; import lombok.Getter; import lombok.Setter; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java similarity index 95% rename from sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapter.java rename to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java index e0e12caa6..aecd45463 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ldevice; import lombok.extern.slf4j.Slf4j; @@ -12,6 +12,12 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.DataSetAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import org.lfenergy.compas.sct.commons.util.LdeviceStatus; import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum; @@ -19,8 +25,8 @@ import java.util.*; -import static org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter.MOD_DO_TYPE_NAME; -import static org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter.STVAL_DA_TYPE_NAME; +import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.MOD_DO_TYPE_NAME; +import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.STVAL_DA_TYPE_NAME; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; import static org.lfenergy.compas.sct.commons.util.Utils.copySclElement; @@ -47,8 +53,8 @@ * * * - * @see org.lfenergy.compas.sct.commons.scl.ied.LNAdapter - * @see org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter + * @see LNAdapter + * @see LN0Adapter * @see org.lfenergy.compas.scl2007b4.model.TLDevice * @see org.lfenergy.compas.scl2007b4.model.TDOI * @see org.lfenergy.compas.scl2007b4.model.TDAI @@ -94,12 +100,12 @@ public void createHmiReportControlBlocks(List fcdas) { private void createHmiReportCB(LN0Adapter ln0, TFCDA fcda) { boolean isFcMx = fcda.getFc() == TFCEnum.MX; String dataSetSuffix = getInst().toUpperCase(Locale.ENGLISH) + ATTRIBUTE_VALUE_SEPARATOR + (isFcMx ? "CYPO" : "DQPO"); - DataSetAdapter dataSet = ln0.createDataSetIfNotExists(DATASET_NAME_PREFIX + dataSetSuffix, ControlBlockEnum.REPORT); + String dataSetName = DATASET_NAME_PREFIX + dataSetSuffix; + DataSetAdapter dataSet = ln0.createDataSetIfNotExists(dataSetName, ControlBlockEnum.REPORT); dataSet.createFCDAIfNotExists(fcda.getLdInst(), fcda.getPrefix(), fcda.getLnClass().get(0), fcda.getLnInst(), fcda.getDoName(), fcda.getDaName(), fcda.getFc()); String cbName = CONTROLBLOCK_NAME_PREFIX + dataSetSuffix; String cbId = ln0.generateControlBlockId(getLdName(), cbName); - String datSet = dataSet.getCurrentElem().getName(); - ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists(cbName, cbId, datSet, ControlBlockEnum.REPORT); + ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists(cbName, cbId, dataSetName, ControlBlockEnum.REPORT); if (isFcMx) { TReportControl tReportControl = (TReportControl) controlBlockAdapter.getCurrentElem(); tReportControl.setIntgPd(INTG_PD_VALUE_FOR_FC_MX); @@ -378,7 +384,7 @@ public Set findSourceDA(TExtRef extRef) { * @param controlBlockEnum the type of DataSet we want to check for creation capability. * @return true if parent AccessPoint has the capability, false otherwise */ - protected boolean hasDataSetCreationCapability(ControlBlockEnum controlBlockEnum) { + public boolean hasDataSetCreationCapability(ControlBlockEnum controlBlockEnum) { Objects.requireNonNull(controlBlockEnum); TAccessPoint accessPoint = getAccessPoint(); if (!accessPoint.isSetServices()) { @@ -404,7 +410,7 @@ private boolean hasDatSetConfOrDyn(TServiceSettings tServiceSettings) { * @param controlBlockEnum the type of ControlBlock we want to check for creation capability. * @return true if parent AccessPoint has the capability, false otherwise */ - protected boolean hasControlBlockCreationCapability(ControlBlockEnum controlBlockEnum) { + public boolean hasControlBlockCreationCapability(ControlBlockEnum controlBlockEnum) { Objects.requireNonNull(controlBlockEnum); TAccessPoint accessPoint = getAccessPoint(); if (!accessPoint.isSetServices()) { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java similarity index 91% rename from sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java rename to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java index 31e00995d..3420274b5 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java @@ -1,13 +1,14 @@ // SPDX-FileCopyrightText: 2021 RTE FRANCE // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ln; import lombok.Getter; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.lfenergy.compas.scl2007b4.model.*; +import org.lfenergy.compas.sct.commons.DataSetService; import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.ObjectReference; @@ -16,6 +17,8 @@ import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.EnumTypeAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import java.util.*; @@ -28,7 +31,7 @@ /** * A representation of the model object - * {@link org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter AbstractLNAdapter}. + * {@link AbstractLNAdapter AbstractLNAdapter}. *

* The following features are supported: *

@@ -321,22 +324,10 @@ protected void updateExtRefBindingInfo(TExtRef extRef, ExtRefInfo extRefInfo) { * @param extRefInfo ExtRef signal data for which Control Blocks should be found (contain binding info to match with FCDA) * @return list of ControlBlock object as ControlBlocks of LNode matching FCDA and ExtRef */ - public List getControlBlocksForMatchingFCDA(@NonNull ExtRefInfo extRefInfo) { - List tDataSets = this.getDataSetMatchingExtRefInfo(extRefInfo); - return getControlBlocks(tDataSets, extRefInfo.getBindingInfo().getServiceType()); - } - - /** - * Gets all Control Blocks from LNode for specified Service Type (GOOSE, SMV and REPORT) and Data Sets - * - * @param tDataSets Data Sets for which Control Blocks are needed - * @param serviceType Service Type of Control Blocks needed - * @return list of ControlBlock objects - */ - protected List getControlBlocks(List tDataSets, TServiceType serviceType) { - return tDataSets.stream() - .map(tDataSet -> getControlBlocksByDataSetRef(tDataSet.getName(), serviceType)) - .flatMap(Collection::stream).toList(); + public Stream getControlBlocksForMatchingFCDA(@NonNull ExtRefInfo extRefInfo) { + return getDataSetMatchingExtRefInfo(extRefInfo) + .map(TDataSet::getName) + .flatMap(dataSetName -> getControlBlocksByDataSetRef(dataSetName, extRefInfo.getBindingInfo().getServiceType())); } /** @@ -346,34 +337,40 @@ protected List getControlBlocks(List tDataSets, TService * @param serviceType service type to be filtered * @return all Control Blocks matching dataSetRef and a Service Type or all Service Types */ - private List getControlBlocksByDataSetRef(String dataSetRef, TServiceType serviceType) { + public Stream getControlBlocksByDataSetRef(String dataSetRef, TServiceType serviceType) { Stream streamGSEControl = Stream.empty(); Stream streamSMVControl = Stream.empty(); Stream streamReportControl = Stream.empty(); LNodeMetaData metaData = LNodeMetaData.from(this); - if (isLN0() && (serviceType == null || serviceType == TServiceType.GOOSE)) { - streamGSEControl = getTControlsByType(TGSEControl.class) - .stream() - .filter(tControl -> dataSetRef.equals(tControl.getDatSet())) - .map(tgseControl -> { - GooseControlBlock gseCbl = new GooseControlBlock(tgseControl); - gseCbl.setMetaData(metaData); - return gseCbl; - }); + if (isLN0()) { + LN0 ln0 = (LN0) currentElem; + //GOOSE et SMV + if (serviceType == null || serviceType == TServiceType.GOOSE) { + streamGSEControl = ln0.getGSEControl() + .stream() + .filter(tControl -> dataSetRef.equals(tControl.getDatSet())) + .map(tgseControl -> { + GooseControlBlock gseCbl = new GooseControlBlock(tgseControl); + gseCbl.setMetaData(metaData); + return gseCbl; + }); + + } + if (serviceType == null || serviceType == TServiceType.SMV) { + streamSMVControl = ln0.getSampledValueControl() + .stream() + .filter(tControl -> dataSetRef.equals(tControl.getDatSet())) + .map(sampledValueControl -> { + SMVControlBlock smvCbl = new SMVControlBlock(sampledValueControl); + smvCbl.setMetaData(metaData); + return smvCbl; + }); + } } - if (isLN0() && (serviceType == null || serviceType == TServiceType.SMV)) { - streamSMVControl = getTControlsByType(TSampledValueControl.class) - .stream() - .filter(tControl -> dataSetRef.equals(tControl.getDatSet())) - .map(sampledValueControl -> { - SMVControlBlock smvCbl = new SMVControlBlock(sampledValueControl); - smvCbl.setMetaData(metaData); - return smvCbl; - }); - } + //REPORT if (serviceType == null || serviceType == TServiceType.REPORT) { - streamReportControl = getTControlsByType(TReportControl.class) + streamReportControl = currentElem.getReportControl() .stream() .filter(tControl -> dataSetRef.equals(tControl.getDatSet())) .map(reportControl -> { @@ -382,7 +379,7 @@ private List getControlBlocksByDataSetRef(String dataSetRef, TServ return rptCbl; }); } - return Stream.concat(Stream.concat(streamGSEControl, streamSMVControl), streamReportControl).toList(); + return Stream.concat(Stream.concat(streamGSEControl, streamSMVControl), streamReportControl); } /** @@ -400,7 +397,7 @@ public List getTControlsByType(Class cls) { } else if (TReportControl.class.equals(cls)) { return (List) currentElem.getReportControl(); } - throw new IllegalArgumentException("Unsupported ControlBlock %s for %s element".formatted(cls.getSimpleName(), elementXPath())); + throw new IllegalArgumentException("Unsupported ControlBlock "+cls.getSimpleName()+" for Lnode"); } /** @@ -431,20 +428,13 @@ public boolean hasControlBlock(String cbName, ControlBlockEnum controlBlockEnum) /** * retrieves all DataSets for which at least one FCDA matches with data given in ExtRefInfo for external binding * - * @param filter contains data for external binding which should match with FCDAs values + * @param extRefInfo contains data for external binding which should match with FCDAs values * @return list of Data for which at least one FCDA matches with filter datas */ - public List getDataSetMatchingExtRefInfo(ExtRefInfo filter) { - if (filter == null) { - return currentElem.getDataSet(); - } + public Stream getDataSetMatchingExtRefInfo(@NonNull ExtRefInfo extRefInfo) { return currentElem.getDataSet() .stream() - .filter(tDataSet -> tDataSet.getFCDA() - .stream() - .anyMatch(filter::checkMatchingFCDA) - ) - .toList(); + .filter(tDataSet -> tDataSet.getFCDA().stream().anyMatch(extRefInfo::checkMatchingFCDA)); } /** @@ -834,20 +824,6 @@ protected boolean matchesDataAttributes(String dataAttribute) { currentElem.getReportControl().stream().anyMatch(rptCtl -> rptCtl.getName().equals(dataAttribute)); } - /** - * Gets Data Set in LNode by its name - * - * @param dataSetName Data Set name - * @return optional of DataSetInfo - */ - public Optional getDataSetByName(String dataSetName) { - return currentElem.getDataSet() - .stream() - .filter(tDataSet -> tDataSet.getName().equals(dataSetName)) - .map(DataSetInfo::from) - .findFirst(); - } - /** * Gets DAI values for specified DA in summaraized Data Type Template * @@ -917,16 +893,16 @@ private void removeExtRefSourceBinding(final TExtRef tExtRef) { * @see LDeviceAdapter#hasDataSetCreationCapability */ public DataSetAdapter createDataSetIfNotExists(String dataSetName, ControlBlockEnum controlBlockEnum) { - return findDataSetByName(dataSetName).orElseGet(() -> { - if (!getParentLDevice().hasDataSetCreationCapability(controlBlockEnum)) { - throw new ScdException("IED/AccessPoint does not have capability to create DataSet of type %s in %s" - .formatted(controlBlockEnum, getXPath())); - } - TDataSet newDataSet = new TDataSet(); - newDataSet.setName(dataSetName); - currentElem.getDataSet().add(newDataSet); - return new DataSetAdapter(this, newDataSet); - }); + return findDataSetByName(dataSetName) + .orElseGet(() -> { + if (!getParentLDevice().hasDataSetCreationCapability(controlBlockEnum)) { + throw new ScdException("IED/AccessPoint does not have capability to create DataSet of type " + controlBlockEnum + " in " + getXPath()); + } + TDataSet newDataSet = new TDataSet(); + newDataSet.setName(dataSetName); + getCurrentElem().getDataSet().add(newDataSet); + return new DataSetAdapter(this, newDataSet); + }); } /** @@ -952,7 +928,8 @@ public ControlBlockAdapter addControlBlock(ControlBlock controlBlock) { ); } - if (this.getDataSetByName(controlBlock.getDataSetRef()).isEmpty()) { + DataSetService dataSetService = new DataSetService(); + if (dataSetService.findDataSet(currentElem, tDataSet -> tDataSet.getName().equals(controlBlock.getDataSetRef())).isEmpty()) { throw new ScdException("Cannot create ControlBlock %s %s because target DataSet %s does not exists in %s" .formatted(controlBlock.getClass().getSimpleName(), controlBlock.getName(), controlBlock.getDataSetRef(), getXPath()) ); diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java similarity index 97% rename from sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java rename to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java index 98d8e8b0c..cab641278 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LN0Adapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java @@ -2,14 +2,16 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ln; import org.apache.commons.lang3.tuple.Pair; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.*; -import org.lfenergy.compas.sct.commons.scl.LDeviceActivation; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceActivation; import org.lfenergy.compas.sct.commons.scl.ObjectReference; +import org.lfenergy.compas.sct.commons.scl.ied.InputsAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import java.util.List; @@ -22,7 +24,7 @@ /** * A representation of the model object - * {@link org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter LN0Adapter}. + * {@link LN0Adapter LN0Adapter}. *

* The following features are supported: *

@@ -65,7 +67,7 @@ * * * @see org.lfenergy.compas.scl2007b4.model.TLN0 - * @see org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter + * @see AbstractLNAdapter */ public class LN0Adapter extends AbstractLNAdapter { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapter.java similarity index 95% rename from sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapter.java rename to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapter.java index 983156336..3a5002b4e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapter.java @@ -2,13 +2,14 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ln; import org.lfenergy.compas.scl2007b4.model.TLN; import org.lfenergy.compas.scl2007b4.model.TServiceType; import org.lfenergy.compas.sct.commons.dto.ExtRefSignalInfo; import org.lfenergy.compas.sct.commons.dto.DataAttributeRef; import org.lfenergy.compas.sct.commons.scl.ObjectReference; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.List; @@ -16,7 +17,7 @@ /** * A representation of the model object - * {@link org.lfenergy.compas.sct.commons.scl.ied.LNAdapter LNAdapter}. + * {@link LNAdapter LNAdapter}. *

* The following features are supported: *

@@ -58,9 +59,9 @@ * LNName = "prefix" + "lnClass" + "lnInst" * * @see org.lfenergy.compas.scl2007b4.model.TAnyLN - * @see org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter + * @see AbstractLNAdapter */ -public class LNAdapter extends AbstractLNAdapter{ +public class LNAdapter extends AbstractLNAdapter { /** * Constructor diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterBuilder.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapterBuilder.java similarity index 90% rename from sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterBuilder.java rename to sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapterBuilder.java index 326acdf40..47bb6dc52 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterBuilder.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapterBuilder.java @@ -2,14 +2,15 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ln; import org.lfenergy.compas.scl2007b4.model.TLLN0Enum; import org.lfenergy.compas.sct.commons.exception.ScdException; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; /** * A representation of the model object - * {@link org.lfenergy.compas.sct.commons.scl.ied.LNAdapterBuilder LNAdapterBuilder}. + * {@link LNAdapterBuilder LNAdapterBuilder}. *

* The following features are supported: *

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 new file mode 100644 index 000000000..8bac31cbf --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java @@ -0,0 +1,38 @@ +// 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.lfenergy.compas.scl2007b4.model.LN0; +import org.lfenergy.compas.scl2007b4.model.TLN; + +import java.util.Optional; + +@Getter +@EqualsAndHashCode +public class LnKey { + + private final String inst; + @EqualsAndHashCode.Exclude + private final String lnType; + private final String lnClass; + /** empty pour les LN0 */ + private final Optional prefix; + + public LnKey(LN0 ln0) { + this.inst = ln0.getInst(); + this.lnType = ln0.getLnType(); + this.lnClass = ln0.getLnClass().get(0); + this.prefix = Optional.empty(); + } + + public LnKey(TLN tln) { + this.inst = tln.getInst(); + this.lnType = tln.getLnType(); + this.lnClass = tln.getLnClass().get(0); + this.prefix = Optional.of(tln.getPrefix()); + } +} + diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/Utils.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/Utils.java index bcbfb36ac..de90ebf22 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/Utils.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/Utils.java @@ -17,9 +17,9 @@ import org.lfenergy.compas.sct.commons.dto.DoTypeName; import org.lfenergy.compas.sct.commons.dto.LDEPFSettingData; import org.lfenergy.compas.sct.commons.exception.ScdException; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import javax.xml.namespace.QName; import java.util.*; @@ -455,7 +455,7 @@ public static boolean isValidDataTypeTemplate(AbstractLNAdapter lnAdapter,LDE return lnAdapter.getDataTypeTemplateAdapter().getLNodeTypeAdapterById(lnAdapter.getLnType()) .filter(lNodeTypeAdapter -> { try { - lNodeTypeAdapter.check(doTypeName, daTypeName); + lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName, daTypeName); } catch (Exception ex) { return false; } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockServiceTest.java index f5b28b367..9045762fa 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockServiceTest.java @@ -12,16 +12,19 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.dto.*; +import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings; +import org.lfenergy.compas.sct.commons.dto.ControlBlockTarget; +import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation; +import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.DataSetAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.FCDARecord; import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; @@ -39,7 +42,6 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.Assertions.assertThatCode; import static org.lfenergy.compas.scl2007b4.model.TFCEnum.ST; import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.*; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataSetServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataSetServiceTest.java new file mode 100644 index 000000000..325a9d868 --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataSetServiceTest.java @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sct.commons; + +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl2007b4.model.TDataSet; +import org.lfenergy.compas.scl2007b4.model.TLN; + +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +class DataSetServiceTest { + + @Test + void getDataSets_whenCalledWithLNContainsMatchingFCDA_shouldReturnDataSet() { + //Given + TDataSet dataSet = new TDataSet(); + dataSet.setName("datasetName"); + TLN tln = new TLN(); + tln.getDataSet().add(dataSet); + DataSetService dataSetService = new DataSetService(); + + //When + Set dataSetInfos = dataSetService.getDataSets(tln).collect(Collectors.toSet()); + + //Then + assertThat(dataSetInfos) + .hasSize(1) + .extracting(TDataSet::getName) + .containsExactly("datasetName"); + } + + @Test + void getDataSets_whenCalledWithNoDataSetInLN_shouldReturnEmptyList(){ + //Given + TLN tln = new TLN(); + DataSetService dataSetService = new DataSetService(); + + //When + Set dataSetInfos = dataSetService.getDataSets(tln).collect(Collectors.toSet()); + + //Then + assertThat(dataSetInfos).isEmpty(); + } +} \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java index 7b94f3c65..aa8f6dc09 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ExtRefServiceTest.java @@ -15,8 +15,8 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.CsvUtils; import org.lfenergy.compas.sct.commons.util.ILDEPFSettings; @@ -28,10 +28,13 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigInteger; -import java.util.*; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/HmiServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/HmiServiceTest.java index a13a86efb..b7a3c56eb 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/HmiServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/HmiServiceTest.java @@ -8,8 +8,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.scl.ied.DataSetAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.CommonConstants; import org.lfenergy.compas.sct.commons.util.LdeviceStatus; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LdeviceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java similarity index 58% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LdeviceTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java index 7682b07b7..b9ac5c975 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LdeviceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java @@ -1,11 +1,12 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE +// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.SCL; +import org.lfenergy.compas.scl2007b4.model.TLDevice; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.LdeviceStatus; @@ -13,16 +14,20 @@ import static org.assertj.core.api.Assertions.assertThat; -class LdeviceTest { +class LdeviceServiceTest { @Test void getLdeviceStatus_should_return_status() { //Given SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml"); - Ldevice ldevice = new Ldevice(std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0)); + TLDevice tlDevice = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0); + LdeviceService ldeviceService = new LdeviceService(); + //When - Optional ldeviceStatus = ldevice.getLdeviceStatus(); + Optional ldeviceStatus = ldeviceService.getLdeviceStatus(tlDevice); + //Then assertThat(ldeviceStatus).contains(LdeviceStatus.OFF); } + } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java index 16c9bbe6f..a6729e8d2 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclElementsProviderServiceTest.java @@ -13,6 +13,8 @@ import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclServiceTest.java index 20680a2ec..defc1b7b6 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclServiceTest.java @@ -16,13 +16,19 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ied.DOIAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.*; +import java.util.List; +import java.util.Optional; +import java.util.UUID; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java index 566261db8..792f4c409 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataAttributeRefTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import java.util.List; import java.util.Map; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java index e500555e6..111b3e71f 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java @@ -4,106 +4,63 @@ package org.lfenergy.compas.sct.commons.dto; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.TDataSet; -import org.lfenergy.compas.scl2007b4.model.TLN; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; - -import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; class DataSetInfoTest { - @Test - @Tag("issue-321") - void testConstructor(){ - //Given When - DataSetInfo dataSetInfo = new DataSetInfo(); - assertThat(dataSetInfo.getName()).isNull(); - //When - dataSetInfo = new DataSetInfo("DATA_INFO"); - //Then - assertThat(dataSetInfo.getName()).isEqualTo("DATA_INFO"); - //Given - dataSetInfo.setName("DATA_INFO1"); - dataSetInfo.addFCDAInfo(new FCDAInfo()); - //When - assertThat(dataSetInfo.getName()).isEqualTo("DATA_INFO1"); - assertThat(dataSetInfo.getFCDAInfos()).isNotEmpty(); - } - @Test void from_WhenCalledWithDataSet_ThenValuesAreFilled(){ //Given - TDataSet dataSet = new TDataSet(); - dataSet.setName("dataset"); - dataSet.getFCDA().add(DTO.createFCDA()); - //When - DataSetInfo dataSetInfo = DataSetInfo.from(dataSet); - //Then - assertThat(dataSetInfo.getName()).isEqualTo("dataset"); - assertThat(dataSetInfo.getFCDAInfos()).hasSize(1); - } + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("dataset"); + tDataSet.getFCDA().add(DTO.createFCDA()); - @Test - void getDataSets_whenCalledWithNoDataSetInLN_shouldReturnEmptyList(){ - //Given - LNAdapter lnAdapter = new LNAdapter(null, new TLN()); //When - Set dataSetInfos = DataSetInfo.getDataSets(lnAdapter); - //Then - assertThat(dataSetInfos).isEmpty(); - } + DataSetInfo dataSetInfo = new DataSetInfo(tDataSet); - @Test - void getDataSets_whenCalledWithLNContainsMatchingFCDA_shouldReturnDataSet(){ - //Given - TDataSet dataSet = new TDataSet(); - dataSet.setName("datasetName"); - dataSet.getFCDA().add(DTO.createFCDA()); - TLN tln = new TLN(); - tln.getDataSet().add(dataSet); - LNAdapter lnAdapter = new LNAdapter(null, tln); - //When - Set dataSetInfos = DataSetInfo.getDataSets(lnAdapter); //Then - assertThat(dataSetInfos).hasSize(1) - .extracting(DataSetInfo::getName).contains("datasetName"); + assertThat(dataSetInfo.getName()).isEqualTo("dataset"); + assertThat(dataSetInfo.getFcdaInfos()).hasSize(1); } - @Test void isValid_whenNameSizeMore32_shouldReturnFalse() { //Given - DataSetInfo dataSetInfo = new DataSetInfo(); - assertThat(dataSetInfo.getName()).isNull(); - dataSetInfo = new DataSetInfo("DATA_INFO_TEST_CHARACTERE_NAME_MORE_THAN_32_CHARACTERES"); + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("DATA_INFO_TEST_CHARACTERE_NAME_MORE_THAN_32_CHARACTERES"); + tDataSet.getFCDA().add(DTO.createFCDA()); + DataSetInfo dataSetInfo = new DataSetInfo(tDataSet); + //When boolean isValid = dataSetInfo.isValid(); + //Then assertThat(isValid).isFalse(); } @Test void isValid_whenFCDAInfoEmpty_shouldReturnFalse() { - DataSetInfo dataSetInfo = new DataSetInfo(); - assertThat(dataSetInfo.getName()).isNull(); - dataSetInfo = new DataSetInfo("DATA_INFO"); + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("DATA_INFO"); + DataSetInfo dataSetInfo = new DataSetInfo(tDataSet); + //When boolean isValid = dataSetInfo.isValid(); + //Then - assertThat(dataSetInfo.getFCDAInfos()).isEmpty(); + assertThat(dataSetInfo.getFcdaInfos()).isEmpty(); assertThat(isValid).isFalse(); } @Test void isValid_whenFCDAInfosValidshouldReturnTrue() { //Given - TDataSet dataSet = new TDataSet(); - dataSet.setName("dataset"); - dataSet.getFCDA().add(DTO.createFCDA()); - DataSetInfo dataSetInfo = DataSetInfo.from(dataSet); + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("dataset"); + tDataSet.getFCDA().add(DTO.createFCDA()); + DataSetInfo dataSetInfo = new DataSetInfo(tDataSet); //When boolean isValid = dataSetInfo.isValid(); //Then diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java index 2cc2612d9..2cc9ea284 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/FCDAInfoTest.java @@ -6,14 +6,8 @@ import org.junit.jupiter.api.Tag; 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.TFCDA; import org.lfenergy.compas.scl2007b4.model.TFCEnum; -import java.util.stream.Stream; - import static org.assertj.core.api.Assertions.assertThat; class FCDAInfoTest { @@ -22,102 +16,24 @@ class FCDAInfoTest { @Tag("issue-321") void constructor_whenCalled_shouldFillValues(){ // Given - TFCDA tfcda = new TFCDA(); - tfcda.setDoName("doName"); - tfcda.setDaName("daName.bda1.bda2.bda3"); - tfcda.setLdInst("LDInst"); - tfcda.setFc(TFCEnum.CF); - tfcda.getLnClass().add("LN_Class"); - tfcda.setLnInst("LNInst"); - tfcda.setPrefix("pre"); - tfcda.setIx(1L); + String dataSetName = "dataSet"; + String ldInst = "LDInst"; + String prefix = "pre"; + String lnClass = "LN_Class"; + String lnInst = "LNInst"; + DoTypeName doName = new DoTypeName("doName"); + DaTypeName daName = new DaTypeName("daName.bda1.bda2.bda3"); + long ix = 1L; + // When - FCDAInfo fcdaInfo = new FCDAInfo("dataSet",tfcda); + FCDAInfo fcdaInfo = new FCDAInfo(dataSetName, TFCEnum.CF, ldInst, prefix, lnClass, lnInst, doName, daName, ix); // Then assertThat(fcdaInfo.getDaName().getName()).isEqualTo("daName"); assertThat(fcdaInfo.getDoName().getName()).isEqualTo("doName"); - assertThat(fcdaInfo.getDaName()).hasToString(tfcda.getDaName()); + assertThat(fcdaInfo.getDaName()).hasToString("daName.bda1.bda2.bda3"); assertThat(fcdaInfo.getDaName().getStructNames()).hasSize(3); - // When - FCDAInfo fcdaInfo1 = new FCDAInfo(); - fcdaInfo1.setIx(fcdaInfo.getIx()); - fcdaInfo1.setLdInst(fcdaInfo.getLdInst()); - fcdaInfo1.setLnInst(fcdaInfo.getLnInst()); - fcdaInfo1.setLnClass(fcdaInfo.getLnClass()); - fcdaInfo1.setDaName(fcdaInfo.getDaName()); - fcdaInfo1.setDoName(fcdaInfo.getDoName()); - fcdaInfo1.setFc(fcdaInfo.getFc()); - fcdaInfo1.setPrefix(fcdaInfo.getPrefix()); - // Then - assertThat(fcdaInfo1.getDaName().getName()).isEqualTo("daName"); - assertThat(fcdaInfo1.getDoName().getName()).isEqualTo("doName"); - assertThat(fcdaInfo1.getDaName()).hasToString(tfcda.getDaName()); - TFCDA tfcda1 = fcdaInfo1.getFCDA(); - assertThat(fcdaInfo1.getFc()).isEqualTo(tfcda1.getFc()); - assertThat(fcdaInfo1.isValid()).isTrue(); - } - - @ParameterizedTest(name = "{0}") - @MethodSource("providerFCDAInfoObjects") - void checkFCDACompatibilitiesForBinding_whenCalled_shouldReturnFalse(String testCase, FCDAInfo fcdaInfo, FCDAInfo expectedFcdaInfo) { - assertThat(fcdaInfo.checkFCDACompatibilitiesForBinding(expectedFcdaInfo)).isFalse(); + assertThat(fcdaInfo.getFc()).isEqualTo(TFCEnum.CF); + assertThat(fcdaInfo.isValid()).isTrue(); } - @Test - void checkFCDACompatibilitiesForBinding_whenCalledWithSameContent_shouldReturnTrue() { - //Given - TFCDA tfcda = new TFCDA(); - tfcda.setLdInst(DTO.createExtRefBindingInfo_Remote().getLdInst()); - tfcda.getLnClass().add(DTO.createExtRefBindingInfo_Remote().getLnClass()); - tfcda.setLnInst(DTO.createExtRefBindingInfo_Remote().getLnInst()); - tfcda.setDoName(DTO.createExtRefSignalInfo().getPDO()); - tfcda.setDaName(DTO.createExtRefSignalInfo().getPDA()); - - FCDAInfo fcdaInfo = new FCDAInfo(tfcda); - FCDAInfo expectedFcdaInfo = new FCDAInfo(tfcda); - //When Then - assertThat(fcdaInfo.checkFCDACompatibilitiesForBinding(expectedFcdaInfo)).isTrue(); - } - - private static Stream providerFCDAInfoObjects(){ - - TFCDA tfcda = new TFCDA(); - tfcda.setLdInst(DTO.createExtRefBindingInfo_Remote().getLdInst()); - tfcda.getLnClass().add(DTO.createExtRefBindingInfo_Remote().getLnClass()); - tfcda.setLnInst(DTO.createExtRefBindingInfo_Remote().getLnInst()); - tfcda.setDoName(DTO.createExtRefSignalInfo().getPDO()); - tfcda.setDaName(DTO.createExtRefSignalInfo().getPDA()); - - FCDAInfo fcdaInfo = new FCDAInfo(tfcda); - - FCDAInfo expectedFcdaInfo = new FCDAInfo(tfcda); - - FCDAInfo expectedLDInstNotMatch = new FCDAInfo(tfcda); - expectedLDInstNotMatch.setLdInst("LDCMDDJ"); - - FCDAInfo expectedLNClassNotMatch = new FCDAInfo(tfcda); - expectedLNClassNotMatch.setLnClass("CSWI"); - - FCDAInfo expectedLNInstNotMatch = new FCDAInfo(tfcda); - expectedLNInstNotMatch.setLnInst("5"); - - FCDAInfo expectedPrefixNotMatch = new FCDAInfo(tfcda); - expectedPrefixNotMatch.setPrefix("Prefix"); - - FCDAInfo expectedDONotMatch = new FCDAInfo(tfcda); - expectedDONotMatch.setDoName(new DoTypeName("do.do1")); - - FCDAInfo expectedDANotMatch = new FCDAInfo(tfcda); - expectedDANotMatch.setDaName(new DaTypeName("da.bda.bda1")); - - return Stream.of( - Arguments.of("return false when LdInst not match ", fcdaInfo, expectedLDInstNotMatch), - Arguments.of("return false when lnClass not match ", fcdaInfo, expectedLNClassNotMatch), - Arguments.of("return false when lnInst not match ", fcdaInfo, expectedLNInstNotMatch), - Arguments.of("return false when Prefix not match ", fcdaInfo, expectedPrefixNotMatch), - Arguments.of("return false when DO not match ", fcdaInfo, expectedDONotMatch), - Arguments.of("return false when DO not match ", fcdaInfo, expectedDANotMatch) - - ); - } } \ No newline at end of file diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java index 128e29246..ac3d0d42f 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTOTest.java @@ -10,7 +10,7 @@ import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import java.util.Set; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java index 3d827e4b0..72f2c5dbc 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/LNodeDTOTest.java @@ -10,8 +10,8 @@ import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter; import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter; -import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import java.util.List; import java.util.Optional; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java index 25c92db6a..3e4b8d355 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java @@ -110,15 +110,22 @@ void hasSameContentAs() { void testCheckAndCompleteStructData() { //Given DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); - //When Then DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); DoTypeName doTypeName = new DoTypeName("Op","origin"); - //When Then + //When assertThatCode(() -> doTypeAdapter.checkAndCompleteStructData(doTypeName)).doesNotThrowAnyException(); assertThat(doTypeName.getCdc()).isEqualTo(TPredefinedCDCEnum.WYE); - DoTypeName doTypeName1 = new DoTypeName("Op","toto"); + } + + @Test + @Tag("issue-321") + void testCheckAndCompleteStructData2() { + //Given + DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID); + DOTypeAdapter doTypeAdapter = assertDoesNotThrow(() -> dttAdapter.getDOTypeAdapterById("DO2").get()); + DoTypeName doTypeName = new DoTypeName("Op","toto"); //When Then - assertThatThrownBy(() -> doTypeAdapter.checkAndCompleteStructData(doTypeName1)).isInstanceOf(ScdException.class); + assertThatThrownBy(() -> doTypeAdapter.checkAndCompleteStructData(doTypeName)).isInstanceOf(ScdException.class); } @Test diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java index c0da58c3f..319c2ee14 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/LNodeTypeAdapterTest.java @@ -211,26 +211,26 @@ void testCheck() { DoTypeName doTypeName1 = new DoTypeName(""); DaTypeName daTypeName1 = new DaTypeName(""); // When Then - assertThatThrownBy(() -> lNodeTypeAdapter.check(doTypeName1,daTypeName1)).isInstanceOf(ScdException.class); + assertThatThrownBy(() -> lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName1,daTypeName1)).isInstanceOf(ScdException.class); DoTypeName doTypeName2 = new DoTypeName("do"); DaTypeName daTypeName2 = new DaTypeName(""); // When Then - assertThatThrownBy(() -> lNodeTypeAdapter.check(doTypeName2,daTypeName2)).isInstanceOf(ScdException.class); + assertThatThrownBy(() -> lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName2,daTypeName2)).isInstanceOf(ScdException.class); DoTypeName doTypeName3 = new DoTypeName("do"); DaTypeName daTypeName3 = new DaTypeName("da"); // When Then - assertThatThrownBy(() -> lNodeTypeAdapter.check(doTypeName3,daTypeName3)).isInstanceOf(ScdException.class); + assertThatThrownBy(() -> lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName3,daTypeName3)).isInstanceOf(ScdException.class); DoTypeName doTypeName = new DoTypeName("Op.res"); DaTypeName daTypeName = new DaTypeName("d"); // When Then - assertThatCode(() -> lNodeTypeAdapter.check(doTypeName,daTypeName)).doesNotThrowAnyException(); + assertThatCode(() -> lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName,daTypeName)).doesNotThrowAnyException(); doTypeName.setName("StrVal"); doTypeName.getStructNames().clear(); daTypeName.setName("origin"); daTypeName.getStructNames().clear(); daTypeName.setStructNames(List.of("origin","ctlVal")); // When Then - assertThatCode(() -> lNodeTypeAdapter.check(doTypeName,daTypeName)).doesNotThrowAnyException(); + assertThatCode(() -> lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName,daTypeName)).doesNotThrowAnyException(); } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java index ada6a9645..2e419e3d4 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/ControlBlockAdapterTest.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.dto.SclReportItem; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclHelper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java index 001ed76c7..a0c3acb9c 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java @@ -11,6 +11,9 @@ import org.lfenergy.compas.sct.commons.dto.DoTypeName; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import static org.assertj.core.api.AssertionsForClassTypes.*; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java index 43df3a0d4..fff80f1c6 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DOIAdapterTest.java @@ -14,6 +14,8 @@ import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.CommonConstants; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java index 654ac3285..c42fa2df6 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DataSetAdapterTest.java @@ -9,6 +9,7 @@ import org.lfenergy.compas.scl2007b4.model.TDataSet; import org.lfenergy.compas.scl2007b4.model.TFCDA; import org.lfenergy.compas.scl2007b4.model.TFCEnum; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import java.util.List; import java.util.Optional; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java index 5b7bcea31..830c5cbe1 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java @@ -15,6 +15,8 @@ import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.ObjectReference; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.util.PrivateUtils; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java index f63950867..92a570c6b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapterTest.java @@ -14,6 +14,9 @@ import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation; import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; import org.lfenergy.compas.sct.commons.testhelpers.FCDARecord; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.CsvUtils; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java similarity index 99% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java index c553282be..8858ed3ac 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/LDeviceActivationTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceActivationTest.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl; +package org.lfenergy.compas.sct.commons.scl.ldevice; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Test; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java similarity index 98% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java index b2a775cc4..f97034241 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapterTest.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ldevice; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -17,6 +17,10 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum; @@ -29,8 +33,8 @@ import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter.MOD_DO_TYPE_NAME; -import static org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter.STVAL_DA_TYPE_NAME; +import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.MOD_DO_TYPE_NAME; +import static org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter.STVAL_DA_TYPE_NAME; import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; import static org.lfenergy.compas.sct.commons.util.CommonConstants.LDEVICE_LDEPF; import static org.lfenergy.compas.sct.commons.util.ControlBlockEnum.*; diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java similarity index 94% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java index 33ce8d924..10233f345 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LN0AdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LN0AdapterTest.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ln; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -15,6 +15,8 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import org.mockito.Mockito; @@ -212,103 +214,115 @@ void testGetDataSetWith() { // Given TDataSet tDataSet = new TDataSet(); ln0.getDataSet().add(tDataSet); - // When - List tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(null); - // Then - assertThat(tDataSets).isNotEmpty(); - - // Given ExtRefInfo extRefInfo = DTO.createExtRefInfo(); extRefInfo = Mockito.spy(extRefInfo); - TFCDA tfcda = new TFCDA(); tDataSet.getFCDA().add(tfcda); // When - tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(extRefInfo); + List tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(extRefInfo).toList(); // Then assertThat(tDataSets).isEmpty(); doReturn(true).when(extRefInfo).checkMatchingFCDA(any(TFCDA.class)); // When - tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(extRefInfo); + tDataSets = ln0Adapter.getDataSetMatchingExtRefInfo(extRefInfo).toList(); // Then assertThat(tDataSets).isNotEmpty(); } @Test - @Tag("issue-321") void testGetControlBlocks() { // Given - LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); - IEDAdapter iedAdapter = mock(IEDAdapter.class); - TLDevice tlDevice = mock(TLDevice.class); - when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); - when(lDeviceAdapter.getParentAdapter()).thenReturn(iedAdapter); - when(iedAdapter.getName()).thenReturn("IED_NAME"); LN0 ln0 = new LN0(); - when(tlDevice.getLN0()).thenReturn(ln0); - // When Then - LN0Adapter ln0Adapter = assertDoesNotThrow(() -> new LN0Adapter(lDeviceAdapter, ln0)); - // Given - TGSEControl tgseControl = new TGSEControl(); - tgseControl.setDatSet("GSE_REF"); - TSampledValueControl tSampledValueControl = new TSampledValueControl(); - tSampledValueControl.setDatSet("SMV_REF"); TReportControl tReportControl = new TReportControl(); - tReportControl.setDatSet("RPT_REF"); - ln0Adapter.getCurrentElem().getGSEControl().add(tgseControl); - ln0Adapter.getCurrentElem().getSampledValueControl().add(tSampledValueControl); - ln0Adapter.getCurrentElem().getReportControl().add(tReportControl); - - TDataSet tDataSetGSE = new TDataSet(); - tDataSetGSE.setName(DTO.CB_DATASET_REF); - - // When Then - List controlBlocks = ln0Adapter.getControlBlocks(List.of(tDataSetGSE), null); - assertThat(controlBlocks).isEmpty(); + tReportControl.setDatSet("dataSetName"); + ln0.getReportControl().add(tReportControl); + TSampledValueControl tSampledValueControl = new TSampledValueControl(); + tSampledValueControl.setDatSet("dataSetName"); + ln0.getSampledValueControl().add(tSampledValueControl); + TGSEControl tgseControl = new TGSEControl(); + tgseControl.setDatSet("dataSetName"); + ln0.getGSEControl().add(tgseControl); - tDataSetGSE.setName("GSE_REF"); - TDataSet tDataSetSMV = new TDataSet(); - tDataSetSMV.setName("SMV_REF"); - TDataSet tDataSetRPT = new TDataSet(); - tDataSetRPT.setName("RPT_REF"); + TInputs tInputs = new TInputs(); + TExtRef extRef = DTO.createExtRef(); + tInputs.getExtRef().add(extRef); + ln0.setInputs(tInputs); + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("dataSetName"); + TFCDA tfcda = new TFCDA(); + tfcda.setDaName("d"); + tfcda.setDoName("FACntRs1.res"); + tfcda.setPrefix("LN_PREFIX_R"); + tfcda.setLdInst("LD_INST_R"); + tfcda.setLnInst("1"); + tfcda.getLnClass().add("LN_CLASS_R"); + tDataSet.getFCDA().add(tfcda); + ln0.getDataSet().add(tDataSet); + ExtRefInfo extRefInfo = DTO.createExtRefInfo(); + ExtRefBindingInfo extRefBindingInfo = DTO.createExtRefBindingInfo_Remote(); + extRefBindingInfo.setServiceType(null); + extRefInfo.setBindingInfo(extRefBindingInfo); - List tDataSets = List.of(tDataSetGSE, tDataSetSMV, tDataSetRPT); + LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); - // When Then - controlBlocks = ln0Adapter.getControlBlocks(tDataSets, TServiceType.REPORT); - assertThat(controlBlocks).hasSize(1); - // When Then - controlBlocks = ln0Adapter.getControlBlocks(tDataSets, TServiceType.SMV); - assertThat(controlBlocks).hasSize(1); - // When Then - controlBlocks = ln0Adapter.getControlBlocks(tDataSets, TServiceType.GOOSE); - assertThat(controlBlocks).hasSize(1); - // When Then - controlBlocks = ln0Adapter.getControlBlocks(tDataSets, null); + // When + List controlBlocks = ln0Adapter.getControlBlocksForMatchingFCDA(extRefInfo).toList(); + // Then assertThat(controlBlocks).hasSize(3); } - @Test - void getControlBlocksForMatchingFCDA_should_return_expected_Items() { + @ParameterizedTest + @MethodSource("provideServiceType") + void getControlBlocksForMatchingFCDA_should_return_expected_Items(LN0 ln0, TServiceType serviceType) { // Given - LN0 ln0 = new LN0(); - LN0Adapter ln0Adapter = Mockito.spy(new LN0Adapter(null, ln0)); - - when(ln0Adapter.getCurrentElem()).thenReturn(ln0); TInputs tInputs = new TInputs(); TExtRef extRef = DTO.createExtRef(); tInputs.getExtRef().add(extRef); ln0.setInputs(tInputs); - ExtRefInfo extRefBindingInfo = DTO.createExtRefInfo(); - doReturn(List.of(new TDataSet())).when(ln0Adapter).getDataSetMatchingExtRefInfo(any(ExtRefInfo.class)); - doReturn(List.of(new ReportControlBlock("rpt", "rptID", "rptDatSet"))) - .when(ln0Adapter).getControlBlocks(any(List.class), any(TServiceType.class)); + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("dataSetName"); + TFCDA tfcda = new TFCDA(); + tfcda.setDaName("d"); + tfcda.setDoName("FACntRs1.res"); + tfcda.setPrefix("LN_PREFIX_R"); + tfcda.setLdInst("LD_INST_R"); + tfcda.setLnInst("1"); + tfcda.getLnClass().add("LN_CLASS_R"); + tDataSet.getFCDA().add(tfcda); + ln0.getDataSet().add(tDataSet); + ExtRefInfo extRefInfo = DTO.createExtRefInfo(); + ExtRefBindingInfo extRefBindingInfo = DTO.createExtRefBindingInfo_Remote(); + extRefBindingInfo.setServiceType(serviceType); + extRefInfo.setBindingInfo(extRefBindingInfo); + + LN0Adapter ln0Adapter = new LN0Adapter(null, ln0); + // When - List controlBlocks = ln0Adapter.getControlBlocksForMatchingFCDA(extRefBindingInfo); + List controlBlocks = ln0Adapter.getControlBlocksForMatchingFCDA(extRefInfo).toList(); // Then - assertThat(controlBlocks).isNotEmpty(); - assertThat(controlBlocks.get(0).getServiceType()).isEqualTo(TServiceType.REPORT); + assertThat(controlBlocks).hasSize(1); + assertThat(controlBlocks.get(0).getServiceType()).isEqualTo(serviceType); + } + + private static Stream provideServiceType() { + LN0 ln0Report = new LN0(); + TReportControl tReportControl = new TReportControl(); + tReportControl.setDatSet("dataSetName"); + ln0Report.getReportControl().add(tReportControl); + LN0 ln0Smv = new LN0(); + TSampledValueControl tSampledValueControl = new TSampledValueControl(); + tSampledValueControl.setDatSet("dataSetName"); + ln0Smv.getSampledValueControl().add(tSampledValueControl); + LN0 ln0Goose = new LN0(); + TGSEControl tgseControl = new TGSEControl(); + tgseControl.setDatSet("dataSetName"); + ln0Goose.getGSEControl().add(tgseControl); + return Stream.of( + Arguments.of(ln0Report, TServiceType.REPORT), + Arguments.of(ln0Smv, TServiceType.SMV), + Arguments.of(ln0Goose, TServiceType.GOOSE) + ); } @Test @@ -386,7 +400,6 @@ void getDOIAdapterByName_should_return_expected_DOIAdapter() { when(iedAdapter.getName()).thenReturn("IED_NAME"); LDeviceAdapter lDeviceAdapter = mock(LDeviceAdapter.class); TLDevice tlDevice = new TLDevice(); - when(lDeviceAdapter.amChildElementRef()).thenReturn(true); when(lDeviceAdapter.getCurrentElem()).thenReturn(tlDevice); when(lDeviceAdapter.getParentAdapter()).thenReturn(iedAdapter); LN0 ln0 = new LN0(); diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapterTest.java similarity index 97% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapterTest.java index e38d29529..a4371332b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/LNAdapterTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LNAdapterTest.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ied; +package org.lfenergy.compas.sct.commons.scl.ln; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -16,6 +16,8 @@ import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; @@ -832,13 +834,22 @@ void getControlBlocks_should_find_ControlBlock_by_name() { .withLDeviceAdapter(lDeviceAdapter) .withLnClass(TLLN0Enum.LLN_0.value()) .build(); - List tDataSets = lnAdapter.getCurrentElem().getDataSet(); + lnAdapter.getCurrentElem().getDataSet().forEach(tDataSet -> tDataSet.getFCDA().forEach(tfcda -> { + tfcda.getLnClass().add("lnClass"); + tfcda.setDoName("FACntRs1.res"); + tfcda.setDaName("d"); + })); + + ExtRefInfo extRefInfo = DTO.createExtRefInfo(); + ExtRefBindingInfo extRefBindingInfo = new ExtRefBindingInfo(); + extRefBindingInfo.setServiceType(TServiceType.GOOSE); + extRefBindingInfo.setLnClass("lnClass"); + extRefInfo.setBindingInfo(extRefBindingInfo); //When - List tControls = lnAdapter.getControlBlocks(tDataSets, TServiceType.GOOSE); + List controlBlocks = lnAdapter.getControlBlocksForMatchingFCDA(extRefInfo).toList(); //Then - assertThat(tControls).isNotEmpty() - .hasSize(1); + assertThat(controlBlocks).hasSize(1); } @Test 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 239cce3e8..fdea655ab 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 @@ -8,6 +8,10 @@ import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.*; +import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; +import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter; +import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; import org.lfenergy.compas.sct.commons.util.ControlBlockEnum; import org.lfenergy.compas.sct.commons.util.Utils; import org.opentest4j.AssertionFailedError;