diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java index 2ccad6508..b48709804 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/LnService.java @@ -9,6 +9,7 @@ import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.api.LnEditor; import org.lfenergy.compas.sct.commons.domain.*; +import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.util.ActiveStatus; import java.util.ArrayList; @@ -81,6 +82,7 @@ public Optional getDaiModStval(TAnyLN tAnyLN) { .map(TVal::getValue)) .map(ActiveStatus::fromValue); } + public Stream getActiveLns(TLDevice tlDevice) { LN0 ln0 = tlDevice.getLN0(); Stream tlnStream = tlDevice.getLN() @@ -99,7 +101,7 @@ public Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLi return tAnyLN.getDOI().stream().filter(doi -> doi.getName().equals(doLinkedToDaFilter.doName())) .findFirst() .flatMap(doi -> { - if(structNamesList.size() > 1) { + if (structNamesList.size() > 1) { String firstSDIName = structNamesList.removeFirst(); return this.getSdiByName(doi, firstSDIName) .map(intermediateSdi -> findSDIByStructName(intermediateSdi, structNamesList)) @@ -116,7 +118,7 @@ public Optional getDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDaFilter doLi return Optional.empty(); }) .stream().findFirst(); - } else if(structNamesList.size() == 1){ + } else if (structNamesList.size() == 1) { return doi.getSDIOrDAI().stream() .filter(unNaming -> unNaming.getClass().equals(TDAI.class)) .map(TDAI.class::cast) @@ -132,13 +134,13 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT createDoiSdiDaiChainIfNotExists(tAnyLN, doLinkedToDa.getDataObject(), doLinkedToDa.getDataAttribute()) .ifPresent(tdai -> { List daiVals = doLinkedToDa.getDataAttribute().getDaiValues(); - if(!hasSettingGroup(tdai) && daiVals.size() == 1 && daiVals.getFirst().settingGroup() == null) { + if (!hasSettingGroup(tdai) && daiVals.size() == 1 && daiVals.getFirst().settingGroup() == null) { String value = daiVals.getFirst().val(); tdai.getVal().stream().findFirst() .ifPresentOrElse(tVal -> tVal.setValue(value), () -> tdai.getVal().add(newVal(value))); } else { - for (DaVal daVal: daiVals) { + for (DaVal daVal : daiVals) { tdai.getVal().stream() .filter(tValElem -> tValElem.isSetSGroup() && tValElem.getSGroup() == daVal.settingGroup()) .findFirst() @@ -152,11 +154,11 @@ public void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedT public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLinkedToDa doLinkedToDa) { getDOAndDAInstances(anyLN, doLinkedToDa.toFilter()) .ifPresent(tdai -> { - if(tdai.isSetVal()) { + if (tdai.isSetVal()) { doLinkedToDa.getDataAttribute().addDaVal(tdai.getVal()); } - if(doLinkedToDa.getDataAttribute().getFc() == TFCEnum.SG || doLinkedToDa.getDataAttribute().getFc() == TFCEnum.SE) { - if(hasSettingGroup(tdai)) { + if (doLinkedToDa.getDataAttribute().getFc() == TFCEnum.SG || doLinkedToDa.getDataAttribute().getFc() == TFCEnum.SE) { + if (hasSettingGroup(tdai)) { boolean isIedHasConfSG = tied.isSetAccessPoint() && tied.getAccessPoint().stream() .filter(tAccessPoint -> tAccessPoint.getServer() != null @@ -170,8 +172,8 @@ public void completeFromDAInstance(TIED tied, String ldInst, TAnyLN anyLN, DoLin } else { log.warn(String.format("Inconsistency in the SCD file - DAI= %s with fc= %s must have a sGroup attribute", tdai.getName(), doLinkedToDa.getDataAttribute().getFc())); doLinkedToDa.getDataAttribute().setValImport(false); - } - } else if(tdai.isSetValImport()) { + } + } else if (tdai.isSetValImport()) { doLinkedToDa.getDataAttribute().setValImport(tdai.isValImport()); } }); @@ -198,22 +200,22 @@ private Optional createDoiSdiDaiChainIfNotExists(TAnyLN tAnyLN, DataObject TDOI doi = tAnyLN.getDOI().stream().filter(doi1 -> doi1.getName().equals(dataObject.getDoName())) .findFirst() - .orElseGet(()-> { + .orElseGet(() -> { TDOI newDOI = new TDOI(); newDOI.setName(dataObject.getDoName()); tAnyLN.getDOI().add(newDOI); return newDOI; }); - if(structInstances.size() > 1){ + if (structInstances.size() > 1) { TSDI firstSDI = findOrCreateSDIFromDOI(doi, structInstances.getFirst()); TSDI lastSDI = findOrCreateSDIByStructName(firstSDI, structInstances); - if(structInstances.size() == 1){ + if (structInstances.size() == 1) { return lastSDI.getSDIOrDAI().stream() .filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class)) .map(TDAI.class::cast) .filter(tdai -> tdai.getName().equals(structInstances.getFirst())) .map(tdai -> { - if(tdai.isSetValImport()) { + if (tdai.isSetValImport()) { tdai.setValImport(dataAttribute.isValImport()); } return tdai; @@ -226,13 +228,13 @@ private Optional createDoiSdiDaiChainIfNotExists(TAnyLN tAnyLN, DataObject return Optional.of(newDAI); }); } - } else if(structInstances.size() == 1){ + } else if (structInstances.size() == 1) { return doi.getSDIOrDAI().stream() .filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class)) .map(TDAI.class::cast) .filter(tdai -> tdai.getName().equals(structInstances.getFirst())) .map(tdai -> { - if(tdai.isSetValImport()) tdai.setValImport(dataAttribute.isValImport()); + if (tdai.isSetValImport()) tdai.setValImport(dataAttribute.isValImport()); return tdai; }) .findFirst() @@ -247,7 +249,7 @@ private Optional createDoiSdiDaiChainIfNotExists(TAnyLN tAnyLN, DataObject } private TSDI findSDIByStructName(TSDI tsdi, List sdiNames) { - if(sdiNames.isEmpty()) return tsdi; + if (sdiNames.isEmpty()) return tsdi; return this.getSdiByName(tsdi, sdiNames.getFirst()) .map(sdi1 -> { sdiNames.removeFirst(); @@ -294,15 +296,72 @@ private Optional getSdiByName(TSDI sdi, String sdiName) { } /** - * - * @param sdi TSDI + * @param sdi TSDI * @param structName list start with sdi name * @return already existing TSDI or newly created TSDI from given TSDI */ private TSDI findOrCreateSDIByStructName(TSDI sdi, List structName) { structName.removeFirst(); - if(structName.isEmpty() || structName.size() == 1) return sdi; + if (structName.isEmpty() || structName.size() == 1) return sdi; return findOrCreateSDIByStructName(findOrCreateSDIFromSDI(sdi, structName.getFirst()), structName); } + @Override + public List updateLnModStValBasedOnLNodeStatus(SCL scl) { + scl.getSubstation().stream() + .flatMap(tSubstation -> tSubstation.getVoltageLevel().stream()) + .flatMap(tVoltageLevel -> tVoltageLevel.getBay().stream()) + .flatMap(tBay -> tBay.getFunction().stream()) + .flatMap(tFunction -> tFunction.getLNode().stream()) + .map(tlNode -> { + String lNodeLnodeStatus = extractStringPrivate(tlNode, "COMPAS-LNodeStatus") + .orElseThrow(); // FIXME + TAnyLN tAnyLN = findLn(scl, tlNode.getIedName(), tlNode.getLdInst(), tlNode.getLnClass().getFirst(), tlNode.getLnInst(), tlNode.getPrefix()) + .orElseThrow();// FIXME + String lnLNodeStatus = extractStringPrivate(tAnyLN, "COMPAS-LNodeStatus") + .orElseThrow(); + switch (lNodeLnodeStatus) { + case "on" -> { + if (lnLNodeStatus.contains("on")) { + // Met à jour Mod stVal s'il existe + } else { + // erreur // FIXME + } + } + case "of" -> { + if (lnLNodeStatus.contains("off")) { + // Met à jour Mod stVal s'il existe + } else { + // erreur // FIXME + } + } + default -> { + // erreur // FIXME + } + } + return null; + } + ); + + return List.of(); + } + + private static Optional extractStringPrivate(TBaseElement tBaseElement, String privateType) { + return tBaseElement.getPrivate().stream() + .filter(tPrivate -> privateType.equals(tPrivate.getType())) + .flatMap(tPrivate -> tPrivate.getContent().stream()) + .filter(String.class::isInstance) + .map(String.class::cast) + .filter(StringUtils::isNotBlank) + .findFirst(); + } + + private Optional findLn(SCL scl, String iedName, String ldInst, String lnClass, String lnInst, String prefix) { + return scl.getIED().stream() + .filter(tied -> iedName.equals(tied.getName())) + .findFirst() + .flatMap(tied -> new LdeviceService().findLdevice(tied, tlDevice -> ldInst.equals(tlDevice.getInst()))) + .flatMap(tlDevice -> findAnyLn(tlDevice, tAnyLN -> matchesLn(tAnyLN, lnInst, lnClass, prefix))); + + } } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java index 889433c17..45f9cae49 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/LnEditor.java @@ -4,11 +4,14 @@ package org.lfenergy.compas.sct.commons.api; +import org.lfenergy.compas.scl2007b4.model.SCL; import org.lfenergy.compas.scl2007b4.model.TAnyLN; import org.lfenergy.compas.scl2007b4.model.TDAI; import org.lfenergy.compas.sct.commons.domain.DoLinkedToDa; import org.lfenergy.compas.sct.commons.domain.DoLinkedToDaFilter; +import org.lfenergy.compas.sct.commons.dto.SclReportItem; +import java.util.List; import java.util.Optional; public interface LnEditor { @@ -17,4 +20,5 @@ public interface LnEditor { void updateOrCreateDOAndDAInstances(TAnyLN tAnyLN, DoLinkedToDa doLinkedToDa); + List updateLnModStValBasedOnLNodeStatus(SCL scl); } diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java index ecc3986cf..3912eb323 100644 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java @@ -18,7 +18,7 @@ import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter; import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter; import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter; -import org.lfenergy.compas.sct.commons.scl.ln.LnKey; +import org.lfenergy.compas.sct.commons.scl.ln.LnId; import org.lfenergy.compas.sct.commons.util.Utils; import java.util.HashSet; @@ -152,14 +152,10 @@ public static LNodeDTO from(AbstractLNAdapter nodeAdapter, public static LNodeDTO from(TAnyLN tAnyLN, LogicalNodeOptions options, String iedName, String ldInst, SCL scl) { log.info(Utils.entering()); - LnKey lnKey = switch (tAnyLN) { - case LN0 ln0 -> new LnKey(ln0); - case TLN tln -> new LnKey(tln); - default -> throw new IllegalStateException("Unexpected value: " + tAnyLN); - }; - String inst = lnKey.getInst(); - String lnClass = lnKey.getLnClass(); - String prefix = lnKey.getPrefix(); + LnId lnId = LnId.from(tAnyLN); + String inst = lnId.lnInst(); + String lnClass = lnId.lnClass(); + String prefix = lnId.prefix(); String lnType = tAnyLN.getLnType(); LNodeDTO lNodeDTO = new LNodeDTO(inst, lnClass, prefix, lnType); if (options.isWithExtRef()) { diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnId.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnId.java new file mode 100644 index 000000000..af80a0eb3 --- /dev/null +++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnId.java @@ -0,0 +1,82 @@ +// SPDX-FileCopyrightText: 2021 RTE FRANCE +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.sct.commons.scl.ln; + +import org.apache.commons.lang3.StringUtils; +import org.lfenergy.compas.scl2007b4.model.*; +import org.lfenergy.compas.sct.commons.exception.ScdException; + +import java.util.List; +import java.util.Objects; + +public record LnId(String lnClass, String lnInst, String prefix) { + private static final String LN0_LNCLASS = TLLN0Enum.LLN_0.value(); + + /** + * Id of LN0. All LN0 have the same lnClass, lnInst and prefix in SCD + */ + public static final LnId LN0_ID = new LnId(LN0_LNCLASS, "", ""); + + /** + * Constructor + * + * @param lnClass always required + * @param lnInst optional. It should be empty for LN0, and should be filled for LN. No verification is done because some Lnode GAPC do not have a lninst. + * @param prefix optional. Is set to empty if null because empty is the default value on LN and the majority of the JAXB Element (LN, LNode, FCDA, ClientLN, but not on ExtRef and IEDName unfortunately) + */ + public LnId(String lnClass, String lnInst, String prefix) { + if (StringUtils.isBlank(lnClass)) { + throw new ScdException("lnClass is required"); + } + this.lnClass = lnClass; + this.lnInst = Objects.requireNonNullElse(lnInst, ""); + this.prefix = Objects.requireNonNullElse(prefix, ""); + } + + /** + * Alternative constructor with lnClass as a List instead of a String. + * JAXB classes lnClass attribute are List, even though it can only contain one element. + * This constructor makes it easier to create LnId from JAXB classes + * + * @param lnClass one element list containing the lnClass value of the LN + * @param lnInst LN lnInst + * @param prefix LN prefix + */ + public LnId(List lnClass, String lnInst, String prefix) { + this(lnClass == null || lnClass.isEmpty() ? null : lnClass.getFirst(), lnInst, prefix); + } + + /** + * Extract id from LN element + * + * @param tAnyLN LN element + * @return id + */ + public static LnId from(TAnyLN tAnyLN) { + if (tAnyLN instanceof TLN0) { + return LN0_ID; + } else if (tAnyLN instanceof TLN tln) { + return new LnId(tln.getLnClass(), tln.getInst(), tln.getPrefix()); + } else { + throw new ScdException("Unexpected class : " + (tAnyLN != null ? tAnyLN.getClass() : null)); + } + } + + /** + * Extract id from LNode element + * + * @param tlNode LNode element + * @return id + */ + public static LnId from(TLNode tlNode) { + if (tlNode.getLnClass().contains(LN0_LNCLASS)) { + return LN0_ID; + } else { + return new LnId(tlNode.getLnClass(), tlNode.getLnInst(), tlNode.getPrefix()); + } + } + + + +} diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java deleted file mode 100644 index 3f37c514f..000000000 --- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LnKey.java +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-FileCopyrightText: 2021 RTE FRANCE -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.sct.commons.scl.ln; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; -import org.lfenergy.compas.scl2007b4.model.*; - -@Getter -@EqualsAndHashCode -public class LnKey { - - private final String inst; - @EqualsAndHashCode.Exclude - private final String lnType; - private final String lnClass; - /** empty for LN0 */ - private final String prefix; - - public LnKey(LN0 ln0) { - this.inst = ln0.getInst(); - this.lnType = ln0.getLnType(); - this.lnClass = ln0.getLnClass().get(0); - this.prefix = StringUtils.EMPTY; - } - - public LnKey(TLN tln) { - this.inst = tln.getInst(); - this.lnType = tln.getLnType(); - this.lnClass = tln.getLnClass().get(0); - this.prefix = tln.getPrefix(); - } - -} - diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java index 8daa222d7..4e728da2a 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/LnServiceTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.params.provider.MethodSource; import org.lfenergy.compas.scl2007b4.model.*; import org.lfenergy.compas.sct.commons.domain.*; +import org.lfenergy.compas.sct.commons.dto.SclReportItem; import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; import org.lfenergy.compas.sct.commons.util.ActiveStatus; @@ -20,6 +21,7 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.lfenergy.compas.sct.commons.testhelpers.SclHelper.*; class LnServiceTest { @@ -167,9 +169,9 @@ void getActiveLns_should_return_lns() { void getDOAndDAInstance_should_return_true_when_DO_and_DA_instances_exists() { //Given TAnyLN tAnyLN = initDOAndDAInstances( - new LinkedList<>(List.of("Do","sdo1", "d")), - new LinkedList<>(List.of("antRef","bda1", "bda2", "bda3")), - "new value",null + new LinkedList<>(List.of("Do", "sdo1", "d")), + new LinkedList<>(List.of("antRef", "bda1", "bda2", "bda3")), + "new value", null ); DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("Do.sdo1.d", "antRef.bda1.bda2.bda3"); //When @@ -185,9 +187,9 @@ void getDOAndDAInstance_should_return_true_when_DO_and_DA_instances_exists() { void getDOAndDAInstance_should_return_false_when_DO_and_DA_instances_not_exists() { //Given TAnyLN tAnyLN = initDOAndDAInstances( - new LinkedList<>(List.of("Do","sdo1", "d")), - new LinkedList<>(List.of("antRef","bda1", "bda2", "bda3")), - "new value",null + new LinkedList<>(List.of("Do", "sdo1", "d")), + new LinkedList<>(List.of("antRef", "bda1", "bda2", "bda3")), + "new value", null ); DoLinkedToDaFilter doLinkedToDaFilter = DoLinkedToDaFilter.from("Do.sdo1.d", "antRef.unknown.bda2.bda3"); //When @@ -223,16 +225,17 @@ void completeFromDataAttributeInstance_should_complete_when_valImport_set_or_not } public static Collection testSettingGroupValuesWithIedHasConfSG() { - return Arrays.asList(new Object[][] { - { false, false, false, TFCEnum.SG, false},//FALSE: warning SG(or SE) should require setting group - { false, true, false, TFCEnum.ST, false}, - { true, false, false, TFCEnum.ST, true}, - { true, false, false, TFCEnum.SE, false},//FALSE: warning SE(or SG) require setting group - { true, true, false, TFCEnum.SE, false}, //FALSE: SE(or SG) require setting group and IED has ConfSG - { true, true, true, TFCEnum.SE, true}, //TRUE: SettingGroup exist and IED has ConfSG - { false, true, true, TFCEnum.SE, false} //FALSE: SettingGroup exist and IED has ConfSG but valImport is not set + return Arrays.asList(new Object[][]{ + {false, false, false, TFCEnum.SG, false},//FALSE: warning SG(or SE) should require setting group + {false, true, false, TFCEnum.ST, false}, + {true, false, false, TFCEnum.ST, true}, + {true, false, false, TFCEnum.SE, false},//FALSE: warning SE(or SG) require setting group + {true, true, false, TFCEnum.SE, false}, //FALSE: SE(or SG) require setting group and IED has ConfSG + {true, true, true, TFCEnum.SE, true}, //TRUE: SettingGroup exist and IED has ConfSG + {false, true, true, TFCEnum.SE, false} //FALSE: SettingGroup exist and IED has ConfSG but valImport is not set }); } + @ParameterizedTest @MethodSource("testSettingGroupValuesWithIedHasConfSG") void completeFromDataAttributeInstance_should_complete_when_settingGroup_set_or_not(Boolean existingValImportSet, @@ -250,8 +253,8 @@ void completeFromDataAttributeInstance_should_complete_when_settingGroup_set_or_ dai.getVal().add(tVal); // dai.setValImport(existingValImportSet); - if(isWithSettingGroup) tVal.setSGroup(1L); - if(isIedHasConfSG){ + if (isWithSettingGroup) tVal.setSGroup(1L); + if (isIedHasConfSG) { TAccessPoint tAccessPoint = new TAccessPoint(); TServer tServer = new TServer(); TLDevice tlDevice = new TLDevice(); @@ -299,7 +302,7 @@ void completeFromDataAttributeInstance__should_not_complete_when_not_found() { doLinkedToDa.setDataAttribute(dataAttribute); //When LnService lnService = new LnService(); - lnService.completeFromDAInstance(tied, "ldInst", tAnyLN, doLinkedToDa); + lnService.completeFromDAInstance(tied, "ldInst", tAnyLN, doLinkedToDa); //Then assertThat(doLinkedToDa.getDataAttribute().isValImport()).isFalse();//initialValue } @@ -310,16 +313,16 @@ void completeFromDataAttributeInstance_should_complete_when_struct(Boolean input //Given TIED tied = new TIED(); TAnyLN tAnyLN = initDOAndDAInstances( - new LinkedList<>(List.of("Do","sdo1", "d")), - new LinkedList<>(List.of("antRef","bda1", "bda2", "bda3")), + new LinkedList<>(List.of("Do", "sdo1", "d")), + new LinkedList<>(List.of("antRef", "bda1", "bda2", "bda3")), "new value", input ); DataObject dataObject = new DataObject(); dataObject.setDoName("Do"); - dataObject.setSdoNames(List.of("sdo1","d")); + dataObject.setSdoNames(List.of("sdo1", "d")); DataAttribute dataAttribute = new DataAttribute(); dataAttribute.setDaName("antRef"); - dataAttribute.setBdaNames(List.of("bda1","bda2","bda3")); + dataAttribute.setBdaNames(List.of("bda1", "bda2", "bda3")); DoLinkedToDa doLinkedToDa = new DoLinkedToDa(); doLinkedToDa.setDataObject(dataObject); @@ -353,13 +356,13 @@ void updateOrCreateDOAndDAInstance_should_create_given_DO_and_DA_instances_when_ assertThat(tAnyLN.getDOI()).hasSize(1); assertThat(tAnyLN.getDOI().getFirst().getName()).isEqualTo("Mod"); assertThat(tAnyLN.getDOI().getFirst().getSDIOrDAI()).hasSize(1); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getName()).isEqualTo("stVal"); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).isSetVal()).isTrue(); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal()).hasSize(2); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().getFirst().getSGroup()).isEqualTo(1L); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().getFirst().getValue()).isEqualTo("new value"); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().get(1).getSGroup()).isEqualTo(2L); - assertThat(((TDAI)tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().get(1).getValue()).isEqualTo("new value 2"); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getName()).isEqualTo("stVal"); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).isSetVal()).isTrue(); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal()).hasSize(2); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().getFirst().getSGroup()).isEqualTo(1L); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().getFirst().getValue()).isEqualTo("new value"); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().get(1).getSGroup()).isEqualTo(2L); + assertThat(((TDAI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getVal().get(1).getValue()).isEqualTo("new value 2"); } @@ -387,34 +390,34 @@ void updateOrCreateDOAndDAInstance_should_create_given_DO_and_DA_instances_when_ assertThat(tAnyLN.getDOI()).hasSize(1); assertThat(tAnyLN.getDOI().getFirst().getName()).isEqualTo("Do"); assertThat(tAnyLN.getDOI().getFirst().getSDIOrDAI()).hasSize(1); - assertThat((( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getName()).isEqualTo("sdo1"); - assertThat((( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); - assertThat((( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getName()).isEqualTo("d"); - assertThat((( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); + assertThat(((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getName()).isEqualTo("sdo1"); + assertThat(((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); + assertThat(((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getName()).isEqualTo("d"); + assertThat(((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); - assertThat((( TSDI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TSDI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getName()).isEqualTo("antRef"); - assertThat((( TSDI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TSDI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); - assertThat((( TDAI )(( TSDI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getName()).isEqualTo("bda1"); - assertThat((( TDAI )(( TSDI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getVal()).hasSize(1); - assertThat((( TDAI )(( TSDI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getVal().getFirst().isSetSGroup()).isFalse(); - assertThat((( TDAI )(( TSDI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getVal().getFirst().getValue()).isEqualTo("new value"); } public static Collection testValImportValues() { - return Arrays.asList(new Object[][] { - { null, true, false, false }, - { null, false, false, false }, - { false, false, true, false }, - { false, true, true, true }, - { true, false, true, false }, - { true, true, true, true } + return Arrays.asList(new Object[][]{ + {null, true, false, false}, + {null, false, false, false}, + {false, false, true, false}, + {false, true, true, true}, + {true, false, true, false}, + {true, true, true, true} }); } @@ -453,27 +456,27 @@ void updateOrCreateDOAndDAInstance_should_complete_DO_and_DA_instances_modificat assertThat(tAnyLN.getDOI()).hasSize(1); assertThat(tAnyLN.getDOI().getFirst().getName()).isEqualTo("DoName1"); assertThat(tAnyLN.getDOI().getFirst().getSDIOrDAI()).hasSize(1); - assertThat((( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getName()).isEqualTo("SdoName1"); - assertThat((( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); + assertThat(((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getName()).isEqualTo("SdoName1"); + assertThat(((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); //final DAI - assertThat((( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getName()).isEqualTo("DaName2"); - assertThat((( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); - assertThat((( TDAI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getName()).isEqualTo("DaName2"); + assertThat(((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()).getSDIOrDAI()).hasSize(1); + assertThat(((TDAI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getName()).isEqualTo("BdaName1"); // ==> valImport Set - assertThat((( TDAI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).isSetValImport()).isEqualTo(expectedIsSetValImport); // ==> valImport Value - if(expectedIsSetValImport) { - assertThat((( TDAI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + if (expectedIsSetValImport) { + assertThat(((TDAI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).isValImport()).isEqualTo(expectedIsValImportValue); } - assertThat((( TDAI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getVal()).hasSize(1); // ==> DAI value - assertThat((( TDAI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getVal().getFirst().getValue()).isEqualTo("new dai value"); - assertThat((( TDAI )(( TSDI )(( TSDI )tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) + assertThat(((TDAI) ((TSDI) ((TSDI) tAnyLN.getDOI().getFirst().getSDIOrDAI().getFirst()).getSDIOrDAI().getFirst()) .getSDIOrDAI().getFirst()).getVal().getFirst().isSetSGroup()).isFalse(); } @@ -508,14 +511,14 @@ private TSDI createSDIFromSDI(TSDI sdi, String sdiName) { private TSDI createSDIByStructName(TSDI tsdi, LinkedList structNames) { structNames.remove(); - if(structNames.isEmpty() || structNames.size() == 1) return tsdi; + if (structNames.isEmpty() || structNames.size() == 1) return tsdi; return createSDIByStructName(createSDIFromSDI(tsdi, structNames.getFirst()), structNames); } private TAnyLN initDOAndDAInstances(LinkedList doInstances, LinkedList daInstances, String daiVal, - Boolean valImport){ + Boolean valImport) { assertThat(doInstances).isNotEmpty(); assertThat(daInstances).isNotEmpty(); LinkedList structInstances = new LinkedList<>(doInstances); @@ -524,10 +527,10 @@ private TAnyLN initDOAndDAInstances(LinkedList doInstances, TDOI tdoi = new TDOI(); tdoi.setName(doInstances.getFirst()); structInstances.remove(); - if(structInstances.size() > 1){ + if (structInstances.size() > 1) { TSDI firstSDI = createSDIFromDOI(tdoi, structInstances.getFirst()); TSDI lastSDI = createSDIByStructName(firstSDI, structInstances); - if(structInstances.size() == 1){ + if (structInstances.size() == 1) { TDAI dai = new TDAI(); dai.setName(daInstances.get(daInstances.size() - 1)); TVal tVal = new TVal(); @@ -536,8 +539,7 @@ private TAnyLN initDOAndDAInstances(LinkedList doInstances, if (valImport != null) dai.setValImport(valImport); lastSDI.getSDIOrDAI().add(dai); } - } else - if(structInstances.size() == 1){ + } else if (structInstances.size() == 1) { TDAI dai = new TDAI(); dai.setName(daInstances.get(daInstances.size() - 1)); TVal tVal = new TVal(); @@ -552,8 +554,8 @@ private TAnyLN initDOAndDAInstances(LinkedList doInstances, private TDAI initDOAndDAInstances(TAnyLN tAnyLN, - LinkedList doInstances, - LinkedList daInstances){ + LinkedList doInstances, + LinkedList daInstances) { assertThat(doInstances).isNotEmpty(); assertThat(daInstances).isNotEmpty(); LinkedList structInstances = new LinkedList<>(doInstances); @@ -562,18 +564,17 @@ private TDAI initDOAndDAInstances(TAnyLN tAnyLN, TDAI dai = new TDAI(); tdoi.setName(doInstances.getFirst()); structInstances.remove(); - if(structInstances.size() > 1){ + if (structInstances.size() > 1) { TSDI firstSDI = createSDIFromDOI(tdoi, structInstances.getFirst()); TSDI lastSDI = createSDIByStructName(firstSDI, structInstances); - if(structInstances.size() == 1){ + if (structInstances.size() == 1) { dai.setName(daInstances.get(daInstances.size() - 1)); TVal tVal = new TVal(); dai.getVal().add(tVal); lastSDI.getSDIOrDAI().add(dai); tAnyLN.getDOI().add(tdoi); } - } else - if(structInstances.size() == 1){ + } else if (structInstances.size() == 1) { dai.setName(daInstances.get(daInstances.size() - 1)); TVal tVal = new TVal(); dai.getVal().add(tVal); @@ -671,4 +672,16 @@ void matchesLn_should_throw_an_exception() { .hasMessageContaining("Unexpected value: "); } + @Test + void updateLnStatusBasedOnPrivateLNodeStatus_should_succeed() { + // Given + SCL scl = SclTestMarshaller.getSCLFromFile("/scl-lnodestatus/lnodestatus.scd"); + // When + List sclReportItems = lnService.updateLnModStValBasedOnLNodeStatus(scl); + // Then + assertThat(sclReportItems).isEmpty(); + assertThat(getValue(findDai(findLn(scl, "IED_NAME_1", "LDEVICE_1", "PDIS", "1", ""), "Mod.stVal"))) + .isEqualTo("on"); + } + } diff --git a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnKeyTest.java b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnIdTest.java similarity index 62% rename from sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnKeyTest.java rename to sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnIdTest.java index 4501f79d4..bdbff7a3b 100644 --- a/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnKeyTest.java +++ b/sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ln/LnIdTest.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -class LnKeyTest { +class LnIdTest { @Test void test_LnKey_withLN() { @@ -24,12 +24,11 @@ void test_LnKey_withLN() { ln.setInst("1"); ln.getLnClass().add(TSystemLNGroupEnum.LGOS.value()); // When - LnKey lnKey = new LnKey(ln); + LnId lnId = LnId.from(ln); // Then - assertThat(lnKey.getLnType()).isEqualTo("LnTypeAny"); - assertThat(lnKey.getLnClass()).isEqualTo("LGOS"); - assertThat(lnKey.getInst()).isEqualTo("1"); - assertThat(lnKey.getPrefix()).isEqualTo(StringUtils.EMPTY); + assertThat(lnId.lnClass()).isEqualTo("LGOS"); + assertThat(lnId.lnInst()).isEqualTo("1"); + assertThat(lnId.prefix()).isEqualTo(StringUtils.EMPTY); } @Test @@ -39,12 +38,11 @@ void test_LnKey_withLN0() { ln0.setLnType("LnType0"); ln0.getLnClass().add(TLLN0Enum.LLN_0.value()); // When - LnKey lnKey = new LnKey(ln0); + LnId lnId = LnId.from(ln0); // Then - assertThat(lnKey.getLnType()).isEqualTo("LnType0"); - assertThat(lnKey.getLnClass()).isEqualTo("LLN0"); - assertThat(lnKey.getInst()).isEqualTo(""); - assertThat(lnKey.getPrefix()).isEqualTo(StringUtils.EMPTY); + assertThat(lnId.lnClass()).isEqualTo("LLN0"); + assertThat(lnId.lnInst()).isEqualTo(""); + assertThat(lnId.prefix()).isEqualTo(StringUtils.EMPTY); } -} \ No newline at end of file +} diff --git a/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus.scd b/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus.scd new file mode 100644 index 000000000..a982faa69 --- /dev/null +++ b/sct-commons/src/test/resources/scl-lnodestatus/lnodestatus.scd @@ -0,0 +1,140 @@ + + + + + + + + SCD + +
+ + + 90 + + + + on + + + on + + + off + + + off + + + + + on + + + on + + + off + + + off + + + + + + + + + + + + on + + + + + + on;off + + + + + + on + + + + + + on;off + + + + + + off + + + + + + + + + + + + + + + on;off + + + + + + + + on + + + + + + + + on;off + + + + + + + + off + + + + + + + + + + + + + + + + + + + + on + off + test + + +