Skip to content

Commit

Permalink
Remove name unicity constraint on temporary limits (#3043)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 authored May 31, 2024
1 parent f48c4e1 commit dc0fb37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
Expand Down Expand Up @@ -548,7 +546,7 @@ public static ValidationLevel checkLoadingLimits(Validable validable, double per
private static ValidationLevel checkLoadingLimits(Validable validable, double permanentLimit, Collection<LoadingLimits.TemporaryLimit> temporaryLimits,
boolean throwException, ReportNode reportNode) {
ValidationLevel validationLevel = ValidationUtil.checkPermanentLimit(validable, permanentLimit, temporaryLimits, throwException, reportNode);
ValidationUtil.checkTemporaryLimits(validable, permanentLimit, temporaryLimits, throwException, reportNode);
ValidationUtil.checkTemporaryLimits(validable, permanentLimit, temporaryLimits);
return validationLevel;
}

Expand All @@ -571,8 +569,7 @@ private static ValidationLevel checkPermanentLimit(Validable validable, double p
return validationLevel;
}

private static ValidationLevel checkTemporaryLimits(Validable validable, double permanentLimit, Collection<LoadingLimits.TemporaryLimit> temporaryLimits,
boolean throwException, ReportNode reportNode) {
private static void checkTemporaryLimits(Validable validable, double permanentLimit, Collection<LoadingLimits.TemporaryLimit> temporaryLimits) {
// check temporary limits are consistent with permanent
if (LOGGER.isDebugEnabled()) {
double previousLimit = Double.NaN;
Expand All @@ -588,17 +585,6 @@ private static ValidationLevel checkTemporaryLimits(Validable validable, double
previousLimit = tl.getValue();
}
}
// check name unicity
AtomicReference<ValidationLevel> validationLevel = new AtomicReference<>(ValidationLevel.STEADY_STATE_HYPOTHESIS);
temporaryLimits.stream()
.collect(Collectors.groupingBy(LoadingLimits.TemporaryLimit::getName))
.forEach((name, temporaryLimits1) -> {
if (temporaryLimits1.size() > 1) {
throwExceptionOrLogError(validable, temporaryLimits1.size() + " temporary limits have the same name " + name, throwException, reportNode);
validationLevel.set(ValidationLevel.min(validationLevel.get(), ValidationLevel.EQUIPMENT));
}
});
return validationLevel.get();
}

public static ValidationLevel checkLossFactor(Validable validable, float lossFactor, ValidationLevel validationLevel, ReportNode reportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,6 @@ public void testSetterGetter() {
// ignore
}

try {
currentLimitsAdder.beginTemporaryLimit()
.setAcceptableDuration(5 * 60)
.setValue(1400.0)
.setName("20'")
.setFictitious(true)
.endTemporaryLimit()
.add();
fail();
} catch (ValidationException ignored) {
// ignore
}

CurrentLimits currentLimits = currentLimitsAdder.beginTemporaryLimit()
.setName("5'")
.setAcceptableDuration(5 * 60)
Expand Down Expand Up @@ -479,6 +466,27 @@ public void ensureNameUnicity() {
assertEquals("TL#1", currentLimits.getTemporaryLimit(5 * 60).getName());
}

@Test
public void testNameDuplicationIsAllowed() {
Line line = createNetwork().getLine("L");
CurrentLimits currentLimits = line.newCurrentLimits1()
.setPermanentLimit(100.0)
.beginTemporaryLimit()
.setName("TL")
.setAcceptableDuration(20 * 60)
.setValue(1200.0)
.endTemporaryLimit()
.beginTemporaryLimit()
.setName("TL")
.setAcceptableDuration(10 * 60)
.setValue(1400.0)
.endTemporaryLimit()
.add();

assertEquals("TL", currentLimits.getTemporaryLimit(20 * 60).getName());
assertEquals("TL", currentLimits.getTemporaryLimit(10 * 60).getName());
}

@Test
public void testAdderGetOwner() {
Line line = createNetwork().getLine("L");
Expand Down

0 comments on commit dc0fb37

Please sign in to comment.