66 */
77package org .gridsuite .modification .server .modifications ;
88
9+ import com .powsybl .commons .PowsyblException ;
910import com .powsybl .commons .reporter .Report ;
1011import com .powsybl .commons .reporter .Reporter ;
1112import com .powsybl .commons .reporter .TypedValue ;
1617import org .gridsuite .modification .server .dto .BranchModificationInfos ;
1718import org .gridsuite .modification .server .dto .CurrentLimitsModificationInfos ;
1819import org .gridsuite .modification .server .dto .CurrentTemporaryLimitModificationInfos ;
20+ import org .gridsuite .modification .server .dto .TemporaryLimitModificationType ;
1921
2022import java .util .ArrayList ;
2123import java .util .List ;
@@ -90,10 +92,10 @@ protected void modifyCurrentLimits(CurrentLimitsModificationInfos currentLimitsI
9092
9193 protected void modifyTemporaryLimits (CurrentLimitsModificationInfos currentLimitsInfos , CurrentLimitsAdder limitsAdder ,
9294 CurrentLimits currentLimits , List <Report > limitsReports ) {
93- // we create a mutable list of temporary limits to be able to remove the limits that are modified
94- List <LoadingLimits .TemporaryLimit > branchTemporaryLimits = null ;
95+ // we create a mutable list of temporary limits to be able to remove the limits that are modified in current modification
96+ List <LoadingLimits .TemporaryLimit > branchTemporaryLimits = new ArrayList <>() ;
9597 if (currentLimits != null ) {
96- branchTemporaryLimits = new ArrayList <> (currentLimits .getTemporaryLimits ());
98+ branchTemporaryLimits . addAll (currentLimits .getTemporaryLimits ());
9799 }
98100 List <Report > temporaryLimitsReports = new ArrayList <>();
99101 for (CurrentTemporaryLimitModificationInfos limit : currentLimitsInfos .getTemporaryLimits ()) {
@@ -104,10 +106,13 @@ protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimit
104106 LoadingLimits .TemporaryLimit limitToModify = null ;
105107 if (currentLimits != null ) {
106108 limitToModify = currentLimits .getTemporaryLimit (limitAcceptableDuration );
107- // we remove the limit to modify from the list of temporary limits so we can log the remaining ones (deleted)
109+ if (limitToModify != null && !limitToModify .getName ().equals (limit .getName ())) {
110+ throw new PowsyblException ("2temporary limits have the same duration " + limitAcceptableDuration );
111+ }
112+ // we remove the limit to modify from the list of temporary limits so we can get the list of temporary limits comming from previous modifications
108113 branchTemporaryLimits .removeIf (temporaryLimit -> temporaryLimit .getAcceptableDuration () == limitAcceptableDuration );
109114 }
110- if (limitToModify == null ) {
115+ if (limitToModify == null && limit . getModificationType () == TemporaryLimitModificationType . ADDED ) {
111116 temporaryLimitsReports .add (Report .builder ().withKey ("temporaryLimitAdded" + limit .getName ())
112117 .withDefaultMessage (" ${name} (${duration}) added with ${value}" )
113118 .withValue (NAME , limit .getName ())
@@ -116,16 +121,33 @@ protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimit
116121 .withSeverity (TypedValue .INFO_SEVERITY )
117122 .build ());
118123
119- } else if (Double .compare (limitToModify .getValue (), limitValue ) != 0 ) {
120- temporaryLimitsReports .add (Report .builder ()
121- .withKey ("temporaryLimitModified" + limit .getName ())
122- .withDefaultMessage (" ${name} (${duration}) : ${oldValue} -> ${value}" )
123- .withValue (NAME , limit .getName ())
124- .withValue (DURATION , limitDurationToReport )
125- .withValue ("value" , limitValueToReport )
126- .withValue ("oldValue" , limitToModify .getValue () == Double .MAX_VALUE ? "no value" : String .valueOf (limitToModify .getValue ()))
127- .withSeverity (TypedValue .INFO_SEVERITY )
128- .build ());
124+ } else if (limitToModify != null ) {
125+ if (limit .getModificationType () == TemporaryLimitModificationType .DELETED ) {
126+ temporaryLimitsReports .add (Report .builder ()
127+ .withKey ("temporaryLimitDeleted" + limit .getName ())
128+ .withDefaultMessage (" ${name} (${duration}) deleted" )
129+ .withValue (NAME , limit .getName ())
130+ .withValue (DURATION , limitDurationToReport )
131+ .withSeverity (TypedValue .INFO_SEVERITY )
132+ .build ());
133+ continue ;
134+ } else if (Double .compare (limitToModify .getValue (), limitValue ) != 0 && limit .getModificationType () != null ) {
135+ temporaryLimitsReports .add (Report .builder ()
136+ .withKey ("temporaryLimitModified" + limit .getName ())
137+ .withDefaultMessage (" ${name} (${duration}) : ${oldValue} -> ${value}" )
138+ .withValue (NAME , limit .getName ())
139+ .withValue (DURATION , limitDurationToReport )
140+ .withValue ("value" , limitValueToReport )
141+ .withValue ("oldValue" ,
142+ limitToModify .getValue () == Double .MAX_VALUE ? "no value"
143+ : String .valueOf (limitToModify .getValue ()))
144+ .withSeverity (TypedValue .INFO_SEVERITY )
145+ .build ());
146+ } else {
147+ limitValue = limitToModify .getValue ();
148+ }
149+ } else {
150+ continue ;
129151 }
130152 limitsAdder
131153 .beginTemporaryLimit ()
@@ -134,15 +156,15 @@ protected void modifyTemporaryLimits(CurrentLimitsModificationInfos currentLimit
134156 .setAcceptableDuration (limitAcceptableDuration )
135157 .endTemporaryLimit ();
136158 }
137- if (branchTemporaryLimits != null ) {
159+ // we add the temporary limits comming from previous modifications
160+ if (!branchTemporaryLimits .isEmpty ()) {
138161 for (LoadingLimits .TemporaryLimit limit : branchTemporaryLimits ) {
139- temporaryLimitsReports .add (Report .builder ()
140- .withKey ("temporaryLimitDeleted" + limit .getName ())
141- .withDefaultMessage (" ${name} (${duration}) deleted" )
142- .withValue (NAME , limit .getName ())
143- .withValue (DURATION , limit .getAcceptableDuration () == Integer .MAX_VALUE ? " " : String .valueOf (limit .getAcceptableDuration ()))
144- .withSeverity (TypedValue .INFO_SEVERITY )
145- .build ());
162+ limitsAdder
163+ .beginTemporaryLimit ()
164+ .setName (limit .getName ())
165+ .setValue (limit .getValue ())
166+ .setAcceptableDuration (limit .getAcceptableDuration ())
167+ .endTemporaryLimit ();
146168 }
147169 }
148170 if (!temporaryLimitsReports .isEmpty ()) {
@@ -162,5 +184,6 @@ protected boolean characteristicsModified(BranchModificationInfos branchModifica
162184 && branchModificationInfos .getSeriesResistance ().getValue () != null ;
163185 }
164186
165- protected abstract void modifyCharacteristics (Branch <?> branch , BranchModificationInfos branchModificationInfos , Reporter subReporter );
187+ protected abstract void modifyCharacteristics (Branch <?> branch , BranchModificationInfos branchModificationInfos ,
188+ Reporter subReporter );
166189}
0 commit comments