Skip to content

Commit

Permalink
feat(#355): use generated POJO defined in xsd for CB and DataSet crea…
Browse files Browse the repository at this point in the history
…tion as configuration data

Signed-off-by: Aliou DIAITE <aliou.diaite@rte-france.com>
  • Loading branch information
AliouDIAITE committed Nov 30, 2023
1 parent 0d76544 commit be8dbcb
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 20,696 deletions.
19 changes: 19 additions & 0 deletions sct-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>cb_po</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>
${project.basedir}/src/main/resources/xsd/CB_REPORT_SUPERVISION_Config_file.xsd
</source>
</sources>
<xjbSources>
<xjbSource>${project.basedir}/src/main/resources/binding_configuration.xjb</xjbSource>
</xjbSources>
<packageName>org.lfenergy.compas.sct.commons.model.cb_po</packageName>
<noPackageLevelAnnotations>true</noPackageLevelAnnotations>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.RangesPerCbType;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.Settings;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.SettingsOrError;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
Expand Down Expand Up @@ -42,15 +42,15 @@ public List<SclReportItem> analyzeDataGroups(SCL scd) {
}

@Override
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, PO allowedFcdas) {
checkFcdaInitDataPresence(allowedFcdas);
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
Stream<LDeviceAdapter> lDeviceAdapters = sclRootAdapter.streamIEDAdapters().flatMap(IEDAdapter::streamLDeviceAdapters);
return createDataSetAndControlBlocks(lDeviceAdapters, allowedFcdas);
}

@Override
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, PO allowedFcdas) {
checkFcdaInitDataPresence(allowedFcdas);
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
Expand All @@ -59,7 +59,7 @@ public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetI
}

@Override
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, PO allowedFcdas) {
if (StringUtils.isBlank(targetIedName)) {
throw new ScdException("IED.name parameter is missing");
}
Expand All @@ -70,13 +70,13 @@ public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetI
return createDataSetAndControlBlocks(Stream.of(lDeviceAdapter), allowedFcdas);
}

private void checkFcdaInitDataPresence(Set<FcdaForDataSetsCreation> allowedFcdas) {
if (allowedFcdas == null || allowedFcdas.isEmpty()) {
private void checkFcdaInitDataPresence(PO allowedFcdas) {
if (allowedFcdas == null || !allowedFcdas.isSetFCDAs() || !allowedFcdas.getFCDAs().isSetFCDA()) {
throw new ScdException("Accepted FCDAs list is empty, you should initialize allowed FCDA lists with CsvHelper class before");
}
}

private List<SclReportItem> createDataSetAndControlBlocks(Stream<LDeviceAdapter> lDeviceAdapters, Set<FcdaForDataSetsCreation> allowedFcdas) {
private List<SclReportItem> createDataSetAndControlBlocks(Stream<LDeviceAdapter> lDeviceAdapters, PO allowedFcdas) {
return lDeviceAdapters
.map(lDeviceAdapter -> lDeviceAdapter.createDataSetAndControlBlocks(allowedFcdas))
.flatMap(List::stream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.List;
import java.util.Set;

/**
* Service class that will be used to create, update or delete elements related to the {@link TExtRef <em>TExtRef</em>} object.
* <p> The following features are supported: </p>
* <ul>
* <li>ExtRef features</li>
* <ol>
* <li>{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, Set) <em>Create DataSet and ControlBlock based on the <b>TExtRef</b></em>}</li>
* <li>{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, String, Set) <em>Create DataSet and ControlBlock based on the <b>TExtRef</b> in given <b>IED</b></em>}</li>
* <li>{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, String,String, Set) <em>Create DataSet and ControlBlock based on the <b>TExtRef</b> in given <b>IED</b> and <b>LDevice</b></em>}</li>
* <li>{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, PO) <em>Create DataSet and ControlBlock based on the <b>TExtRef</b></em>}</li>
* <li>{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, PO) <em>Create DataSet and ControlBlock based on the <b>TExtRef</b> in given <b>IED</b></em>}</li>
* <li>{@link ControlBlockEditor#createDataSetAndControlBlocks(SCL, String, PO) <em>Create DataSet and ControlBlock based on the <b>TExtRef</b> in given <b>IED</b> and <b>LDevice</b></em>}</li>
* <li>{@link ControlBlockEditor#configureNetworkForAllControlBlocks <em>Configure the network for the <b>ControlBlocks</b></em>}</li>
* <li>{@link ControlBlockEditor#removeAllControlBlocksAndDatasetsAndExtRefSrcBindings <em>Removes all ControlBlocks and DataSets for all LNs in <b>SCL</b></em>}</li>
* <li>{@link ControlBlockEditor#analyzeDataGroups(SCL)} <em>Checks Control Blocks, DataSets and FCDA number limitation into Access Points </em>}</li>
Expand Down Expand Up @@ -53,31 +52,31 @@ public interface ControlBlockEditor {
* Create All DataSet and ControlBlock in the SCL based on the ExtRef
*
* @param scd input SCD object. It could be modified by adding new DataSet and ControlBlocks
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
* @param allowedFcdas object containing list of allowed FCDA for DataSets and Control Blocks creation
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, Set<FcdaForDataSetsCreation> allowedFcdas);
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, PO allowedFcdas);

/**
* Create All DataSet and ControlBlock for the ExtRef in given IED
*
* @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
* @param targetIedName the name of the IED where the ExtRef are
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
* @param allowedFcdas object containing list of allowed FCDA for DataSets and Control Blocks creation
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, Set<FcdaForDataSetsCreation> allowedFcdas);
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, PO allowedFcdas);

/**
* Create All DataSet and ControlBlock for the ExtRef in given IED and LDevice
*
* @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
* @param targetIedName the name of the IED where the ExtRef are
* @param targetLDeviceInst the name of the LDevice where the ExtRef are
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
* @param allowedFcdas object containing list of allowed FCDA for DataSets and Control Blocks creation
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set<FcdaForDataSetsCreation> allowedFcdas);
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, PO allowedFcdas);

/**
* Configure the network for all the ControlBlocks.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.ExtRefService;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
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;
Expand Down Expand Up @@ -73,6 +73,17 @@ public InputsAdapter(LN0Adapter parentAdapter, TInputs tInputs) {
super(parentAdapter, tInputs);
}

private static String generateDataSetSuffix(TExtRef extRef, DataAttributeRef sourceDa, boolean isBayInternal) {
return extRef.getLdInst().toUpperCase(Locale.ENGLISH) + ATTRIBUTE_VALUE_SEPARATOR
+ switch (extRef.getServiceType()) {
case GOOSE -> "G" + ((sourceDa.getFc() == TFCEnum.ST) ? "S" : "M");
case SMV -> "SV";
case REPORT -> (sourceDa.getFc() == TFCEnum.ST) ? "DQC" : "CYC";
case POLL -> throw new IllegalArgumentException(MESSAGE_POLL_SERVICE_TYPE_NOT_SUPPORTED);
}
+ (isBayInternal ? "I" : "E");
}

/**
* Check if current element is a child of the parent element
*
Expand Down Expand Up @@ -179,7 +190,8 @@ private Optional<SclReportItem> validateExtRefSource(TExtRef extRef, IEDAdapter
try {
ActiveStatus lDeviceStatus = ActiveStatus.fromValue(sourceLDeviceStatus);
return switch (lDeviceStatus) {
case OFF -> SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF, sourceLDevice.getXPath()));
case OFF ->
SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF, sourceLDevice.getXPath()));
case ON -> null;
};
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -259,7 +271,7 @@ private AbstractLNAdapter<?> getLNAdapter() {
return parentAdapter;
}

public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(PO allowedFcdas) {
String currentBayUuid = getIedAdapter().getPrivateCompasBay().map(TCompasBay::getUUID).orElse(null);
if (StringUtils.isBlank(currentBayUuid)) {
return List.of(getIedAdapter().buildFatalReportItem(MESSAGE_IED_MISSING_COMPAS_BAY_UUID));
Expand Down Expand Up @@ -292,7 +304,7 @@ private boolean areBindingAttributesPresent(TExtRef tExtRef) {
&& StringUtils.isNotBlank(tExtRef.getDoName());
}

private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid, Set<FcdaForDataSetsCreation> allowedFcdas) {
private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid, PO allowedFcdas) {
if (extRef.getServiceType() == null) {
return fatalReportItem(extRef, MESSAGE_SERVICE_TYPE_MISSING);
}
Expand Down Expand Up @@ -372,18 +384,7 @@ private void setExtRefSrcAttributes(TExtRef extRef, String cbName) {
extRef.unsetSrcLNClass();
}

private static String generateDataSetSuffix(TExtRef extRef, DataAttributeRef sourceDa, boolean isBayInternal) {
return extRef.getLdInst().toUpperCase(Locale.ENGLISH) + ATTRIBUTE_VALUE_SEPARATOR
+ switch (extRef.getServiceType()) {
case GOOSE -> "G" + ((sourceDa.getFc() == TFCEnum.ST) ? "S" : "M");
case SMV -> "SV";
case REPORT -> (sourceDa.getFc() == TFCEnum.ST) ? "DQC" : "CYC";
case POLL -> throw new IllegalArgumentException(MESSAGE_POLL_SERVICE_TYPE_NOT_SUPPORTED);
}
+ (isBayInternal ? "I" : "E");
}

private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Set<DataAttributeRef> sourceDas, Set<FcdaForDataSetsCreation> allowedFcdas) {
private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Set<DataAttributeRef> sourceDas, PO allowedFcdas) {
sourceDas.removeIf(da -> da.getFc() != TFCEnum.MX && da.getFc() != TFCEnum.ST);
return switch (extRef.getServiceType()) {
case GOOSE, SMV -> {
Expand All @@ -395,15 +396,19 @@ private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Se
};
}

private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, Set<FcdaForDataSetsCreation> allowedFcdas) {
private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, PO allowedFcdas) {
String lnClass = dataAttributeRef.getLnClass();
String doName = dataAttributeRef.getDoName().toStringWithoutInst();
String daName = dataAttributeRef.getDaName().toString();
String fc = dataAttributeRef.getFc().value();
if (StringUtils.isBlank(lnClass) || StringUtils.isBlank(doName) || StringUtils.isBlank(daName) || StringUtils.isBlank(fc)) {
throw new IllegalArgumentException("parameters must not be blank");
}
return allowedFcdas.contains(new FcdaForDataSetsCreation(lnClass, doName, daName, fc));
return allowedFcdas.getFCDAs().getFCDA().stream()
.anyMatch(tFcdaFilter -> lnClass.equals(tFcdaFilter.getLnClass())
&& doName.equals(tFcdaFilter.getDoName())
&& daName.equals(tFcdaFilter.getDaName())
&& fc.equals(tFcdaFilter.getFc().value()));
}

private Optional<SclReportItem> removeFilterSourceDaForReport(TExtRef extRef, Set<DataAttributeRef> sourceDas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter;
Expand Down Expand Up @@ -357,7 +358,7 @@ public List<AbstractLNAdapter<?>> getLNAdaptersIncludingLN0() {
return aLNAdapters;
}

public List<SclReportItem> createDataSetAndControlBlocks(Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> createDataSetAndControlBlocks(PO allowedFcdas) {
LN0Adapter ln0Adapter = getLN0Adapter();
if (!ln0Adapter.hasInputs()) {
return Collections.emptyList();
Expand Down
Loading

0 comments on commit be8dbcb

Please sign in to comment.