Skip to content

Commit

Permalink
Fix maxStrategy() implementation to handle ALL_COLLECTIONS_NEEDED_FOR…
Browse files Browse the repository at this point in the history
…_BUS_VIEW strategy (#497)

Signed-off-by: BOUHOURS Antoine <[email protected]>
  • Loading branch information
antoinebhs authored Jul 10, 2024
1 parent 6928386 commit 7fc7663
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slimane.amar at rte-france.com>
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down Expand Up @@ -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;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <antoine.bouhours at rte-france.com>
*/
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));
}
}

0 comments on commit 7fc7663

Please sign in to comment.