From 5edb9958a9621d0581b660eaf4a574060097c486 Mon Sep 17 00:00:00 2001 From: massifben <105049157+massifben@users.noreply.github.com> Date: Mon, 18 May 2026 16:31:19 +0200 Subject: [PATCH] feat(#604): RSR-1589 - use extrefs of all ln Signed-off-by: massifben <105049157+massifben@users.noreply.github.com> --- .../SclAutomationServiceIntegrationTest.java | 7 +- .../commons/ControlBlockEditorService.java | 8 +- .../sct/commons/ExtRefReaderService.java | 21 ----- .../compas/sct/commons/SclService.java | 5 +- .../compas/sct/commons/api/ExtRefReader.java | 15 ---- .../compas/sct/commons/dto/LNodeDTO.java | 85 +++++++++++-------- .../compas/sct/commons/scl/ExtRefService.java | 30 +++---- .../commons/scl/ied/AccessPointAdapter.java | 74 ++++++++-------- .../sct/commons/scl/ied/InputsAdapter.java | 14 +-- .../commons/scl/ldevice/LDeviceAdapter.java | 41 +++++++-- .../sct/commons/scl/ln/AbstractLNAdapter.java | 43 ++++++---- .../compas/sct/commons/scl/ln/LN0Adapter.java | 10 --- .../ControlBlockEditorServiceTest.java | 3 +- .../compas/sct/commons/SclServiceTest.java | 5 +- .../sct/commons/scl/ExtRefServiceTest.java | 18 ++-- .../commons/scl/ied/InputsAdapterTest.java | 41 --------- 16 files changed, 178 insertions(+), 242 deletions(-) delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java delete mode 100644 sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefReader.java 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 8935f0082..25692ea3e 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 @@ -16,6 +16,7 @@ import org.lfenergy.compas.sct.commons.dto.HeaderDTO; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.scl.ControlService; +import org.lfenergy.compas.sct.commons.scl.ExtRefService; 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; @@ -33,12 +34,12 @@ class SclAutomationServiceIntegrationTest { private SclAutomationService sclAutomationService; private static final IedService iedService = new IedService(); private static final LnService lnService = new LnService(); - private static final ExtRefReaderService extRefReaderService = new ExtRefReaderService(); + private static final ExtRefService extRefService = new ExtRefService(); private static final DataTypeTemplateReader dataTypeTemplatesService = new DataTypeTemplatesService() ; private static final LdeviceService ldeviceService = new LdeviceService(lnService); - private static final SclEditor sclEditor = new SclService(iedService, ldeviceService, lnService, extRefReaderService, dataTypeTemplatesService) ; + private static final SclEditor sclEditor = new SclService(iedService, ldeviceService, lnService, extRefService, dataTypeTemplatesService); private static final SubstationEditor substationEditor = new SubstationService(new VoltageLevelService()); - private static final ControlBlockEditor controlBlockEditor = new ControlBlockEditorService(new ControlService(), new LdeviceService(new LnService()), new ConnectedAPService(), new SubNetworkService()); + private static final ControlBlockEditor controlBlockEditor = new ControlBlockEditorService(new ControlService(), new LdeviceService(new LnService()), new ConnectedAPService(), new SubNetworkService(), extRefService); private HeaderDTO headerDTO; diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java index 3c78c2617..fa24a9ef8 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ControlBlockEditorService.java @@ -13,6 +13,7 @@ import org.lfenergy.compas.sct.commons.model.cbcom.*; import org.lfenergy.compas.sct.commons.model.da_comm.DACOMM; import org.lfenergy.compas.sct.commons.scl.ControlService; +import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; @@ -50,6 +51,7 @@ public class ControlBlockEditorService implements ControlBlockEditor { private final LdeviceService ldeviceService; private final ConnectedAPService connectedAPService; private final SubNetworkService subNetworkService; + private final ExtRefService extRefService; @Override public List analyzeDataGroups(SCL scd) { @@ -169,8 +171,7 @@ private List findExcludedMacAddresses(SCL scl, TIED ied, TCBType tcbType) List iedWithExtRefFromCurrentCB = scl.getIED().stream() .filter(tied -> !tied.getName().equals(ied.getName())) .filter(tied -> ldeviceService.getLdevices(tied) - .filter(lDevice -> lDevice.getLN0().isSetInputs()) - .flatMap(tlDevice -> tlDevice.getLN0().getInputs().getExtRef().stream()) + .flatMap(extRefService::getExtRefs) .anyMatch(tExtRef -> ied.getName().equals(tExtRef.getIedName())) ) .toList(); @@ -189,8 +190,7 @@ private List findExcludedMacAddresses(SCL scl, TIED ied, TCBType tcbType) private Stream getExtRefAddress(SCL scl, TIED tied) { return ldeviceService.getLdevices(tied) - .filter(lDevice -> lDevice.getLN0().isSetInputs()) - .flatMap(tlDevice -> tlDevice.getLN0().getInputs().getExtRef().stream()) + .flatMap(extRefService::getExtRefs) .filter(TExtRef::isSetSrcCBName) .map(tExtRef -> new CbKey(tExtRef.getIedName(), tExtRef.getLdInst(), tExtRef.getSrcCBName())) .flatMap(cbKey -> scl.getCommunication().getSubNetwork().stream() 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 deleted file mode 100644 index 63d1bc6d3..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefReaderService.java +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-FileCopyrightText: 2022 2023 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.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/SclService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclService.java index b17e7e92a..d9ea985cd 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 @@ -15,6 +15,7 @@ import org.lfenergy.compas.sct.commons.domain.DataRef; import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; +import org.lfenergy.compas.sct.commons.scl.ExtRefService; import org.lfenergy.compas.sct.commons.scl.SclRootAdapter; import org.lfenergy.compas.sct.commons.scl.com.CommunicationAdapter; import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter; @@ -50,7 +51,7 @@ public class SclService implements SclEditor { private final IedService iedService; private final LdeviceService ldeviceService; private final LnService lnService; - private final ExtRefReaderService extRefReaderService; + private final ExtRefService extRefService; private final DataTypeTemplateReader dataTypeTemplateService; @Getter @@ -216,7 +217,7 @@ public List manageMonitoringLns(SCL scd) { iedService.getFilteredIeds(scd, ied -> !ied.getName().contains(IED_TEST_NAME)) .forEach(tied -> { Map> serviceTypeToIedSource = ldeviceService.getLdevices(tied) - .flatMap(tlDevice -> extRefReaderService.getExtRefs(tlDevice.getLN0())) + .flatMap(extRefService::getExtRefs) .filter(tExtRef -> tExtRef.isSetServiceType() && tExtRef.isSetSrcCBName() && (tExtRef.getServiceType().equals(TServiceType.GOOSE) || tExtRef.getServiceType().equals(TServiceType.SMV))) .collect(Collectors.groupingBy(tExtRef -> new IedSource(tExtRef.getIedName(), tExtRef.getSrcCBName(), tExtRef.getSrcLDInst(), tExtRef.getServiceType()))) .keySet() 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 deleted file mode 100644 index 68853e5ec..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefReader.java +++ /dev/null @@ -1,15 +0,0 @@ -// 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/dto/LNodeDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java index e072c3ff8..e40472be9 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 @@ -13,7 +13,6 @@ import org.lfenergy.compas.scl2007b4.model.TExtRef; import org.lfenergy.compas.scl2007b4.model.TLNodeType; 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; @@ -71,10 +70,11 @@ public class LNodeDTO { /** * Constructor - * @param inst input - * @param lnClass input + * + * @param inst input + * @param lnClass input * @param lnPrefix input - * @param lnType input + * @param lnType input */ public LNodeDTO(String inst, String lnClass, String lnPrefix, String lnType) { this.inst = inst; @@ -85,48 +85,49 @@ public LNodeDTO(String inst, String lnClass, String lnPrefix, String lnType) { /** * Initialize LN + * * @param nodeAdapter input - * @param options input + * @param options input + * @param LNode type (LLN0 or other LN's) * @return LNodeDTO object - * @param LNode type (LLN0 or other LN's) */ public static LNodeDTO from(AbstractLNAdapter nodeAdapter, LogicalNodeOptions options) { log.info(Utils.entering()); LNodeDTO lNodeDTO = new LNodeDTO(); - if(nodeAdapter == null) return lNodeDTO; + if (nodeAdapter == null) return lNodeDTO; lNodeDTO.nodeType = nodeAdapter.getLnType(); lNodeDTO.nodeClass = nodeAdapter.getLNClass(); - if(!nodeAdapter.getPrefix().isBlank()){ + if (!nodeAdapter.getPrefix().isBlank()) { lNodeDTO.prefix = nodeAdapter.getPrefix(); } lNodeDTO.inst = nodeAdapter.getLNInst(); - if(options == null) { + if (options == null) { log.info(Utils.leaving()); return lNodeDTO; } - if(options.isWithExtRef()) { - List extRefList = nodeAdapter.getExtRefs(null); + if (options.isWithExtRef()) { + List extRefList = nodeAdapter.getExtRefs(null); LDeviceAdapter lDeviceAdapter = nodeAdapter.getParentAdapter(); String holderIedName = lDeviceAdapter.getParentAdapter().getName(); String holderLDInst = lDeviceAdapter.getInst(); lNodeDTO.extRefs.addAll( extRefList.stream() .map(tExtRef -> - ExtRefInfo.from(tExtRef,holderIedName,holderLDInst,lNodeDTO.nodeClass, - lNodeDTO.inst,lNodeDTO.prefix - )) - .collect(Collectors.toList()) + ExtRefInfo.from(tExtRef, holderIedName, holderLDInst, lNodeDTO.nodeClass, + lNodeDTO.inst, lNodeDTO.prefix + )) + .toList() ); } - if(options.isWithDatSet()) { + if (options.isWithDatSet()) { DataSetService dataSetService = new DataSetService(); lNodeDTO.datSets = dataSetService.getDataSets(nodeAdapter.getCurrentElem()).map(DataSetInfo::new).collect(Collectors.toSet()); } - if(options.isWithDataAttributeRef()) { + if (options.isWithDataAttributeRef()) { DataTypeTemplateAdapter dttAdapter = nodeAdapter.getDataTypeTemplateAdapter(); LNodeTypeAdapter lNodeTypeAdapter = dttAdapter.getLNodeTypeAdapterById(nodeAdapter.getLnType()) .orElseThrow( @@ -138,15 +139,15 @@ public static LNodeDTO from(AbstractLNAdapter nodeAdapter, ) ); DataAttributeRef filter = DataAttributeRef.builder() - .lnInst(nodeAdapter.getLNInst()) - .lnClass(nodeAdapter.getLNClass()) - .prefix(nodeAdapter.getPrefix()) - .lnType(nodeAdapter.getLnType()).build(); + .lnInst(nodeAdapter.getLNInst()) + .lnClass(nodeAdapter.getLNClass()) + .prefix(nodeAdapter.getPrefix()) + .lnType(nodeAdapter.getLnType()).build(); List dataAttributeRefList = lNodeTypeAdapter.getDataAttributeRefs(filter); lNodeDTO.addAllDataAttributeRef(dataAttributeRefList); } - if(options.isWithCB()) { + if (options.isWithCB()) { //TODO } log.info(Utils.leaving()); @@ -162,9 +163,11 @@ public static LNodeDTO from(TAnyLN tAnyLN, LogicalNodeOptions options, String ie 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(); + List extRefInfos = tAnyLN.isSetInputs() ? + tAnyLN.getInputs().getExtRef().stream() + .map(extRef -> ExtRefInfo.from(extRef, iedName, ldInst, lnClass, inst, prefix)) + .toList() + : List.of(); lNodeDTO.addAllExtRefInfo(extRefInfos); } if (options.isWithDatSet()) { @@ -195,45 +198,50 @@ public static LNodeDTO from(TAnyLN tAnyLN, LogicalNodeOptions options, String ie /** * Sets LNode Inst value + * * @param inst input */ - public void setInst(String inst){ + public void setInst(String inst) { this.inst = inst; } /** * Sets LNode Class value + * * @param lnClass input */ - public void setNodeClass(String lnClass){ + public void setNodeClass(String lnClass) { this.nodeClass = lnClass; } /** - * Sets LNode Type + * Sets LNode Type + * * @param lnType */ - public void setNodeType(String lnType){ + public void setNodeType(String lnType) { this.nodeType = lnType; } /** * Sets LNode Prefix value + * * @param prefix input */ - public void setPrefix(String prefix){ + public void setPrefix(String prefix) { this.prefix = prefix; } /** * Extracts LNode ExtRef informations + * * @param lnAdapter input * @return LNodeDTO object */ public static LNodeDTO extractExtRefInfo(LNAdapter lnAdapter) { String lnClass = lnAdapter.getLNClass() == null ? "" : lnAdapter.getLNClass(); - LNodeDTO lNodeDTO = new LNodeDTO(lnAdapter.getLNInst(),lnClass,lnAdapter.getPrefix(), lnAdapter.getLnType()); - if(lnAdapter.hasInputs()){ + LNodeDTO lNodeDTO = new LNodeDTO(lnAdapter.getLNInst(), lnClass, lnAdapter.getPrefix(), lnAdapter.getLnType()); + if (lnAdapter.hasInputs()) { lnAdapter.getExtRefs(null).forEach(tExtRef -> { ExtRefInfo extRefInfo = new ExtRefInfo(tExtRef); lNodeDTO.addExtRefInfo(extRefInfo); @@ -244,6 +252,7 @@ public static LNodeDTO extractExtRefInfo(LNAdapter lnAdapter) { /** * Adds ExtRef Info to LNode ExtRefs + * * @param extRef input */ public void addExtRefInfo(ExtRefInfo extRef) { @@ -252,6 +261,7 @@ public void addExtRefInfo(ExtRefInfo extRef) { /** * Adds list of ExtRef Info into LNode + * * @param extRefs input */ public void addAllExtRefInfo(List extRefs) { @@ -260,6 +270,7 @@ public void addAllExtRefInfo(List extRefs) { /** * Adds Control Block to LNode Control Blocks + * * @param controlBlock input */ public void addControlBlock(ControlBlock controlBlock) { @@ -278,14 +289,16 @@ public void addControlBlock(ControlBlock controlBlock) { /** * Adds lis of Control Block to LNode Control Blocks + * * @param controlBlockInfoList input */ - public void addAllControlBlocks(List controlBlockInfoList){ + public void addAllControlBlocks(List controlBlockInfoList) { controlBlockInfoList.forEach(this::addControlBlock); } /** * Adds list of DataSet to LNode + * * @param dataSetList input */ public void addAllDatSets(List dataSetList) { @@ -294,6 +307,7 @@ public void addAllDatSets(List dataSetList) { /** * Adds DataTypeTemplate's sumarised data + * * @param dataAttributeRef input */ public void addDataAttributeRef(DataAttributeRef dataAttributeRef) { @@ -302,6 +316,7 @@ public void addDataAttributeRef(DataAttributeRef dataAttributeRef) { /** * Adds list of DataTypeTemplate's sumarised data + * * @param dataAttributeRefs input */ public void addAllDataAttributeRef(List dataAttributeRefs) { @@ -310,14 +325,16 @@ public void addAllDataAttributeRef(List dataAttributeRefs) { /** * Gets DataTypeTemplate's sumarised data + * * @return Set of DataAttributeRef object */ - public Set getDataAttributeRefs(){ + public Set getDataAttributeRefs() { return Set.of(dataAttributeRefs.toArray(new DataAttributeRef[0])); } /** * Adds DataSet information to LNode + * * @param dataSetInfo input */ public void addDataSet(DataSetInfo dataSetInfo) { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java index 1f806744e..3ec4b27a9 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ExtRefService.java @@ -6,16 +6,12 @@ package org.lfenergy.compas.sct.commons.scl; -import org.lfenergy.compas.scl2007b4.model.TExtRef; -import org.lfenergy.compas.scl2007b4.model.TInputs; -import org.lfenergy.compas.scl2007b4.model.TLDevice; -import org.lfenergy.compas.scl2007b4.model.TLLN0Enum; +import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; @@ -27,9 +23,10 @@ public class ExtRefService { * @return Stream of ExtRefs */ public Stream getExtRefs(TLDevice tlDevice) { - return getInputs(tlDevice) + return Stream.concat(Stream.of(tlDevice.getLN0()), tlDevice.getLN().stream()) + .filter(TAnyLN::isSetInputs) + .map(TAnyLN::getInputs) .filter(TInputs::isSetExtRef) - .stream() .flatMap(tInputs -> tInputs.getExtRef().stream()); } @@ -75,12 +72,12 @@ public boolean isExtRefFeedBySameControlBlock(TExtRef t1, TExtRef t2) { String srcLNClass1 = (t1.isSetSrcLNClass()) ? t1.getSrcLNClass().getFirst() : TLLN0Enum.LLN_0.value(); String srcLNClass2 = (t2.isSetSrcLNClass()) ? t2.getSrcLNClass().getFirst() : TLLN0Enum.LLN_0.value(); return Utils.equalsOrBothBlank(t1.getIedName(), t2.getIedName()) - && Utils.equalsOrBothBlank(t1.getSrcLDInst(), t2.getSrcLDInst()) - && srcLNClass1.equals(srcLNClass2) - && Utils.equalsOrBothBlank(t1.getSrcLNInst(), t2.getSrcLNInst()) - && Utils.equalsOrBothBlank(t1.getSrcPrefix(), t2.getSrcPrefix()) - && Utils.equalsOrBothBlank(t1.getSrcCBName(), t2.getSrcCBName()) - && Objects.equals(t1.getServiceType(), t2.getServiceType()); + && Utils.equalsOrBothBlank(t1.getSrcLDInst(), t2.getSrcLDInst()) + && srcLNClass1.equals(srcLNClass2) + && Utils.equalsOrBothBlank(t1.getSrcLNInst(), t2.getSrcLNInst()) + && Utils.equalsOrBothBlank(t1.getSrcPrefix(), t2.getSrcPrefix()) + && Utils.equalsOrBothBlank(t1.getSrcCBName(), t2.getSrcCBName()) + && Objects.equals(t1.getServiceType(), t2.getServiceType()); } /** @@ -97,11 +94,4 @@ public List filterDuplicatedExtRefs(List tExtRefs) { return filteredList; } - private Optional getInputs(TLDevice tlDevice){ - if (!tlDevice.isSetLN0() || !tlDevice.getLN0().isSetInputs()) { - return Optional.empty(); - } - return Optional.of(tlDevice.getLN0().getInputs()); - } - } 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 b2f38cbd5..626f2f1f5 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 @@ -39,6 +39,8 @@ public class AccessPointAdapter extends SclElementAdapter checkFCDALimitations() { return currentElem.getServer().getLDevice().stream() .map(tlDevice -> new LDeviceAdapter(parentAdapter, tlDevice)) .map(lDeviceAdapter -> - lDeviceAdapter.getLNAdaptersIncludingLN0().stream() + lDeviceAdapter.streamLNAdaptersIncludingLN0() .map(abstractLNAdapter -> abstractLNAdapter.getCurrentElem().getDataSet()) .flatMap(Collection::stream) .filter(tDataSet -> tDataSet.getFCDA().size() > max) .map(tDataSet -> SclReportItem.error(getXPath(), String.format("There are too much FCDA for the DataSet %s for the LDevice %s" - + " in IED %s: %d > %d max", tDataSet.getName(), lDeviceAdapter.getInst(), parentAdapter.getName(), - tDataSet.getFCDA().size(), max)) + + " in IED %s: %d > %d max", tDataSet.getName(), lDeviceAdapter.getInst(), parentAdapter.getName(), + tDataSet.getFCDA().size(), max)) ).toList() ).flatMap(Collection::stream).toList(); } @@ -108,7 +110,7 @@ public Optional checkControlsLimitation(ServicesConfigEnum servic long max = getMaxInstanceAuthorized(servicesConfigEnum); long value = getNumberOfItems(servicesConfigEnum); return max == MAX_OCCURRENCE_NO_LIMIT_VALUE || value <= max ? Optional.empty() : Optional.of(SclReportItem.error(getXPath(), - String.format("There are too much %ss for the IED %s: %d > %d max", servicesConfigEnum.getDisplayName(), parentAdapter.getName(), value, max))); + String.format("There are too much %ss for the IED %s: %d > %d max", servicesConfigEnum.getDisplayName(), parentAdapter.getName(), value, max))); } /** @@ -160,14 +162,11 @@ private long getMaxInstanceAuthorized(ServicesConfigEnum servicesConfigEnum) { TServices tServices = currentElem.getServices(); return switch (servicesConfigEnum) { - case DATASET -> - tServices.isSetConfDataSet() && tServices.getConfDataSet().isSetMax() ? - tServices.getConfDataSet().getMax() : MAX_OCCURRENCE_NO_LIMIT_VALUE; - case FCDA -> - tServices.isSetConfDataSet() && tServices.getConfDataSet().isSetMaxAttributes() ? - tServices.getConfDataSet().getMaxAttributes() : MAX_OCCURRENCE_NO_LIMIT_VALUE; - case REPORT -> - tServices.isSetConfReportControl() && tServices.getConfReportControl().isSetMax() ? + case DATASET -> tServices.isSetConfDataSet() && tServices.getConfDataSet().isSetMax() ? + tServices.getConfDataSet().getMax() : MAX_OCCURRENCE_NO_LIMIT_VALUE; + case FCDA -> tServices.isSetConfDataSet() && tServices.getConfDataSet().isSetMaxAttributes() ? + tServices.getConfDataSet().getMaxAttributes() : MAX_OCCURRENCE_NO_LIMIT_VALUE; + case REPORT -> tServices.isSetConfReportControl() && tServices.getConfReportControl().isSetMax() ? tServices.getConfReportControl().getMax() : MAX_OCCURRENCE_NO_LIMIT_VALUE; case GSE -> tServices.isSetGOOSE() && tServices.getGOOSE().isSetMax() ? tServices.getGOOSE().getMax() : MAX_OCCURRENCE_NO_LIMIT_VALUE; case SMV -> tServices.isSetSMVsc() && tServices.getSMVsc().isSetMax() ? tServices.getSMVsc().getMax() : MAX_OCCURRENCE_NO_LIMIT_VALUE; @@ -188,7 +187,7 @@ public Optional checkLimitationForBoundIedFcdas(List tEx TClientServices tClientServices = currentElem.getServices().getClientServices(); max = tClientServices != null && tClientServices.isSetMaxAttributes() ? tClientServices.getMaxAttributes() : MAX_OCCURRENCE_NO_LIMIT_VALUE; } - if (max == MAX_OCCURRENCE_NO_LIMIT_VALUE){ + if (max == MAX_OCCURRENCE_NO_LIMIT_VALUE) { return Optional.empty(); } long value = tExtRefs.stream() @@ -204,7 +203,7 @@ public Optional checkLimitationForBoundIedFcdas(List tEx if (!tExtRef.isSetSrcLNClass() || tExtRef.getSrcLNClass().contains(TLLN0Enum.LLN_0.value())) { abstractLNAdapter = lDeviceAdapter.getLN0Adapter(); } else { - abstractLNAdapter = lDeviceAdapter.getLNAdapter(tExtRef.getSrcLNClass().get(0), tExtRef.getSrcLNInst(), tExtRef.getSrcPrefix()); + abstractLNAdapter = lDeviceAdapter.getLNAdapter(tExtRef.getSrcLNClass().getFirst(), tExtRef.getSrcLNInst(), tExtRef.getSrcPrefix()); } return abstractLNAdapter.getFCDAs(tExtRef); }) @@ -214,7 +213,7 @@ public Optional checkLimitationForBoundIedFcdas(List tEx return value <= max ? Optional.empty() : Optional.of(SclReportItem.error(getParentAdapter().getXPath(), - "The Client IED %s subscribes to too much FCDA: %d > %d max".formatted(getParentAdapter().getName(), value, max))); + "The Client IED %s subscribes to too much FCDA: %d > %d max".formatted(getParentAdapter().getName(), value, max))); } /** @@ -232,17 +231,20 @@ public record ExtRefAnalyzeRecord(List sclReportItems, List sclReportItems = new ArrayList<>(); List tExtRefList = streamLDeviceAdapters() - .map(LDeviceAdapter::getLN0Adapter) - .map(ln0Adapter -> { - List extRefs = new ArrayList<>(); - if (ln0Adapter.hasInputs()) { - extRefs.addAll(ln0Adapter.getInputsAdapter().filterDuplicatedExtRefs() - .stream().filter(TExtRef::isSetSrcCBName).collect(Collectors.toCollection(ArrayList::new))); - sclReportItems.addAll(checkExtRefWithoutServiceType(extRefs, ln0Adapter.getXPath())); - extRefs.removeIf(tExtRef -> !tExtRef.isSetServiceType()); + .flatMap(lDeviceAdapter -> { + List tExtRefs = lDeviceAdapter.streamInputsAdapters() + .map(SclElementAdapter::getCurrentElem) + .flatMap(tInputs -> tInputs.getExtRef().stream()) + .filter(TExtRef::isSetSrcCBName) + .toList(); + if (tExtRefs.isEmpty()) { + return Stream.empty(); } - return extRefs; - }).flatMap(Collection::stream) + List filteredList = extRefService.filterDuplicatedExtRefs(tExtRefs); + sclReportItems.addAll(checkExtRefWithoutServiceType(filteredList, getXPath())); + return filteredList.stream() + .filter(TExtRef::isSetServiceType); + }) .toList(); return new ExtRefAnalyzeRecord(sclReportItems, new ExtRefService().filterDuplicatedExtRefs(tExtRefList)); } @@ -258,8 +260,8 @@ private List checkExtRefWithoutServiceType(List tExtRefs .filter(tExtRef -> !tExtRef.isSetServiceType()) .map(tExtRef -> SclReportItem.error("%s/Inputs/ExtRef[%s]".formatted(xPath, - Utils.xpathAttributeFilter("desc", tExtRef.getDesc())), - "ExtRef is missing ServiceType attribute")) + Utils.xpathAttributeFilter("desc", tExtRef.getDesc())), + "ExtRef is missing ServiceType attribute")) .toList(); } @@ -289,9 +291,9 @@ private Optional checkLimitationForOneControlType(Set tE long max = getMaxInstanceAuthorizedForBoundIED(servicesConfigEnum); long value = tExtRefs.size(); return max == AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE || value <= max ? Optional.empty() : - Optional.of(SclReportItem.error(getParentAdapter().getXPath(), - "The Client IED %s subscribes to too much %ss: %d > %d max".formatted(getParentAdapter().getName(), servicesConfigEnum.getDisplayName(), - value, max))); + Optional.of(SclReportItem.error(getParentAdapter().getXPath(), + "The Client IED %s subscribes to too much %ss: %d > %d max".formatted(getParentAdapter().getName(), servicesConfigEnum.getDisplayName(), + value, max))); } /** @@ -306,14 +308,10 @@ private long getMaxInstanceAuthorizedForBoundIED(ServicesConfigEnum servicesConf } TClientServices tClientServices = currentElem.getServices().getClientServices(); return switch (servicesConfigEnum) { - case FCDA -> - tClientServices.isSetMaxAttributes() ? tClientServices.getMaxAttributes() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; - case REPORT -> - tClientServices.isSetMaxReports() ? tClientServices.getMaxReports() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; - case GSE -> - tClientServices.isSetMaxGOOSE() ? tClientServices.getMaxGOOSE() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; - case SMV -> - tClientServices.isSetMaxSMV() ? tClientServices.getMaxSMV() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; + case FCDA -> tClientServices.isSetMaxAttributes() ? tClientServices.getMaxAttributes() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; + case REPORT -> tClientServices.isSetMaxReports() ? tClientServices.getMaxReports() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; + case GSE -> tClientServices.isSetMaxGOOSE() ? tClientServices.getMaxGOOSE() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; + case SMV -> tClientServices.isSetMaxSMV() ? tClientServices.getMaxSMV() : AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE; default -> throw new ScdException("Unsupported value: " + servicesConfigEnum); }; 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 e83f549a5..5a948d03a 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 @@ -12,7 +12,6 @@ import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.exception.ScdException; import org.lfenergy.compas.sct.commons.model.da_comm.TFCDA; -import org.lfenergy.compas.sct.commons.scl.ExtRefService; 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; @@ -39,7 +38,7 @@ * @see AbstractLNAdapter */ @Slf4j -public class InputsAdapter extends SclElementAdapter { +public class InputsAdapter extends SclElementAdapter, TInputs> { private static final String MESSAGE_SOURCE_LDEVICE_NOT_FOUND = "The signal ExtRef ExtRefldinst does not match any " + "LDevice with same inst attribute in source IED %s"; @@ -62,7 +61,7 @@ public class InputsAdapter extends SclElementAdapter { * @param parentAdapter Parent container reference * @param tInputs Current reference */ - public InputsAdapter(LN0Adapter parentAdapter, TInputs tInputs) { + public InputsAdapter(AbstractLNAdapter parentAdapter, TInputs tInputs) { super(parentAdapter, tInputs); } @@ -278,13 +277,4 @@ private SclRootAdapter getSclRootAdapter() { return getIedAdapter().getParentAdapter(); } - /** - * Remove ExtRef which are fed by same Control Block - * - * @return list ExtRefs without duplication - */ - public List filterDuplicatedExtRefs() { - return new ExtRefService().filterDuplicatedExtRefs(currentElem.getExtRef()); - } - } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java index 847a0530e..4ab15484e 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java @@ -13,6 +13,7 @@ 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.IEDAdapter; +import org.lfenergy.compas.sct.commons.scl.ied.InputsAdapter; 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; @@ -20,6 +21,7 @@ import org.lfenergy.compas.sct.commons.util.Utils; import java.util.*; +import java.util.stream.Stream; /** * A representation of the model object @@ -163,10 +165,19 @@ public boolean hasLN0() { * @return list of LNAdapter object */ public List getLNAdapters() { + return streamLnAdapters() + .toList(); + } + + /** + * Stream current LDevice LNodes (except LN0) + * + * @return stream of LNAdapter object + */ + public Stream streamLnAdapters() { return currentElem.getLN() .stream() - .map(tln -> new LNAdapter(this, tln)) - .toList(); + .map(tln -> new LNAdapter(this, tln)); } /** @@ -220,7 +231,7 @@ public Optional findLnAdapter(String lnClass, String lnInst, String p */ public List getExtRefBinders(ExtRefSignalInfo signalInfo) { DataTypeTemplateAdapter dttAdapter = parentAdapter.getParentAdapter().getDataTypeTemplateAdapter(); - return getLNAdaptersIncludingLN0().stream() + return streamLNAdaptersIncludingLN0() .filter(abstractLNAdapter -> StringUtils.isBlank(signalInfo.getPLN()) || abstractLNAdapter.getLNClass().equals(signalInfo.getPLN())) .map(lnAdapter -> { String lnType = lnAdapter.getLnType(); @@ -295,13 +306,25 @@ public List> getLNAdaptersIncludingLN0() { return aLNAdapters; } + /** + * Stream all LN of LDevice including LN0 + * + * @return list of all LN of LDevice + */ + public Stream> streamLNAdaptersIncludingLN0() { + return Stream.concat(Stream.of(getLN0Adapter()), streamLnAdapters()); + } + public List createDataSetAndControlBlocks(List allowedFcdas) { - LN0Adapter ln0Adapter = getLN0Adapter(); - if (!ln0Adapter.hasInputs()) { - return Collections.emptyList(); - } - return ln0Adapter.getInputsAdapter() - .updateAllSourceDataSetsAndControlBlocks(allowedFcdas); + return streamInputsAdapters() + .flatMap(inputsAdapter -> inputsAdapter.updateAllSourceDataSetsAndControlBlocks(allowedFcdas).stream()) + .toList(); + } + + public Stream streamInputsAdapters() { + return streamLNAdaptersIncludingLN0() + .filter(AbstractLNAdapter::hasInputs) + .map(AbstractLNAdapter::getInputsAdapter); } public Set findSourceDA(TExtRef extRef) { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java index 44a4c3045..44c2d06b3 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/AbstractLNAdapter.java @@ -192,11 +192,11 @@ public List getExtRefs(ExtRefSignalInfo filter) { .stream() .filter(tExtRef -> ((filter.getDesc() == null && tExtRef.getDesc().isEmpty()) - || Objects.equals(filter.getDesc(), tExtRef.getDesc())) && - Objects.equals(filter.getPDO(), tExtRef.getPDO()) && - Objects.equals(filter.getPDA(), tExtRef.getPDA()) && - Objects.equals(filter.getIntAddr(), tExtRef.getIntAddr()) && - Objects.equals(filter.getPServT(), tExtRef.getPServT())) + || Objects.equals(filter.getDesc(), tExtRef.getDesc())) && + Objects.equals(filter.getPDO(), tExtRef.getPDO()) && + Objects.equals(filter.getPDA(), tExtRef.getPDA()) && + Objects.equals(filter.getIntAddr(), tExtRef.getIntAddr()) && + Objects.equals(filter.getPServT(), tExtRef.getPServT())) .toList(); } @@ -224,9 +224,9 @@ public void isExtRefExist(ExtRefSignalInfo signalInfo) { boolean extRefExist = currentElem.getInputs().getExtRef() .stream() .anyMatch(tExtRef -> Objects.equals(signalInfo.getDesc(), tExtRef.getDesc()) && - Objects.equals(tExtRef.getPDO(), signalInfo.getPDO()) && - Objects.equals(signalInfo.getIntAddr(), tExtRef.getIntAddr()) && - Objects.equals(signalInfo.getPServT(), tExtRef.getPServT())); + Objects.equals(tExtRef.getPDO(), signalInfo.getPDO()) && + Objects.equals(signalInfo.getIntAddr(), tExtRef.getIntAddr()) && + Objects.equals(signalInfo.getPServT(), tExtRef.getPServT())); if (!extRefExist) { throw new ScdException("ExtRef signal does not exist in target LN"); } @@ -389,7 +389,7 @@ public List getTControlsByType(Class cls) { } else if (TReportControl.class.equals(cls)) { return (List) currentElem.getReportControl(); } - throw new IllegalArgumentException("Unsupported ControlBlock "+cls.getSimpleName()+" for Lnode"); + throw new IllegalArgumentException("Unsupported ControlBlock " + cls.getSimpleName() + " for Lnode"); } /** @@ -400,9 +400,9 @@ public List getTControlsByType(Class cls) { */ private boolean isCBKnown(String cbName) { return isLN0() - && (((LN0) currentElem).getGSEControl().stream().anyMatch(tgse -> tgse.getName().equals(cbName)) || - ((LN0) currentElem).getSampledValueControl().stream().anyMatch(tsmv -> tsmv.getName().equals(cbName))) - || currentElem.getReportControl().stream().anyMatch(trpt -> trpt.getName().equals(cbName)); + && (((LN0) currentElem).getGSEControl().stream().anyMatch(tgse -> tgse.getName().equals(cbName)) || + ((LN0) currentElem).getSampledValueControl().stream().anyMatch(tsmv -> tsmv.getName().equals(cbName))) + || currentElem.getReportControl().stream().anyMatch(trpt -> trpt.getName().equals(cbName)); } /** @@ -561,8 +561,8 @@ public TExtRef extractExtRefFromExtRefInfo(@NonNull ExtRefInfo extRefInfo) { /** * Returns a list of Data Attribute Reference for DataAttribute (updatable or not) * - * @param dataAttributeRef Data Attribute Reference (used as filter) - * @param updatableOnly true to retrieve DataTypeTemplate's related to only updatable DAI, false to retrieve all + * @param dataAttributeRef Data Attribute Reference (used as filter) + * @param updatableOnly true to retrieve DataTypeTemplate's related to only updatable DAI, false to retrieve all * @return List of Data Attribute Reference (updatable or not) * @throws ScdException SCD illegal arguments exception */ @@ -802,7 +802,16 @@ public boolean matches(ObjectReference objRef) { List dataAttributeRefs = lNodeTypeAdapter.getDataAttributeRefs(filter); return matchesDataAttributes(dataAttribute) || - dataAttributeRefs.stream().anyMatch(dataAttributeRef -> dataAttributeRef.getDataAttributes().startsWith(dataAttribute)); + dataAttributeRefs.stream().anyMatch(dataAttributeRef -> dataAttributeRef.getDataAttributes().startsWith(dataAttribute)); + } + + /** + * Gets Inputs node as an adapter + * + * @return an InputsAdapter + */ + public InputsAdapter getInputsAdapter() { + return new InputsAdapter(this, currentElem.getInputs()); } /** @@ -813,7 +822,7 @@ public boolean matches(ObjectReference objRef) { */ protected boolean matchesDataAttributes(String dataAttribute) { return currentElem.getDataSet().stream().anyMatch(tDataSet -> tDataSet.getName().equals(dataAttribute)) || - currentElem.getReportControl().stream().anyMatch(rptCtl -> rptCtl.getName().equals(dataAttribute)); + currentElem.getReportControl().stream().anyMatch(rptCtl -> rptCtl.getName().equals(dataAttribute)); } /** @@ -831,7 +840,7 @@ public Map getDAIValues(DataAttributeRef dataAttributeRef) { List tVals; IDataAdapter daiAdapter = daiTracker.getBdaiOrDaiAdapter(); if (daiAdapter.getClass().equals(SDIAdapter.DAIAdapter.class)) { - tVals = ((RootSDIAdapter.DAIAdapter) daiAdapter).getCurrentElem().getVal(); + tVals = ((SDIAdapter.DAIAdapter) daiAdapter).getCurrentElem().getVal(); } else if (daiAdapter.getClass().equals(RootSDIAdapter.DAIAdapter.class)) { tVals = ((RootSDIAdapter.DAIAdapter) daiAdapter).getCurrentElem().getVal(); } else { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java index 8bf391aa1..92824232b 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java @@ -10,7 +10,6 @@ import org.lfenergy.compas.sct.commons.dto.DataAttributeRef; import org.lfenergy.compas.sct.commons.dto.ExtRefSignalInfo; 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; /** @@ -124,15 +123,6 @@ public String getPrefix() { return ""; } - /** - * Gets Inputs node as an adapter - * - * @return an InputsAdapter - */ - public InputsAdapter getInputsAdapter() { - return new InputsAdapter(this, currentElem.getInputs()); - } - /** * Checks if given attibrute corresponds to DataSet or ReportControl or SMVControl or GSEControl in current LN0 * diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java index 33b30cdfe..1d28faebf 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/ControlBlockEditorServiceTest.java @@ -15,6 +15,7 @@ import org.lfenergy.compas.sct.commons.model.cbcom.*; import org.lfenergy.compas.sct.commons.model.da_comm.DACOMM; import org.lfenergy.compas.sct.commons.scl.ControlService; +import org.lfenergy.compas.sct.commons.scl.ExtRefService; 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.IEDAdapter; @@ -49,7 +50,7 @@ class ControlBlockEditorServiceTest { @BeforeEach void init() { - controlBlockEditorService = new ControlBlockEditorService(new ControlService(), new LdeviceService(new LnService()), new ConnectedAPService(), new SubNetworkService()); + controlBlockEditorService = new ControlBlockEditorService(new ControlService(), new LdeviceService(new LnService()), new ConnectedAPService(), new SubNetworkService(), new ExtRefService()); } @Test 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 c61724e62..e43de1be2 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 @@ -12,6 +12,7 @@ import org.lfenergy.compas.sct.commons.api.DataTypeTemplateReader; import org.lfenergy.compas.sct.commons.dto.*; import org.lfenergy.compas.sct.commons.exception.ScdException; +import org.lfenergy.compas.sct.commons.scl.ExtRefService; 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.LNAdapter; @@ -34,14 +35,14 @@ class SclServiceTest { private final IedService iedService = new IedService(); private final LnService lnService = new LnService(); - private final ExtRefReaderService extRefReaderService = new ExtRefReaderService(); + private final ExtRefService extRefService = new ExtRefService(); private final DataTypeTemplateReader dataTypeTemplatesService = new DataTypeTemplatesService(); private final LdeviceService ldeviceService = new LdeviceService(lnService); private SclService sclService; @BeforeEach void setUp() { - sclService = new SclService(iedService, ldeviceService, lnService, extRefReaderService, dataTypeTemplatesService); + sclService = new SclService(iedService, ldeviceService, lnService, extRefService, dataTypeTemplatesService); } @Test diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java index 21a635549..21f7c1cb3 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ExtRefServiceTest.java @@ -47,25 +47,17 @@ void getExtRefs_should_return_extRefs() { assertThat(result).hasSize(2); } - @ParameterizedTest - @MethodSource("provideLDevices") - void getExtRefs_should_return_empty_stream(TLDevice tlDevice) { - //Given : parameters + @Test + void getExtRefs_should_return_empty_stream() { + //Given + TLDevice tlDevice = new TLDevice(); + tlDevice.setLN0(new LN0()); //When Stream result = extRefService.getExtRefs(tlDevice); //Then assertThat(result).isEmpty(); } - private static Stream provideLDevices() { - TLDevice tlDeviceWithoutLn0 = new TLDevice(); - tlDeviceWithoutLn0.setLN0(new LN0()); - return Stream.of( - Arguments.of(named("LDevice without LN0 should return empty stream", tlDeviceWithoutLn0)), - Arguments.of(named("LDevice with empty Inputs should return empty stream", new TLDevice())) - ); - } - @Test void getFilteredExtRefs_should_succeed() { //Given 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 96f1e4c54..afa4db723 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 @@ -252,47 +252,6 @@ private static InputsAdapter keepOnlyThisExtRef(SclRootAdapter sclRootAdapter, S return foundInputsAdapter; } - @Test - void filterDuplicatedExtRefs_should_remove_duplicated_extrefs() { - // Given - TExtRef tExtRefLnClass = createExtRefExample("CB_Name1", TServiceType.GOOSE); - tExtRefLnClass.getSrcLNClass().add(TLLN0Enum.LLN_0.value()); - TExtRef tExtRef = createExtRefExample("CB_Name1", TServiceType.GOOSE); - List tExtRefList = List.of(tExtRef, tExtRefLnClass, createExtRefExample("CB", TServiceType.GOOSE), - createExtRefExample("CB", TServiceType.GOOSE)); - TInputs tInputs = new TInputs(); - tInputs.getExtRef().addAll(tExtRefList); - InputsAdapter inputsAdapter = new InputsAdapter(null, tInputs); - // When - List result = inputsAdapter.filterDuplicatedExtRefs(); - // Then - assertThat(result).hasSizeLessThan(tExtRefList.size()) - .hasSize(2); - } - - @Test - void filterDuplicatedExtRefs_should_not_remove_not_duplicated_extrefs() { - // Given - TExtRef tExtRefIedName = createExtRefExample("CB_1", TServiceType.GOOSE); - tExtRefIedName.setIedName("IED_XXX"); - TExtRef tExtRefLdInst = createExtRefExample("CB_1", TServiceType.GOOSE); - tExtRefLdInst.setSrcLDInst("LD_XXX"); - TExtRef tExtRefLnInst = createExtRefExample("CB_1", TServiceType.GOOSE); - tExtRefLnInst.setSrcLNInst("X"); - TExtRef tExtRefPrefix = createExtRefExample("CB_1", TServiceType.GOOSE); - tExtRefPrefix.setSrcPrefix("X"); - List tExtRefList = List.of(tExtRefIedName, tExtRefLdInst, tExtRefLnInst, tExtRefPrefix, - createExtRefExample("CB_1", TServiceType.GOOSE), createExtRefExample("CB_1", TServiceType.SMV)); - TInputs tInputs = new TInputs(); - tInputs.getExtRef().addAll(tExtRefList); - InputsAdapter inputsAdapter = new InputsAdapter(null, tInputs); - // When - List result = inputsAdapter.filterDuplicatedExtRefs(); - // Then - assertThat(result).hasSameSizeAs(tExtRefList) - .hasSize(6); - } - @ParameterizedTest(name = "updateAllSourceDataSetsAndControlBlocks should use gooseType for extRef={0}") @CsvSource({ "test daName ST, DS_LD_INST21_GMI",