Skip to content

Commit 6828be0

Browse files
authored
Merge pull request #594 from com-pas/develop
Release 0.2.63
2 parents 3b5bd06 + c85edb0 commit 6828be0

7 files changed

Lines changed: 18 additions & 612 deletions

File tree

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
2828
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
2929
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
30-
import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter;
3130
import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum;
3231
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
3332
import org.lfenergy.compas.sct.commons.util.Utils;
@@ -88,9 +87,9 @@ public void updateHeader(@NonNull SCL scd, @NonNull HeaderDTO headerDTO) {
8887
}
8988
if (hUpdated && !headerDTO.getHistoryItems().isEmpty()) {
9089
headerAdapter.addHistoryItem(
91-
headerDTO.getHistoryItems().get(0).getWho(),
92-
headerDTO.getHistoryItems().get(0).getWhat(),
93-
headerDTO.getHistoryItems().get(0).getWhy()
90+
headerDTO.getHistoryItems().getFirst().getWho(),
91+
headerDTO.getHistoryItems().getFirst().getWhat(),
92+
headerDTO.getHistoryItems().getFirst().getWhy()
9493
);
9594
}
9695
}
@@ -193,9 +192,9 @@ public void importSTDElementsInSCD(SCL scd, List<SCL> stds) throws ScdException
193192
if (!mapICDSystemVersionUuidAndSTDFile.containsKey(icdSysVerUuid))
194193
throw new ScdException("There is no STD file found corresponding to " + icdHeader);
195194
// import /ied /dtt in Scd
196-
SCL std = mapICDSystemVersionUuidAndSTDFile.get(icdSysVerUuid).stdList().get(0);
195+
SCL std = mapICDSystemVersionUuidAndSTDFile.get(icdSysVerUuid).stdList().getFirst();
197196
SclRootAdapter stdRootAdapter = new SclRootAdapter(std);
198-
IEDAdapter stdIedAdapter = new IEDAdapter(stdRootAdapter, std.getIED().get(0));
197+
IEDAdapter stdIedAdapter = new IEDAdapter(stdRootAdapter, std.getIED().getFirst());
199198
Optional<TPrivate> optionalTPrivate = stdIedAdapter.getPrivateHeader(COMPAS_ICDHEADER.getPrivateType());
200199
if (optionalTPrivate.isPresent() && optionalTPrivate.flatMap(PrivateUtils::extractCompasICDHeader).map(IcdHeader::new).get().equals(icdHeader)) {
201200
PrivateUtils.copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(optionalTPrivate.get(), icdHeader.toTCompasICDHeader());
@@ -208,18 +207,6 @@ public void importSTDElementsInSCD(SCL scd, List<SCL> stds) throws ScdException
208207
});
209208
}
210209

211-
@Override
212-
public List<SclReportItem> updateDoInRef(SCL scd) {
213-
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
214-
return sclRootAdapter.streamIEDAdapters()
215-
.flatMap(IEDAdapter::streamLDeviceAdapters)
216-
.map(LDeviceAdapter::getLN0Adapter)
217-
.map(LN0Adapter::updateDoInRef)
218-
.flatMap(List::stream)
219-
.toList();
220-
}
221-
222-
223210
@Override
224211
public List<SclReportItem> manageMonitoringLns(SCL scd) {
225212
errorHandler.get().clear();

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
package org.lfenergy.compas.sct.commons.api;
66

7-
import jakarta.xml.bind.JAXBContext;
87
import lombok.NonNull;
98
import org.lfenergy.compas.scl2007b4.model.SCL;
10-
import org.lfenergy.compas.sct.commons.dto.*;
9+
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
10+
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
11+
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
12+
import org.lfenergy.compas.sct.commons.dto.SubNetworkDTO;
1113
import org.lfenergy.compas.sct.commons.exception.ScdException;
1214

1315
import java.util.List;
@@ -38,7 +40,6 @@
3840
* </ul>
3941
* @see ExtRefEditor
4042
* @see SubstationEditor
41-
* @see HmiEditor
4243
*/
4344
public interface SclEditor {
4445

@@ -137,14 +138,6 @@ public interface SclEditor {
137138
*/
138139
void importSTDElementsInSCD(SCL scd, List<SCL> stds) throws ScdException;
139140

140-
/**
141-
* Update DAIs of DO InRef in all LN0 of the SCD using matching ExtRef information.
142-
*
143-
* @param scd SCL file for which DOs InRef should be updated with matching ExtRef information
144-
* @return list of encountered errors
145-
*/
146-
List<SclReportItem> updateDoInRef(SCL scd);
147-
148141
/**
149142
* Update and/or create Monitoring LNs (LSVS and LGOS) for bound GOOSE and SMV Control Blocks
150143
*

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

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
package org.lfenergy.compas.sct.commons.scl.ied;
66

77
import org.lfenergy.compas.scl2007b4.model.*;
8-
import org.lfenergy.compas.sct.commons.dto.*;
9-
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
8+
import org.lfenergy.compas.sct.commons.dto.DaTypeName;
9+
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
10+
import org.lfenergy.compas.sct.commons.dto.DoTypeName;
11+
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
1012
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1113
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
1214
import org.lfenergy.compas.sct.commons.util.Utils;
1315

14-
import java.util.ArrayList;
1516
import java.util.List;
1617
import java.util.Optional;
1718

18-
import static org.lfenergy.compas.sct.commons.util.CommonConstants.SETSRCCB_DA_NAME;
19-
import static org.lfenergy.compas.sct.commons.util.CommonConstants.SETSRCREF_DA_NAME;
20-
2119

2220
/**
2321
* A representation of the model object
@@ -93,30 +91,6 @@ public AbstractDAIAdapter<?> toAdapter(TDAI childTDAI) {
9391
return new DAIAdapter(this, childTDAI);
9492
}
9593

96-
/**
97-
* Update the DAI/Val according to the ExtRef attributes.
98-
* If the ExtRef.desc start with DAI[name='purpose']/Val and end with "_1" (nominal case):
99-
* - DAI[name='setSrcRef']/Val is updated with ExtRef attributes concatenation
100-
* - DAI[name='setSrcCB']/Val is updated with ExtRef attributes concatenation if ExtRef.srcCBName is present
101-
*
102-
* @param tExtRefs all the ExtRefs contained in the current LDevice/LLN0
103-
* @return a filled SclReportItem if an error occurs, empty SclReportItem otherwise
104-
*/
105-
public List<SclReportItem> updateDaiFromExtRef(List<TExtRef> tExtRefs) {
106-
List<SclReportItem> sclReportItems = new ArrayList<>();
107-
tExtRefs.stream()
108-
.filter(tExtRef -> tExtRef.getDesc().endsWith("_1"))
109-
.forEach(tExtRefMin -> {
110-
String valueSrcRef = createInRefValNominalString(tExtRefMin);
111-
updateDAI(SETSRCREF_DA_NAME, valueSrcRef).ifPresent(sclReportItems::add);
112-
if (tExtRefMin.isSetSrcCBName()) {
113-
String valueSrcCb = createInRefValTestString(tExtRefMin);
114-
updateDAI(SETSRCCB_DA_NAME, valueSrcCb).ifPresent(sclReportItems::add);
115-
}
116-
});
117-
return sclReportItems;
118-
}
119-
12094
/**
12195
* Check and update DAI identified by name with given value
12296
*
@@ -137,14 +111,6 @@ public Optional<SclReportItem> updateDAI(String daName, String value) {
137111

138112
}
139113

140-
private String createInRefValNominalString(TExtRef extRef) {
141-
return new ObjectReference(extRef, ExtrefTarget.SRC_REF).getReference();
142-
}
143-
144-
private String createInRefValTestString(TExtRef extRef) {
145-
return new ObjectReference(extRef, ExtrefTarget.SRC_CB).getReference();
146-
}
147-
148114
/**
149115
* A representation of the model object
150116
* <em><b>{@link org.lfenergy.compas.sct.commons.scl.ied.DOIAdapter.DAIAdapter DOIAdapter.DAIAdapter}</b></em>.

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ln/LN0Adapter.java

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
package org.lfenergy.compas.sct.commons.scl.ln;
66

77

8-
import org.lfenergy.compas.scl2007b4.model.*;
9-
import org.lfenergy.compas.sct.commons.dto.*;
8+
import org.lfenergy.compas.scl2007b4.model.LN0;
9+
import org.lfenergy.compas.scl2007b4.model.TLLN0Enum;
10+
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
11+
import org.lfenergy.compas.sct.commons.dto.ExtRefSignalInfo;
1012
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
1113
import org.lfenergy.compas.sct.commons.scl.ied.InputsAdapter;
1214
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
13-
import java.util.List;
14-
import java.util.Optional;
15-
import java.util.regex.Pattern;
16-
import java.util.stream.Collectors;
17-
import java.util.stream.Stream;
18-
19-
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
2015

2116
/**
2217
* A representation of the model object
@@ -64,8 +59,6 @@
6459
*/
6560
public class LN0Adapter extends AbstractLNAdapter<LN0> {
6661

67-
private static final Pattern LDEFP_DIGITAL_CHANNEL_PATTERN = Pattern.compile("DYN_LDEPF_DIGITAL CHANNEL \\d+_\\d+_BOOLEAN");
68-
6962
/**
7063
* Constructor
7164
*
@@ -163,48 +156,4 @@ public void removeAllControlBlocksAndDatasets() {
163156
currentElem.unsetSampledValueControl();
164157
}
165158

166-
/**
167-
* Update DAIs of DO InRef in all LN0 of the SCD using matching ExtRef information.
168-
*
169-
* @return A list of SclReport Objects that contain errors
170-
*/
171-
public List<SclReportItem> updateDoInRef() {
172-
return getDOIAdapters().stream()
173-
.filter(doiAdapter -> doiAdapter.getCurrentElem().isSetName()
174-
&& doiAdapter.getCurrentElem().getName().startsWith(INREF_PREFIX)
175-
&& doiAdapter.findDataAdapterByName(PURPOSE_DA_NAME).isPresent())
176-
.map(doiAdapter -> doiAdapter.getDataAdapterByName(PURPOSE_DA_NAME).getCurrentElem().getVal().stream()
177-
.findFirst()
178-
.map(tVal -> doiAdapter.updateDaiFromExtRef(getExtRefsBoundToInRef(tVal.getValue())))
179-
.orElse(List.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath()))))
180-
)
181-
.flatMap(List::stream)
182-
.collect(Collectors.toList());
183-
}
184-
185-
private List<TExtRef> getExtRefsBoundToInRef(String desc) {
186-
List<TExtRef> boundExtRefs = getBoundExtRefsByDesc(desc);
187-
// Special case for LDEPF DIGITAL CHANNEL of type BOOLEAN RSR-1048
188-
if (boundExtRefs.isEmpty() && LDEFP_DIGITAL_CHANNEL_PATTERN.matcher(desc).matches()) {
189-
String descWithoutType = desc.substring(0, desc.lastIndexOf("_"));
190-
return getBoundExtRefsByDesc(descWithoutType);
191-
}
192-
return boundExtRefs;
193-
}
194-
195-
private List<TExtRef> getBoundExtRefsByDesc(String desc) {
196-
return getExtRefs().stream()
197-
//This separation is done so in case we have 2 identical ExtRef with a different type, we always prioritize the one who have the same type as the purpose value.
198-
.flatMap(tExtRef -> {
199-
boolean isSetDesc = tExtRef.isSetIedName() && tExtRef.isSetLdInst() && tExtRef.isSetLnClass() && tExtRef.isSetDoName() && tExtRef.isSetDesc();
200-
if(isSetDesc && tExtRef.getDesc().contains(desc)){
201-
return Stream.of(tExtRef);
202-
}
203-
else if(isSetDesc && tExtRef.getDesc().contains(desc.substring(0, desc.lastIndexOf("_")))){
204-
return Stream.of(tExtRef);
205-
}
206-
return Stream.empty();
207-
})
208-
.toList();
209-
}
210159
}

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/SclServiceTest.java

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@
88
import org.junit.jupiter.api.BeforeEach;
99
import org.junit.jupiter.api.Tag;
1010
import org.junit.jupiter.api.Test;
11-
import org.junit.jupiter.params.ParameterizedTest;
12-
import org.junit.jupiter.params.provider.CsvSource;
1311
import org.lfenergy.compas.scl2007b4.model.*;
1412
import org.lfenergy.compas.sct.commons.api.DataTypeTemplateReader;
1513
import org.lfenergy.compas.sct.commons.dto.*;
1614
import org.lfenergy.compas.sct.commons.exception.ScdException;
1715
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
18-
import org.lfenergy.compas.sct.commons.scl.ied.DOIAdapter;
19-
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
2016
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
21-
import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter;
2217
import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter;
2318
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
2419

2520
import java.util.List;
26-
import java.util.Optional;
2721
import java.util.UUID;
2822

2923
import static org.assertj.core.api.Assertions.assertThat;
@@ -345,124 +339,6 @@ void importSTDElementsInSCD_whenNoSTDMatch_shouldThrowException() {
345339
.hasMessage("There is no STD file found corresponding to headerId = f8dbc8c1-2db7-4652-a9d6-0b414bdeccfa, headerVersion = 01.00.00, headerRevision = 01.00.00 and ICDSystemVersionUUID = IED4d4fe1a8cda64cf88a5ee4176a1a0eef");
346340
}
347341

348-
@ParameterizedTest(name = "{0}")
349-
@CsvSource({
350-
"Test update setSrcRef Value,LD_WITH_1_InRef,InRef2,setSrcRef,IED_NAME1LD_WITH_1_InRef/PRANCR1.Do11.sdo11",
351-
"Test update setSrcCB Value,LD_WITH_1_InRef,InRef2,setSrcCB,OLD_VAL",
352-
"Test update setSrcRef Value,LD_WITH_3_InRef,InRef3,setSrcRef,IED_NAME1LD_WITH_3_InRef/PRANCR1.Do11.sdo11",
353-
"Test update setSrcCB Value,LD_WITH_3_InRef,InRef3,setSrcCB,IED_NAME1LD_WITH_3_InRef/prefixANCR1.GSE1"
354-
})
355-
void updateDoInRef_shouldReturnUpdatedFile(String testName, String ldInst, String doName, String daName, String expected) {
356-
// Given
357-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_issue_231_test_ok.xml");
358-
// When
359-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
360-
// Then
361-
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
362-
assertSclValidateXsd(givenScl);
363-
assertThat(getValFromDaiName(givenScl, "IED_NAME1", ldInst, doName, daName)
364-
.map(TVal::getValue))
365-
.hasValue(expected);
366-
assertSclValidateXsd(givenScl);
367-
}
368-
369-
@ParameterizedTest(name = "{0}")
370-
@CsvSource({
371-
"Test with only 1 ExtRef should not update DO when IedName not present,LD_WITH_1_InRef_ExtRef_Without_IedName,InRef4,setSrcRef",
372-
"Test with only 1 ExtRef should not update DO when LdInst not present,LD_WITH_1_InRef_ExtRef_Without_LdInst,InRef5,setSrcRef",
373-
"Test with only 1 ExtRef should not update DO when lnClass not present,LD_WITH_1_InRef_ExtRef_Without_LnClass,InRef6,setSrcRef"
374-
})
375-
void updateDoInRef_should_not_update_DAI(String testName, String ldInst, String doName, String daName) {
376-
// Given
377-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_issue_231_test_ok.xml");
378-
// When
379-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
380-
// Then
381-
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
382-
assertThat(getValFromDaiName(givenScl, "IED_NAME1", ldInst, doName, daName)).isNotPresent();
383-
}
384-
385-
@Test
386-
void updateDoInRef_when_No_ExtRef_for_InRef_should_not_return_error() {
387-
// Given
388-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_no_Extref.xml");
389-
// When
390-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
391-
// Then
392-
assertThat(sclReportItems).isEmpty();
393-
}
394-
395-
@Test
396-
void updateDoInRef_when_ExtRef_bind_and_desc_suffix_not_match_should_not_return_error() {
397-
// Given
398-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_extref_bind_desc_suffix_not_match.xml");
399-
// When
400-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
401-
// Then
402-
assertThat(sclReportItems).isEmpty();
403-
}
404-
405-
@Test
406-
void updateDoInRef_when_ExtRef_bind_should_succeed() {
407-
// Given
408-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_extref_bind.xml");
409-
// When
410-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
411-
// Then
412-
assertThat(sclReportItems).isEmpty();
413-
assertThat(givenScl.getIED())
414-
.filteredOn(tied -> tied.getName().equals("IED_NAME1"))
415-
.flatExtracting(TIED::getAccessPoint)
416-
.extracting(TAccessPoint::getServer)
417-
.flatExtracting(TServer::getLDevice)
418-
.filteredOn(tlDevice -> tlDevice.getInst().equals("LD1"))
419-
.map(TLDevice::getLN0)
420-
.flatExtracting(TAnyLN::getDOI)
421-
.filteredOn(tdoi -> tdoi.getName().equals("InRef1"))
422-
.flatExtracting(TDOI::getSDIOrDAI)
423-
.filteredOn(tUnNaming -> tUnNaming.getClass().equals(TDAI.class) && ((TDAI)tUnNaming).getName().equals("setSrcRef"))
424-
.map(tUnNaming -> ((TDAI)tUnNaming).getVal().getFirst().getValue())
425-
.containsExactly("IED_NAME1LD2/PRANCR1.Do11.sdo11");
426-
}
427-
428-
@Test
429-
void updateDoInRef_when_ExtRef_bind_should_not_return_error() {
430-
// Given
431-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_extref_not_bind.xml");
432-
// When
433-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
434-
// Then
435-
assertThat(sclReportItems).isEmpty();
436-
}
437-
438-
@Test
439-
void updateDoInRef_when_Inref_purpose_not_set_should_return_report_with_warning() {
440-
// Given
441-
SCL givenScl = SclTestMarshaller.getSCLFromResource("scd-test-update-inref/scd_update_inref_when_inref_purpose_not_set.xml");
442-
// When
443-
List<SclReportItem> sclReportItems = sclService.updateDoInRef(givenScl);
444-
// Then
445-
assertThat(sclReportItems.stream().filter(sclReportItem -> !sclReportItem.isError()).map(SclReportItem::message))
446-
.hasSize(1)
447-
.containsExactly("The DOI /SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_Without_Val_in_DAI_purpose\"]/LN0 can't be bound with an ExtRef");
448-
}
449-
450-
private Optional<TVal> getValFromDaiName(SCL scl, String iedName, String ldInst, String doiName, String daiName) {
451-
SclRootAdapter sclRootAdapter = new SclRootAdapter(scl);
452-
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName);
453-
Optional<LDeviceAdapter> lDeviceAdapter = iedAdapter.findLDeviceAdapterByLdInst(ldInst);
454-
LN0Adapter ln0Adapter = lDeviceAdapter.orElseThrow().getLN0Adapter();
455-
Optional<DOIAdapter> doiAdapter = ln0Adapter.getDOIAdapters().stream()
456-
.filter(doiAdapter1 -> doiAdapter1.getCurrentElem().getName().equals(doiName))
457-
.findFirst();
458-
return doiAdapter.flatMap(adapter -> adapter.getCurrentElem().getSDIOrDAI().stream()
459-
.filter(tUnNaming -> tUnNaming.getClass().equals(TDAI.class))
460-
.map(TDAI.class::cast)
461-
.filter(tdai -> tdai.getName().equals(daiName) && !tdai.getVal().isEmpty())
462-
.map(tdai -> tdai.getVal().getFirst())
463-
.findFirst());
464-
}
465-
466342
@Test
467343
void manageMonitoringLns_should_update_and_create_lsvs_and_goose() {
468344
// Given

0 commit comments

Comments
 (0)