Skip to content

Commit

Permalink
[Expert filter] Ignore case-sensitive for IN and NOT_IN operator for …
Browse files Browse the repository at this point in the history
…String and Property expert rule
  • Loading branch information
thangqp committed Jul 3, 2024
1 parent e49183a commit 0fb4925
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import org.gridsuite.filter.identifierlistfilter.FilterEquipments;
import org.gridsuite.filter.utils.expertfilter.DataType;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.gridsuite.filter.utils.expertfilter.ExpertFilterUtils.getFieldValue;

Expand Down Expand Up @@ -46,7 +49,7 @@ public boolean evaluateRule(Identifiable<?> identifiable, FilterLoader filterLoa
return false;
}
return switch (this.getOperator()) {
case IN -> this.getPropertyValues().contains(propertyValue);
case IN -> this.getPropertyValues().stream().anyMatch(propertyValue::equalsIgnoreCase);
default -> throw new PowsyblException(this.getOperator() + " operator not supported with " + this.getDataType() + " rule data type");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.gridsuite.filter.identifierlistfilter.FilterEquipments;
import org.gridsuite.filter.utils.expertfilter.DataType;

import java.util.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.gridsuite.filter.utils.expertfilter.ExpertFilterUtils.getFieldValue;
import static org.gridsuite.filter.utils.expertfilter.OperatorType.NOT_EXISTS;
Expand Down Expand Up @@ -68,8 +71,8 @@ public boolean evaluateRule(Identifiable<?> identifiable, FilterLoader filterLoa
case ENDS_WITH -> StringUtils.endsWithIgnoreCase(identifiableValue, this.getValue());
case EXISTS -> !StringUtils.isEmpty(identifiableValue);
case NOT_EXISTS -> StringUtils.isEmpty(identifiableValue);
case IN -> this.getValues().contains(identifiableValue);
case NOT_IN -> !this.getValues().contains(identifiableValue);
case IN -> this.getValues().stream().anyMatch(identifiableValue::equalsIgnoreCase);
case NOT_IN -> this.getValues().stream().noneMatch(identifiableValue::equalsIgnoreCase);
default -> throw new PowsyblException(this.getOperator() + " operator not supported with " + this.getDataType() + " rule data type");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ private static Stream<Arguments> provideArgumentsForSubstationTest() {

return Stream.of(
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "cvgRegion", List.of("LILLE", "PARIS"), substation, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "cvgRegion", List.of("PARIS"), substation, false)
Arguments.of(IN, FieldType.FREE_PROPERTIES, "cvgRegion", List.of("Lille", "PARIS"), substation, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "cvgRegion", List.of("Paris"), substation, false)
);
}

Expand Down Expand Up @@ -145,8 +145,8 @@ private static Stream<Arguments> provideArgumentsForGeneratorTest() {
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "CodeOI", List.of("11"), generator, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "CodeOI", List.of("22"), generator, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("LILLE"), generator, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("PARIS"), generator, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Lille"), generator, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Paris"), generator, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES, "CodeOI", List.of("22"), generator, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES, "CodeOI", List.of("11"), generator, false)
);
Expand Down Expand Up @@ -184,10 +184,10 @@ private static Stream<Arguments> provideArgumentsForLineTest() {
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "region", List.of("north"), line, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "region", List.of("south"), line, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("LILLE"), line, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("PARIS"), line, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("PARIS"), line, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("LILLE"), line, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Lille"), line, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Paris"), line, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Paris"), line, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Lille"), line, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("22"), line, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("33"), line, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("33"), line, true),
Expand All @@ -199,7 +199,7 @@ private static Stream<Arguments> provideArgumentsForLoadTest() {

Load load = Mockito.mock(Load.class);
Mockito.when(load.getType()).thenReturn(IdentifiableType.LOAD);
Mockito.when(load.getProperty("propertyNameLoad")).thenReturn("propertyValueLoad");
Mockito.when(load.getProperty("propertyNameLoad")).thenReturn("PropertyValueLoad");

Substation substation = Mockito.mock(Substation.class);
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Expand All @@ -208,7 +208,7 @@ private static Stream<Arguments> provideArgumentsForLoadTest() {
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
Mockito.when(load.getTerminal()).thenReturn(terminal);
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("propertyValueSubstation");
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("PropertyValueSubstation");

return Stream.of(
// --- IN --- //
Expand All @@ -225,7 +225,7 @@ private static Stream<Arguments> provideArgumentsForShuntCompensatorTest() {

ShuntCompensator shuntCompensator = Mockito.mock(ShuntCompensator.class);
Mockito.when(shuntCompensator.getType()).thenReturn(IdentifiableType.SHUNT_COMPENSATOR);
Mockito.when(shuntCompensator.getProperty("propertyNameSC")).thenReturn("propertyValueSC");
Mockito.when(shuntCompensator.getProperty("propertyNameSC")).thenReturn("PropertyValueSC");

Substation substation = Mockito.mock(Substation.class);
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Expand All @@ -234,7 +234,7 @@ private static Stream<Arguments> provideArgumentsForShuntCompensatorTest() {
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
Mockito.when(shuntCompensator.getTerminal()).thenReturn(terminal);
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("propertyValueSubstation");
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("PropertyValueSubstation");

return Stream.of(
// --- IN --- //
Expand All @@ -251,7 +251,7 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()

TwoWindingsTransformer twoWindingsTransformer = Mockito.mock(TwoWindingsTransformer.class);
Mockito.when(twoWindingsTransformer.getType()).thenReturn(IdentifiableType.TWO_WINDINGS_TRANSFORMER);
Mockito.when(twoWindingsTransformer.getProperty("propertyNameTWT")).thenReturn("propertyValueTWT");
Mockito.when(twoWindingsTransformer.getProperty("propertyNameTWT")).thenReturn("PropertyValueTWT");

Terminal terminal1 = Mockito.mock(Terminal.class);
Mockito.when(twoWindingsTransformer.getTerminal1()).thenReturn(terminal1);
Expand All @@ -278,10 +278,10 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
// --- IN --- //
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT2"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("LILLE"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("PARIS"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("PARIS"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("LILLE"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Lille"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Paris"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Paris"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Lille"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("22"), twoWindingsTransformer, true),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("33"), twoWindingsTransformer, false),
Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("33"), twoWindingsTransformer, true),
Expand All @@ -292,7 +292,7 @@ private static Stream<Arguments> provideArgumentsForTwoWindingTransformerTest()
private static Stream<Arguments> provideArgumentsForStaticVarCompensatorTest() {
StaticVarCompensator svar = Mockito.mock(StaticVarCompensator.class);
Mockito.when(svar.getType()).thenReturn(IdentifiableType.STATIC_VAR_COMPENSATOR);
Mockito.when(svar.getProperty("propertyNameSVAR")).thenReturn("propertyValueSVAR");
Mockito.when(svar.getProperty("propertyNameSVAR")).thenReturn("PropertyValueSVAR");

Substation substation = Mockito.mock(Substation.class);
VoltageLevel voltageLevel = Mockito.mock(VoltageLevel.class);
Expand All @@ -301,7 +301,7 @@ private static Stream<Arguments> provideArgumentsForStaticVarCompensatorTest() {
Terminal terminal = Mockito.mock(Terminal.class);
Mockito.when(terminal.getVoltageLevel()).thenReturn(voltageLevel);
Mockito.when(svar.getTerminal()).thenReturn(terminal);
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("propertyValueSubstation");
Mockito.when(substation.getProperty("propertyNameSubstation")).thenReturn("PropertyValueSubstation");

return Stream.of(
// --- IN --- //
Expand Down
Loading

0 comments on commit 0fb4925

Please sign in to comment.