Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove name unicity constraint on temporary limits #3043

Merged
merged 3 commits into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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>}
@@ -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;
}

@@ -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;
@@ -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) {
Original file line number Diff line number Diff line change
@@ -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)
@@ -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");