From 39aae82f4793bad1156614ab768a06751b0859db Mon Sep 17 00:00:00 2001 From: gleizesDor <115622893+gleizesDor@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:09:23 +0100 Subject: [PATCH] retours MR Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com> --- pom.xml | 3 +- sct-app/pom.xml | 9 -- sct-commons/pom.xml | 9 -- .../compas/sct/commons/DataSetService.java | 30 +++++++ .../sct/commons/ExtRefReaderService.java | 20 +++++ .../compas/sct/commons/IedService.java | 20 +++++ .../compas/sct/commons/LdeviceService.java | 55 ++++++++++++ .../compas/sct/commons/LnService.java | 13 +++ .../compas/sct/commons/api/DataSetReader.java | 15 ++++ .../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 ++++ .../compas/sct/commons/dto/DataSetInfo.java | 68 ++------------- .../compas/sct/commons/dto/ExtRefInfo.java | 2 +- .../compas/sct/commons/dto/FCDAInfo.java | 34 -------- .../sct/commons/dto/GooseControlBlock.java | 2 +- .../compas/sct/commons/dto/LNodeDTO.java | 47 ++++++---- .../sct/commons/dto/ReportControlBlock.java | 2 +- .../sct/commons/dto/SMVControlBlock.java | 2 +- .../compas/sct/commons/scl/Private.java | 36 -------- .../lfenergy/compas/sct/commons/scl/Scd.java | 28 ------ .../compas/sct/commons/scl/doi/Doi.java | 22 ----- .../compas/sct/commons/scl/extref/ExtRef.java | 16 ---- .../sct/commons/scl/ied/DataSetAdapter.java | 4 +- .../compas/sct/commons/scl/ied/Ied.java | 61 ------------- .../sct/commons/scl/ldevice/Ldevice.java | 56 ------------ .../commons/scl/lnode/AbstractLNAdapter.java | 19 +--- .../compas/sct/commons/scl/lnode/Anyln.java | 76 ---------------- .../compas/sct/commons/scl/lnode/DataSet.java | 55 ------------ .../compas/sct/commons/scl/lnode/Fcda.java | 61 ------------- .../compas/sct/commons/scl/lnode/LnKey.java | 38 ++++++++ .../sct/commons/DataSetServiceTest.java | 45 ++++++++++ ...eviceTest.java => LdeviceServiceTest.java} | 17 ++-- .../sct/commons/dto/DataSetInfoTest.java | 87 +++++-------------- .../compas/sct/commons/dto/FCDAInfoTest.java | 3 +- 36 files changed, 386 insertions(+), 642 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/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/api/DataSetReader.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 delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Private.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Scd.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/doi/Doi.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/extref/ExtRef.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ied.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/Ldevice.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Anyln.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/DataSet.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Fcda.java create mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/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/ldevice/LdeviceTest.java => LdeviceServiceTest.java} (60%) diff --git a/pom.xml b/pom.xml index ab5a58a6b..17e482332 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,8 @@ maven-surefire-plugin 2.22.2 - + + @{argLine} --enable-preview diff --git a/sct-app/pom.xml b/sct-app/pom.xml index 28667e119..23cd3d5a7 100644 --- a/sct-app/pom.xml +++ b/sct-app/pom.xml @@ -67,19 +67,10 @@ org.apache.maven.plugins maven-compiler-plugin - - ${java.version} - ${java.version} - --enable-preview - org.apache.maven.plugins maven-surefire-plugin - - - @{argLine} --enable-preview - org.jacoco diff --git a/sct-commons/pom.xml b/sct-commons/pom.xml index 40e0c04aa..ebf2db877 100644 --- a/sct-commons/pom.xml +++ b/sct-commons/pom.xml @@ -98,19 +98,10 @@ org.apache.maven.plugins maven-compiler-plugin - - ${java.version} - ${java.version} - --enable-preview - org.apache.maven.plugins maven-surefire-plugin - - - @{argLine} --enable-preview - org.jacoco 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..f4c82af99 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DataSetService.java @@ -0,0 +1,30 @@ +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/ExtRefReaderService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java new file mode 100644 index 000000000..3c0c62755 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java @@ -0,0 +1,20 @@ +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/IedService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/IedService.java new file mode 100644 index 000000000..e99acb00b --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/IedService.java @@ -0,0 +1,20 @@ +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..b88c4c2fc --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LdeviceService.java @@ -0,0 +1,55 @@ +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..2f735cae5 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java @@ -0,0 +1,13 @@ +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/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/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/dto/DataSetInfo.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DataSetInfo.java index 3618e8154..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,16 +5,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import org.lfenergy.compas.scl2007b4.model.TAnyLN; -import org.lfenergy.compas.sct.commons.scl.lnode.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.lnode.DataSet; -import org.lfenergy.compas.sct.commons.scl.lnode.Fcda; +import org.lfenergy.compas.scl2007b4.model.TDataSet; 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. @@ -24,7 +18,7 @@ *

*
    *
  • {@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 @@ -32,63 +26,17 @@ @Getter @NoArgsConstructor public class DataSetInfo extends LNodeMetaDataEmbedder { - //TODO cet objet est un DTO; il est utilisé pour transporter l'information; il doit être créé par celui qui transporte l'info -> RCONF + //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) { - super(); - this.name = name; - } - - public DataSetInfo(String name, List fcdas) { + public DataSetInfo(TDataSet tDataSet) { super(); - this.name = name; - this.fcdaInfos = fcdas.stream() - .map(fcda -> fcda.toDto(name)) - .toList(); - } - - /** - * Get Set of DataSet from LnAdapter - * @param lnAdapter object LnAdapter - * @return Set of DataSetInfo - */ - public static Set getDataSets(AbstractLNAdapter lnAdapter) { - return lnAdapter.getCurrentElem() - .getDataSet() + this.name = tDataSet.getName(); + this.fcdaInfos = tDataSet.getFCDA() .stream() - .map(DataSet::new) - .map(DataSet::toDto) - .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; + .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(); } /** 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 8917087cf..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 @@ -38,7 +38,7 @@ @NoArgsConstructor @AllArgsConstructor public class ExtRefInfo extends LNodeMetaDataEmbedder{ - //TODO cet objet est un DTO; il est utilisé pour transporter l'information; il doit être créé par celui qui transporte l'info -> RCONF + //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; 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 5a75da198..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 @@ -32,7 +32,6 @@ @Getter @AllArgsConstructor @NoArgsConstructor -@Builder public class FCDAInfo { private String dataSet; @@ -46,39 +45,6 @@ public class FCDAInfo { private DaTypeName daName; //daName.[...bdaNames] private Long ix; - /** - * 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 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 b94a9d932..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,7 +36,7 @@ @Getter @Setter public class GooseControlBlock extends ControlBlock { - //TODO cet objet est un DTO; il est utilisé pour transporter l'information; il doit être créé par celui qui transporte l'info -> RCONF + //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/LNodeDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java index b6863d099..5a8859d7a 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,9 +7,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.lfenergy.compas.scl2007b4.model.SCL; -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.scl.dtt.DataTypeTemplate; import org.lfenergy.compas.sct.commons.scl.dtt.LnodeType; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; @@ -17,9 +17,8 @@ import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter; import org.lfenergy.compas.sct.commons.scl.lnode.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; -import org.lfenergy.compas.sct.commons.scl.lnode.Anyln; -import org.lfenergy.compas.sct.commons.scl.lnode.DataSet; import org.lfenergy.compas.sct.commons.scl.lnode.LNAdapter; +import org.lfenergy.compas.sct.commons.scl.lnode.LnKey; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.HashSet; @@ -51,7 +50,7 @@ @Getter @NoArgsConstructor public class LNodeDTO { - //TODO cet objet est un DTO; il est utilisé pour transporter l'information; il doit être créé par celui qui transporte l'info -> RCONF + //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; @@ -116,7 +115,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()) { @@ -146,18 +146,27 @@ public static LNodeDTO from(AbstractLNAdapter nodeAdapter, return lNodeDTO; } - public static LNodeDTO from(Anyln anyln, LogicalNodeOptions options, String iedName, String ldInst, SCL scl) { + public static LNodeDTO from(TAnyLN tAnyLN, LogicalNodeOptions options, String iedName, String ldInst, SCL scl) { log.info(Utils.entering()); - LNodeDTO lNodeDTO = new LNodeDTO(anyln.getInst(), anyln.getLnClass(), anyln.getPrefix().orElse(""), anyln.getLnType()); + 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 = anyln.getExtRefs() - .map(extRef -> ExtRefInfo.from(extRef.getTExtRef(), iedName, ldInst, anyln.getLnClass(), anyln.getInst(), anyln.getPrefix().orElse(""))) + 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 = anyln.getDataSets() - .map(DataSet::toDto) + List dataSetInfos = new DataSetService().getDataSets(tAnyLN) + .map(DataSetInfo::new) .distinct() .toList(); lNodeDTO.addAllDatSets(dataSetInfos); @@ -165,13 +174,13 @@ public static LNodeDTO from(Anyln anyln, LogicalNodeOptions options, String iedN if (options.isWithDataAttributeRef()) { DataAttributeRef filter = DataAttributeRef.builder() - .lnInst(anyln.getInst()) - .lnClass(anyln.getLnClass()) - .prefix(anyln.getPrefix().orElse("")) - .lnType(anyln.getLnType()) + .lnInst(inst) + .lnClass(lnClass) + .prefix(prefix) + .lnType(lnType) .build(); - LnodeType lnodeType = new DataTypeTemplate(scl.getDataTypeTemplates()).getLnodeType(lnodeType1 -> lnodeType1.getTlNodeType().getId().equals(anyln.getLnType())) - .orElseThrow(() -> new IllegalArgumentException("Corrupted SCD file: reference to unknown lnType(" + anyln.getLnType() + ")")); + LnodeType lnodeType = new DataTypeTemplate(scl.getDataTypeTemplates()).getLnodeType(lnodeType1 -> lnodeType1.getTlNodeType().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.getTlNodeType()) .getDataAttributeRefs(filter); lNodeDTO.addAllDataAttributeRef(dataAttributeRefList); 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 e5736cce4..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 cet objet est un DTO; il est utilisé pour transporter l'information; il doit être créé par celui qui transporte l'info -> RCONF + //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 99f8bf694..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 @@ -40,7 +40,7 @@ @Getter @Setter public class SMVControlBlock extends ControlBlock { - //TODO cet objet est un DTO; il est utilisé pour transporter l'information; il doit être créé par celui qui transporte l'info -> RCONF + //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/Private.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Private.java deleted file mode 100644 index 2abd1882e..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Private.java +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl; - -import jakarta.xml.bind.JAXBElement; -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.TPrivate; - -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Getter -public class Private { - - private final String type; - private final Stream content; - - public Private(TPrivate tPrivate) { - this.type = tPrivate.getType(); - this.content = tPrivate.getContent() - .stream() - .filter(JAXBElement.class::isInstance) - .map(JAXBElement.class::cast) - .filter(Predicate.not(JAXBElement::isNil)) - .map(JAXBElement::getValue); - } - - public TPrivate toTPrivate() { - TPrivate tPrivate = new TPrivate(); - tPrivate.setType(type); - tPrivate.getContent().addAll(content.toList()); - return tPrivate; - } -} - diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Scd.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Scd.java deleted file mode 100644 index f6c085955..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/Scd.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.lfenergy.compas.sct.commons.scl; - -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.SCL; -import org.lfenergy.compas.sct.commons.scl.ied.Ied; - -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Getter -public class Scd { - - //est-qu'il faut faire des vérification du nombre d'IED sur un SCD ? - private final Stream ieds; - - public Scd(SCL scl) { - this.ieds = scl.getIED().stream().map(Ied::new); - } - - public Stream getFilteredIeds(Predicate iedPredicate) { - return ieds.filter(iedPredicate); - } - - public Optional getIed(Predicate iedPredicate) { - return getFilteredIeds(iedPredicate).findFirst(); - } -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/doi/Doi.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/doi/Doi.java deleted file mode 100644 index 31a14092b..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/doi/Doi.java +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.doi; - -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.TDOI; -import org.lfenergy.compas.sct.commons.scl.Private; - -import java.util.stream.Stream; - -@Getter -public class Doi { - private final String name; - private final Stream privates; - - public Doi(TDOI tdoi) { - this.name = tdoi.getName(); - this.privates = tdoi.getPrivate().stream().map(Private::new); - } -} - diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/extref/ExtRef.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/extref/ExtRef.java deleted file mode 100644 index a467b7900..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/extref/ExtRef.java +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.extref; - -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.TExtRef; - -@Getter -public class ExtRef { - private final TExtRef tExtRef; - - public ExtRef(TExtRef extRef) { - this.tExtRef = extRef; //TODO to change - } -} 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 8651d4eb8..29082e793 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 @@ -12,8 +12,6 @@ import org.lfenergy.compas.scl2007b4.model.TFCEnum; import org.lfenergy.compas.sct.commons.scl.SclElementAdapter; import org.lfenergy.compas.sct.commons.scl.lnode.AbstractLNAdapter; -import org.lfenergy.compas.sct.commons.scl.lnode.DataSet; -import org.lfenergy.compas.sct.commons.scl.lnode.Fcda; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.Comparator; @@ -52,7 +50,7 @@ public class DataSetAdapter extends SclElementAdapter FCDA_COMPARATOR = Comparator + private static final Comparator FCDA_COMPARATOR = Comparator .comparing(TFCDA::getLdInst, Utils::blanksFirstComparator) .thenComparing(TFCDA::getPrefix, Utils::blanksFirstComparator) .thenComparing(tfcda -> tfcda.isSetLnClass() ? tfcda.getLnClass().get(0) : null, Utils::blanksFirstComparator) diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ied.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ied.java deleted file mode 100644 index 2b74fd4a5..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/Ied.java +++ /dev/null @@ -1,61 +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.*; -import org.lfenergy.compas.sct.commons.scl.ldevice.Ldevice; - -import java.util.Objects; -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Getter -public class Ied { - - private final String name; - private final String type; - private final String configVersion; - private final TRightEnum engRight; - private final TServices services; - private final String manufacturer; - private final short originalSclRelease; - private final String originalSclRevision; - private final String originalSclVersion; - private final String desc; - private final String owner; - private final Stream ldevices; - - public Ied(TIED tied) { - this.name = tied.getName(); - this.type = tied.getType(); - this.configVersion = tied.getConfigVersion(); - this.engRight = tied.getEngRight(); - this.services = tied.getServices(); - this.manufacturer = tied.getManufacturer(); - this.originalSclRelease = tied.getOriginalSclRelease(); - this.originalSclRevision = tied.getOriginalSclRevision(); - this.originalSclVersion = tied.getOriginalSclVersion(); - this.desc = tied.getDesc(); - this.owner = tied.getOwner(); - this.ldevices = tied.isSetAccessPoint() ? tied.getAccessPoint() - .stream() - .map(TAccessPoint::getServer) - .filter(Objects::nonNull) - .filter(TServer::isSetLDevice) - .flatMap(tServer -> tServer.getLDevice().stream()) - .map(Ldevice::new): - Stream.empty(); - } - - public Stream getFilteredLdevices(Predicate ldevicePredicate) { - return ldevices.filter(ldevicePredicate); - } - - public Optional getLdevice(Predicate ldevicePredicate) { - return getFilteredLdevices(ldevicePredicate).findFirst(); - } -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/Ldevice.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/Ldevice.java deleted file mode 100644 index 6394fff03..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/Ldevice.java +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.ldevice; - -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.scl.lnode.Anyln; -import org.lfenergy.compas.sct.commons.util.LdeviceStatus; - -import java.util.Collection; -import java.util.Optional; -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; - -/** - * 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; - private final Stream lnodes; - - 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); - lnodes = Stream.concat(Stream.of(new Anyln(tlDevice.getLN0())), tlDevice.getLN().stream().map(Anyln::new)); - } -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/AbstractLNAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/AbstractLNAdapter.java index 3158f4f73..3a3edd841 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/AbstractLNAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/AbstractLNAdapter.java @@ -8,6 +8,7 @@ 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; @@ -823,21 +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(DataSet::new) - .map(DataSet::toDto) - .findFirst(); - } - /** * Gets DAI values for specified DA in summaraized Data Type Template * @@ -942,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/lnode/Anyln.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Anyln.java deleted file mode 100644 index c3a28767e..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Anyln.java +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.lnode; - -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.*; -import org.lfenergy.compas.sct.commons.scl.doi.Doi; -import org.lfenergy.compas.sct.commons.scl.extref.ExtRef; - -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Getter -public class Anyln { - - private final String inst; - private final String lnType; - private final String lnClass; - /** empty pour les LN0 */ - private final Optional prefix; - private final Stream dois; - private final Stream extRefs; - private final Stream dataSets; - private final Stream gseControls; - private final Stream sampledValueControls; - private final Stream reportControls; - - public Anyln(LN0 ln0) { - this.inst = ln0.getInst(); - this.lnType = ln0.getLnType(); - this.lnClass = ln0.getLnClass().get(0); - this.prefix = Optional.empty(); - this.dois = ln0.getDOI().stream().map(Doi::new); - this.extRefs = ln0.isSetInputs() ? ln0.getInputs().getExtRef().stream().map(ExtRef::new) : Stream.empty(); - this.dataSets = ln0.isSetDataSet() ? ln0.getDataSet().stream().map(DataSet::new) : Stream.empty(); - this.gseControls = ln0.getGSEControl().stream(); - this.sampledValueControls = ln0.getSampledValueControl().stream(); - this.reportControls = ln0.getReportControl().stream(); - } - - public Anyln(TLN tln) { - this.inst = tln.getInst(); - this.lnType = tln.getLnType(); - this.lnClass = tln.getLnClass().get(0); - this.prefix = Optional.of(tln.getPrefix()); - this.dois = tln.getDOI().stream().map(Doi::new); - this.extRefs = tln.isSetInputs() ? tln.getInputs().getExtRef().stream().map(ExtRef::new) : Stream.empty(); - this.dataSets = tln.isSetDataSet() ? tln.getDataSet().stream().map(DataSet::new) : Stream.empty(); - this.gseControls = Stream.empty(); - this.sampledValueControls = Stream.empty(); - this.reportControls = tln.getReportControl().stream(); - } - - public Stream getFilteredDataSets(Predicate dataSetPredicate) { - return dataSets.filter(dataSetPredicate); - } - - public Optional getDataSet(Predicate dataSetPredicate) { - return getFilteredDataSets(dataSetPredicate).findFirst(); - } - - public Stream getGseControlBlocks(Predicate tgseControlPredicate) { - return gseControls.filter(tgseControlPredicate); - } - - public Stream getSampledValueControlBlocks(Predicate tSampledValueControlPredicate) { - return sampledValueControls.filter(tSampledValueControlPredicate); - } - - public Stream getReportControlBlocks(Predicate tReportControlPredicate) { - return reportControls.filter(tReportControlPredicate); - } -} - diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/DataSet.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/DataSet.java deleted file mode 100644 index aa46c3956..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/DataSet.java +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.lnode; - -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.TDataSet; -import org.lfenergy.compas.scl2007b4.model.TText; -import org.lfenergy.compas.sct.commons.dto.DataSetInfo; -import org.lfenergy.compas.sct.commons.scl.Private; - -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Getter -public class DataSet { - - private final String name; - private final Stream fcdas; - private final String desc; - private final TText text; - private final Stream privates; - - public DataSet(TDataSet tDataSet) { - this.name = tDataSet.getName(); - this.desc = tDataSet.getDesc(); - this.text = tDataSet.getText(); - this.fcdas = tDataSet.isSetFCDA() ? tDataSet.getFCDA().stream().map(Fcda::new) : Stream.empty(); - this.privates = tDataSet.isSetPrivate() ? tDataSet.getPrivate().stream().map(Private::new) : Stream.empty(); - } - - public Stream getFilteredFcdas(Predicate fcdaPredicate) { - return fcdas.filter(fcdaPredicate); - } - - public Optional getFcda(Predicate fcdaPredicate) { - return getFilteredFcdas(fcdaPredicate).findFirst(); - } - - public DataSetInfo toDto() { - return new DataSetInfo(name, fcdas.toList()); - } - - public TDataSet toTDataSet() { - TDataSet tDataSet = new TDataSet(); - tDataSet.setName(name); - tDataSet.setDesc(desc); - tDataSet.setText(text); - tDataSet.getFCDA().addAll(fcdas.map(Fcda::toTFCDA).toList()); - tDataSet.getPrivate().addAll(privates.map(Private::toTPrivate).toList()); - return tDataSet; - } -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Fcda.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Fcda.java deleted file mode 100644 index 333cded42..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/Fcda.java +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.lnode; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import org.lfenergy.compas.scl2007b4.model.TFCDA; -import org.lfenergy.compas.scl2007b4.model.TFCEnum; -import org.lfenergy.compas.sct.commons.dto.DaTypeName; -import org.lfenergy.compas.sct.commons.dto.DoTypeName; -import org.lfenergy.compas.sct.commons.dto.FCDAInfo; - -import java.util.Objects; - -import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.apache.commons.lang3.StringUtils.trimToNull; - -@EqualsAndHashCode -@Getter -public class Fcda { - - private final TFCEnum fc; - private final String ldInst; - private final String prefix; - private final String lnClass; - private final String lnInst; - private final String doName; //doName.[...sdoNames] - private final String daName; //daName.[...bdaNames] - @EqualsAndHashCode.Exclude //Faut-il vraiment l'exclure ? - private final long ix; - - public Fcda(TFCDA tfcda) { - this.fc = Objects.requireNonNull(tfcda.getFc()); // fc is required by XSD - this.ldInst = trimToNull(tfcda.getLdInst()); - this.prefix = trimToNull(tfcda.getPrefix()); - this.lnClass = tfcda.getLnClass().isEmpty() ? null : trimToNull(tfcda.getLnClass().get(0)); - this.lnInst = trimToNull(tfcda.getLnInst()); - this.doName = trimToNull(tfcda.getDoName()); - this.daName = trimToNull(tfcda.getDaName()); - this.ix = tfcda.getIx(); - } - - public FCDAInfo toDto(String dataSetName) { - return new FCDAInfo(dataSetName, fc, ldInst, prefix, lnClass, lnInst, new DoTypeName(doName), new DaTypeName(daName), ix); - } - - public TFCDA toTFCDA() { - TFCDA tfcda = new TFCDA(); - tfcda.setLdInst(ldInst); - if (isNotBlank(lnClass)) tfcda.getLnClass().add(lnClass); - tfcda.setLnInst(lnInst); - tfcda.setPrefix(prefix); - tfcda.setDoName(doName); - tfcda.setDaName(daName); - tfcda.setFc(fc); - tfcda.setIx(ix); - return tfcda; - } - -} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/LnKey.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/LnKey.java new file mode 100644 index 000000000..82c356eb4 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/lnode/LnKey.java @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2021 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.sct.commons.scl.lnode; + +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/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..a55cb3e0b --- /dev/null +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DataSetServiceTest.java @@ -0,0 +1,45 @@ +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/scl/ldevice/LdeviceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java similarity index 60% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LdeviceTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java index 082dd82f0..7972ef97d 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ldevice/LdeviceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LdeviceServiceTest.java @@ -1,11 +1,8 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sct.commons.scl.ldevice; +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 +10,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/dto/DataSetInfoTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/dto/DataSetInfoTest.java index 1c2516c3a..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,108 +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.lnode.Fcda; -import org.lfenergy.compas.sct.commons.scl.lnode.LNAdapter; - -import java.util.List; -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 - String datasetName = "dataset"; - List fcdas = List.of(new Fcda(DTO.createFCDA())); + TDataSet tDataSet = new TDataSet(); + tDataSet.setName("dataset"); + tDataSet.getFCDA().add(DTO.createFCDA()); //When - DataSetInfo dataSetInfo = new DataSetInfo(datasetName, fcdas); + DataSetInfo dataSetInfo = new DataSetInfo(tDataSet); //Then assertThat(dataSetInfo.getName()).isEqualTo("dataset"); - assertThat(dataSetInfo.getFCDAInfos()).hasSize(1); + assertThat(dataSetInfo.getFcdaInfos()).hasSize(1); } - @Test - void getDataSets_whenCalledWithNoDataSetInLN_shouldReturnEmptyList(){ - //Given - LNAdapter lnAdapter = new LNAdapter(null, new TLN()); - //When - Set dataSetInfos = DataSetInfo.getDataSets(lnAdapter); - //Then - assertThat(dataSetInfos).isEmpty(); - } - - @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"); - } - - @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 - String datasetName = "dataset"; - List fcdas = List.of(new Fcda(DTO.createFCDA())); - DataSetInfo dataSetInfo = new DataSetInfo(datasetName, fcdas); + 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 1de6053c1..3edf91131 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 @@ -33,8 +33,7 @@ void constructor_whenCalled_shouldFillValues(){ assertThat(fcdaInfo.getDoName().getName()).isEqualTo("doName"); assertThat(fcdaInfo.getDaName()).hasToString("daName.bda1.bda2.bda3"); assertThat(fcdaInfo.getDaName().getStructNames()).hasSize(3); - TFCDA fcda = fcdaInfo.getFCDA(); - assertThat(fcdaInfo.getFc()).isEqualTo(fcda.getFc()); + assertThat(fcdaInfo.getFc()).isEqualTo(TFCEnum.CF); assertThat(fcdaInfo.isValid()).isTrue(); }