Skip to content

Commit fa79326

Browse files
authored
fix temporary limits modification (#277)
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent 60a82ed commit fa79326

File tree

4 files changed

+72
-26
lines changed

4 files changed

+72
-26
lines changed

src/main/java/org/gridsuite/modification/server/dto/TemporaryLimitModificationType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
public enum TemporaryLimitModificationType {
1313
ADDED,
1414
MODIFIED,
15+
DELETED,
1516
}

src/main/java/org/gridsuite/modification/server/modifications/AbstractBranchModification.java

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.gridsuite.modification.server.modifications;
88

9+
import com.powsybl.commons.PowsyblException;
910
import com.powsybl.commons.reporter.Report;
1011
import com.powsybl.commons.reporter.Reporter;
1112
import com.powsybl.commons.reporter.TypedValue;
@@ -16,6 +17,7 @@
1617
import org.gridsuite.modification.server.dto.BranchModificationInfos;
1718
import org.gridsuite.modification.server.dto.CurrentLimitsModificationInfos;
1819
import org.gridsuite.modification.server.dto.CurrentTemporaryLimitModificationInfos;
20+
import org.gridsuite.modification.server.dto.TemporaryLimitModificationType;
1921

2022
import java.util.ArrayList;
2123
import 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
}

src/test/java/org/gridsuite/modification/server/modifications/LineModificationTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected ModificationInfos buildModification() {
4848
.acceptableDuration(null)
4949
.name("name31")
5050
.value(null)
51+
.modificationType(TemporaryLimitModificationType.ADDED)
5152
.build()))
5253
.build())
5354
.currentLimits2(CurrentLimitsModificationInfos.builder()
@@ -56,6 +57,7 @@ protected ModificationInfos buildModification() {
5657
.acceptableDuration(32)
5758
.name("name32")
5859
.value(42.0)
60+
.modificationType(TemporaryLimitModificationType.ADDED)
5961
.build()))
6062
.build())
6163
.build();
@@ -296,8 +298,26 @@ public void testTemporaryLimitsModification() {
296298
.setValue(15.0)
297299
.endTemporaryLimit()
298300
.add();
299-
LineModificationInfos lineModificationInfos = (LineModificationInfos) buildModification();
300-
301+
LineModificationInfos lineModificationInfos = LineModificationInfos.builder().equipmentId("line1")
302+
.equipmentName(new AttributeModification<>("LineModified", OperationType.SET))
303+
.currentLimits1(CurrentLimitsModificationInfos.builder()
304+
.temporaryLimits(List.of(CurrentTemporaryLimitModificationInfos.builder()
305+
.acceptableDuration(null)
306+
.name("name31")
307+
.value(22.0)
308+
.modificationType(TemporaryLimitModificationType.MODIFIED)
309+
.build()))
310+
.build())
311+
.currentLimits2(CurrentLimitsModificationInfos.builder()
312+
.permanentLimit(22.0)
313+
.temporaryLimits(List.of(CurrentTemporaryLimitModificationInfos.builder()
314+
.acceptableDuration(33)
315+
.name("name33")
316+
.value(15.0)
317+
.modificationType(TemporaryLimitModificationType.DELETED)
318+
.build()))
319+
.build())
320+
.build();
301321
String modificationToCreateJson = mapper.writeValueAsString(lineModificationInfos);
302322

303323
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))

src/test/java/org/gridsuite/modification/server/modifications/TwoWindingsTransformerModificationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected ModificationInfos buildModification() {
5555
.acceptableDuration(null)
5656
.name("name31")
5757
.value(null)
58+
.modificationType(TemporaryLimitModificationType.ADDED)
5859
.build()))
5960
.build())
6061
.currentLimits2(CurrentLimitsModificationInfos.builder()
@@ -63,6 +64,7 @@ protected ModificationInfos buildModification() {
6364
.acceptableDuration(32)
6465
.name("name32")
6566
.value(42.0)
67+
.modificationType(TemporaryLimitModificationType.ADDED)
6668
.build()))
6769
.build())
6870
.build();

0 commit comments

Comments
 (0)