diff --git a/src/main/java/org/gridsuite/filter/server/dto/AbstractLineFilter.java b/src/main/java/org/gridsuite/filter/server/dto/AbstractLineFilter.java new file mode 100644 index 00000000..241cfd7b --- /dev/null +++ b/src/main/java/org/gridsuite/filter/server/dto/AbstractLineFilter.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2023, 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.filter.server.dto; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.springframework.util.CollectionUtils; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; + +/** + * @author Antoine Bouhours + */ +@Getter +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@ToString(callSuper = true) +@Schema(description = "Line Filters", allOf = CriteriaFilter.class) +public abstract class AbstractLineFilter extends AbstractEquipmentFilterForm { + + @Schema(description = "SubstationName1") + String substationName1; + + @Schema(description = "SubstationName2") + String substationName2; + + @Schema(description = "Countries1") + private SortedSet countries1; + + @Schema(description = "Countries2") + private SortedSet countries2; + + @Schema(description = "Free properties 1") + // LinkedHashMap to keep order too + @JsonDeserialize(as = LinkedHashMap.class) + private Map> freeProperties1; + + @Schema(description = "Free properties 2") + // LinkedHashMap to keep order too + @JsonDeserialize(as = LinkedHashMap.class) + private Map> freeProperties2; + + AbstractLineFilter(String equipmentID, String equipmentName, String substationName1, String substationName2, SortedSet countries1, SortedSet countries2) { + super(equipmentID, equipmentName); + this.substationName1 = substationName1; + this.substationName2 = substationName2; + this.countries1 = countries1; + this.countries2 = countries2; + } + + @Override + public boolean isEmpty() { + return super.isEmpty() + && substationName1 == null + && substationName2 == null + && CollectionUtils.isEmpty(countries1) + && CollectionUtils.isEmpty(countries2) + && CollectionUtils.isEmpty(freeProperties1) + && CollectionUtils.isEmpty(freeProperties2); + } +} diff --git a/src/main/java/org/gridsuite/filter/server/dto/AbstractTransformerFilter.java b/src/main/java/org/gridsuite/filter/server/dto/AbstractTransformerFilter.java new file mode 100644 index 00000000..60ef393e --- /dev/null +++ b/src/main/java/org/gridsuite/filter/server/dto/AbstractTransformerFilter.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2023, 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.filter.server.dto; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.springframework.util.CollectionUtils; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; + +/** + * @author Antoine Bouhours + */ +@Getter +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder +@ToString(callSuper = true) +@Schema(description = "Transformer Filters", allOf = CriteriaFilter.class) +public abstract class AbstractTransformerFilter extends AbstractEquipmentFilterForm { + + @Schema(description = "SubstationName") + private String substationName; + + @Schema(description = "Countries") + private SortedSet countries; + + @Schema(description = "Free properties") + // LinkedHashMap to keep order too + @JsonDeserialize(as = LinkedHashMap.class) + private Map> freeProperties; + + AbstractTransformerFilter(String equipmentID, String equipmentName, String substationName, SortedSet countries, Map> freeProperties) { + super(equipmentID, equipmentName); + this.substationName = substationName; + this.countries = countries; + this.freeProperties = freeProperties; + } + + @Override + public boolean isEmpty() { + return super.isEmpty() + && substationName == null + && CollectionUtils.isEmpty(countries) + && CollectionUtils.isEmpty(freeProperties); + } +} diff --git a/src/main/java/org/gridsuite/filter/server/dto/HvdcLineFilter.java b/src/main/java/org/gridsuite/filter/server/dto/HvdcLineFilter.java index 3c849867..236eae86 100644 --- a/src/main/java/org/gridsuite/filter/server/dto/HvdcLineFilter.java +++ b/src/main/java/org/gridsuite/filter/server/dto/HvdcLineFilter.java @@ -6,21 +6,15 @@ */ package org.gridsuite.filter.server.dto; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; - -import org.gridsuite.filter.server.utils.EquipmentType; -import org.springframework.util.CollectionUtils; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; import lombok.experimental.SuperBuilder; +import org.gridsuite.filter.server.utils.EquipmentType; + +import java.util.SortedSet; /** * @author Franck Lecuyer @@ -30,58 +24,26 @@ @AllArgsConstructor @SuperBuilder @ToString(callSuper = true) -@Schema(description = "Hvdc Filters", allOf = AbstractEquipmentFilterForm.class) -public class HvdcLineFilter extends AbstractEquipmentFilterForm { +@Schema(description = "Hvdc Filters", allOf = AbstractLineFilter.class) +public class HvdcLineFilter extends AbstractLineFilter { @Override public EquipmentType getEquipmentType() { return EquipmentType.HVDC_LINE; } - @Schema(description = "SubstationName1") - String substationName1; - - @Schema(description = "SubstationName2") - String substationName2; - - @Schema(description = "Countries1") - private SortedSet countries1; - - @Schema(description = "Countries2") - private SortedSet countries2; - - @Schema(description = "Free properties 1") - // LinkedHashMap to keep order too - @JsonDeserialize(as = LinkedHashMap.class) - private Map> freeProperties1; - - @Schema(description = "Free properties 2") - // LinkedHashMap to keep order too - @JsonDeserialize(as = LinkedHashMap.class) - private Map> freeProperties2; - @Schema(description = "Nominal voltage") private NumericalFilter nominalVoltage; public HvdcLineFilter(String equipmentID, String equipmentName, String substationName1, String substationName2, - SortedSet countries1, SortedSet countries2, - NumericalFilter nominalVoltage) { - super(equipmentID, equipmentName); - this.substationName1 = substationName1; - this.substationName2 = substationName2; - this.countries1 = countries1; - this.countries2 = countries2; + SortedSet countries1, SortedSet countries2, + NumericalFilter nominalVoltage) { + super(equipmentID, equipmentName, substationName1, substationName2, countries1, countries2); this.nominalVoltage = nominalVoltage; } @Override public boolean isEmpty() { return super.isEmpty() - && substationName1 == null - && substationName2 == null - && CollectionUtils.isEmpty(countries1) - && CollectionUtils.isEmpty(countries2) - && CollectionUtils.isEmpty(freeProperties1) - && CollectionUtils.isEmpty(freeProperties2) - && nominalVoltage == null; + && nominalVoltage == null; } } diff --git a/src/main/java/org/gridsuite/filter/server/dto/LineFilter.java b/src/main/java/org/gridsuite/filter/server/dto/LineFilter.java index 50688766..76ae816f 100644 --- a/src/main/java/org/gridsuite/filter/server/dto/LineFilter.java +++ b/src/main/java/org/gridsuite/filter/server/dto/LineFilter.java @@ -6,22 +6,10 @@ */ package org.gridsuite.filter.server.dto; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; - -import org.gridsuite.filter.server.utils.EquipmentType; -import org.springframework.util.CollectionUtils; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; +import lombok.*; import lombok.experimental.SuperBuilder; +import org.gridsuite.filter.server.utils.EquipmentType; /** * @author Jacques Borsenberger @@ -32,34 +20,13 @@ @AllArgsConstructor @SuperBuilder @ToString(callSuper = true) -@Schema(description = "Line Filters", allOf = CriteriaFilter.class) -public class LineFilter extends AbstractEquipmentFilterForm { +@Schema(description = "Line Filters", allOf = AbstractLineFilter.class) +public class LineFilter extends AbstractLineFilter { + @Override public EquipmentType getEquipmentType() { return EquipmentType.LINE; } - @Schema(description = "SubstationName1") - String substationName1; - - @Schema(description = "SubstationName2") - String substationName2; - - @Schema(description = "Countries1") - private SortedSet countries1; - - @Schema(description = "Countries2") - private SortedSet countries2; - - @Schema(description = "Free properties 1") - // LinkedHashMap to keep order too - @JsonDeserialize(as = LinkedHashMap.class) - private Map> freeProperties1; - - @Schema(description = "Free properties 2") - // LinkedHashMap to keep order too - @JsonDeserialize(as = LinkedHashMap.class) - private Map> freeProperties2; - @Schema(description = "Nominal voltage 1") private NumericalFilter nominalVoltage1; @@ -69,13 +36,7 @@ public EquipmentType getEquipmentType() { @Override public boolean isEmpty() { return super.isEmpty() - && substationName1 == null - && substationName2 == null - && CollectionUtils.isEmpty(countries1) - && CollectionUtils.isEmpty(countries2) - && CollectionUtils.isEmpty(freeProperties1) - && CollectionUtils.isEmpty(freeProperties2) - && nominalVoltage1 == null - && nominalVoltage2 == null; + && nominalVoltage1 == null + && nominalVoltage2 == null; } } diff --git a/src/main/java/org/gridsuite/filter/server/dto/ThreeWindingsTransformerFilter.java b/src/main/java/org/gridsuite/filter/server/dto/ThreeWindingsTransformerFilter.java index 856622cb..0218bd98 100644 --- a/src/main/java/org/gridsuite/filter/server/dto/ThreeWindingsTransformerFilter.java +++ b/src/main/java/org/gridsuite/filter/server/dto/ThreeWindingsTransformerFilter.java @@ -6,21 +6,13 @@ */ package org.gridsuite.filter.server.dto; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; - -import org.gridsuite.filter.server.utils.EquipmentType; -import org.springframework.util.CollectionUtils; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; import lombok.experimental.SuperBuilder; +import org.gridsuite.filter.server.utils.EquipmentType; /** * @author Franck Lecuyer @@ -30,24 +22,13 @@ @AllArgsConstructor @SuperBuilder @ToString(callSuper = true) -@Schema(description = "Three windings transformer Filters", allOf = CriteriaFilter.class) -public class ThreeWindingsTransformerFilter extends AbstractEquipmentFilterForm { +@Schema(description = "Three windings transformer Filters", allOf = AbstractTransformerFilter.class) +public class ThreeWindingsTransformerFilter extends AbstractTransformerFilter { @Override public EquipmentType getEquipmentType() { return EquipmentType.THREE_WINDINGS_TRANSFORMER; } - @Schema(description = "SubstationName") - String substationName; - - @Schema(description = "Countries") - private SortedSet countries; - - @Schema(description = "Free properties") - // LinkedHashMap to keep order too - @JsonDeserialize(as = LinkedHashMap.class) - private Map> freeProperties; - @Schema(description = "Nominal voltage 1") private NumericalFilter nominalVoltage1; @@ -60,11 +41,8 @@ public EquipmentType getEquipmentType() { @Override public boolean isEmpty() { return super.isEmpty() - && substationName == null - && CollectionUtils.isEmpty(countries) - && nominalVoltage1 == null - && nominalVoltage2 == null - && nominalVoltage3 == null - && CollectionUtils.isEmpty(freeProperties); + && nominalVoltage1 == null + && nominalVoltage2 == null + && nominalVoltage3 == null; } } diff --git a/src/main/java/org/gridsuite/filter/server/dto/TwoWindingsTransformerFilter.java b/src/main/java/org/gridsuite/filter/server/dto/TwoWindingsTransformerFilter.java index 396cd4d8..864dcede 100644 --- a/src/main/java/org/gridsuite/filter/server/dto/TwoWindingsTransformerFilter.java +++ b/src/main/java/org/gridsuite/filter/server/dto/TwoWindingsTransformerFilter.java @@ -6,21 +6,17 @@ */ package org.gridsuite.filter.server.dto; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; - -import org.gridsuite.filter.server.utils.EquipmentType; -import org.springframework.util.CollectionUtils; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; import lombok.experimental.SuperBuilder; +import org.gridsuite.filter.server.utils.EquipmentType; + +import java.util.List; +import java.util.Map; +import java.util.SortedSet; /** * @author Franck Lecuyer @@ -30,24 +26,13 @@ @AllArgsConstructor @SuperBuilder @ToString(callSuper = true) -@Schema(description = "Two windings transformer Filters", allOf = CriteriaFilter.class) -public class TwoWindingsTransformerFilter extends AbstractEquipmentFilterForm { +@Schema(description = "Two windings transformer Filters", allOf = AbstractTransformerFilter.class) +public class TwoWindingsTransformerFilter extends AbstractTransformerFilter { @Override public EquipmentType getEquipmentType() { return EquipmentType.TWO_WINDINGS_TRANSFORMER; } - @Schema(description = "SubstationName") - String substationName; - - @Schema(description = "Countries") - private SortedSet countries; - - @Schema(description = "Free properties") - // LinkedHashMap to keep order too - @JsonDeserialize(as = LinkedHashMap.class) - private Map> freeProperties; - @Schema(description = "Nominal voltage 1") private NumericalFilter nominalVoltage1; @@ -55,12 +40,9 @@ public EquipmentType getEquipmentType() { private NumericalFilter nominalVoltage2; public TwoWindingsTransformerFilter(String equipmentID, String equipmentName, String substationName, - SortedSet countries, Map> freeProperties, - NumericalFilter nominalVoltage1, NumericalFilter nominalVoltage2) { - super(equipmentID, equipmentName); - this.substationName = substationName; - this.countries = countries; - this.freeProperties = freeProperties; + SortedSet countries, Map> freeProperties, + NumericalFilter nominalVoltage1, NumericalFilter nominalVoltage2) { + super(equipmentID, equipmentName, substationName, countries, freeProperties); this.nominalVoltage1 = nominalVoltage1; this.nominalVoltage2 = nominalVoltage2; } @@ -68,10 +50,7 @@ public TwoWindingsTransformerFilter(String equipmentID, String equipmentName, St @Override public boolean isEmpty() { return super.isEmpty() - && substationName == null - && CollectionUtils.isEmpty(countries) - && nominalVoltage1 == null - && nominalVoltage2 == null - && CollectionUtils.isEmpty(freeProperties); + && nominalVoltage1 == null + && nominalVoltage2 == null; } } diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 50b423f9..460fe0b6 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -1539,4 +1539,34 @@ public void testExpertLoadFilter() throws Exception { [{"id":"LOAD","type":"LOAD"}] """, EquipmentType.LOAD); } + + @Test + public void lineFilterIsEmpty() { + HvdcLineFilter hvdcFilter = new HvdcLineFilter( + null, + null, + null, + null, + new TreeSet<>(), + new TreeSet<>(), + new NumericalFilter(RangeType.RANGE, 50., null) + ); + assertFalse(hvdcFilter.isEmpty()); + } + + @Test + public void transformerFilterIsEmpty() { + TwoWindingsTransformerFilter transformerFilter = + TwoWindingsTransformerFilter.builder() + .equipmentID(null) + .equipmentName(null) + .substationName(null) + .countries(new TreeSet<>()) + .freeProperties(Map.of("region", List.of("north"))) + .nominalVoltage1(NumericalFilter.builder().type(RangeType.RANGE).value1(370.).value2(390.).build()) + .nominalVoltage2(NumericalFilter.builder().type(RangeType.EQUALITY).value1(225.).build()) + .build(); + + assertFalse(transformerFilter.isEmpty()); + } }