55package org .lfenergy .compas .sct .commons ;
66
77import lombok .RequiredArgsConstructor ;
8- import org .apache .commons .lang3 .StringUtils ;
98import org .lfenergy .compas .scl2007b4 .model .*;
109import org .lfenergy .compas .sct .commons .api .ExtRefEditor ;
1110import org .lfenergy .compas .sct .commons .dto .*;
2726
2827import java .math .BigInteger ;
2928import java .util .*;
29+ import java .util .function .BinaryOperator ;
3030import java .util .function .Function ;
3131import java .util .stream .Collectors ;
3232
@@ -90,7 +90,7 @@ private static List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBa
9090 */
9191 private List <ExtRefInfo .ExtRefWithBayReference > getExtRefWithBayReferenceInLDEPF (TDataTypeTemplates dataTypeTemplates , TIED tied , final TLDevice tlDevice , final List <SclReportItem > sclReportItems ) {
9292 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 () + "\" ]" ;
9494 Optional <TCompasBay > tCompasBay = PrivateUtils .extractCompasPrivate (tied , TCompasBay .class );
9595 if (tCompasBay .isEmpty ()) {
9696 sclReportItems .add (SclReportItem .error (lDevicePath , "The IED has no Private Bay" ));
@@ -405,8 +405,7 @@ private List<SclReportItem> updateLDEPFDos(LDeviceAdapter lDeviceAdapter, TExtRe
405405 private Optional <SclReportItem > updateVal (AbstractLNAdapter <?> lnAdapter , String doName , String daName , TExtRef extRef , TChannel setting ) {
406406 String value = switch (daName ) {
407407 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 ();
410409 case STVAL_DA_NAME -> ActiveStatus .ON .getValue ();
411410 case SETSRCREF_DA_NAME -> computeDaiValue (lnAdapter , extRef , setting .getDAName ());
412411 default -> null ;
@@ -464,7 +463,7 @@ public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd) {
464463
465464
466465 @ Override
467- public void updateIedNameBasedOnLnode (SCL scl ) {
466+ public List < SclReportItem > updateIedNameBasedOnLnode (SCL scl ) {
468467 Map <TopoKey , TBay > bayByTopoKey = scl .getSubstation ().stream ()
469468 .flatMap (tSubstation -> tSubstation .getVoltageLevel ().stream ())
470469 .flatMap (tVoltageLevel -> tVoltageLevel .getBay ().stream ())
@@ -475,6 +474,7 @@ public void updateIedNameBasedOnLnode(SCL scl) {
475474 .flatMap (Optional ::stream )
476475 .collect (Collectors .toMap (BayTopoKey ::topoKey , BayTopoKey ::bay ));
477476
477+ List <SclReportItem > sclReportItems = new ArrayList <>();
478478 scl .getIED ().stream ()
479479 .flatMap (ldeviceService ::getLdevices )
480480 .forEach (tlDevice ->
@@ -488,9 +488,21 @@ public void updateIedNameBasedOnLnode(SCL scl) {
488488 && Objects .equals (tlNode .getLnInst (), tCompasFlow .getExtReflnInst ())
489489 && Utils .lnClassEquals (tlNode .getLnClass (), tCompasFlow .getExtReflnClass ())
490490 && 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+ })
491504 .map (TLNode ::getIedName )
492- .filter (StringUtils ::isNotBlank )
493- .findFirst ()
505+ .reduce (checkOnlyOneIed (tCompasFlow , tBay , sclReportItems ))
494506 )
495507 .ifPresentOrElse (iedName -> {
496508 extRefService .getMatchingExtRefs (tlDevice , tCompasFlow ).forEach (tExtRef -> tExtRef .setIedName (iedName ));
@@ -503,6 +515,17 @@ public void updateIedNameBasedOnLnode(SCL scl) {
503515 )
504516 )
505517 );
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+ };
506529 }
507530
508531 record TopoKey (String FlowNode , BigInteger FlowNodeOrder ) {
0 commit comments