Skip to content

Commit

Permalink
Refactor line and transformer filter entities to avoid code duplicati…
Browse files Browse the repository at this point in the history
…on (#77)

* Refactor line and transformer filter entities
In order to be able to organize files by filter type.

Signed-off-by: BOUHOURS Antoine <[email protected]>
  • Loading branch information
antoinebhs authored Nov 8, 2023
1 parent a80cb59 commit 52629db
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -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 <antoine.bouhours at rte-france.com>
*/
@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<String> countries1;

@Schema(description = "Countries2")
private SortedSet<String> countries2;

@Schema(description = "Free properties 1")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties1;

@Schema(description = "Free properties 2")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties2;

AbstractLineFilter(String equipmentID, String equipmentName, String substationName1, String substationName2, SortedSet<String> countries1, SortedSet<String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <antoine.bouhours at rte-france.com>
*/
@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<String> countries;

@Schema(description = "Free properties")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties;

AbstractTransformerFilter(String equipmentID, String equipmentName, String substationName, SortedSet<String> countries, Map<String, List<String>> 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);
}
}
56 changes: 9 additions & 47 deletions src/main/java/org/gridsuite/filter/server/dto/HvdcLineFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <franck.lecuyer at rte-france.com>
Expand All @@ -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<String> countries1;

@Schema(description = "Countries2")
private SortedSet<String> countries2;

@Schema(description = "Free properties 1")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties1;

@Schema(description = "Free properties 2")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties2;

@Schema(description = "Nominal voltage")
private NumericalFilter nominalVoltage;

public HvdcLineFilter(String equipmentID, String equipmentName, String substationName1, String substationName2,
SortedSet<String> countries1, SortedSet<String> countries2,
NumericalFilter nominalVoltage) {
super(equipmentID, equipmentName);
this.substationName1 = substationName1;
this.substationName2 = substationName2;
this.countries1 = countries1;
this.countries2 = countries2;
SortedSet<String> countries1, SortedSet<String> 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;
}
}
53 changes: 7 additions & 46 deletions src/main/java/org/gridsuite/filter/server/dto/LineFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jacques.borsenberger at rte-france.com>
Expand All @@ -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<String> countries1;

@Schema(description = "Countries2")
private SortedSet<String> countries2;

@Schema(description = "Free properties 1")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties1;

@Schema(description = "Free properties 2")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties2;

@Schema(description = "Nominal voltage 1")
private NumericalFilter nominalVoltage1;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <franck.lecuyer at rte-france.com>
Expand All @@ -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<String> countries;

@Schema(description = "Free properties")
// LinkedHashMap to keep order too
@JsonDeserialize(as = LinkedHashMap.class)
private Map<String, List<String>> freeProperties;

@Schema(description = "Nominal voltage 1")
private NumericalFilter nominalVoltage1;

Expand All @@ -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;
}
}
Loading

0 comments on commit 52629db

Please sign in to comment.