diff --git a/src/main/java/org/gridsuite/modification/server/ModificationType.java b/src/main/java/org/gridsuite/modification/server/ModificationType.java index 13ceb1408..0f055ca6d 100644 --- a/src/main/java/org/gridsuite/modification/server/ModificationType.java +++ b/src/main/java/org/gridsuite/modification/server/ModificationType.java @@ -8,8 +8,6 @@ import com.powsybl.network.store.client.PreloadingStrategy; -import static org.gridsuite.modification.server.NetworkModificationException.Type.PRELOADING_STRATEGY_NOT_ALLOWED; - /** * @author Slimane Amar * @author Franck Lecuyer @@ -65,9 +63,20 @@ public PreloadingStrategy getStrategy() { } public ModificationType maxStrategy(ModificationType other) { - if (strategy == PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW || other.strategy == PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW) { - throw new NetworkModificationException(PRELOADING_STRATEGY_NOT_ALLOWED, "Preloading strategy ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW not allowed"); - } - return strategy != PreloadingStrategy.NONE ? this : other; + return switch (strategy) { + case NONE -> { + if (other.strategy != PreloadingStrategy.NONE) { + yield other; + } + yield this; + } + case COLLECTION -> { + if (other.strategy == PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW) { + yield other; + } + yield this; + } + case ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW -> this; + }; } } diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationException.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationException.java index 9c57aae3f..139111089 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationException.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationException.java @@ -103,7 +103,6 @@ public enum Type { DELETE_ATTACHING_LINE_NOT_FOUND(HttpStatus.NOT_FOUND), FILTERS_NOT_FOUND(HttpStatus.NOT_FOUND), GENERATION_DISPATCH_ERROR(HttpStatus.INTERNAL_SERVER_ERROR), - PRELOADING_STRATEGY_NOT_ALLOWED(HttpStatus.INTERNAL_SERVER_ERROR), VOLTAGE_INIT_MODIFICATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR), TABULAR_MODIFICATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR), TABULAR_CREATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR), diff --git a/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java b/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java new file mode 100644 index 000000000..8a3bb005e --- /dev/null +++ b/src/test/java/org/gridsuite/modification/server/ModificationTypeTest.java @@ -0,0 +1,56 @@ +/* + Copyright (c) 2024, RTE (http://www.rte-france.com) + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.modification.server; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author Antoine Bouhours + */ +public class ModificationTypeTest { + @Test + public void testMaxStrategyNoneVsNone() { + ModificationType noneStrategy1 = ModificationType.LOAD_CREATION; + ModificationType noneStrategy2 = ModificationType.LOAD_MODIFICATION; + assertEquals(noneStrategy1, noneStrategy1.maxStrategy(noneStrategy2)); + assertEquals(noneStrategy2, noneStrategy2.maxStrategy(noneStrategy1)); + } + + @Test + public void testMaxStrategyNoneVsCollection() { + ModificationType noneStrategy = ModificationType.LOAD_CREATION; + ModificationType collectionStrategy = ModificationType.TABULAR_MODIFICATION; + assertEquals(collectionStrategy, noneStrategy.maxStrategy(collectionStrategy)); + assertEquals(collectionStrategy, collectionStrategy.maxStrategy(noneStrategy)); + } + + @Test + public void testMaxStrategyNoneVsAllCollectionsNeededForBusView() { + ModificationType noneStrategy = ModificationType.LOAD_CREATION; + ModificationType allCollectionsNeededForBusViewStrategy = ModificationType.VOLTAGE_INIT_MODIFICATION; + assertEquals(allCollectionsNeededForBusViewStrategy, noneStrategy.maxStrategy(allCollectionsNeededForBusViewStrategy)); + assertEquals(allCollectionsNeededForBusViewStrategy, allCollectionsNeededForBusViewStrategy.maxStrategy(noneStrategy)); + } + + @Test + public void testMaxStrategyCollectionVsCollection() { + ModificationType collectionStrategy1 = ModificationType.TABULAR_MODIFICATION; + ModificationType collectionStrategy2 = ModificationType.TABULAR_CREATION; + assertEquals(collectionStrategy1, collectionStrategy1.maxStrategy(collectionStrategy2)); + assertEquals(collectionStrategy2, collectionStrategy2.maxStrategy(collectionStrategy1)); + } + + @Test + public void testMaxStrategyCollectionVsAllCollectionsNeededForBusView() { + ModificationType collectionStrategy = ModificationType.TABULAR_MODIFICATION; + ModificationType allCollectionsNeededForBusViewStrategy = ModificationType.VOLTAGE_INIT_MODIFICATION; + assertEquals(allCollectionsNeededForBusViewStrategy, collectionStrategy.maxStrategy(allCollectionsNeededForBusViewStrategy)); + assertEquals(allCollectionsNeededForBusViewStrategy, allCollectionsNeededForBusViewStrategy.maxStrategy(collectionStrategy)); + } +}