Skip to content

Commit

Permalink
Merge pull request #388 from com-pas/feat/355-rsr-988-use-generated-p…
Browse files Browse the repository at this point in the history
…ojo-defined-in-xsd-file-for-configuration-data-for-cb-and-data-creation

feat(#355): change setting file from CSV to XML
  • Loading branch information
samirromdhani authored Apr 9, 2024
2 parents 86509d1 + b36392d commit 452bbe1
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 20,991 deletions.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@
<junit-version>5.9.0</junit-version>
<logback-classic.version>1.4.5</logback-classic.version>
<assertj.version>3.22.0</assertj.version>
<!-- lombok est compatible jdk21 à partir de la 18.30-->
<!-- with version 18.30, lombok is compatible with JDK 21 -->
<lombok.version>1.18.30</lombok.version>
<mockito.version>5.5.0</mockito.version>
<jackson-databind.version>2.13.4.1</jackson-databind.version>

<!-- utils -->
<commons-beanutils.version>1.9.4</commons-beanutils.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -111,6 +114,12 @@
<artifactId>compas-scl-xsd</artifactId>
<version>${compas-scl-xsd.version}</version>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>commons</artifactId>
<version>${compas-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions sct-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class SclAutomationServiceTest {

@InjectMocks
private SclAutomationService sclAutomationService ;
private SclAutomationService sclAutomationService;
@Mock
private SclEditor sclEditor;
@Mock
Expand Down
30 changes: 23 additions & 7 deletions sct-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
<name>SCT-COMMONS</name>

<properties>
<opencsv.version>5.7.1</opencsv.version>
<jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version>
<jaxb-runtime.version>4.0.3</jaxb-runtime.version>
</properties>

<dependencies>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>commons</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -34,7 +38,7 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<!-- pour l'Object Mapper-->
<!-- for Object Mapper -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -84,11 +88,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -234,6 +233,23 @@
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>da_cb_com</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/main/resources/xsd/CB_COMM_V1.xsd</source>
</sources>
<xjbSources>
<xjbSource>${project.basedir}/src/main/resources/binding_configuration.xjb</xjbSource>
</xjbSources>
<packageName>org.lfenergy.compas.sct.commons.model.da_comm</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 @@ -8,10 +8,11 @@
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.api.ControlBlockEditor;
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.cbcom.*;
import org.lfenergy.compas.sct.commons.model.da_comm.DACOMM;
import org.lfenergy.compas.sct.commons.model.da_comm.FCDAs;
import org.lfenergy.compas.sct.commons.scl.ControlService;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
Expand Down Expand Up @@ -58,41 +59,11 @@ public List<SclReportItem> analyzeDataGroups(SCL scd) {
}

@Override
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, Set<FcdaForDataSetsCreation> allowedFcdas) {
checkFcdaInitDataPresence(allowedFcdas);
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, DACOMM dacomm) {
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) {
checkFcdaInitDataPresence(allowedFcdas);
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
return createDataSetAndControlBlocks(iedAdapter.streamLDeviceAdapters(), allowedFcdas);

}

@Override
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set<FcdaForDataSetsCreation> allowedFcdas) {
requireNotBlank(targetIedName, "IED.name parameter is missing");
checkFcdaInitDataPresence(allowedFcdas);
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(targetLDeviceInst);
return createDataSetAndControlBlocks(Stream.of(lDeviceAdapter), allowedFcdas);
}

private void checkFcdaInitDataPresence(Set<FcdaForDataSetsCreation> allowedFcdas) {
if (allowedFcdas == null || allowedFcdas.isEmpty()) {
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) {
return lDeviceAdapters
.map(lDeviceAdapter -> lDeviceAdapter.createDataSetAndControlBlocks(allowedFcdas))
return sclRootAdapter.streamIEDAdapters()
.flatMap(IEDAdapter::streamLDeviceAdapters)
.map(lDeviceAdapter -> lDeviceAdapter.createDataSetAndControlBlocks(dacomm.getFCDAs().getFCDA()))
.flatMap(List::stream)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.model.cbcom.CBCom;
import org.lfenergy.compas.sct.commons.model.da_comm.DACOMM;
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#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 All @@ -39,7 +35,6 @@ public interface ControlBlockEditor {
*/
void removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(final SCL scl);


/**
* Checks Control Blocks, DataSets and FCDA number limitation into Access Points
*
Expand All @@ -48,36 +43,14 @@ public interface ControlBlockEditor {
*/
List<SclReportItem> analyzeDataGroups(SCL scd);


/**
* 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
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, Set<FcdaForDataSetsCreation> 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
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, Set<FcdaForDataSetsCreation> 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
* @return list of encountered errors
* @param dacomm object containing a 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, DACOMM dacomm);

/**
* 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 @@ -9,9 +9,9 @@
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
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.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;
Expand Down Expand Up @@ -202,7 +202,7 @@ private AbstractLNAdapter<?> getLNAdapter() {
return parentAdapter;
}

public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(List<TFCDA> 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 @@ -235,7 +235,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, List<TFCDA> allowedFcdas) {
if (extRef.getServiceType() == null) {
return fatalReportItem(extRef, MESSAGE_SERVICE_TYPE_MISSING);
}
Expand Down Expand Up @@ -326,7 +326,7 @@ private static String generateDataSetSuffix(TExtRef extRef, DataAttributeRef sou
+ (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, List<TFCDA> allowedFcdas) {
sourceDas.removeIf(da -> da.getFc() != TFCEnum.MX && da.getFc() != TFCEnum.ST);
return switch (extRef.getServiceType()) {
case GOOSE, SMV -> {
Expand All @@ -338,15 +338,18 @@ private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Se
};
}

private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, Set<FcdaForDataSetsCreation> allowedFcdas) {
private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, List<TFCDA> 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.stream().anyMatch(tfcda -> tfcda.getDoName().equals(doName)
&& tfcda.getDaName().equals(daName)
&& tfcda.getLnClass().equals(lnClass)
&& tfcda.getFc().value().equals(fc));
}

private Optional<SclReportItem> removeFilterSourceDaForReport(TExtRef extRef, Set<DataAttributeRef> sourceDas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public List<AbstractLNAdapter<?>> getLNAdaptersIncludingLN0() {
return aLNAdapters;
}

public List<SclReportItem> createDataSetAndControlBlocks(Set<FcdaForDataSetsCreation> allowedFcdas) {
public List<SclReportItem> createDataSetAndControlBlocks(List<org.lfenergy.compas.sct.commons.model.da_comm.TFCDA> allowedFcdas) {
LN0Adapter ln0Adapter = getLN0Adapter();
if (!ln0Adapter.hasInputs()) {
return Collections.emptyList();
Expand Down
Loading

0 comments on commit 452bbe1

Please sign in to comment.