Skip to content

Commit 8de14b7

Browse files
fix(preloading-strategy): make sure only applicable modifications are taken into account (#727)
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
1 parent 8f76c60 commit 8de14b7

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public NetworkModificationApplicator(NetworkStoreService networkStoreService, Eq
9898
*/
9999
public CompletableFuture<NetworkModificationResult> applyModifications(ModificationApplicationGroup modificationInfosGroup, NetworkInfos networkInfos) {
100100
PreloadingStrategy preloadingStrategy = modificationInfosGroup.modifications().stream()
101+
.filter(m -> m.getActivated() && !m.getStashed())
101102
.map(ModificationEntity::getType)
102103
.map(ModificationType::valueOf)
103104
.reduce(ModificationType::maxStrategy)
@@ -140,6 +141,7 @@ public NetworkModificationResult applyModifications(List<ModificationApplication
140141
PreloadingStrategy preloadingStrategy = modificationInfosGroups.stream()
141142
.map(ModificationApplicationGroup::modifications)
142143
.flatMap(List::stream)
144+
.filter(m -> m.getActivated() && !m.getStashed())
143145
.map(ModificationEntity::getType)
144146
.map(ModificationType::valueOf)
145147
.reduce(ModificationType::maxStrategy)

src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ public NetworkModificationResult buildVariant(@NonNull UUID networkUuid, @NonNul
314314

315315
PreloadingStrategy preloadingStrategy = modificationGroupsInfos.stream().map(ModificationApplicationGroup::modifications)
316316
.flatMap(Collection::stream)
317+
.filter(m -> m.getActivated() && !m.getStashed())
317318
.map(ModificationEntity::getType)
318319
.map(ModificationType::valueOf)
319320
.reduce(ModificationType::maxStrategy).map(ModificationType::getStrategy).orElse(PreloadingStrategy.NONE);
@@ -371,6 +372,7 @@ public Map<UUID, UUID> duplicateGroup(UUID sourceGroupUuid, UUID groupUuid) {
371372
private CompletableFuture<Optional<NetworkModificationResult>> applyModifications(UUID networkUuid, String variantId, ModificationApplicationGroup modificationGroupInfos) {
372373
if (!modificationGroupInfos.modifications().isEmpty()) {
373374
PreloadingStrategy preloadingStrategy = modificationGroupInfos.modifications().stream()
375+
.filter(m -> m.getActivated() && !m.getStashed())
374376
.map(ModificationEntity::getType)
375377
.map(ModificationType::valueOf)
376378
.reduce(ModificationType::maxStrategy).map(ModificationType::getStrategy).orElse(PreloadingStrategy.NONE);

src/test/java/org/gridsuite/modification/server/service/NetworkModificationApplicatorTest.java

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
import com.powsybl.commons.report.TypedValue;
1414
import com.powsybl.network.store.client.NetworkStoreService;
1515
import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl;
16-
import org.gridsuite.modification.ModificationType;
16+
import org.gridsuite.modification.dto.VoltageInitModificationInfos;
17+
import org.gridsuite.modification.dto.VoltageLevelModificationInfos;
1718
import org.gridsuite.modification.server.dto.ModificationApplicationGroup;
1819
import org.gridsuite.modification.server.dto.NetworkInfos;
1920
import org.gridsuite.modification.server.dto.NetworkModificationResult;
2021
import org.gridsuite.modification.server.dto.NetworkModificationResult.ApplicationStatus;
2122
import org.gridsuite.modification.server.dto.ReportInfos;
2223
import org.gridsuite.modification.server.entities.ModificationEntity;
24+
import org.gridsuite.modification.server.entities.equipment.modification.VoltageInitModificationEntity;
25+
import org.gridsuite.modification.server.entities.equipment.modification.VoltageLevelModificationEntity;
2326
import org.gridsuite.modification.server.modifications.NetworkModificationApplicator;
2427
import org.gridsuite.modification.server.utils.TestUtils;
2528
import org.gridsuite.modification.server.utils.elasticsearch.DisableElasticsearch;
@@ -79,28 +82,97 @@ void setUp() {
7982

8083
@Test
8184
void testApplyModificationsWithAllCollectionsNeededForBusView() {
82-
List<ModificationEntity> modificationInfosList = List.of(mock(ModificationEntity.class));
83-
84-
when(modificationInfosList.get(0).getType()).thenReturn(ModificationType.VOLTAGE_INIT_MODIFICATION.name());
85+
var modificationInfos = VoltageInitModificationInfos.builder()
86+
.stashed(false)
87+
.activated(true)
88+
.build();
89+
List<ModificationEntity> modificationInfosList = List.of(new VoltageInitModificationEntity(modificationInfos));
8590

86-
NetworkModificationResult result = TestUtils.applyModificationsBlocking(networkModificationApplicator, new ModificationApplicationGroup(UUID.randomUUID(), modificationInfosList, reportInfos), networkInfos);
91+
NetworkModificationResult result = TestUtils.applyModificationsBlocking(
92+
networkModificationApplicator,
93+
new ModificationApplicationGroup(UUID.randomUUID(), modificationInfosList, reportInfos),
94+
networkInfos
95+
);
8796

8897
assertNotNull(result);
8998
verify(largeNetworkModificationExecutionService).supplyAsync(any());
9099
}
91100

92101
@Test
93102
void testApplyModificationsWithGroupsAndAllCollectionsNeededForBusView() {
94-
List<ModificationApplicationGroup> modificationInfosGroups = List.of(new ModificationApplicationGroup(UUID.randomUUID(), List.of(mock(ModificationEntity.class)), mock(ReportInfos.class)));
95-
96-
when(modificationInfosGroups.get(0).modifications().get(0).getType()).thenReturn(ModificationType.VOLTAGE_INIT_MODIFICATION.name());
103+
var modificationInfos = VoltageInitModificationInfos.builder()
104+
.stashed(false)
105+
.activated(true)
106+
.build();
107+
List<ModificationEntity> modificationInfosList = List.of(new VoltageInitModificationEntity(modificationInfos));
108+
List<ModificationApplicationGroup> modificationInfosGroups = List.of(
109+
new ModificationApplicationGroup(
110+
UUID.randomUUID(),
111+
modificationInfosList,
112+
mock(ReportInfos.class)
113+
));
97114

98115
NetworkModificationResult result = networkModificationApplicator.applyModifications(modificationInfosGroups, networkInfos);
99116

100117
assertNotNull(result);
101118
verify(largeNetworkModificationExecutionService).supplyAsync(any());
102119
}
103120

121+
@Test
122+
void testApplyModificationsWithAllCollectionsNeededForBusViewStashedAndNotActivated() {
123+
var modificationInfosList = createModificationsWithUnactiveAllCollectionAndActiveNone();
124+
125+
NetworkModificationResult result = TestUtils.applyModificationsBlocking(
126+
networkModificationApplicator,
127+
new ModificationApplicationGroup(UUID.randomUUID(), modificationInfosList, reportInfos),
128+
networkInfos
129+
);
130+
131+
assertNotNull(result);
132+
verifyNoInteractions(largeNetworkModificationExecutionService);
133+
}
134+
135+
@Test
136+
void testApplyModificationsWithGroupsAndAllCollectionsNeededForBusViewStashedAndNotActivated() {
137+
var modificationInfosList = createModificationsWithUnactiveAllCollectionAndActiveNone();
138+
List<ModificationApplicationGroup> modificationInfosGroups = List.of(
139+
new ModificationApplicationGroup(
140+
UUID.randomUUID(),
141+
modificationInfosList,
142+
mock(ReportInfos.class)
143+
));
144+
145+
NetworkModificationResult result = networkModificationApplicator.applyModifications(modificationInfosGroups, networkInfos);
146+
147+
assertNotNull(result);
148+
verifyNoInteractions(largeNetworkModificationExecutionService);
149+
}
150+
151+
private List<ModificationEntity> createModificationsWithUnactiveAllCollectionAndActiveNone() {
152+
// All collections but stashed
153+
var modificationInfosStashed = VoltageInitModificationInfos.builder()
154+
.stashed(true)
155+
.activated(true)
156+
.build();
157+
// All collections but not activated
158+
var modificationInfosNotActivated = VoltageInitModificationInfos.builder()
159+
.stashed(true)
160+
.activated(false)
161+
.build();
162+
// None and active
163+
var modificationInfosPreloadingNone = VoltageLevelModificationInfos.builder()
164+
.stashed(false)
165+
.activated(true)
166+
.equipmentId(UUID.randomUUID().toString())
167+
.build();
168+
// So in the end strategy should be none
169+
return List.of(
170+
new VoltageInitModificationEntity(modificationInfosStashed),
171+
new VoltageInitModificationEntity(modificationInfosNotActivated),
172+
new VoltageLevelModificationEntity(modificationInfosPreloadingNone)
173+
);
174+
}
175+
104176
@ParameterizedTest
105177
@MethodSource("provideArgumentsForComputeHigherSeverity")
106178
void computeHigherSeverity(List<ReportNode> reports, ApplicationStatus expectedSeverity) {

0 commit comments

Comments
 (0)