Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
* @author Antoine Bouhours <antoine.bouhours at rte-france.com>
Expand Down Expand Up @@ -65,4 +66,9 @@ public Map<String, String> getMapMessageValues() {
mapMessageValues.put("equipmentType", getEquipmentType().name());
return mapMessageValues;
}

@Override
public Stream<FilterInfos> getFiltersStream() {
return Stream.ofNullable(filters).flatMap(List::stream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand Down Expand Up @@ -65,7 +66,13 @@
}

@Override
public Stream<FilterInfos> getFiltersStream() {
return Stream.ofNullable(formulaInfosList)
.flatMap(List::stream)
.flatMap(formulaInfos -> Stream.ofNullable(formulaInfos.getFilters()).flatMap(List::stream));
}

public Map<String, String> getMapMessageValues() {

Check warning on line 75 in src/main/java/org/gridsuite/modification/dto/ByFormulaModificationInfos.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add the "@Override" annotation above this method signature

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification&issues=AaGC57mUxLux756IX8HI&open=AaGC57mUxLux756IX8HI&pullRequest=245
Map<String, String> mapMessageValues = new HashMap<>();
mapMessageValues.put("equipmentType", getIdentifiableType().name());
return mapMessageValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class FilterInfos {
@Schema(description = "id of filter")
private UUID id;

@Schema(description = "name of filter")
@Schema(description = "name of filter, null if the filter no longer exists")
private String name;

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class GenerationDispatchInfos extends ModificationInfos {

@Override
public AbstractModification toModification(ModificationContext modificationContext) {
List<UUID> referencedFilterIds = streamReferencedFilters().map(FilterInfos::getId).distinct().toList();
List<UUID> referencedFilterIds = getFiltersStream().map(FilterInfos::getId).distinct().toList();
Map<UUID, Filter> filtersById = referencedFilterIds.isEmpty()
? Map.of()
: modificationContext.filterLoader().load(referencedFilterIds);
Expand All @@ -80,14 +80,6 @@ public AbstractModification toModification(ModificationContext modificationConte
.build();
}

private Stream<FilterInfos> streamReferencedFilters() {
return Stream.of(
nullToEmpty(getGeneratorsWithoutOutage()).stream(),
nullToEmpty(getGeneratorsWithFixedSupply()).stream(),
nullToEmpty(getGeneratorsFrequencyReserve()).stream().flatMap(reserve -> nullToEmpty(reserve.getGeneratorsFilters()).stream())
).flatMap(Function.identity());
}

private static <T> List<T> nullToEmpty(List<T> list) {
return list == null ? List.of() : list;
}
Expand All @@ -98,4 +90,15 @@ public ReportNode createSubReportNode(ReportNode reportNode) {
.withMessageTemplate("network.modification.generationDispatch")
.add();
}

@Override
public Stream<FilterInfos> getFiltersStream() {
return Stream.of(
Stream.ofNullable(generatorsWithoutOutage).flatMap(List::stream),
Stream.ofNullable(generatorsWithFixedSupply).flatMap(List::stream),
Stream.ofNullable(generatorsFrequencyReserve)
.flatMap(List::stream)
.flatMap(frequencyReserve -> Stream.ofNullable(frequencyReserve.getGeneratorsFilters()).flatMap(List::stream)))
.flatMap(Function.identity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
Expand Down Expand Up @@ -59,7 +60,13 @@
}

@Override
public Stream<FilterInfos> getFiltersStream() {
return Stream.ofNullable(assignmentInfosList)
.flatMap(List::stream)
.flatMap(assignmentInfos -> Stream.ofNullable(assignmentInfos.getFilters()).flatMap(List::stream));
}

public Map<String, String> getMapMessageValues() {

Check warning on line 69 in src/main/java/org/gridsuite/modification/dto/ModificationByAssignmentInfos.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add the "@Override" annotation above this method signature

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification&issues=AaGC57jwxLux756IX8HH&open=AaGC57jwxLux756IX8HH&pullRequest=245
Map<String, String> mapMessageValues = new HashMap<>();
mapMessageValues.put("equipmentType", getEquipmentType().name());
return mapMessageValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

import static org.gridsuite.modification.error.NetworkModificationExceptionType.MISSING_ROOT_NETWORK_APPLICABILITY;

Expand Down Expand Up @@ -149,6 +150,15 @@ public AbstractModification toModification(ModificationContext context) {
return toModification();
}

/**
* @return the filters this modification references, not those of the modifications it holds. Only their ids are
* stored: the directory owns their names, which the caller resolves before exposing or applying the modification.
*/
@JsonIgnore
public Stream<FilterInfos> getFiltersStream() {
return Stream.empty();
}

public final ModificationType getType() {
return type.get() != null ? type.get() : ModificationType.valueOf(this.getClass().getAnnotation(JsonTypeName.class).value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;

import static org.gridsuite.modification.error.NetworkModificationException.createModificationAttributeMissing;

Expand Down Expand Up @@ -69,4 +70,11 @@ public void check() {
}
}
}

@Override
public Stream<FilterInfos> getFiltersStream() {
return Stream.ofNullable(variations)
.flatMap(List::stream)
.flatMap(variation -> Stream.ofNullable(variation.getFilters()).flatMap(List::stream));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2026, 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.dto;

import org.gridsuite.modification.dto.byfilter.assignment.DoubleAssignmentInfos;
import org.gridsuite.modification.dto.byfilter.formula.FormulaInfos;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Filters referenced by modifications, whose names are resolved from the directory by the caller.
*
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
*/
class ModificationFiltersTest {

private static FilterInfos filter() {
return FilterInfos.builder().id(UUID.randomUUID()).build();
}

@Test
void testReferencedFilters() {
FilterInfos deletionFilter = filter();
assertEquals(List.of(deletionFilter),
ByFilterDeletionInfos.builder().filters(List.of(deletionFilter)).build().getFiltersStream().toList());

FilterInfos scalingFilter1 = filter();
FilterInfos scalingFilter2 = filter();
assertEquals(List.of(scalingFilter1, scalingFilter2),
GeneratorScalingInfos.builder().variations(List.of(
ScalingVariationInfos.builder().filters(List.of(scalingFilter1)).build(),
ScalingVariationInfos.builder().filters(List.of(scalingFilter2)).build())).build()
.getFiltersStream().toList());

FilterInfos withoutOutage = filter();
FilterInfos withFixedSupply = filter();
FilterInfos frequencyReserve = filter();
assertEquals(List.of(withoutOutage, withFixedSupply, frequencyReserve),
GenerationDispatchInfos.builder()
.generatorsWithoutOutage(List.of(withoutOutage))
.generatorsWithFixedSupply(List.of(withFixedSupply))
.generatorsFrequencyReserve(List.of(GeneratorsFrequencyReserveInfos.builder().generatorsFilters(List.of(frequencyReserve)).build()))
.build()
.getFiltersStream().toList());

FilterInfos formulaFilter = filter();
assertEquals(List.of(formulaFilter),
ByFormulaModificationInfos.builder().formulaInfosList(List.of(FormulaInfos.builder().filters(List.of(formulaFilter)).build())).build()
.getFiltersStream().toList());

FilterInfos assignmentFilter = filter();
assertEquals(List.of(assignmentFilter),
ModificationByAssignmentInfos.builder().assignmentInfosList(List.of(DoubleAssignmentInfos.builder().filters(List.of(assignmentFilter)).build())).build()
.getFiltersStream().toList());
}

@Test
void testNoReferencedFilters() {
assertEquals(0, new ModificationInfos().getFiltersStream().count());
assertEquals(0, new ByFilterDeletionInfos().getFiltersStream().count());
assertEquals(0, new GeneratorScalingInfos().getFiltersStream().count());
assertEquals(0, GeneratorScalingInfos.builder().variations(List.of(new ScalingVariationInfos())).build().getFiltersStream().count());
assertEquals(0, new GenerationDispatchInfos().getFiltersStream().count());
assertEquals(0, new ByFormulaModificationInfos().getFiltersStream().count());
assertEquals(0, new ModificationByAssignmentInfos().getFiltersStream().count());
}
}
Loading