Skip to content

Commit c374dd0

Browse files
committed
feat(#332): move FCDA parameter csv file management out of compas
Signed-off-by: Aliou DIAITE <[email protected]>
1 parent a68f379 commit c374dd0

File tree

12 files changed

+237
-20457
lines changed

12 files changed

+237
-20457
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/ExtRefService.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,41 +112,50 @@ public List<SclReportItem> updateAllExtRefIedNames(SCL scd) {
112112
}
113113

114114
@Override
115-
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd) {
115+
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, Set<FcdaForDataSetsCreation> allowedFcdas) {
116+
checkFcdaInitDataPresence(allowedFcdas);
116117
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
117118
Stream<LDeviceAdapter> lDeviceAdapters = sclRootAdapter.streamIEDAdapters().flatMap(IEDAdapter::streamLDeviceAdapters);
118-
return createDataSetAndControlBlocks(lDeviceAdapters);
119+
return createDataSetAndControlBlocks(lDeviceAdapters, allowedFcdas);
119120
}
120121

121122
@Override
122-
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName) {
123+
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, Set<FcdaForDataSetsCreation> allowedFcdas) {
124+
checkFcdaInitDataPresence(allowedFcdas);
123125
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
124126
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
125-
return createDataSetAndControlBlocks(iedAdapter.streamLDeviceAdapters());
127+
return createDataSetAndControlBlocks(iedAdapter.streamLDeviceAdapters(), allowedFcdas);
126128

127129
}
128130

129131
@Override
130-
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst) {
132+
public List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set<FcdaForDataSetsCreation> allowedFcdas) {
131133
if (StringUtils.isBlank(targetIedName)) {
132134
throw new ScdException("IED.name parameter is missing");
133135
}
136+
checkFcdaInitDataPresence(allowedFcdas);
134137
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
135138
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(targetIedName);
136139
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(targetLDeviceInst);
137-
return createDataSetAndControlBlocks(Stream.of(lDeviceAdapter));
140+
return createDataSetAndControlBlocks(Stream.of(lDeviceAdapter), allowedFcdas);
138141
}
139142

140-
private List<SclReportItem> createDataSetAndControlBlocks(Stream<LDeviceAdapter> lDeviceAdapters) {
143+
private void checkFcdaInitDataPresence(Set<FcdaForDataSetsCreation> allowedFcdas) {
144+
if (allowedFcdas == null || allowedFcdas.isEmpty()) {
145+
throw new ScdException("Accepted FCDAs list is empty, you should initialize allowed FCDA lists with CsvHelper class before");
146+
}
147+
}
148+
149+
private List<SclReportItem> createDataSetAndControlBlocks(Stream<LDeviceAdapter> lDeviceAdapters, Set<FcdaForDataSetsCreation> allowedFcdas) {
141150
return lDeviceAdapters
142-
.map(LDeviceAdapter::createDataSetAndControlBlocks)
151+
.map(lDeviceAdapter -> lDeviceAdapter.createDataSetAndControlBlocks(allowedFcdas))
143152
.flatMap(List::stream)
144153
.toList();
145154
}
146155

147156
@Override
148157
public List<SclReportItem> configureNetworkForAllControlBlocks(SCL scd, ControlBlockNetworkSettings controlBlockNetworkSettings,
149-
RangesPerCbType rangesPerCbType) {
158+
RangesPerCbType rangesPerCbType) {
150159
List<SclReportItem> sclReportItems = new ArrayList<>();
151160
sclReportItems.addAll(configureNetworkForControlBlocks(scd, controlBlockNetworkSettings, rangesPerCbType.gse(), ControlBlockEnum.GSE));
152161
sclReportItems.addAll(configureNetworkForControlBlocks(scd, controlBlockNetworkSettings, rangesPerCbType.sampledValue(), ControlBlockEnum.SAMPLED_VALUE));

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/ExtRefEditor.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
import org.lfenergy.compas.scl2007b4.model.SCL;
88
import org.lfenergy.compas.scl2007b4.model.TExtRef;
9-
import org.lfenergy.compas.sct.commons.dto.*;
9+
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
10+
import org.lfenergy.compas.sct.commons.dto.ExtRefInfo;
11+
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
12+
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
1013
import org.lfenergy.compas.sct.commons.exception.ScdException;
1114
import org.lfenergy.compas.sct.commons.util.ILDEPFSettings;
1215
import org.lfenergy.compas.sct.commons.util.Utils;
1316

1417
import java.util.List;
18+
import java.util.Set;
1519

1620
/**
1721
* Service class that will be used to create, update or delete elements related to the {@link TExtRef <em>TExtRef</em>} object.
@@ -61,29 +65,32 @@ public interface ExtRefEditor {
6165
/**
6266
* Create All DataSet and ControlBlock in the SCL based on the ExtRef
6367
*
64-
* @param scd input SCD object. It could be modified by adding new DataSet and ControlBlocks
68+
* @param scd input SCD object. It could be modified by adding new DataSet and ControlBlocks
69+
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
6570
* @return list of encountered errors
6671
*/
67-
List<SclReportItem> createDataSetAndControlBlocks(SCL scd);
72+
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, Set<FcdaForDataSetsCreation> allowedFcdas);
6873

6974
/**
7075
* Create All DataSet and ControlBlock for the ExtRef in given IED
7176
*
7277
* @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
7378
* @param targetIedName the name of the IED where the ExtRef are
79+
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
7480
* @return list of encountered errors
7581
*/
76-
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName);
82+
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, Set<FcdaForDataSetsCreation> allowedFcdas);
7783

7884
/**
7985
* Create All DataSet and ControlBlock for the ExtRef in given IED and LDevice
8086
*
8187
* @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
8288
* @param targetIedName the name of the IED where the ExtRef are
8389
* @param targetLDeviceInst the name of the LDevice where the ExtRef are
90+
* @param allowedFcdas List of allowed FCDA for DataSets and Control Blocks creation
8491
* @return list of encountered errors
8592
*/
86-
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst);
93+
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst, Set<FcdaForDataSetsCreation> allowedFcdas);
8794

8895
/**
8996
* Configure the network for all the ControlBlocks.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* // SPDX-FileCopyrightText: 2023 RTE FRANCE
3+
* //
4+
* // SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package org.lfenergy.compas.sct.commons.dto;
8+
9+
import com.opencsv.bean.CsvBindByPosition;
10+
import lombok.AllArgsConstructor;
11+
import lombok.EqualsAndHashCode;
12+
import lombok.Getter;
13+
import lombok.NoArgsConstructor;
14+
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
@Getter
18+
@EqualsAndHashCode
19+
public class FcdaForDataSetsCreation {
20+
21+
@CsvBindByPosition(position = 0)
22+
private String lnClass;
23+
@CsvBindByPosition(position = 1)
24+
private String doName;
25+
@CsvBindByPosition(position = 2)
26+
private String daName;
27+
@CsvBindByPosition(position = 3)
28+
private String fc;
29+
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/InputsAdapter.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
import lombok.extern.slf4j.Slf4j;
99
import org.apache.commons.lang3.StringUtils;
1010
import org.lfenergy.compas.scl2007b4.model.*;
11+
import org.lfenergy.compas.sct.commons.ExtRefService;
1112
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
13+
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
1214
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
1315
import org.lfenergy.compas.sct.commons.exception.ScdException;
14-
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
1516
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1617
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
17-
import org.lfenergy.compas.sct.commons.ExtRefService;
1818
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
19-
import org.lfenergy.compas.sct.commons.util.FcdaCandidates;
2019
import org.lfenergy.compas.sct.commons.util.LdeviceStatus;
20+
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
2121
import org.lfenergy.compas.sct.commons.util.Utils;
2222

2323
import java.util.*;
@@ -257,7 +257,7 @@ private AbstractLNAdapter<?> getLNAdapter() {
257257
return parentAdapter;
258258
}
259259

260-
public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks() {
260+
public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(Set<FcdaForDataSetsCreation> allowedFcdas) {
261261
String currentBayUuid = getIedAdapter().getPrivateCompasBay().map(TCompasBay::getUUID).orElse(null);
262262
if (StringUtils.isBlank(currentBayUuid)) {
263263
return List.of(getIedAdapter().buildFatalReportItem(MESSAGE_IED_MISSING_COMPAS_BAY_UUID));
@@ -266,7 +266,7 @@ public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks() {
266266
.filter(this::areBindingAttributesPresent)
267267
.filter(this::isExternalBound)
268268
.filter(this::matchingCompasFlowIsActiveOrUntested)
269-
.map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid))
269+
.map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid, allowedFcdas))
270270
.flatMap(Optional::stream)
271271
.toList();
272272
}
@@ -290,7 +290,7 @@ private boolean areBindingAttributesPresent(TExtRef tExtRef) {
290290
&& StringUtils.isNotBlank(tExtRef.getDoName());
291291
}
292292

293-
private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid) {
293+
private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid, Set<FcdaForDataSetsCreation> allowedFcdas) {
294294
if (extRef.getServiceType() == null) {
295295
return fatalReportItem(extRef, MESSAGE_SERVICE_TYPE_MISSING);
296296
}
@@ -318,7 +318,7 @@ private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef ext
318318
return warningReportItem(extRef, String.format(MESSAGE_SOURCE_LN_NOT_FOUND, optionalSourceLDevice.get().getXPath()));
319319
}
320320

321-
Optional<SclReportItem> sclReportItem = removeFilteredSourceDas(extRef, sourceDas);
321+
Optional<SclReportItem> sclReportItem = removeFilteredSourceDas(extRef, sourceDas, allowedFcdas);
322322
if (sclReportItem.isPresent()) {
323323
return sclReportItem;
324324
}
@@ -381,18 +381,29 @@ private static String generateDataSetSuffix(TExtRef extRef, DataAttributeRef sou
381381
+ (isBayInternal ? "I" : "E");
382382
}
383383

384-
private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Set<DataAttributeRef> sourceDas) {
384+
private Optional<SclReportItem> removeFilteredSourceDas(TExtRef extRef, final Set<DataAttributeRef> sourceDas, Set<FcdaForDataSetsCreation> allowedFcdas) {
385385
sourceDas.removeIf(da -> da.getFc() != TFCEnum.MX && da.getFc() != TFCEnum.ST);
386386
return switch (extRef.getServiceType()) {
387387
case GOOSE, SMV -> {
388-
sourceDas.removeIf(Predicate.not(FcdaCandidates.SINGLETON::contains));
388+
sourceDas.removeIf(Predicate.not(dataAttributeRef -> isFcdaAllowed(dataAttributeRef, allowedFcdas)));
389389
yield Optional.empty();
390390
}
391391
case REPORT -> removeFilterSourceDaForReport(extRef, sourceDas);
392392
default -> fatalReportItem(extRef, String.format(MESSAGE_INVALID_SERVICE_TYPE, extRef.getServiceType()));
393393
};
394394
}
395395

396+
private boolean isFcdaAllowed(DataAttributeRef dataAttributeRef, Set<FcdaForDataSetsCreation> allowedFcdas) {
397+
String lnClass = dataAttributeRef.getLnClass();
398+
String doName = dataAttributeRef.getDoName().toStringWithoutInst();
399+
String daName = dataAttributeRef.getDaName().toString();
400+
String fc = dataAttributeRef.getFc().value();
401+
if (StringUtils.isBlank(lnClass) || StringUtils.isBlank(doName) || StringUtils.isBlank(daName) || StringUtils.isBlank(fc)) {
402+
throw new IllegalArgumentException("parameters must not be blank");
403+
}
404+
return allowedFcdas.contains(new FcdaForDataSetsCreation(lnClass, doName, daName, fc));
405+
}
406+
396407
private Optional<SclReportItem> removeFilterSourceDaForReport(TExtRef extRef, Set<DataAttributeRef> sourceDas) {
397408
String daName = Utils.extractField(extRef.getDesc(), ATTRIBUTE_VALUE_SEPARATOR, EXTREF_DESC_DA_NAME_POSITION);
398409
if (StringUtils.isBlank(daName)) {

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/LDeviceAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ public List<AbstractLNAdapter<?>> getLNAdaptersIncludingLN0() {
351351
return aLNAdapters;
352352
}
353353

354-
public List<SclReportItem> createDataSetAndControlBlocks() {
354+
public List<SclReportItem> createDataSetAndControlBlocks(Set<FcdaForDataSetsCreation> allowedFcdas) {
355355
LN0Adapter ln0Adapter = getLN0Adapter();
356356
if (!ln0Adapter.hasInputs()) {
357357
return Collections.emptyList();
358358
}
359359
return ln0Adapter.getInputsAdapter()
360-
.updateAllSourceDataSetsAndControlBlocks();
360+
.updateAllSourceDataSetsAndControlBlocks(allowedFcdas);
361361
}
362362

363363
public Set<DataAttributeRef> findSourceDA(TExtRef extRef) {

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/FcdaCandidates.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/FcdaCsvHelper.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,52 @@
66

77
import com.opencsv.bean.CsvBindByPosition;
88
import lombok.Getter;
9+
import org.lfenergy.compas.scl2007b4.model.SCL;
910
import org.lfenergy.compas.scl2007b4.model.TFCDA;
1011
import org.lfenergy.compas.scl2007b4.model.TFCEnum;
12+
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
1113

1214
import java.io.Reader;
15+
import java.util.HashSet;
1316
import java.util.List;
17+
import java.util.Set;
1418

1519
/**
16-
* This class is a helper method to load FCDA from a CSV file for use with {@link IHmiService#createAllHmiReportControlBlocks}
20+
* This class is a helper method to load FCDA from a CSV files for use with
21+
* {@link org.lfenergy.compas.sct.commons.HmiService#createAllHmiReportControlBlocks(SCL, List)}
22+
* {@link org.lfenergy.compas.sct.commons.ExtRefService#createDataSetAndControlBlocks(SCL, Set)}
23+
* {@link org.lfenergy.compas.sct.commons.ExtRefService#createDataSetAndControlBlocks(SCL, String, Set)}
24+
* {@link org.lfenergy.compas.sct.commons.ExtRefService#createDataSetAndControlBlocks(SCL, String, String, Set)}
1725
* Use the getter to access the list of parsed FCDA.
1826
*
1927
* @see CsvUtils
20-
* @see IHmiService#createAllHmiReportControlBlocks
2128
*/
2229
public class FcdaCsvHelper {
2330

2431
@Getter
25-
private final List<TFCDA> fcdas;
32+
private final List<TFCDA> fcdaForHmiReportControls;
33+
34+
@Getter
35+
private final Set<FcdaForDataSetsCreation> fcdaForDataSets;
2636

2737
/**
2838
* Constructor
29-
* Provide the CSV file as a Reader. For example, you can create a reader like this :
39+
* Provide the CSV files as a Reader. For example, you can create a reader like this :
3040
* <code>new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName), StandardCharsets.UTF_8);</code>
3141
*
32-
* @param csvSource a reader that provides the data as CSV
42+
* @param csvSourceForHmiReportControl a reader that provides the FCDA datas for HMI ReportControl Blocks as CSV
43+
* @param csvSourceForDataSetAndControlBlocks a reader that provides the FCDA datas for DataSets and Control Blocks creation as CSV
3344
*/
34-
public FcdaCsvHelper(Reader csvSource) {
35-
fcdas = CsvUtils.parseRows(csvSource, Row.class).stream()
36-
.map(row ->
37-
SclConstructorHelper.newFcda(row.ldInst, row.lnClass, row.lnInst, row.prefix, row.doName, null, row.fc)
45+
public FcdaCsvHelper(Reader csvSourceForHmiReportControl, Reader csvSourceForDataSetAndControlBlocks) {
46+
fcdaForHmiReportControls = CsvUtils.parseRows(csvSourceForHmiReportControl, FcdaForHmiReportControl.class).stream()
47+
.map(fcdaForHmiReportControl ->
48+
SclConstructorHelper.newFcda(fcdaForHmiReportControl.ldInst, fcdaForHmiReportControl.lnClass, fcdaForHmiReportControl.lnInst, fcdaForHmiReportControl.prefix, fcdaForHmiReportControl.doName, null, fcdaForHmiReportControl.fc)
3849
)
3950
.toList();
51+
fcdaForDataSets = new HashSet<>(CsvUtils.parseRows(csvSourceForDataSetAndControlBlocks, FcdaForDataSetsCreation.class));
4052
}
4153

42-
public static class Row {
54+
public static class FcdaForHmiReportControl {
4355
@CsvBindByPosition(position = 0)
4456
private String ldInst;
4557
@CsvBindByPosition(position = 1)
@@ -54,4 +66,19 @@ public static class Row {
5466
private TFCEnum fc;
5567
}
5668

69+
/* @NoArgsConstructor
70+
@AllArgsConstructor
71+
@Getter
72+
@EqualsAndHashCode
73+
public static class FcdaForDataSets {
74+
@CsvBindByPosition(position = 0)
75+
private String lnClass;
76+
@CsvBindByPosition(position = 1)
77+
private String doName;
78+
@CsvBindByPosition(position = 2)
79+
private String daName;
80+
@CsvBindByPosition(position = 3)
81+
private String fc;
82+
} */
83+
5784
}

0 commit comments

Comments
 (0)