From b75a670fbe39c4037fa2b86bf707fe3e4fc985a7 Mon Sep 17 00:00:00 2001 From: basseche Date: Wed, 20 Nov 2024 14:52:41 +0100 Subject: [PATCH 1/5] Fix - Transformers have only one substation --- .../utils/expertfilter/ExpertFilterUtils.java | 10 ++---- .../filter/utils/expertfilter/FieldType.java | 1 - .../PropertiesExpertRuleTest.java | 36 ++++++------------- 3 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java index 378dd32..37ca539 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java @@ -371,8 +371,7 @@ private static String getTwoWindingsTransformerFieldValue(FieldType field, Strin case HAS_PHASE_TAP_CHANGER -> String.valueOf(twoWindingsTransformer.hasPhaseTapChanger()); case PHASE_REGULATION_MODE, PHASE_REGULATION_VALUE -> getPhaseTapChangerFieldValue(field, twoWindingsTransformer.getPhaseTapChanger()); - case SUBSTATION_PROPERTIES_1 -> twoWindingsTransformer.getTerminal1().getVoltageLevel().getNullableSubstation().getProperty(propertyName); - case SUBSTATION_PROPERTIES_2 -> twoWindingsTransformer.getTerminal2().getVoltageLevel().getNullableSubstation().getProperty(propertyName); + case SUBSTATION_PROPERTIES -> twoWindingsTransformer.getNullableSubstation().getProperty(propertyName); case VOLTAGE_LEVEL_PROPERTIES_1 -> twoWindingsTransformer.getTerminal1().getVoltageLevel().getProperty(propertyName); case VOLTAGE_LEVEL_PROPERTIES_2 -> twoWindingsTransformer.getTerminal2().getVoltageLevel().getProperty(propertyName); default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + twoWindingsTransformer.getType() + "]"); @@ -383,6 +382,7 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str return switch (field) { case COUNTRY -> threeWindingsTransformer.getSubstation().flatMap(Substation::getCountry).map(String::valueOf).orElse(null); case RATED_VOLTAGE_0 -> String.valueOf(threeWindingsTransformer.getRatedU0()); + case SUBSTATION_PROPERTIES -> threeWindingsTransformer.getNullableSubstation().getProperty(propertyName); case CONNECTED_1, NOMINAL_VOLTAGE_1, RATED_VOLTAGE_1, @@ -399,7 +399,6 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str HAS_PHASE_TAP_CHANGER_1, PHASE_REGULATION_MODE_1, PHASE_REGULATION_VALUE_1, - SUBSTATION_PROPERTIES_1, VOLTAGE_LEVEL_PROPERTIES_1 -> getThreeWindingsTransformerLegFieldValue(field, propertyName, threeWindingsTransformer.getLeg1()); case CONNECTED_2, NOMINAL_VOLTAGE_2, @@ -417,7 +416,6 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str HAS_PHASE_TAP_CHANGER_2, PHASE_REGULATION_MODE_2, PHASE_REGULATION_VALUE_2, - SUBSTATION_PROPERTIES_2, VOLTAGE_LEVEL_PROPERTIES_2 -> getThreeWindingsTransformerLegFieldValue(field, propertyName, threeWindingsTransformer.getLeg2()); case CONNECTED_3, NOMINAL_VOLTAGE_3, @@ -435,7 +433,6 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str HAS_PHASE_TAP_CHANGER_3, PHASE_REGULATION_MODE_3, PHASE_REGULATION_VALUE_3, - SUBSTATION_PROPERTIES_3, VOLTAGE_LEVEL_PROPERTIES_3 -> getThreeWindingsTransformerLegFieldValue(field, propertyName, threeWindingsTransformer.getLeg3()); default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + threeWindingsTransformer.getType() + "]"); @@ -492,9 +489,6 @@ private static String getThreeWindingsTransformerLegFieldValue(FieldType field, PHASE_REGULATION_VALUE_2, PHASE_REGULATION_MODE_3, PHASE_REGULATION_VALUE_3 -> getPhaseTapChangerFieldValue(field, leg.getPhaseTapChanger()); - case SUBSTATION_PROPERTIES_1, - SUBSTATION_PROPERTIES_2, - SUBSTATION_PROPERTIES_3 -> leg.getTerminal().getVoltageLevel().getNullableSubstation().getProperty(propertyName); case VOLTAGE_LEVEL_PROPERTIES_1, VOLTAGE_LEVEL_PROPERTIES_2, VOLTAGE_LEVEL_PROPERTIES_3 -> leg.getTerminal().getVoltageLevel().getProperty(propertyName); diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java index cc05837..d9701f3 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java @@ -115,7 +115,6 @@ public enum FieldType { SUBSTATION_PROPERTIES, SUBSTATION_PROPERTIES_1, SUBSTATION_PROPERTIES_2, - SUBSTATION_PROPERTIES_3, VOLTAGE_LEVEL_PROPERTIES, VOLTAGE_LEVEL_PROPERTIES_1, VOLTAGE_LEVEL_PROPERTIES_2, diff --git a/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java b/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java index 914d54b..38d2d26 100644 --- a/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java +++ b/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java @@ -92,7 +92,6 @@ private static Stream provideArgumentsForTestWithException() { Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, line, "region", List.of("east"), PowsyblException.class), Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, battery, "region", List.of("east"), PowsyblException.class), Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, svar, "region", List.of("east"), PowsyblException.class), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_3, twoWindingsTransformer, "region", List.of("east"), PowsyblException.class), Arguments.of(IN, FieldType.SERIE_REACTANCE, threeWindingsTransformer, "region", List.of("east"), PowsyblException.class), Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, hvdcLine, "region", List.of("east"), PowsyblException.class), @@ -279,21 +278,16 @@ private static Stream provideArgumentsForTwoWindingTransformerTest() Mockito.when(voltageLevel2.getProperty("CodeOI")).thenReturn("33"); Mockito.when(terminal2.getVoltageLevel()).thenReturn(voltageLevel2); - Substation substation1 = Mockito.mock(Substation.class); - Substation substation2 = Mockito.mock(Substation.class); - Mockito.when(voltageLevel1.getNullableSubstation()).thenReturn(substation1); - Mockito.when(voltageLevel2.getNullableSubstation()).thenReturn(substation2); - Mockito.when(substation1.getProperty("regionCSV")).thenReturn("LILLE"); - Mockito.when(substation2.getProperty("regionCSV")).thenReturn("PARIS"); + Substation substation = Mockito.mock(Substation.class); + Mockito.when(twoWindingsTransformer.getNullableSubstation()).thenReturn(substation); + Mockito.when(substation.getProperty("regionCSV")).thenReturn("LILLE"); return Stream.of( // --- 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, "regionCSV", List.of("Lille"), twoWindingsTransformer, true), + Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Paris"), 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), @@ -359,27 +353,17 @@ private static Stream provideArgumentsForThreeWindingTransformerTest( Mockito.when(voltageLevel3.getProperty("CodeOI")).thenReturn("44"); Mockito.when(terminal3.getVoltageLevel()).thenReturn(voltageLevel3); - Substation substation1 = Mockito.mock(Substation.class); - Substation substation2 = Mockito.mock(Substation.class); - Substation substation3 = Mockito.mock(Substation.class); - Mockito.when(voltageLevel1.getNullableSubstation()).thenReturn(substation1); - Mockito.when(voltageLevel2.getNullableSubstation()).thenReturn(substation2); - Mockito.when(voltageLevel3.getNullableSubstation()).thenReturn(substation3); - Mockito.when(substation1.getProperty("regionCSV")).thenReturn("LILLE"); - Mockito.when(substation2.getProperty("regionCSV")).thenReturn("PARIS"); - Mockito.when(substation3.getProperty("regionCSV")).thenReturn("MARSEILLE"); + Substation substation = Mockito.mock(Substation.class); + Mockito.when(threeWindingsTransformer.getNullableSubstation()).thenReturn(substation); + Mockito.when(substation.getProperty("regionCSV")).thenReturn("LILLE"); return Stream.of( // --- IN --- // Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT"), threeWindingsTransformer, true), Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT2"), threeWindingsTransformer, false), Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT3"), threeWindingsTransformer, false), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Lille"), threeWindingsTransformer, true), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_1, "regionCSV", List.of("Paris"), threeWindingsTransformer, false), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Paris"), threeWindingsTransformer, true), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_2, "regionCSV", List.of("Lille"), threeWindingsTransformer, false), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_3, "regionCSV", List.of("Marseille"), threeWindingsTransformer, true), - Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES_3, "regionCSV", List.of("Lille"), threeWindingsTransformer, false), + Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Lille"), threeWindingsTransformer, true), + Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Paris"), threeWindingsTransformer, false), Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("22"), threeWindingsTransformer, true), Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_1, "CodeOI", List.of("33"), threeWindingsTransformer, false), Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("33"), threeWindingsTransformer, true), From 21cafd5b47bc111ea37f39d9c1668812ed376cbd Mon Sep 17 00:00:00 2001 From: basseche Date: Fri, 22 Nov 2024 14:50:48 +0100 Subject: [PATCH 2/5] delete useless code for 2 windings and 3 windings transformers --- src/main/java/org/gridsuite/filter/utils/FiltersUtils.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/utils/FiltersUtils.java b/src/main/java/org/gridsuite/filter/utils/FiltersUtils.java index 8b39c85..56fdd38 100644 --- a/src/main/java/org/gridsuite/filter/utils/FiltersUtils.java +++ b/src/main/java/org/gridsuite/filter/utils/FiltersUtils.java @@ -334,8 +334,7 @@ private static List> get2WTransformerList(Network network, Abstr countryFilter(twoWindingsTransformer.getTerminal2(), twoWindingsTransformerFilter.getCountries())) .filter(twoWindingsTransformer -> freePropertiesFilter(twoWindingsTransformer.getTerminal1(), twoWindingsTransformerFilter.getSubstationFreeProperties()) || freePropertiesFilter(twoWindingsTransformer.getTerminal2(), twoWindingsTransformerFilter.getSubstationFreeProperties())) - .filter(twoWindingsTransformer -> substationNameFilter(twoWindingsTransformer.getTerminal1(), twoWindingsTransformerFilter.getSubstationName()) || - substationNameFilter(twoWindingsTransformer.getTerminal2(), twoWindingsTransformerFilter.getSubstationName())); + .filter(twoWindingsTransformer -> substationNameFilter(twoWindingsTransformer.getTerminal1(), twoWindingsTransformerFilter.getSubstationName())); return new ArrayList<>(stream.toList()); } else if (filter instanceof IdentifierListFilter identifierListFilter) { List equipmentIds = getIdentifierListFilterEquipmentIds(identifierListFilter); @@ -366,9 +365,7 @@ private static List> get3WTransformerList(Network network, Abstr .filter(threeWindingsTransformer -> freePropertiesFilter(threeWindingsTransformer.getLeg1().getTerminal(), threeWindingsTransformerFilter.getSubstationFreeProperties()) || freePropertiesFilter(threeWindingsTransformer.getLeg2().getTerminal(), threeWindingsTransformerFilter.getSubstationFreeProperties()) || freePropertiesFilter(threeWindingsTransformer.getLeg3().getTerminal(), threeWindingsTransformerFilter.getSubstationFreeProperties())) - .filter(threeWindingsTransformer -> substationNameFilter(threeWindingsTransformer.getLeg1().getTerminal(), threeWindingsTransformerFilter.getSubstationName()) || - substationNameFilter(threeWindingsTransformer.getLeg2().getTerminal(), threeWindingsTransformerFilter.getSubstationName()) || - substationNameFilter(threeWindingsTransformer.getLeg3().getTerminal(), threeWindingsTransformerFilter.getSubstationName())); + .filter(threeWindingsTransformer -> substationNameFilter(threeWindingsTransformer.getLeg1().getTerminal(), threeWindingsTransformerFilter.getSubstationName())); return new ArrayList<>(stream.toList()); } else if (filter instanceof IdentifierListFilter identifierListFilter) { List equipmentIds = getIdentifierListFilterEquipmentIds(identifierListFilter); From db0eb74d0009248e2e5f29270ac2e9203ce17774 Mon Sep 17 00:00:00 2001 From: basseche Date: Tue, 26 Nov 2024 16:35:21 +0100 Subject: [PATCH 3/5] control if substation is null --- .../filter/utils/expertfilter/ExpertFilterUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java index 37ca539..99aaff8 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/ExpertFilterUtils.java @@ -371,7 +371,8 @@ private static String getTwoWindingsTransformerFieldValue(FieldType field, Strin case HAS_PHASE_TAP_CHANGER -> String.valueOf(twoWindingsTransformer.hasPhaseTapChanger()); case PHASE_REGULATION_MODE, PHASE_REGULATION_VALUE -> getPhaseTapChangerFieldValue(field, twoWindingsTransformer.getPhaseTapChanger()); - case SUBSTATION_PROPERTIES -> twoWindingsTransformer.getNullableSubstation().getProperty(propertyName); + case SUBSTATION_PROPERTIES -> twoWindingsTransformer.getNullableSubstation() != null ? + twoWindingsTransformer.getNullableSubstation().getProperty(propertyName) : null; case VOLTAGE_LEVEL_PROPERTIES_1 -> twoWindingsTransformer.getTerminal1().getVoltageLevel().getProperty(propertyName); case VOLTAGE_LEVEL_PROPERTIES_2 -> twoWindingsTransformer.getTerminal2().getVoltageLevel().getProperty(propertyName); default -> throw new PowsyblException(FIELD_AND_TYPE_NOT_IMPLEMENTED + " [" + field + "," + twoWindingsTransformer.getType() + "]"); @@ -382,7 +383,8 @@ private static String getThreeWindingsTransformerFieldValue(FieldType field, Str return switch (field) { case COUNTRY -> threeWindingsTransformer.getSubstation().flatMap(Substation::getCountry).map(String::valueOf).orElse(null); case RATED_VOLTAGE_0 -> String.valueOf(threeWindingsTransformer.getRatedU0()); - case SUBSTATION_PROPERTIES -> threeWindingsTransformer.getNullableSubstation().getProperty(propertyName); + case SUBSTATION_PROPERTIES -> threeWindingsTransformer.getNullableSubstation() != null ? + threeWindingsTransformer.getNullableSubstation().getProperty(propertyName) : null; case CONNECTED_1, NOMINAL_VOLTAGE_1, RATED_VOLTAGE_1, From 4b01a4f380124b8f6d3c94273be8818dd79650b7 Mon Sep 17 00:00:00 2001 From: basseche Date: Wed, 27 Nov 2024 11:29:25 +0100 Subject: [PATCH 4/5] unit test modified --- .../filter/expertfilter/PropertiesExpertRuleTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java b/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java index 38d2d26..c11428a 100644 --- a/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java +++ b/src/test/java/org/gridsuite/filter/expertfilter/PropertiesExpertRuleTest.java @@ -282,6 +282,10 @@ private static Stream provideArgumentsForTwoWindingTransformerTest() Mockito.when(twoWindingsTransformer.getNullableSubstation()).thenReturn(substation); Mockito.when(substation.getProperty("regionCSV")).thenReturn("LILLE"); + TwoWindingsTransformer transformerWithNullSub = Mockito.mock(TwoWindingsTransformer.class); + Mockito.when(transformerWithNullSub.getType()).thenReturn(IdentifiableType.TWO_WINDINGS_TRANSFORMER); + Mockito.when(transformerWithNullSub.getNullableSubstation()).thenReturn(null); + return Stream.of( // --- IN --- // Arguments.of(IN, FieldType.FREE_PROPERTIES, "propertyNameTWT", List.of("propertyValueTWT"), twoWindingsTransformer, true), @@ -291,7 +295,8 @@ private static Stream provideArgumentsForTwoWindingTransformerTest() 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), - Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("22"), twoWindingsTransformer, false) + Arguments.of(IN, FieldType.VOLTAGE_LEVEL_PROPERTIES_2, "CodeOI", List.of("22"), twoWindingsTransformer, false), + Arguments.of(IN, FieldType.SUBSTATION_PROPERTIES, "regionCSV", List.of("Paris"), transformerWithNullSub, false) ); } From 3a97c12ad1641afda2ff7243ce237463595939a1 Mon Sep 17 00:00:00 2001 From: basseche Date: Wed, 27 Nov 2024 12:51:12 +0100 Subject: [PATCH 5/5] keep obselete value to avoid crash Co-authored-by: Mathieu Deharbe <148252167+Mathieu-Deharbe@users.noreply.github.com> --- .../java/org/gridsuite/filter/utils/expertfilter/FieldType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java b/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java index d9701f3..378eca9 100644 --- a/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java +++ b/src/main/java/org/gridsuite/filter/utils/expertfilter/FieldType.java @@ -115,6 +115,7 @@ public enum FieldType { SUBSTATION_PROPERTIES, SUBSTATION_PROPERTIES_1, SUBSTATION_PROPERTIES_2, + SUBSTATION_PROPERTIES_3, // this FieldType value is obsolete but kept here to avoid crashes in case of remaining filters using it VOLTAGE_LEVEL_PROPERTIES, VOLTAGE_LEVEL_PROPERTIES_1, VOLTAGE_LEVEL_PROPERTIES_2,