Skip to content

Commit

Permalink
Merge pull request #275 from com-pas/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
AliouDIAITE authored Apr 18, 2023
2 parents 6cb2401 + c4c1c2d commit c5e74c7
Show file tree
Hide file tree
Showing 66 changed files with 1,282 additions and 386 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@

<properties>
<java.version>17</java.version>
<compas.core.version>local-SNAPSHOT</compas.core.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.coverage.exclusions>sct-coverage/**</sonar.coverage.exclusions>
<aggregate.report.dir>../sct-coverage/target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
<compas-core.version>0.13.0</compas-core.version>
<compas-core.version>0.14.0</compas-core.version>
<compas-scl-xsd.version>0.0.4</compas-scl-xsd.version>
<maven.plugin.javadoc>3.4.1</maven.plugin.javadoc>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
Expand Down
6 changes: 5 additions & 1 deletion sct-app/src/test/resources/std_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
<compas:SystemVersion MainSystemVersion="01.00" MinorSystemVersion="009.001.001"/>
</Private>
<Private type="COMPAS-ICDHeader">
<compas:ICDHeader IEDType="SCU" ICDSystemVersionUUID="b4f8089e-4170-47f1-b6ad-dd1f50885518" VendorName="RTE" IEDredundancy="A" IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00" headerId="f8dbc8c1-2db7-4652-a9d6-0b414bdeccfa" headerVersion="01.00.00" headerRevision="01.00.00"/>
<compas:ICDHeader IEDType="SCU" ICDSystemVersionUUID="b4f8089e-4170-47f1-b6ad-dd1f50885518"
IEDSystemVersioninstance="1" IEDSubstationinstance="1" VendorName="RTE" IEDredundancy="A"
IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00"
headerId="f8dbc8c1-2db7-4652-a9d6-0b414bdeccfa" headerVersion="01.00.00"
headerRevision="01.00.00"/>
</Private>
<Services nameLength="64">
<ConfLNs fixPrefix="true" fixLnInst="true"/>
Expand Down
6 changes: 5 additions & 1 deletion sct-app/src/test/resources/std_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
<compas:SystemVersion MainSystemVersion="01.00" MinorSystemVersion="009.001.001"/>
</Private>
<Private type="COMPAS-ICDHeader">
<compas:ICDHeader IEDType="PDB" ICDSystemVersionUUID="ad27d262-7c90-46df-b480-68088f9fe8a4" VendorName="RTE" IEDredundancy="A" IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00" headerId="6b4d51eb-c391-4eef-b118-f516bc09f20c" headerVersion="01.00.00" headerRevision="01.00.00"/>
<compas:ICDHeader IEDType="PDB" ICDSystemVersionUUID="ad27d262-7c90-46df-b480-68088f9fe8a4"
IEDSubstationinstance="1" IEDSystemVersioninstance="1" VendorName="RTE" IEDredundancy="A"
IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00"
headerId="6b4d51eb-c391-4eef-b118-f516bc09f20c" headerVersion="01.00.00"
headerRevision="01.00.00"/>
</Private>
<Services nameLength="64">
<ConfLNs fixPrefix="true" fixLnInst="true"/>
Expand Down
6 changes: 5 additions & 1 deletion sct-app/src/test/resources/std_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
<compas:SystemVersion MainSystemVersion="01.00" MinorSystemVersion="009.001.001"/>
</Private>
<Private type="COMPAS-ICDHeader">
<compas:ICDHeader IEDType="BCU" ICDSystemVersionUUID="ed36220c-5577-4f0c-aaef-c6efa9f7d7c8" VendorName="RTE" IEDredundancy="A" IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00" headerId="9aea4c6f-7ab8-4341-8d84-14c17d73a57d" headerVersion="01.00.00" headerRevision="01.00.00"/>
<compas:ICDHeader IEDType="BCU" ICDSystemVersionUUID="ed36220c-5577-4f0c-aaef-c6efa9f7d7c8"
IEDSubstationinstance="1" IEDSystemVersioninstance="1" VendorName="RTE" IEDredundancy="A"
IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00"
headerId="9aea4c6f-7ab8-4341-8d84-14c17d73a57d" headerVersion="01.00.00"
headerRevision="01.00.00"/>
</Private>
<Services nameLength="64">
<ConfLNs fixPrefix="true" fixLnInst="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.util.Objects;

import static org.lfenergy.compas.scl2007b4.model.TControlWithIEDName.IEDName;
import static org.lfenergy.compas.sct.commons.util.Utils.emptyIfBlank;
import static org.lfenergy.compas.sct.commons.util.Utils.nullIfBlank;

/**
* Record that hold the data for TClientLN and TControlWithIEDName.IEDName which have the same fields.
Expand Down Expand Up @@ -50,8 +48,8 @@ public TClientLN toTClientLn() {
newTClientLn.getLnClass().add(lnClass);
}
// LnInst is required on TClientLN, so it cannot be null, but it can be empty
newTClientLn.setLnInst(emptyIfBlank(lnInst));
newTClientLn.setPrefix(nullIfBlank(prefix));
newTClientLn.setLnInst(StringUtils.trimToEmpty(lnInst));
newTClientLn.setPrefix(StringUtils.trimToNull(prefix));
newTClientLn.setDesc(desc);
return newTClientLn;
}
Expand All @@ -69,8 +67,8 @@ public IEDName toIedName() {
newIedName.getLnClass().add(lnClass);
}
// LnInst is optional on IEDName, so it can be null, but cannot be empty
newIedName.setLnInst(nullIfBlank(lnInst));
newIedName.setPrefix(nullIfBlank(prefix));
newIedName.setLnInst(StringUtils.trimToNull(lnInst));
newIedName.setPrefix(StringUtils.trimToNull(prefix));
return newIedName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;
Expand All @@ -15,7 +16,7 @@
import java.util.Optional;

import static org.lfenergy.compas.sct.commons.util.CommonConstants.MOD_DO_NAME;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.STVAL_DA_NAME;


/**
Expand Down Expand Up @@ -54,13 +55,23 @@ public class ResumedDataTemplate {
/**
* Constructor
*/
public ResumedDataTemplate(AbstractLNAdapter<?> lnAdapter, String doName, String daName) {
public ResumedDataTemplate(AbstractLNAdapter<?> lnAdapter, DoTypeName doName, DaTypeName daName) {
this.lnClass = lnAdapter.getLNClass();
this.lnInst = lnAdapter.getLNInst();
this.prefix = lnAdapter.getPrefix();
this.lnType = lnAdapter.getLnType();
this.doName = new DoTypeName(doName);
this.daName = new DaTypeName(daName);
this.doName = doName;
this.daName = daName;
}

public ResumedDataTemplate(TFCDA fcda) {
this.lnClass = fcda.isSetLnClass() ? fcda.getLnClass().get(0) : null;
this.lnInst = fcda.getLnInst();
this.prefix = fcda.getPrefix();
this.lnType = null;
this.doName = new DoTypeName(StringUtils.trimToEmpty(fcda.getDoName()));
this.daName = new DaTypeName(StringUtils.trimToEmpty(fcda.getDaName()));
if (daName.isDefined()) this.setFc(fcda.getFc());
}

/**
Expand Down Expand Up @@ -94,7 +105,7 @@ public boolean isUpdatable(){
* @return true if DO is "Mod" and DA is "stVal", false otherwise
*/
private boolean isDOModDAstVal(){
return doName.getName().equals(MOD_DO_NAME) && daName.getName().equals(STVAL);
return doName.getName().equals(MOD_DO_NAME) && daName.getName().equals(STVAL_DA_NAME);
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.lfenergy.compas.sct.commons.scl;

import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TCompasICDHeader;
Expand All @@ -30,11 +29,14 @@
import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.*;
import static org.lfenergy.compas.sct.commons.util.Utils.isExtRefFeedBySameControlBlock;

@UtilityClass
public class ExtRefService {
public final class ExtRefService {

private static final String MESSAGE_MISSING_IED_NAME_PARAMETER = "IED.name parameter is missing";

private ExtRefService() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
* Updates iedName attribute of all ExtRefs in the Scd.
*
Expand Down Expand Up @@ -203,7 +205,7 @@ private static List<SclReportItem> configureNetworkForControlBlocks(SCL scd, Con

private static Optional<SclReportItem> configureControlBlockNetwork(ControlBlockNetworkSettings controlBlockNetworkSettings, PrimitiveIterator.OfLong appIdIterator, Iterator<String> macAddressIterator, ControlBlockAdapter controlBlockAdapter) {
SettingsOrError settingsOrError = controlBlockNetworkSettings.getNetworkSettings(controlBlockAdapter);
if (settingsOrError.errorMessage() != null){
if (settingsOrError.errorMessage() != null) {
return Optional.of(controlBlockAdapter.buildFatalReportItem(
"Cannot configure network for this ControlBlock because: " + settingsOrError.errorMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.scl;

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TFCDA;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;

import java.util.List;

public final class HmiService {

private HmiService() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
* Create the DataSet and ReportControl Blocks for the HMI with the given FCDAs.
*
* @param fcdas List of FCDA for which we must create the DataSet and ReportControl Blocks
*/
public static void createAllHmiReportControlBlocks(SCL scd, List<TFCDA> fcdas) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
sclRootAdapter.streamIEDAdapters()
.flatMap(IEDAdapter::streamLDeviceAdapters)
.forEach(lDeviceAdapter -> lDeviceAdapter.createHmiReportControlBlocks(fcdas));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.scl2007b4.model.TLLN0Enum;
import org.lfenergy.compas.sct.commons.dto.ExtrefTarget;
import org.lfenergy.compas.sct.commons.util.Utils;

/**
* A representation of the model object
Expand Down Expand Up @@ -55,16 +54,22 @@ public ObjectReference(String reference) {
public ObjectReference(TExtRef extRef, ExtrefTarget target) {
this.ldName = extRef.getIedName() + extRef.getLdInst();
if(target.equals(ExtrefTarget.SRC_REF)) {
this.lNodeName = Utils.emptyIfBlank(extRef.getPrefix())
+ (extRef.isSetLnClass() ? extRef.getLnClass().get(0): TLLN0Enum.LLN_0.value())
+ Utils.emptyIfBlank(extRef.getLnInst());
this.dataAttributes = Utils.emptyIfBlank(extRef.getDoName());
String s1 = extRef.getLnInst();
String s2 = extRef.getPrefix();
this.lNodeName = StringUtils.trimToEmpty(s2)
+ (extRef.isSetLnClass() ? extRef.getLnClass().get(0) : TLLN0Enum.LLN_0.value())
+ StringUtils.trimToEmpty(s1);
String s = extRef.getDoName();
this.dataAttributes = StringUtils.trimToEmpty(s);
}
if(target.equals(ExtrefTarget.SRC_CB)) {
this.lNodeName = Utils.emptyIfBlank(extRef.getSrcPrefix())
+ (extRef.isSetSrcLNClass() ? extRef.getSrcLNClass().get(0): TLLN0Enum.LLN_0.value())
+ Utils.emptyIfBlank(extRef.getSrcLNInst());
this.dataAttributes = Utils.emptyIfBlank(extRef.getSrcCBName());
String s1 = extRef.getSrcLNInst();
String s2 = extRef.getSrcPrefix();
this.lNodeName = StringUtils.trimToEmpty(s2)
+ (extRef.isSetSrcLNClass() ? extRef.getSrcLNClass().get(0) : TLLN0Enum.LLN_0.value())
+ StringUtils.trimToEmpty(s1);
String s = extRef.getSrcCBName();
this.dataAttributes = StringUtils.trimToEmpty(s);
}
this.reference = this.ldName + "/" + this.lNodeName + "." + this.dataAttributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setValImport(boolean b) {

private boolean isDOModDAstVal() {
if (parentAdapter.getCurrentElem() instanceof final TDOI tdoi) {
return currentElem.getName().equals(CommonConstants.STVAL) && tdoi.getName().equals(CommonConstants.MOD_DO_NAME);
return currentElem.getName().equals(CommonConstants.STVAL_DA_NAME) && tdoi.getName().equals(CommonConstants.MOD_DO_NAME);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.stream.Collectors;
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;


/**
* A representation of the model object
Expand Down Expand Up @@ -73,6 +76,10 @@
public abstract class AbstractLNAdapter<T extends TAnyLN> extends SclElementAdapter<LDeviceAdapter, T> {


public static final DoTypeName MOD_DO_TYPE_NAME = new DoTypeName(MOD_DO_NAME);
public static final DaTypeName STVAL_DA_TYPE_NAME = new DaTypeName(STVAL_DA_NAME);
private static final String DAI_MOD_STVAL_VALUE_ON = "on";

/**
* Constructor
*
Expand Down Expand Up @@ -967,6 +974,17 @@ public Stream<ControlBlockAdapter> streamControlBlocks(ControlBlockEnum controlB
.map(tControl -> new ControlBlockAdapter(this, tControl));
}

/**
* Create ControlBlock if there is no ControlBlock of the same type (controlBlockEnum) and with the same cbName in this LN/LN0.
* When the controlBlock already exists, the id and datSet attributes are NOT updated with the given values.
*
* @param cbName cbName of the controlBlock to look for. When not found, the cbName of the controlBlock to create.
* @param id When controlBlock not found, the id of the controlBlock to create
* @param datSet the datSet of the controlBlock to create
* @param controlBlockEnum the type of ControlBlock to create
* @return existing controlBlock if a controlBlock of the same type and with same cbName was found in this LN/LN0, otherwise the created ControlBlock.
* The returned ControlBlock is always a child of this LN/LN0.
*/
public ControlBlockAdapter createControlBlockIfNotExists(String cbName, String id, String datSet, ControlBlockEnum controlBlockEnum) {
return findControlBlock(cbName, controlBlockEnum)
.orElseGet(() -> addControlBlock(
Expand All @@ -980,6 +998,25 @@ public ControlBlockAdapter createControlBlockIfNotExists(String cbName, String i
);
}

/**
* Generate a ControlBlock Id based on the current LN and the given ldName (ldName can be different from the parent LD.name)
*
* @param ldName LD name to use for generating the id
* @param cbName name of the ControlBlock
* @return "ldName/LnPrefixLnClassLnInst.cbName". Blank values are omitted (e.g "IEDNAME1LD1/LLN0.CBNAME1")
*/
public String generateControlBlockId(String ldName, String cbName) {
String s = getLNInst();
String s1 = getPrefix();
return StringUtils.trimToEmpty(ldName)
+ "/"
+ StringUtils.trimToEmpty(s1)
+ StringUtils.defaultString(getLNClass(), "")
+ StringUtils.trimToEmpty(s)
+ "."
+ StringUtils.trimToEmpty(cbName);
}

/**
* Finds all FCDAs in DataSet of Control Block feeding ExtRef
*
Expand All @@ -997,4 +1034,20 @@ public List<TFCDA> getFCDAs(TExtRef tExtRef) {
.flatMap(Collection::stream)
.toList();
}

/**
* Get the value of "Mod.stVal" of the current LN
*
* @return Mod.stVal value if present, else empty Optional
*/
public Optional<String> getDaiModStValValue() {
return getDaiModStVal()
.flatMap(ResumedDataTemplate::findFirstValue);
}

protected Optional<ResumedDataTemplate> getDaiModStVal() {
ResumedDataTemplate daiModFilter = new ResumedDataTemplate(this, MOD_DO_TYPE_NAME, STVAL_DA_TYPE_NAME);
return getDAI(daiModFilter, false).stream()
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newDurationInMilliSec;
import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newP;
import static org.lfenergy.compas.sct.commons.util.Utils.xpathAttributeFilter;

/**
Expand Down Expand Up @@ -147,16 +148,16 @@ public Optional<SclReportItem> configureNetwork(long appId, String macAddress, I
}
ConnectedAPAdapter connectedAPAdapter = optConApAdapter.get();
List<TP> listOfPs = new ArrayList<>();
listOfPs.add(SclConstructorHelper.newP(APPID_P_TYPE, Utils.toHex(appId, APPID_LENGTH)));
listOfPs.add(SclConstructorHelper.newP(MAC_ADDRESS_P_TYPE, macAddress));
listOfPs.add(newP(APPID_P_TYPE, Utils.toHex(appId, APPID_LENGTH)));
listOfPs.add(newP(MAC_ADDRESS_P_TYPE, macAddress));
if (vlanId != null) {
listOfPs.add(SclConstructorHelper.newP(VLAN_ID_P_TYPE, Utils.toHex(vlanId, VLAN_ID_LENGTH)));
listOfPs.add(newP(VLAN_ID_P_TYPE, Utils.toHex(vlanId, VLAN_ID_LENGTH)));
if (vlanPriority != null) {
listOfPs.add(SclConstructorHelper.newP(VLAN_PRIORITY_P_TYPE, String.valueOf(vlanPriority)));
listOfPs.add(newP(VLAN_PRIORITY_P_TYPE, String.valueOf(vlanPriority)));
}
}
switch (getControlBlockEnum()) {
case GSE -> connectedAPAdapter.updateGseOrCreateIfNotExists(getParentLDeviceAdapter().getInst(), currentElem.getName(), listOfPs, clone(minTime), clone(maxTime));
case GSE -> connectedAPAdapter.updateGseOrCreateIfNotExists(getParentLDeviceAdapter().getInst(), currentElem.getName(), listOfPs, newDurationInMilliSec(minTime), newDurationInMilliSec(maxTime));
case SAMPLED_VALUE -> connectedAPAdapter.updateSmvOrCreateIfNotExists(getParentLDeviceAdapter().getInst(), currentElem.getName(), listOfPs);
default -> {
return Optional.of(buildFatalReportItem("configureNetwork not yet implemented for %s ControlBlocks".formatted(getControlBlockEnum())));
Expand All @@ -165,13 +166,6 @@ public Optional<SclReportItem> configureNetwork(long appId, String macAddress, I
return Optional.empty();
}

private TDurationInMilliSec clone(TDurationInMilliSec tDurationInMilliSec){
if (tDurationInMilliSec == null) {
return null;
}
return SclConstructorHelper.newDurationInMilliSec(tDurationInMilliSec.getValue(), tDurationInMilliSec.getUnit(), tDurationInMilliSec.getMultiplier());
}

/**
* Get parent LDevice
* @return ControlBlock's parent lDeviceAdapter
Expand Down
Loading

0 comments on commit c5e74c7

Please sign in to comment.