3333
3434import  static  com .powsybl .iidm .network .TwoSides .ONE ;
3535import  static  org .gridsuite .modification .NetworkModificationException .Type .*;
36+ import  static  org .gridsuite .modification .modifications .AbstractBranchModification .*;
3637
3738/** 
3839 * @author Slimane Amar <slimane.amar at rte-france.com> 
@@ -549,6 +550,20 @@ public ReportNode reportModifications(ReportNode reportNode, List<ReportNode> re
549550        return  reportModifications (reportNode , reports , subReportNodeKey , Map .of ());
550551    }
551552
553+     public  void  reportModifications (ReportNode  reportNode , List <ReportNode > reports ) {
554+         List <ReportNode > validReports  = reports .stream ().filter (Objects ::nonNull ).toList ();
555+         if  (!validReports .isEmpty () && reportNode  != null ) {
556+             for  (ReportNode  report  : validReports ) {
557+                 ReportNodeAdder  reportNodeAdder  = reportNode .newReportNode ().withMessageTemplate (report .getMessageKey ()).withSeverity (TypedValue .DETAIL_SEVERITY );
558+                 for  (Map .Entry <String , TypedValue > valueEntry  : report .getValues ().entrySet ()) {
559+                     reportNodeAdder .withUntypedValue (valueEntry .getKey (), valueEntry .getValue ().toString ());
560+                 }
561+                 report .getValue (ReportConstants .SEVERITY_KEY ).ifPresent (reportNodeAdder ::withSeverity );
562+                 reportNodeAdder .add ();
563+             }
564+         }
565+     }
566+ 
552567    public  ReportNode  reportModifications (ReportNode  reportNode , List <ReportNode > reports , String  subReportNodeKey , Map <String , Object > subReportNodeKeyArgs ) {
553568        List <ReportNode > validReports  = reports .stream ().filter (Objects ::nonNull ).toList ();
554569        ReportNode  subReportNode  = null ;
@@ -1064,33 +1079,36 @@ public Identifiable<?> getEquipmentByIdentifiableType(Network network, Identifia
10641079    }
10651080
10661081    /** 
1082+      * @param reportNode Limit sets report node 
10671083     * @param opLimitGroups added current limits 
10681084     * @param branch branch to which limits are going to be added 
10691085     * @param side which side of the branch receives the limits 
1070-      * @param limitsReporter reporter limits on side 
10711086     */ 
1072-     public  void  setCurrentLimitsOnASide (List <OperationalLimitsGroupInfos > opLimitGroups , Branch <?> branch , TwoSides  side , ReportNode  limitsReporter ) {
1073-         List <ReportNode > limitSetsOnSideReportNodes  = new  ArrayList <>();
1087+     public  void  setCurrentLimitsOnASide (ReportNode  reportNode , List <OperationalLimitsGroupInfos > opLimitGroups , Branch <?> branch , TwoSides  side ) {
1088+ 
1089+         if  (CollectionUtils .isEmpty (opLimitGroups )) {
1090+             return ;
1091+         }
1092+ 
10741093        for  (OperationalLimitsGroupInfos  opLimitsGroup  : opLimitGroups ) {
10751094            boolean  hasPermanent  = opLimitsGroup .getCurrentLimits ().getPermanentLimit () != null ;
10761095            boolean  hasTemporary  = !CollectionUtils .isEmpty (opLimitsGroup .getCurrentLimits ().getTemporaryLimits ());
10771096            boolean  hasLimits  = hasPermanent  || hasTemporary ;
10781097
1079-             if  (!hasLimits ) {
1098+             if  (!hasLimits  ||  opLimitsGroup . getId () ==  null ) {
10801099                continue ;
10811100            }
10821101
10831102            OperationalLimitsGroup  opGroup  = side  == ONE 
10841103                    ? branch .newOperationalLimitsGroup1 (opLimitsGroup .getId ())
10851104                    : branch .newOperationalLimitsGroup2 (opLimitsGroup .getId ());
1086-             if  (opLimitsGroup .getId () != null ) {
1087-                 limitSetsOnSideReportNodes .add (ReportNode .newRootReportNode ()
1088-                         .withAllResourceBundlesFromClasspath ()
1089-                         .withMessageTemplate ("network.modification.limitSetAdded" )
1090-                         .withUntypedValue ("name" , opLimitsGroup .getId ())
1091-                         .withSeverity (TypedValue .INFO_SEVERITY )
1092-                         .build ());
1093-             }
1105+ 
1106+             ReportNode  limitSetNode  = reportNode .newReportNode ()
1107+                 .withMessageTemplate ("network.modification.limitSetAdded" )
1108+                 .withUntypedValue ("name" , opLimitsGroup .getId ())
1109+                 .withSeverity (TypedValue .INFO_SEVERITY )
1110+                 .add ();
1111+ 
10941112            CurrentLimitsAdder  limitsAdder  = opGroup .newCurrentLimits ();
10951113            if  (hasPermanent ) {
10961114                limitsAdder .setPermanentLimit (opLimitsGroup .getCurrentLimits ().getPermanentLimit ());
@@ -1108,11 +1126,41 @@ public void setCurrentLimitsOnASide(List<OperationalLimitsGroupInfos> opLimitGro
11081126                });
11091127            }
11101128            limitsAdder .add ();
1129+ 
1130+             //add properties 
1131+             List <ReportNode > detailsOnLimitSet  = new  ArrayList <>();
1132+             if  (!CollectionUtils .isEmpty (opLimitsGroup .getLimitsProperties ()) &&
1133+                 checkPropertiesUnicity (opLimitsGroup .getLimitsProperties (), detailsOnLimitSet )) {
1134+                 opLimitsGroup .getLimitsProperties ().forEach (property  -> {
1135+                     detailsOnLimitSet .add (
1136+                             ReportNode .newRootReportNode ().withSeverity (TypedValue .DETAIL_SEVERITY )
1137+                             .withMessageTemplate ("network.modification.propertyAdded" )
1138+                             .withUntypedValue (NAME , property .name ())
1139+                             .withUntypedValue (VALUE , property .value ()).build ());
1140+                     opGroup .setProperty (property .name (), property .value ());
1141+                 });
1142+                 if  (!detailsOnLimitSet .isEmpty ()) {
1143+                     ModificationUtils .getInstance ().reportModifications (limitSetNode , detailsOnLimitSet );
1144+                 }
1145+             }
1146+         }
1147+     }
1148+ 
1149+     private  static  boolean  checkPropertiesUnicity (List <LimitsPropertyInfos > properties , List <ReportNode > reportNodeList ) {
1150+ 
1151+         if  (CollectionUtils .isEmpty (properties )) {
1152+             return  true ;
11111153        }
1112-         if  (!limitSetsOnSideReportNodes .isEmpty ()) {
1113-             ModificationUtils .getInstance ().reportModifications (limitsReporter , limitSetsOnSideReportNodes ,
1114-                     "network.modification.LimitsSetsOnSide"  + side .getNum ());
1154+         boolean  unicity  = true ;
1155+         for  (LimitsPropertyInfos  property  : properties ) {
1156+             if  (properties .stream ().filter (prop  -> prop .name ().equals (property .name ())).toList ().size () > 1 ) {
1157+                 reportNodeList .add (ReportNode .newRootReportNode ().withSeverity (TypedValue .ERROR_SEVERITY )
1158+                     .withMessageTemplate ("network.modification.propertyNameUnique" )
1159+                     .withUntypedValue (NAME , property .name ()).build ());
1160+                 unicity  = false ;
1161+             }
11151162        }
1163+         return  unicity ;
11161164    }
11171165
11181166    public  <T > ReportNode  buildCreationReport (T  value , String  fieldName ) {
0 commit comments