5
5
package org .lfenergy .compas .sct .commons ;
6
6
7
7
import lombok .RequiredArgsConstructor ;
8
- import org .apache .commons .lang3 .StringUtils ;
9
8
import org .lfenergy .compas .scl2007b4 .model .*;
10
9
import org .lfenergy .compas .sct .commons .api .ExtRefEditor ;
11
10
import org .lfenergy .compas .sct .commons .dto .*;
27
26
28
27
import java .math .BigInteger ;
29
28
import java .util .*;
29
+ import java .util .function .BinaryOperator ;
30
30
import java .util .function .Function ;
31
31
import java .util .stream .Collectors ;
32
32
@@ -90,7 +90,7 @@ private static List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBa
90
90
*/
91
91
private List <ExtRefInfo .ExtRefWithBayReference > getExtRefWithBayReferenceInLDEPF (TDataTypeTemplates dataTypeTemplates , TIED tied , final TLDevice tlDevice , final List <SclReportItem > sclReportItems ) {
92
92
List <ExtRefInfo .ExtRefWithBayReference > extRefBayReferenceList = new ArrayList <>();
93
- String lDevicePath = "SCL/IED[@name=\" " + tied .getName () + "\" ]/AccessPoint/Server/LDevice[@inst=\" " + tlDevice .getInst () + "\" ]" ;
93
+ String lDevicePath = "SCL/IED[@name=\" " + tied .getName () + "\" ]/AccessPoint/Server/LDevice[@inst=\" " + tlDevice .getInst () + "\" ]" ;
94
94
Optional <TCompasBay > tCompasBay = PrivateUtils .extractCompasPrivate (tied , TCompasBay .class );
95
95
if (tCompasBay .isEmpty ()) {
96
96
sclReportItems .add (SclReportItem .error (lDevicePath , "The IED has no Private Bay" ));
@@ -405,8 +405,7 @@ private List<SclReportItem> updateLDEPFDos(LDeviceAdapter lDeviceAdapter, TExtRe
405
405
private Optional <SclReportItem > updateVal (AbstractLNAdapter <?> lnAdapter , String doName , String daName , TExtRef extRef , TChannel setting ) {
406
406
String value = switch (daName ) {
407
407
case DU_DA_NAME -> setting .getChannelShortLabel ();
408
- case SETVAL_DA_NAME ->
409
- LN_PREFIX_B .equals (lnAdapter .getPrefix ()) || LN_PREFIX_A .equals (lnAdapter .getPrefix ()) ? setting .getChannelLevModQ ().value () : setting .getChannelLevMod ().value ();
408
+ case SETVAL_DA_NAME -> LN_PREFIX_B .equals (lnAdapter .getPrefix ()) || LN_PREFIX_A .equals (lnAdapter .getPrefix ()) ? setting .getChannelLevModQ ().value () : setting .getChannelLevMod ().value ();
410
409
case STVAL_DA_NAME -> ActiveStatus .ON .getValue ();
411
410
case SETSRCREF_DA_NAME -> computeDaiValue (lnAdapter , extRef , setting .getDAName ());
412
411
default -> null ;
@@ -464,7 +463,7 @@ public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd) {
464
463
465
464
466
465
@ Override
467
- public void updateIedNameBasedOnLnode (SCL scl ) {
466
+ public List < SclReportItem > updateIedNameBasedOnLnode (SCL scl ) {
468
467
Map <TopoKey , TBay > bayByTopoKey = scl .getSubstation ().stream ()
469
468
.flatMap (tSubstation -> tSubstation .getVoltageLevel ().stream ())
470
469
.flatMap (tVoltageLevel -> tVoltageLevel .getBay ().stream ())
@@ -475,6 +474,7 @@ public void updateIedNameBasedOnLnode(SCL scl) {
475
474
.flatMap (Optional ::stream )
476
475
.collect (Collectors .toMap (BayTopoKey ::topoKey , BayTopoKey ::bay ));
477
476
477
+ List <SclReportItem > sclReportItems = new ArrayList <>();
478
478
scl .getIED ().stream ()
479
479
.flatMap (ldeviceService ::getLdevices )
480
480
.forEach (tlDevice ->
@@ -488,9 +488,21 @@ public void updateIedNameBasedOnLnode(SCL scl) {
488
488
&& Objects .equals (tlNode .getLnInst (), tCompasFlow .getExtReflnInst ())
489
489
&& Utils .lnClassEquals (tlNode .getLnClass (), tCompasFlow .getExtReflnClass ())
490
490
&& Objects .equals (tlNode .getPrefix (), tCompasFlow .getExtRefprefix ()))
491
+ .filter (tlNode -> {
492
+ Optional <TCompasICDHeader > tCompasICDHeader = PrivateUtils .extractCompasPrivate (tlNode , TCompasICDHeader .class );
493
+ if (tCompasICDHeader .isPresent ()) {
494
+ return Objects .equals (tCompasFlow .getFlowSourceIEDType (), tCompasICDHeader .get ().getIEDType ())
495
+ && Objects .equals (tCompasFlow .getFlowIEDSystemVersioninstance (), tCompasICDHeader .get ().getIEDSystemVersioninstance ())
496
+ && Objects .equals (tCompasFlow .getFlowSourceIEDredundancy (), tCompasICDHeader .get ().getIEDredundancy ());
497
+ } else {
498
+ sclReportItems .add (SclReportItem .error ("" , ("The substation LNode with following attributes : IedName:%s / LdInst:%s / LnClass:%s / LnInst:%s " +
499
+ "does not contain the needed (COMPAS - ICDHeader) private" )
500
+ .formatted (tlNode .getIedName (), tlNode .getLdInst (), tlNode .getLnClass ().getFirst (), tlNode .getLnInst ())));
501
+ return false ;
502
+ }
503
+ })
491
504
.map (TLNode ::getIedName )
492
- .filter (StringUtils ::isNotBlank )
493
- .findFirst ()
505
+ .reduce (checkOnlyOneIed (tCompasFlow , tBay , sclReportItems ))
494
506
)
495
507
.ifPresentOrElse (iedName -> {
496
508
extRefService .getMatchingExtRefs (tlDevice , tCompasFlow ).forEach (tExtRef -> tExtRef .setIedName (iedName ));
@@ -503,6 +515,17 @@ public void updateIedNameBasedOnLnode(SCL scl) {
503
515
)
504
516
)
505
517
);
518
+ return sclReportItems ;
519
+ }
520
+
521
+ private static BinaryOperator <String > checkOnlyOneIed (TCompasFlow tCompasFlow , TBay tBay , List <SclReportItem > sclReportItems ) {
522
+ return (iedName1 , iedName2 ) -> {
523
+ sclReportItems .add (SclReportItem .error ("" ,
524
+ ("Several LNode@IedName ('%s', '%s') are found in the bay '%s' for the following compas-flow attributes :" +
525
+ " @FlowSourceIEDType '%s' @FlowSourceIEDredundancy '%s' @FlowIEDSystemVersioninstance '%s'" ).
526
+ formatted (iedName1 , iedName2 , tBay .getName (), tCompasFlow .getFlowSourceIEDType (), tCompasFlow .getFlowSourceIEDredundancy (), tCompasFlow .getFlowIEDSystemVersioninstance ())));
527
+ return iedName1 ;
528
+ };
506
529
}
507
530
508
531
record TopoKey (String FlowNode , BigInteger FlowNodeOrder ) {
0 commit comments