Skip to content

Commit bf6dddc

Browse files
authored
Merge pull request #236 from com-pas/235-error-while-importing-std-files
fix(#235): Error occurs when importing STD file during SCD automated creation
2 parents b2a9cc8 + 02a8ccf commit bf6dddc

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.xml.bind.JAXBElement;
1313
import java.util.*;
1414
import java.util.function.Predicate;
15+
import java.util.stream.Collectors;
1516
import java.util.stream.Stream;
1617

1718
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
@@ -298,21 +299,23 @@ public static String stdCheckFormatExceptionMessage(TPrivate key) throws ScdExce
298299

299300

300301
/**
301-
* Creates map of IEDName and related Private for all Privates COMPAS-ICDHeader in /Substation of SCL
302+
* Creates stream of Private for all Privates COMPAS-ICDHeader in /Substation of SCL
302303
*
303304
* @param scdRootAdapter SCL file in which Private should be found
304-
* @return map of Private and its IEDName parameter
305+
* @return stream of COMPAS-ICDHeader Private
305306
*/
306-
public static Stream<TPrivate> createMapIEDNameAndPrivate(SclRootAdapter scdRootAdapter) {
307+
public static Stream<TPrivate> streamIcdHeaderPrivatesWithDistinctIEDName(SclRootAdapter scdRootAdapter) {
307308
return scdRootAdapter.getCurrentElem().getSubstation().get(0).getVoltageLevel().stream()
308309
.map(TVoltageLevel::getBay).flatMap(Collection::stream)
309310
.map(TBay::getFunction).flatMap(Collection::stream)
310311
.map(TFunction::getLNode).flatMap(Collection::stream)
311312
.map(TLNode::getPrivate).flatMap(Collection::stream)
312313
.filter(tPrivate ->
313314
tPrivate.getType().equals(COMPAS_ICDHEADER.getPrivateType())
314-
&& PrivateService.extractCompasICDHeader(tPrivate).isPresent()
315-
&& PrivateService.extractCompasICDHeader(tPrivate).get().getIEDName() != null);
315+
&& PrivateService.extractCompasICDHeader(tPrivate).map(TCompasICDHeader::getIEDName).isPresent())
316+
.collect(Collectors.groupingBy(tPrivate -> PrivateService.extractCompasICDHeader(tPrivate).get().getIEDName()))
317+
.values().stream()
318+
.map(tPrivates -> tPrivates.get(0));
316319
}
317320

318321

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public static SclRootAdapter importSTDElementsInSCD(@NonNull SclRootAdapter scdR
502502
PrivateService.checkSTDCorrespondanceWithLNodeCompasICDHeader(mapICDSystemVersionUuidAndSTDFile);
503503
// List all Private and remove duplicated one with same iedName
504504
//For each Private.ICDSystemVersionUUID and Private.iedName find STD File
505-
PrivateService.createMapIEDNameAndPrivate(scdRootAdapter).forEach(tPrivate -> {
505+
PrivateService.streamIcdHeaderPrivatesWithDistinctIEDName(scdRootAdapter).forEach(tPrivate -> {
506506
String iedName = PrivateService.extractCompasICDHeader(tPrivate).get().getIEDName();
507507
String icdSysVerUuid = PrivateService.extractCompasICDHeader(tPrivate).map(TCompasICDHeader::getICDSystemVersionUUID)
508508
.orElseThrow(() -> new ScdException(ICD_SYSTEM_VERSION_UUID + " is not present in COMPAS-ICDHeader in LNode")

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/PrivateServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void createMapIEDNameAndPrivate_should_return_map_of_three_items() {
437437
//When
438438
SclRootAdapter sclRootAdapter = SclService.initScl(Optional.empty(), "hv", "hr");
439439
sclRootAdapter.setCurrentElem(scl);
440-
Stream<TPrivate> tPrivateStream = PrivateService.createMapIEDNameAndPrivate(sclRootAdapter);
440+
Stream<TPrivate> tPrivateStream = PrivateService.streamIcdHeaderPrivatesWithDistinctIEDName(sclRootAdapter);
441441

442442
//Then
443443
assertThat(tPrivateStream.toList()).hasSize(3)
@@ -467,7 +467,7 @@ void createMapIEDNameAndPrivate_should_return_empty_map_when_no_compasicdheader_
467467
//When
468468
SclRootAdapter sclRootAdapter = SclService.initScl(Optional.empty(), "hv", "hr");
469469
sclRootAdapter.setCurrentElem(scl);
470-
Stream<TPrivate> tPrivateStream = PrivateService.createMapIEDNameAndPrivate(sclRootAdapter);
470+
Stream<TPrivate> tPrivateStream = PrivateService.streamIcdHeaderPrivatesWithDistinctIEDName(sclRootAdapter);
471471

472472
//Then
473473
assertThat(tPrivateStream.toList()).isEmpty();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,17 @@ void testImportSTDElementsInSCD_Several_STD_Match_Compas_ICDHeader() {
792792
assertIsMarshallable(scd);
793793
}
794794

795+
@Test
796+
void test_importSTDElementsInSCD_should_not_throw_exception_when_SCD_file_contains_same_ICDHeader_in_two_different_functions() {
797+
//Given
798+
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd_with_same_compas_icd_header_in_different_functions.xml");
799+
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
800+
SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
801+
//When Then
802+
assertDoesNotThrow(() -> SclService.importSTDElementsInSCD(scdRootAdapter, Set.of(std), DTO.comMap));
803+
assertIsMarshallable(scd);
804+
}
805+
795806
@Test
796807
void testImportSTDElementsInSCD_Compas_ICDHeader_Not_Match() {
797808
//Given
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ // SPDX-FileCopyrightText: 2021 RTE FRANCE
4+
~ //
5+
~ // SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<SCL xmlns:compas="https://www.lfenergy.org/compas/extension/v1" xmlns="http://www.iec.ch/61850/2003/SCL" version="2007" revision="B" release="4">
8+
<Private type="COMPAS-SclFileType">
9+
<compas:SclFileType>SCD</compas:SclFileType>
10+
</Private>
11+
<Header id="HeaderId" version="HeaderVersion" revision="HeaderRevision"/>
12+
<Substation name="SITE">
13+
<VoltageLevel nomFreq="50" numPhases="3" name="0">
14+
<Voltage unit="V" multiplier="k">0</Voltage>
15+
<Bay name="BAY_1">
16+
<Function name="FUNCTION_1">
17+
<LNode iedName="None" ldInst="LDGW" lnClass="LLN0">
18+
<Private type="COMPAS-ICDHeader">
19+
<compas:ICDHeader IEDType="SCU" IEDinstance="0" BayLabel="SITE1" IEDName="SITESITE1SCU0" ICDSystemVersionUUID="IED4d4fe1a8cda64cf88a5ee4176a1a0eef" 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"/>
20+
</Private>
21+
</LNode>
22+
</Function>
23+
<Function name="FUNCTION_2">
24+
<LNode iedName="None" ldInst="LDGW" lnClass="GAPC">
25+
<Private type="COMPAS-ICDHeader">
26+
<compas:ICDHeader IEDType="SCU" IEDinstance="0" BayLabel="SITE1" IEDName="SITESITE1SCU0" ICDSystemVersionUUID="IED4d4fe1a8cda64cf88a5ee4176a1a0eef" 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"/>
27+
</Private>
28+
</LNode>
29+
</Function>
30+
</Bay>
31+
</VoltageLevel>
32+
</Substation>
33+
</SCL>

0 commit comments

Comments
 (0)