From d534a2296c9c790bbe8da5addfbbf7b447f03a0f Mon Sep 17 00:00:00 2001 From: basseche Date: Wed, 13 Nov 2024 11:46:07 +0100 Subject: [PATCH 01/27] Migration equipment filter - first phase Ok --- pom.xml | 1 - .../migrations/MigrateEquipmentFilter.java | 511 ++++++++++++++++++ .../changesets/changelog_20241105T114300Z.xml | 9 + .../db/changelog/db.changelog-master.yaml | 3 + 4 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java create mode 100644 src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml diff --git a/pom.xml b/pom.xml index 9e2e2008..c94144a5 100644 --- a/pom.xml +++ b/pom.xml @@ -179,7 +179,6 @@ org.liquibase liquibase-core - runtime org.springframework.cloud diff --git a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java new file mode 100644 index 00000000..21c65356 --- /dev/null +++ b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java @@ -0,0 +1,511 @@ +package org.gridsuite.filter.server.migrations; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.UUID; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import liquibase.change.custom.CustomSqlChange; +import liquibase.database.Database; +import liquibase.database.jvm.JdbcConnection; +import liquibase.exception.CustomChangeException; +import liquibase.exception.DatabaseException; +import liquibase.exception.SetupException; +import liquibase.exception.ValidationErrors; +import liquibase.resource.ResourceAccessor; +import liquibase.statement.SqlStatement; +import liquibase.statement.core.InsertStatement; +import static org.gridsuite.filter.server.migrations.MigrateEquipmentFilter.ExpertRuleCol.*; + +public class MigrateEquipmentFilter implements CustomSqlChange +{ + private static final String EXPERT_RULE_TABLE = "expert_rule"; + private static final String EXPERT_RULE_VALUE_TABLE = "expert_rule_value"; + private static final String FREE_PROPS_ID = "free_properties_id"; + private static final String SUB_FREE_PROPS_ID = "substation_free_properties_id"; + private static final String NUMERIC_FILTER_ID = "numeric_filter_id_id"; + private static final String VALUE_COL = "value_"; + + enum ExpertRuleCol { + ID("id"), + COMBINATOR("combinator"), + DATA_TYPE("data_type"), + FIELD("field"), + OPERATOR("operator"), + PARENT_RULE_ID("parent_rule_id"); + + ExpertRuleCol(String colName) { + name_ = colName; + } + String name_; + + @Override + public String toString() { + return name_; + } + } + + enum ColType { + NUMERIC, + PROPERTY, + SUBSTATION_PROPERTY, + ENUM + } + + static class Column { + private final String name_; + private final ColType type_; + private String fieldValue_; + + String name() { return name_; } + ColType type() { return type_; } + String fieldValue() { return fieldValue_; } + + Column(String name, ColType type, String fieldValue) { + name_ = name; + type_ = type; + fieldValue_ = fieldValue; + } + } + + static class CountryTable { + private final String name_; + private final String idCol_; + private final String valueCol_; + private final String fieldValue_; + + CountryTable(String name, String idCol, String valueCol, String fieldValue) { + name_ = name; + idCol_ = idCol; + valueCol_ = valueCol; + fieldValue_ = fieldValue; + } + + public String name() { return name_; } + public String idCol() { return idCol_; } + public String valueCol() { return valueCol_; } + public String fieldValue() { return fieldValue_; } + } + + private enum Equipment + { + BATTERY("battery_filter"), + DANGLING_LINE( "dangling_line_filter"), + GENERATOR("generator_filter") { + @Override + Column[] columns() { + return new Column[] + { new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES"), + new Column("energy_source", ColType.ENUM, "ENERGY_SOURCE") + }; + } + } , + HVDC_LINE("hvdc_line_filter") { + @Override + Column[] columns() { + return new Column[] + { new Column("hvdc_line_filter_entity_numeric_filter_id_id", ColType.NUMERIC, "DC_NOMINAL_VOLTAGE"), + new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1"), + new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_2") + }; + } + @Override + CountryTable[] countriesTables() + { + return new CountryTable[] + { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + "_entity_id", "countries1", "COUNTRY_1"), + new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + "_entity_id", "countries2", "COUNTRY_2") + }; + } + }, + LINE("line_filter") { + @Override + Column[] columns() { + return new Column[] + { new Column("numeric_filter_id1_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_1"), + new Column("numeric_filter_id2_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_2"), + new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1"), + new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_2"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES"), + }; + } + + @Override + CountryTable[] countriesTables() + { + return new CountryTable[] + { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + "_entity_id", "countries1", "COUNTRY_1"), + new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + "_entity_id", "countries2", "COUNTRY_2") + }; + } + }, + LOAD("load_filter"), + SHUNT_COMPENSATOR("shunt_compensator_filter"), + STATIC_VAR_COMPENSATOR("static_var_compensator_filter"), + SUBSTATION("substation_filter") { + @Override + Column[] columns() { + return new Column[] { new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES") }; + } + }, + THREE_WINDINGS_TRANSFORMER("three_windings_transformer_filter") { + @Override + Column[] columns() { + return new Column[] + { new Column("three_windings_transformer_numeric_filter_id1_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_1"), + new Column("three_windings_transformer_numeric_filter_id2_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_2"), + new Column("three_windings_transformer_numeric_filter_id3_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_3"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1") + }; + } + }, + TWO_WINDINGS_TRANSFORMER("two_windings_transformer_filter") { + @Override + Column[] columns() { + return new Column[] + { new Column("numeric_filter_id1_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_1"), + new Column("two_windings_transformernumeric_filter_id2_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_2"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES") + }; + } + }, + VOLTAGE_LEVEL("voltage_level_filter"); + + Equipment(String equipmentTable) { + equipmentTable_ = equipmentTable; + } + String table() { return equipmentTable_; } + CountryTable[] countriesTables() { + return new CountryTable[] + {new CountryTable(equipmentTable_ + "_entity_countries", equipmentTable_ + "_entity_id", "countries", "COUNTRY")}; + } + Column[] columns() { + return new Column[] + { new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES") + }; + } + String equipmentTable_; + } + + @Override + public SqlStatement[] generateStatements(Database database) throws CustomChangeException + { + List statements = new ArrayList<>(); + + for (Equipment equipment : Equipment.values()) { + StringBuilder builder = new StringBuilder(""); + builder.append("select * from ").append(equipment.table()); + + try { + JdbcConnection connection = (JdbcConnection) database.getConnection(); + + // All filters to migrate in equipment filter table + try (ResultSet filters = connection.createStatement().executeQuery(builder.toString())) { + while (filters.next()) { + // Add a parent rule (And combinator) in expert_rule table + UUID parentRuleId = createParentRuleStatement(statements, database); + + // create and add filter + createFilterStatement(statements, database, parentRuleId, filters, equipment.name()); + + for (Column column : equipment.columns()) { + String colId = filters.getString(column.name()); + + switch (column.type()) { + case NUMERIC: + createNumericRuleStatements(connection, statements, database, parentRuleId, colId, column.fieldValue()); + break; + case SUBSTATION_PROPERTY, PROPERTY: + createPropertiesStatements(statements, database, connection, colId, parentRuleId, column.fieldValue()); + break; + case ENUM: + createEnumRuleStatement(statements, database, parentRuleId, colId, column.fieldValue()); + break; + default: break; + } + } + + // Countries + for (int i = 0; i < equipment.countriesTables().length; i++) { + CountryTable countryTable = equipment.countriesTables()[i]; + createCountryStatement(connection, statements, database, parentRuleId, countryTable, filters.getString("id")); + } + } + } + } catch (Exception throwables) { + throwables.printStackTrace(); + return new SqlStatement[0]; // If any exception occurs don't do any migration + } + } + + + //Create Rule from numeric_filter + Substation free properties id + free properties id + + return statements.toArray(new SqlStatement[0]); + } + + private String convertOperator(String operatorCriteriaFilter) + { + if (operatorCriteriaFilter == null) { + return ""; + } + + return switch (operatorCriteriaFilter) { + case "EQUALITY" -> "EQUALS"; + case "GREATER_THAN" -> "GREATER"; + case "GREATER_OR_EQUAL" -> "GREATER_OR_EQUALS"; + case "LESS_THAN" -> "LOWER"; + case "LESS_OR_EQUAL" -> "LOWER_OR_EQUALS"; + case "RANGE" -> "BETWEEN"; + default -> ""; + }; + } + + private void createFilterStatement (List statements, Database database, UUID parentRuleId, ResultSet filters, String equipment) + throws SQLException + { + InsertStatement filterStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_filter") + .addColumnValue("id", filters.getString("id")) + .addColumnValue("modification_date", filters.getString("modification_date")) + .addColumnValue("equipment_type", equipment) + .addColumnValue("rules_id", parentRuleId.toString() ); + statements.add(filterStatement); + } + + private UUID createParentRuleStatement(List statements, Database database) { + UUID parentRuleId = UUID.randomUUID(); + EnumMap values = new EnumMap<>(ExpertRuleCol.class); + values.put(ID, parentRuleId.toString()); + values.put(COMBINATOR, "AND"); + values.put(DATA_TYPE, "COMBINATOR"); + createRuleStatement(statements, database, values); + return parentRuleId; + } + + private void createRuleStatement(List statements, Database database, EnumMap values) + { + InsertStatement ruleStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), + EXPERT_RULE_TABLE); + + values.forEach((key, value) -> + { + if (value != null) { + ruleStatement.addColumnValue(key.toString(), value); + } + }); + statements.add(ruleStatement); + } + + private void createPropertiesStatements(List statements, Database database, JdbcConnection connection, + String propId, UUID parentRuleId, String fieldValue) throws SQLException, DatabaseException + { + if (propId == null) { return; } + StringBuilder builder = new StringBuilder(""); + + builder.append("select free_property_filter_entities_id from free_properties_free_property_filter_entities") + .append(" where free_properties_filter_entity_id = ").append("'").append(propId).append("'"); + + try (ResultSet propertyQuery = connection.createStatement().executeQuery(builder.toString())) { + while (propertyQuery.next()) { + String propertyId = propertyQuery.getString(1); + + builder.setLength(0); + builder.append("select prop_name from free_property where id = ").append("'").append(propertyId).append("'"); + + // Property name + String propName = null; + try (ResultSet propertyNameQuery = connection.createStatement().executeQuery(builder.toString())) { + if (propertyNameQuery.next()) { + propName = propertyNameQuery.getString("prop_name"); + } + } + + //Property values + if (propName == null) { continue; } + builder.setLength(0); + builder.append("select prop_values from prop_value where free_property_filter_entity_id = ").append("'").append(propertyId).append("'"); + + try (ResultSet propertyValueQuery = connection.createStatement().executeQuery(builder.toString())) { + createPropertyRuleStatements(statements, database, parentRuleId, propName, propertyValueQuery, fieldValue); + } + } + } + } + + + private void createPropertyRuleStatements(List statements, Database database, UUID parentRuleId, String propName, + ResultSet propertyValueQuery, String fieldValue) throws SQLException + { + UUID propsRuleId = UUID.randomUUID(); + EnumMap values = new EnumMap<>(ExpertRuleCol.class); + values.put(ID, propsRuleId.toString()); + values.put(DATA_TYPE, "PROPERTIES"); + values.put(FIELD, fieldValue); + values.put(OPERATOR, "IN"); + values.put(PARENT_RULE_ID, parentRuleId.toString()); + createRuleStatement(statements, database, values); + + //add property name + SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_properties") + .addColumnValue("id", propsRuleId.toString()) + .addColumnValue("property_name", propName); + statements.add(statement); + + //insert Values + int pos = 0; + while(propertyValueQuery.next()) { + String propValue = propertyValueQuery.getString(1); + statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_property_value") + .addColumnValue("expert_rule_properties_entity_id", propsRuleId.toString()) + .addColumnValue("property_values", propValue) + .addColumnValue("pos", String.valueOf(pos)); + pos++; + statements.add(statement); + } + + } + + private void createCountryStatement(JdbcConnection connection, List statements, Database database, UUID parentRuleId, + CountryTable countryTable, String filterIdToMigrate) + throws DatabaseException, SQLException + { + + // Add country values + StringBuilder builder = new StringBuilder(); + builder.append("select ").append(countryTable.valueCol()).append(" from ").append(countryTable.name()) + .append(" where ").append(countryTable.idCol()).append(" = ") + .append("'").append(filterIdToMigrate).append("'"); + + // Add country Country rule + UUID ruleId = UUID.randomUUID(); + EnumMap values = new EnumMap<>(ExpertRuleCol.class); + values.put(ID, ruleId.toString()); + values.put(DATA_TYPE, "ENUM"); + values.put(FIELD, countryTable.fieldValue()); + values.put(OPERATOR, "IN"); + values.put(PARENT_RULE_ID, parentRuleId.toString()); + + try (ResultSet countryValueQuery = connection.createStatement().executeQuery(builder.toString())) { + ArrayList countries = new ArrayList<>(); + while (countryValueQuery.next()) { + String country = countryValueQuery.getString(countryTable.valueCol()); + if (country != null) { countries.add(country); } + } + String countriesValue = !countries.isEmpty() ? String.join(",", countries) : null; + if (countriesValue == null) { return; } //don't create a rule for countries if null + + SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), + EXPERT_RULE_VALUE_TABLE) + .addColumnValue("id", ruleId.toString()) + .addColumnValue(VALUE_COL, countriesValue); + statements.add(statement); + + } + createRuleStatement(statements, database, values); + } + + private void createEnumRuleStatement(List statements, Database database, UUID parentRuleId, String value, + String fieldValue) { + + if (value != null) { + EnumMap values = new EnumMap<>(ExpertRuleCol.class); + UUID ruleId = UUID.randomUUID(); + values.put(ID, ruleId.toString()); + values.put(DATA_TYPE, "ENUM"); + values.put(FIELD, fieldValue); + values.put(OPERATOR, "EQUALS"); + values.put(PARENT_RULE_ID, parentRuleId.toString()); + createRuleStatement(statements, database, values); + + // value table + InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), + database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) + .addColumnValue("id", ruleId.toString()) + .addColumnValue(VALUE_COL, value); + statements.add(ruleValueStatement); + } + } + + private void createNumericRuleStatements(JdbcConnection connection, List statements, + Database database, UUID parentRuleId, String numericId, String fieldValue) + throws SQLException, DatabaseException + { + + if (numericId == null) { return; } + StringBuilder builder = new StringBuilder(""); + builder.append("select * from numeric_filter where id = ").append("'").append(numericId).append("'"); + + try (ResultSet infosFromNumericFilter = connection.createStatement().executeQuery(builder.toString())) { + List values = new ArrayList<>(); + UUID ruleId = UUID.randomUUID(); + String operatorExpert = null; + + // values + if (infosFromNumericFilter.next()) { + operatorExpert = convertOperator(infosFromNumericFilter.getString("range_type")); + // insert rule into expert_rule table (get id and then insert values + String valueTmp = infosFromNumericFilter.getString("value1"); + if (valueTmp != null) { + values.add(valueTmp); + } + + valueTmp = infosFromNumericFilter.getString("value2"); + if (valueTmp != null) { + values.add(valueTmp); + } + } + + if (values.isEmpty()) { return; } // No value don't add anything + + // insert in expert_rule + EnumMap enumValues = new EnumMap<>(ExpertRuleCol.class); + enumValues.put(ID, ruleId.toString()); + enumValues.put(DATA_TYPE, "NUMBER"); + enumValues.put(FIELD, fieldValue); + enumValues.put(OPERATOR, operatorExpert); + enumValues.put(PARENT_RULE_ID, parentRuleId.toString()); + createRuleStatement(statements, database, enumValues); + + // insert expert_rule_value + String value = String.join(",", values); + InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), + database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) + .addColumnValue("id", ruleId.toString()) + .addColumnValue(VALUE_COL, value); + statements.add(ruleValueStatement); + + } + } + + @Override + public String getConfirmationMessage() + { + return null; + } + + @Override + public void setUp() throws SetupException + { + // implement + } + + @Override + public void setFileOpener(ResourceAccessor resourceAccessor) + { + // implement + } + + @Override + public ValidationErrors validate(Database database) + { + return null; + } +} diff --git a/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml new file mode 100644 index 00000000..324ecdc2 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 325cdfaa..baef517b 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -49,3 +49,6 @@ databaseChangeLog: - include: file: changesets/changelog_20240902T233408Z.xml relativeToChangelogFile: true + - include: + file: changesets/changelog_20241105T114300Z.xml + relativeToChangelogFile: true From 692a804e9b0f11dea23237175941315b6d8b3810 Mon Sep 17 00:00:00 2001 From: basseche Date: Thu, 14 Nov 2024 13:36:42 +0100 Subject: [PATCH 02/27] refactoring --- .../migrations/MigrateEquipmentFilter.java | 164 +++++++++--------- 1 file changed, 83 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java index 21c65356..f9591d1c 100644 --- a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java +++ b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java @@ -1,8 +1,8 @@ package org.gridsuite.filter.server.migrations; import java.util.ArrayList; -import java.util.EnumMap; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.sql.ResultSet; @@ -18,34 +18,46 @@ import liquibase.resource.ResourceAccessor; import liquibase.statement.SqlStatement; import liquibase.statement.core.InsertStatement; -import static org.gridsuite.filter.server.migrations.MigrateEquipmentFilter.ExpertRuleCol.*; public class MigrateEquipmentFilter implements CustomSqlChange { - private static final String EXPERT_RULE_TABLE = "expert_rule"; + private static final String EXPERT_RULE_TABLE = "expert_rule"; private static final String EXPERT_RULE_VALUE_TABLE = "expert_rule_value"; private static final String FREE_PROPS_ID = "free_properties_id"; private static final String SUB_FREE_PROPS_ID = "substation_free_properties_id"; private static final String NUMERIC_FILTER_ID = "numeric_filter_id_id"; private static final String VALUE_COL = "value_"; - enum ExpertRuleCol { - ID("id"), - COMBINATOR("combinator"), - DATA_TYPE("data_type"), - FIELD("field"), - OPERATOR("operator"), - PARENT_RULE_ID("parent_rule_id"); - - ExpertRuleCol(String colName) { - name_ = colName; + class ExpertRuleParam { + private String id_; + private String dataType_; + private Optional combinator_; + private Optional operator_; + private Optional fieldValue_; + private Optional parentRuleId_; + + ExpertRuleParam(String id, String dataType, String combinator) { + id_ = id; + dataType_ = dataType; + combinator_ = Optional.ofNullable(combinator); + operator_ = Optional.empty(); + fieldValue_ = Optional.empty(); + parentRuleId_ = Optional.empty(); } - String name_; - @Override - public String toString() { - return name_; + ExpertRuleParam(String id, String dataType, String operator, String fieldValue, String parentRuleId) { + this(id, dataType, null); + fieldValue_ = Optional.ofNullable(fieldValue); + parentRuleId_ = Optional.ofNullable(parentRuleId); + operator_ = Optional.ofNullable(operator); } + + public String id() { return id_; } + public String dataType() { return dataType_; } + public Optional operator() { return operator_; } + public Optional fieldValue() { return fieldValue_; } + public Optional combinator() { return combinator_; } + public Optional parentRuleId() { return parentRuleId_; } } enum ColType { @@ -100,7 +112,7 @@ Column[] columns() { return new Column[] { new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), - new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES), new Column("energy_source", ColType.ENUM, "ENERGY_SOURCE") }; } @@ -110,16 +122,16 @@ Column[] columns() { Column[] columns() { return new Column[] { new Column("hvdc_line_filter_entity_numeric_filter_id_id", ColType.NUMERIC, "DC_NOMINAL_VOLTAGE"), - new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1"), - new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_2") + new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_2) }; } @Override CountryTable[] countriesTables() { return new CountryTable[] - { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + "_entity_id", "countries1", "COUNTRY_1"), - new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + "_entity_id", "countries2", "COUNTRY_2") + { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + ENTITY_ID, "countries1", "COUNTRY_1"), + new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + ENTITY_ID, "countries2", "COUNTRY_2") }; } }, @@ -127,11 +139,11 @@ CountryTable[] countriesTables() @Override Column[] columns() { return new Column[] - { new Column("numeric_filter_id1_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_1"), - new Column("numeric_filter_id2_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_2"), - new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1"), - new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_2"), - new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES"), + { new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), + new Column("numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), + new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_2), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES), }; } @@ -139,8 +151,8 @@ Column[] columns() { CountryTable[] countriesTables() { return new CountryTable[] - { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + "_entity_id", "countries1", "COUNTRY_1"), - new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + "_entity_id", "countries2", "COUNTRY_2") + { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + ENTITY_ID, "countries1", "COUNTRY_1"), + new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + ENTITY_ID, "countries2", "COUNTRY_2") }; } }, @@ -150,17 +162,17 @@ CountryTable[] countriesTables() SUBSTATION("substation_filter") { @Override Column[] columns() { - return new Column[] { new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES") }; + return new Column[] { new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES) }; } }, THREE_WINDINGS_TRANSFORMER("three_windings_transformer_filter") { @Override Column[] columns() { return new Column[] - { new Column("three_windings_transformer_numeric_filter_id1_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_1"), - new Column("three_windings_transformer_numeric_filter_id2_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_2"), + { new Column("three_windings_transformer_numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), + new Column("three_windings_transformer_numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), new Column("three_windings_transformer_numeric_filter_id3_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_3"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1") + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1) }; } }, @@ -168,28 +180,35 @@ Column[] columns() { @Override Column[] columns() { return new Column[] - { new Column("numeric_filter_id1_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_1"), - new Column("two_windings_transformernumeric_filter_id2_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_2"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES_1"), - new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES") + { new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), + new Column("two_windings_transformernumeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES) }; } }, VOLTAGE_LEVEL("voltage_level_filter"); + private static final String NOMINAL_VOLTAGE_1 = "NOMINAL_VOLTAGE_1"; + private static final String NOMINAL_VOLTAGE_2 = "NOMINAL_VOLTAGE_2"; + private static final String SUBSTATION_PROPERTIES_1 = "SUBSTATION_PROPERTIES_1"; + private static final String SUBSTATION_PROPERTIES_2 = "SUBSTATION_PROPERTIES_2"; + private static final String FREE_PROPERTIES = "FREE_PROPERTIES"; + private static final String ENTITY_ID = "_entity_id"; + Equipment(String equipmentTable) { equipmentTable_ = equipmentTable; } String table() { return equipmentTable_; } CountryTable[] countriesTables() { return new CountryTable[] - {new CountryTable(equipmentTable_ + "_entity_countries", equipmentTable_ + "_entity_id", "countries", "COUNTRY")}; + {new CountryTable(equipmentTable_ + "_entity_countries", equipmentTable_ + ENTITY_ID, "countries", "COUNTRY")}; } Column[] columns() { return new Column[] { new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), - new Column(FREE_PROPS_ID, ColType.PROPERTY, "FREE_PROPERTIES") + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES) }; } String equipmentTable_; @@ -282,25 +301,30 @@ private void createFilterStatement (List statements, Database data private UUID createParentRuleStatement(List statements, Database database) { UUID parentRuleId = UUID.randomUUID(); - EnumMap values = new EnumMap<>(ExpertRuleCol.class); - values.put(ID, parentRuleId.toString()); - values.put(COMBINATOR, "AND"); - values.put(DATA_TYPE, "COMBINATOR"); - createRuleStatement(statements, database, values); + ExpertRuleParam param = new ExpertRuleParam(parentRuleId.toString(), "COMBINATOR", "AND"); + createRuleStatement(statements, database, param); return parentRuleId; } - private void createRuleStatement(List statements, Database database, EnumMap values) + private void createRuleStatement(List statements, Database database, ExpertRuleParam params) { InsertStatement ruleStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), EXPERT_RULE_TABLE); - values.forEach((key, value) -> - { - if (value != null) { - ruleStatement.addColumnValue(key.toString(), value); - } - }); + if (params.id() == null || params.dataType() == null) { + return; + } + + //mandatory + ruleStatement.addColumnValue("id", params.id()); + ruleStatement.addColumnValue("data_type", params.dataType()); + + //optional + if (!params.operator().isEmpty()) { ruleStatement.addColumnValue("operator", params.operator().get()); } + if (!params.fieldValue().isEmpty()) { ruleStatement.addColumnValue("field", params.fieldValue().get()); } + if (!params.parentRuleId().isEmpty()) { ruleStatement.addColumnValue("parent_rule_id", params.parentRuleId().get()); } + if (!params.combinator().isEmpty()) { ruleStatement.addColumnValue("combinator", params.combinator().get()); } + statements.add(ruleStatement); } @@ -345,13 +369,8 @@ private void createPropertyRuleStatements(List statements, Databas ResultSet propertyValueQuery, String fieldValue) throws SQLException { UUID propsRuleId = UUID.randomUUID(); - EnumMap values = new EnumMap<>(ExpertRuleCol.class); - values.put(ID, propsRuleId.toString()); - values.put(DATA_TYPE, "PROPERTIES"); - values.put(FIELD, fieldValue); - values.put(OPERATOR, "IN"); - values.put(PARENT_RULE_ID, parentRuleId.toString()); - createRuleStatement(statements, database, values); + ExpertRuleParam param = new ExpertRuleParam(propsRuleId.toString(), "PROPERTIES", "IN", fieldValue, parentRuleId.toString()); + createRuleStatement(statements, database, param); //add property name SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_properties") @@ -370,14 +389,12 @@ private void createPropertyRuleStatements(List statements, Databas pos++; statements.add(statement); } - } private void createCountryStatement(JdbcConnection connection, List statements, Database database, UUID parentRuleId, CountryTable countryTable, String filterIdToMigrate) throws DatabaseException, SQLException { - // Add country values StringBuilder builder = new StringBuilder(); builder.append("select ").append(countryTable.valueCol()).append(" from ").append(countryTable.name()) @@ -386,12 +403,7 @@ private void createCountryStatement(JdbcConnection connection, List values = new EnumMap<>(ExpertRuleCol.class); - values.put(ID, ruleId.toString()); - values.put(DATA_TYPE, "ENUM"); - values.put(FIELD, countryTable.fieldValue()); - values.put(OPERATOR, "IN"); - values.put(PARENT_RULE_ID, parentRuleId.toString()); + ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "ENUM", "IN", countryTable.fieldValue(), parentRuleId.toString()); try (ResultSet countryValueQuery = connection.createStatement().executeQuery(builder.toString())) { ArrayList countries = new ArrayList<>(); @@ -409,21 +421,16 @@ private void createCountryStatement(JdbcConnection connection, List statements, Database database, UUID parentRuleId, String value, String fieldValue) { if (value != null) { - EnumMap values = new EnumMap<>(ExpertRuleCol.class); UUID ruleId = UUID.randomUUID(); - values.put(ID, ruleId.toString()); - values.put(DATA_TYPE, "ENUM"); - values.put(FIELD, fieldValue); - values.put(OPERATOR, "EQUALS"); - values.put(PARENT_RULE_ID, parentRuleId.toString()); - createRuleStatement(statements, database, values); + ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "ENUM", "EQUALS", fieldValue, parentRuleId.toString()); + createRuleStatement(statements, database, param); // value table InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), @@ -466,13 +473,8 @@ private void createNumericRuleStatements(JdbcConnection connection, List enumValues = new EnumMap<>(ExpertRuleCol.class); - enumValues.put(ID, ruleId.toString()); - enumValues.put(DATA_TYPE, "NUMBER"); - enumValues.put(FIELD, fieldValue); - enumValues.put(OPERATOR, operatorExpert); - enumValues.put(PARENT_RULE_ID, parentRuleId.toString()); - createRuleStatement(statements, database, enumValues); + ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "NUMBER", operatorExpert, fieldValue, parentRuleId.toString()); + createRuleStatement(statements, database, param); // insert expert_rule_value String value = String.join(",", values); From 6ad27eb7fc39cf3bcfa4683deef8195490c38da0 Mon Sep 17 00:00:00 2001 From: basseche Date: Thu, 14 Nov 2024 17:51:18 +0100 Subject: [PATCH 03/27] checkStyle Ok --- .../migrations/MigrateEquipmentFilter.java | 915 +++++++++--------- 1 file changed, 469 insertions(+), 446 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java index f9591d1c..0e15b033 100644 --- a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java +++ b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.UUID; import java.sql.ResultSet; @@ -19,495 +18,519 @@ import liquibase.statement.SqlStatement; import liquibase.statement.core.InsertStatement; -public class MigrateEquipmentFilter implements CustomSqlChange -{ - private static final String EXPERT_RULE_TABLE = "expert_rule"; - private static final String EXPERT_RULE_VALUE_TABLE = "expert_rule_value"; - private static final String FREE_PROPS_ID = "free_properties_id"; - private static final String SUB_FREE_PROPS_ID = "substation_free_properties_id"; - private static final String NUMERIC_FILTER_ID = "numeric_filter_id_id"; - private static final String VALUE_COL = "value_"; - - class ExpertRuleParam { - private String id_; - private String dataType_; - private Optional combinator_; - private Optional operator_; - private Optional fieldValue_; - private Optional parentRuleId_; - - ExpertRuleParam(String id, String dataType, String combinator) { - id_ = id; - dataType_ = dataType; - combinator_ = Optional.ofNullable(combinator); - operator_ = Optional.empty(); - fieldValue_ = Optional.empty(); - parentRuleId_ = Optional.empty(); - } +public class MigrateEquipmentFilter implements CustomSqlChange { + private static final String EXPERT_RULE_TABLE = "expert_rule"; + private static final String EXPERT_RULE_VALUE_TABLE = "expert_rule_value"; + private static final String FREE_PROPS_ID = "free_properties_id"; + private static final String SUB_FREE_PROPS_ID = "substation_free_properties_id"; + private static final String NUMERIC_FILTER_ID = "numeric_filter_id_id"; + private static final String VALUE_COL = "value_"; + + static class ExpertRuleParam { + private final String id; + private final String dataType; + private final String combinator; + private String operator; + private String fieldValue; + private String parentRuleId; + + ExpertRuleParam(String id, String dataType, String combinator) { + this.id = id; + this.dataType = dataType; + this.combinator = combinator; + } - ExpertRuleParam(String id, String dataType, String operator, String fieldValue, String parentRuleId) { - this(id, dataType, null); - fieldValue_ = Optional.ofNullable(fieldValue); - parentRuleId_ = Optional.ofNullable(parentRuleId); - operator_ = Optional.ofNullable(operator); - } + ExpertRuleParam(String id, String dataType, String operator, String fieldValue, String parentRuleId) { + this(id, dataType, null); + this.fieldValue = fieldValue; + this.parentRuleId = parentRuleId; + this.operator = operator; + } - public String id() { return id_; } - public String dataType() { return dataType_; } - public Optional operator() { return operator_; } - public Optional fieldValue() { return fieldValue_; } - public Optional combinator() { return combinator_; } - public Optional parentRuleId() { return parentRuleId_; } - } - - enum ColType { - NUMERIC, - PROPERTY, - SUBSTATION_PROPERTY, - ENUM - } - - static class Column { - private final String name_; - private final ColType type_; - private String fieldValue_; - - String name() { return name_; } - ColType type() { return type_; } - String fieldValue() { return fieldValue_; } - - Column(String name, ColType type, String fieldValue) { - name_ = name; - type_ = type; - fieldValue_ = fieldValue; - } - } - - static class CountryTable { - private final String name_; - private final String idCol_; - private final String valueCol_; - private final String fieldValue_; - - CountryTable(String name, String idCol, String valueCol, String fieldValue) { - name_ = name; - idCol_ = idCol; - valueCol_ = valueCol; - fieldValue_ = fieldValue; + public String id() { + return id; + } + + public String dataType() { + return dataType; + } + + public String operator() { + return operator; + } + + public String fieldValue() { + return fieldValue; + } + + public String combinator() { + return combinator; + } + + public String parentRuleId() { + return parentRuleId; + } } - public String name() { return name_; } - public String idCol() { return idCol_; } - public String valueCol() { return valueCol_; } - public String fieldValue() { return fieldValue_; } - } - - private enum Equipment - { - BATTERY("battery_filter"), - DANGLING_LINE( "dangling_line_filter"), - GENERATOR("generator_filter") { - @Override - Column[] columns() { - return new Column[] - { new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), - new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES), - new Column("energy_source", ColType.ENUM, "ENERGY_SOURCE") - }; - } - } , - HVDC_LINE("hvdc_line_filter") { - @Override - Column[] columns() { - return new Column[] - { new Column("hvdc_line_filter_entity_numeric_filter_id_id", ColType.NUMERIC, "DC_NOMINAL_VOLTAGE"), - new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), - new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_2) - }; - } - @Override - CountryTable[] countriesTables() - { - return new CountryTable[] - { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + ENTITY_ID, "countries1", "COUNTRY_1"), - new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + ENTITY_ID, "countries2", "COUNTRY_2") - }; - } - }, - LINE("line_filter") { - @Override - Column[] columns() { - return new Column[] - { new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), - new Column("numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), - new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), - new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_2), - new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES), - }; - } - - @Override - CountryTable[] countriesTables() - { - return new CountryTable[] - { new CountryTable(equipmentTable_ + "_entity_countries1", equipmentTable_ + ENTITY_ID, "countries1", "COUNTRY_1"), - new CountryTable(equipmentTable_ + "_entity_countries2", equipmentTable_ + ENTITY_ID, "countries2", "COUNTRY_2") - }; - } - }, - LOAD("load_filter"), - SHUNT_COMPENSATOR("shunt_compensator_filter"), - STATIC_VAR_COMPENSATOR("static_var_compensator_filter"), - SUBSTATION("substation_filter") { - @Override - Column[] columns() { - return new Column[] { new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES) }; - } - }, - THREE_WINDINGS_TRANSFORMER("three_windings_transformer_filter") { - @Override - Column[] columns() { - return new Column[] - { new Column("three_windings_transformer_numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), - new Column("three_windings_transformer_numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), - new Column("three_windings_transformer_numeric_filter_id3_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_3"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1) - }; - } - }, - TWO_WINDINGS_TRANSFORMER("two_windings_transformer_filter") { - @Override - Column[] columns() { - return new Column[] - { new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), - new Column("two_windings_transformernumeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), - new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES) - }; - } - }, - VOLTAGE_LEVEL("voltage_level_filter"); - - private static final String NOMINAL_VOLTAGE_1 = "NOMINAL_VOLTAGE_1"; - private static final String NOMINAL_VOLTAGE_2 = "NOMINAL_VOLTAGE_2"; - private static final String SUBSTATION_PROPERTIES_1 = "SUBSTATION_PROPERTIES_1"; - private static final String SUBSTATION_PROPERTIES_2 = "SUBSTATION_PROPERTIES_2"; - private static final String FREE_PROPERTIES = "FREE_PROPERTIES"; - private static final String ENTITY_ID = "_entity_id"; - - Equipment(String equipmentTable) { - equipmentTable_ = equipmentTable; + enum ColType { + NUMERIC, + PROPERTY, + SUBSTATION_PROPERTY, + ENUM } - String table() { return equipmentTable_; } - CountryTable[] countriesTables() { - return new CountryTable[] - {new CountryTable(equipmentTable_ + "_entity_countries", equipmentTable_ + ENTITY_ID, "countries", "COUNTRY")}; + + static class Column { + private final String name; + private final ColType type; + private String fieldValue; + + String name() { + return name; + } + + ColType type() { + return type; + } + + String fieldValue() { + return fieldValue; + } + + Column(String name, ColType type, String fieldValue) { + this.name = name; + this.type = type; + this.fieldValue = fieldValue; + } } - Column[] columns() { - return new Column[] - { new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), - new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES) - }; + + static class CountryTable { + private final String name; + private final String idCol; + private final String valueCol; + private final String fieldValue; + + CountryTable(String name, String idCol, String valueCol, String fieldValue) { + this.name = name; + this.idCol = idCol; + this.valueCol = valueCol; + this.fieldValue = fieldValue; + } + + public String name() { + return name; + } + + public String idCol() { + return idCol; + } + + public String valueCol() { + return valueCol; + } + + public String fieldValue() { + return fieldValue; + } } - String equipmentTable_; - } - - @Override - public SqlStatement[] generateStatements(Database database) throws CustomChangeException - { - List statements = new ArrayList<>(); - - for (Equipment equipment : Equipment.values()) { - StringBuilder builder = new StringBuilder(""); - builder.append("select * from ").append(equipment.table()); - - try { - JdbcConnection connection = (JdbcConnection) database.getConnection(); - - // All filters to migrate in equipment filter table - try (ResultSet filters = connection.createStatement().executeQuery(builder.toString())) { - while (filters.next()) { - // Add a parent rule (And combinator) in expert_rule table - UUID parentRuleId = createParentRuleStatement(statements, database); - - // create and add filter - createFilterStatement(statements, database, parentRuleId, filters, equipment.name()); - - for (Column column : equipment.columns()) { - String colId = filters.getString(column.name()); - - switch (column.type()) { - case NUMERIC: - createNumericRuleStatements(connection, statements, database, parentRuleId, colId, column.fieldValue()); - break; - case SUBSTATION_PROPERTY, PROPERTY: - createPropertiesStatements(statements, database, connection, colId, parentRuleId, column.fieldValue()); - break; - case ENUM: - createEnumRuleStatement(statements, database, parentRuleId, colId, column.fieldValue()); - break; - default: break; - } + + private enum Equipment { + BATTERY("battery_filter"), + DANGLING_LINE("dangling_line_filter"), + GENERATOR("generator_filter") { + @Override + Column[] columns() { + return new Column[]{new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES), + new Column("energy_source", ColType.ENUM, "ENERGY_SOURCE")}; + } + }, + HVDC_LINE("hvdc_line_filter") { + @Override + Column[] columns() { + return new Column[]{new Column("hvdc_line_filter_entity_numeric_filter_id_id", ColType.NUMERIC, "DC_NOMINAL_VOLTAGE"), + new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_2)}; + } + + @Override + CountryTable[] countriesTables() { + return new CountryTable[]{new CountryTable(equipmentTable + "_entity_countries1", equipmentTable + ENTITY_ID, "countries1", "COUNTRY_1"), + new CountryTable(equipmentTable + "_entity_countries2", equipmentTable + ENTITY_ID, "countries2", "COUNTRY_2")}; + } + }, + LINE("line_filter") { + @Override + Column[] columns() { + return new Column[]{new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), + new Column("numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), + new Column("substation_free_properties1_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column("substation_free_properties2_id", ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_2), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES)}; } - // Countries - for (int i = 0; i < equipment.countriesTables().length; i++) { - CountryTable countryTable = equipment.countriesTables()[i]; - createCountryStatement(connection, statements, database, parentRuleId, countryTable, filters.getString("id")); + @Override + CountryTable[] countriesTables() { + return new CountryTable[]{new CountryTable(equipmentTable + "_entity_countries1", equipmentTable + ENTITY_ID, "countries1", "COUNTRY_1"), + new CountryTable(equipmentTable + "_entity_countries2", equipmentTable + ENTITY_ID, "countries2", "COUNTRY_2")}; } - } + }, + LOAD("load_filter"), + SHUNT_COMPENSATOR("shunt_compensator_filter"), + STATIC_VAR_COMPENSATOR("static_var_compensator_filter"), + SUBSTATION("substation_filter") { + @Override + Column[] columns() { + return new Column[]{new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES)}; + } + }, + THREE_WINDINGS_TRANSFORMER("three_windings_transformer_filter") { + @Override + Column[] columns() { + return new Column[]{new Column("three_windings_transformer_numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), + new Column("three_windings_transformer_numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), + new Column("three_windings_transformer_numeric_filter_id3_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_3"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1)}; + } + }, + TWO_WINDINGS_TRANSFORMER("two_windings_transformer_filter") { + @Override + Column[] columns() { + return new Column[]{new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), + new Column("two_windings_transformernumeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES)}; + } + }, + VOLTAGE_LEVEL("voltage_level_filter"); + + private static final String NOMINAL_VOLTAGE_1 = "NOMINAL_VOLTAGE_1"; + private static final String NOMINAL_VOLTAGE_2 = "NOMINAL_VOLTAGE_2"; + private static final String SUBSTATION_PROPERTIES_1 = "SUBSTATION_PROPERTIES_1"; + private static final String SUBSTATION_PROPERTIES_2 = "SUBSTATION_PROPERTIES_2"; + private static final String FREE_PROPERTIES = "FREE_PROPERTIES"; + private static final String ENTITY_ID = "_entity_id"; + + Equipment(String equipmentTable) { + this.equipmentTable = equipmentTable; } - } catch (Exception throwables) { - throwables.printStackTrace(); - return new SqlStatement[0]; // If any exception occurs don't do any migration - } - } + String table() { + return equipmentTable; + } - //Create Rule from numeric_filter + Substation free properties id + free properties id + CountryTable[] countriesTables() { + return new CountryTable[]{new CountryTable(equipmentTable + "_entity_countries", equipmentTable + ENTITY_ID, "countries", "COUNTRY")}; + } - return statements.toArray(new SqlStatement[0]); - } + Column[] columns() { + return new Column[]{new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), + new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES)}; + } - private String convertOperator(String operatorCriteriaFilter) - { - if (operatorCriteriaFilter == null) { - return ""; + final String equipmentTable; } - return switch (operatorCriteriaFilter) { - case "EQUALITY" -> "EQUALS"; - case "GREATER_THAN" -> "GREATER"; - case "GREATER_OR_EQUAL" -> "GREATER_OR_EQUALS"; - case "LESS_THAN" -> "LOWER"; - case "LESS_OR_EQUAL" -> "LOWER_OR_EQUALS"; - case "RANGE" -> "BETWEEN"; - default -> ""; - }; - } - - private void createFilterStatement (List statements, Database database, UUID parentRuleId, ResultSet filters, String equipment) - throws SQLException - { - InsertStatement filterStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_filter") - .addColumnValue("id", filters.getString("id")) - .addColumnValue("modification_date", filters.getString("modification_date")) - .addColumnValue("equipment_type", equipment) - .addColumnValue("rules_id", parentRuleId.toString() ); - statements.add(filterStatement); - } - - private UUID createParentRuleStatement(List statements, Database database) { - UUID parentRuleId = UUID.randomUUID(); - ExpertRuleParam param = new ExpertRuleParam(parentRuleId.toString(), "COMBINATOR", "AND"); - createRuleStatement(statements, database, param); - return parentRuleId; - } - - private void createRuleStatement(List statements, Database database, ExpertRuleParam params) - { - InsertStatement ruleStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), - EXPERT_RULE_TABLE); - - if (params.id() == null || params.dataType() == null) { - return; + @Override + public SqlStatement[] generateStatements(Database database) throws CustomChangeException { + List statements = new ArrayList<>(); + + for (Equipment equipment : Equipment.values()) { + StringBuilder builder = new StringBuilder(); + builder.append("select * from ").append(equipment.table()); + + try { + JdbcConnection connection = (JdbcConnection) database.getConnection(); + + // All filters to migrate in equipment filter table + try (ResultSet filters = connection.createStatement().executeQuery(builder.toString())) { + while (filters.next()) { + // Add a parent rule (And combinator) in expert_rule table + UUID parentRuleId = createParentRuleStatement(statements, database); + + // create and add filter + createFilterStatement(statements, database, parentRuleId, filters, equipment.name()); + + for (Column column : equipment.columns()) { + String colId = filters.getString(column.name()); + + switch (column.type()) { + case NUMERIC: + createNumericRuleStatements(connection, statements, database, parentRuleId, colId, column.fieldValue()); + break; + case SUBSTATION_PROPERTY, PROPERTY: + createPropertiesStatements(statements, database, connection, colId, parentRuleId, column.fieldValue()); + break; + case ENUM: + createEnumRuleStatement(statements, database, parentRuleId, colId, column.fieldValue()); + break; + default: + break; + } + } + + // Countries + for (int i = 0; i < equipment.countriesTables().length; i++) { + CountryTable countryTable = equipment.countriesTables()[i]; + createCountryStatement(connection, statements, database, parentRuleId, countryTable, filters.getString("id")); + } + } + } + } catch (Exception throwables) { + throwables.printStackTrace(); + return new SqlStatement[0]; // If any exception occurs don't do any migration + } + } + + return statements.toArray(new SqlStatement[0]); } - //mandatory - ruleStatement.addColumnValue("id", params.id()); - ruleStatement.addColumnValue("data_type", params.dataType()); + private String convertOperator(String operatorCriteriaFilter) { + if (operatorCriteriaFilter == null) { + return ""; + } - //optional - if (!params.operator().isEmpty()) { ruleStatement.addColumnValue("operator", params.operator().get()); } - if (!params.fieldValue().isEmpty()) { ruleStatement.addColumnValue("field", params.fieldValue().get()); } - if (!params.parentRuleId().isEmpty()) { ruleStatement.addColumnValue("parent_rule_id", params.parentRuleId().get()); } - if (!params.combinator().isEmpty()) { ruleStatement.addColumnValue("combinator", params.combinator().get()); } + return switch (operatorCriteriaFilter) { + case "EQUALITY" -> "EQUALS"; + case "GREATER_THAN" -> "GREATER"; + case "GREATER_OR_EQUAL" -> "GREATER_OR_EQUALS"; + case "LESS_THAN" -> "LOWER"; + case "LESS_OR_EQUAL" -> "LOWER_OR_EQUALS"; + case "RANGE" -> "BETWEEN"; + default -> ""; + }; + } - statements.add(ruleStatement); - } + private void createFilterStatement(List statements, Database database, UUID parentRuleId, ResultSet filters, String equipment) + throws SQLException { + InsertStatement filterStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_filter") + .addColumnValue("id", filters.getString("id")) + .addColumnValue("modification_date", filters.getString("modification_date")) + .addColumnValue("equipment_type", equipment) + .addColumnValue("rules_id", parentRuleId.toString()); + statements.add(filterStatement); + } - private void createPropertiesStatements(List statements, Database database, JdbcConnection connection, - String propId, UUID parentRuleId, String fieldValue) throws SQLException, DatabaseException - { - if (propId == null) { return; } - StringBuilder builder = new StringBuilder(""); + private UUID createParentRuleStatement(List statements, Database database) { + UUID parentRuleId = UUID.randomUUID(); + ExpertRuleParam param = new ExpertRuleParam(parentRuleId.toString(), "COMBINATOR", "AND"); + createRuleStatement(statements, database, param); + return parentRuleId; + } - builder.append("select free_property_filter_entities_id from free_properties_free_property_filter_entities") - .append(" where free_properties_filter_entity_id = ").append("'").append(propId).append("'"); + private void createRuleStatement(List statements, Database database, ExpertRuleParam params) { + InsertStatement ruleStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), + EXPERT_RULE_TABLE); - try (ResultSet propertyQuery = connection.createStatement().executeQuery(builder.toString())) { - while (propertyQuery.next()) { - String propertyId = propertyQuery.getString(1); + if (params.id() == null || params.dataType() == null) { + return; + } - builder.setLength(0); - builder.append("select prop_name from free_property where id = ").append("'").append(propertyId).append("'"); + //mandatory + ruleStatement.addColumnValue("id", params.id()); + ruleStatement.addColumnValue("data_type", params.dataType()); - // Property name - String propName = null; - try (ResultSet propertyNameQuery = connection.createStatement().executeQuery(builder.toString())) { - if (propertyNameQuery.next()) { - propName = propertyNameQuery.getString("prop_name"); - } + //optional + if (params.operator() != null) { + ruleStatement.addColumnValue("operator", params.operator()); + } + if (params.fieldValue() != null) { + ruleStatement.addColumnValue("field", params.fieldValue()); + } + if (params.parentRuleId() != null) { + ruleStatement.addColumnValue("parent_rule_id", params.parentRuleId()); + } + if (params.combinator() != null) { + ruleStatement.addColumnValue("combinator", params.combinator()); } - //Property values - if (propName == null) { continue; } - builder.setLength(0); - builder.append("select prop_values from prop_value where free_property_filter_entity_id = ").append("'").append(propertyId).append("'"); + statements.add(ruleStatement); + } - try (ResultSet propertyValueQuery = connection.createStatement().executeQuery(builder.toString())) { - createPropertyRuleStatements(statements, database, parentRuleId, propName, propertyValueQuery, fieldValue); + private void createPropertiesStatements(List statements, Database database, JdbcConnection connection, + String propId, UUID parentRuleId, String fieldValue) throws SQLException, DatabaseException { + if (propId == null) { + return; + } + StringBuilder builder = new StringBuilder(); + + builder.append("select free_property_filter_entities_id from free_properties_free_property_filter_entities") + .append(" where free_properties_filter_entity_id = ").append("'").append(propId).append("'"); + + try (ResultSet propertyQuery = connection.createStatement().executeQuery(builder.toString())) { + while (propertyQuery.next()) { + String propertyId = propertyQuery.getString(1); + + builder.setLength(0); + builder.append("select prop_name from free_property where id = ").append("'").append(propertyId).append("'"); + + // Property name + String propName = null; + try (ResultSet propertyNameQuery = connection.createStatement().executeQuery(builder.toString())) { + if (propertyNameQuery.next()) { + propName = propertyNameQuery.getString("prop_name"); + } + } + + //Property values + if (propName == null) { + continue; + } + builder.setLength(0); + builder.append("select prop_values from prop_value where free_property_filter_entity_id = ").append("'").append(propertyId).append("'"); + + try (ResultSet propertyValueQuery = connection.createStatement().executeQuery(builder.toString())) { + createPropertyRuleStatements(statements, database, parentRuleId, propName, propertyValueQuery, fieldValue); + } + } } - } - } - } - - - private void createPropertyRuleStatements(List statements, Database database, UUID parentRuleId, String propName, - ResultSet propertyValueQuery, String fieldValue) throws SQLException - { - UUID propsRuleId = UUID.randomUUID(); - ExpertRuleParam param = new ExpertRuleParam(propsRuleId.toString(), "PROPERTIES", "IN", fieldValue, parentRuleId.toString()); - createRuleStatement(statements, database, param); - - //add property name - SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_properties") - .addColumnValue("id", propsRuleId.toString()) - .addColumnValue("property_name", propName); - statements.add(statement); - - //insert Values - int pos = 0; - while(propertyValueQuery.next()) { - String propValue = propertyValueQuery.getString(1); - statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_property_value") - .addColumnValue("expert_rule_properties_entity_id", propsRuleId.toString()) - .addColumnValue("property_values", propValue) - .addColumnValue("pos", String.valueOf(pos)); - pos++; - statements.add(statement); } - } - - private void createCountryStatement(JdbcConnection connection, List statements, Database database, UUID parentRuleId, - CountryTable countryTable, String filterIdToMigrate) - throws DatabaseException, SQLException - { - // Add country values - StringBuilder builder = new StringBuilder(); - builder.append("select ").append(countryTable.valueCol()).append(" from ").append(countryTable.name()) - .append(" where ").append(countryTable.idCol()).append(" = ") - .append("'").append(filterIdToMigrate).append("'"); - - // Add country Country rule - UUID ruleId = UUID.randomUUID(); - ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "ENUM", "IN", countryTable.fieldValue(), parentRuleId.toString()); - - try (ResultSet countryValueQuery = connection.createStatement().executeQuery(builder.toString())) { - ArrayList countries = new ArrayList<>(); - while (countryValueQuery.next()) { - String country = countryValueQuery.getString(countryTable.valueCol()); - if (country != null) { countries.add(country); } - } - String countriesValue = !countries.isEmpty() ? String.join(",", countries) : null; - if (countriesValue == null) { return; } //don't create a rule for countries if null - - SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), - EXPERT_RULE_VALUE_TABLE) - .addColumnValue("id", ruleId.toString()) - .addColumnValue(VALUE_COL, countriesValue); - statements.add(statement); + private void createPropertyRuleStatements(List statements, Database database, UUID parentRuleId, String propName, + ResultSet propertyValueQuery, String fieldValue) throws SQLException { + UUID propsRuleId = UUID.randomUUID(); + ExpertRuleParam param = new ExpertRuleParam(propsRuleId.toString(), "PROPERTIES", "IN", fieldValue, parentRuleId.toString()); + createRuleStatement(statements, database, param); + + //add property name + SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_properties") + .addColumnValue("id", propsRuleId.toString()) + .addColumnValue("property_name", propName); + statements.add(statement); + + //insert Values + int pos = 0; + while (propertyValueQuery.next()) { + String propValue = propertyValueQuery.getString(1); + statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), "expert_rule_property_value") + .addColumnValue("expert_rule_properties_entity_id", propsRuleId.toString()) + .addColumnValue("property_values", propValue) + .addColumnValue("pos", String.valueOf(pos)); + pos++; + statements.add(statement); + } } - createRuleStatement(statements, database, param); - } - - private void createEnumRuleStatement(List statements, Database database, UUID parentRuleId, String value, - String fieldValue) { - - if (value != null) { - UUID ruleId = UUID.randomUUID(); - ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "ENUM", "EQUALS", fieldValue, parentRuleId.toString()); - createRuleStatement(statements, database, param); - - // value table - InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), - database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) - .addColumnValue("id", ruleId.toString()) - .addColumnValue(VALUE_COL, value); - statements.add(ruleValueStatement); + + private void createCountryStatement(JdbcConnection connection, List statements, Database database, UUID parentRuleId, + CountryTable countryTable, String filterIdToMigrate) + throws DatabaseException, SQLException { + // Add country values + StringBuilder builder = new StringBuilder(); + builder.append("select ").append(countryTable.valueCol()).append(" from ").append(countryTable.name()) + .append(" where ").append(countryTable.idCol()).append(" = ") + .append("'").append(filterIdToMigrate).append("'"); + + // Add country Country rule + UUID ruleId = UUID.randomUUID(); + ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "ENUM", "IN", countryTable.fieldValue(), parentRuleId.toString()); + + try (ResultSet countryValueQuery = connection.createStatement().executeQuery(builder.toString())) { + ArrayList countries = new ArrayList<>(); + while (countryValueQuery.next()) { + String country = countryValueQuery.getString(countryTable.valueCol()); + if (country != null) { + countries.add(country); + } + } + String countriesValue = !countries.isEmpty() ? String.join(",", countries) : null; + if (countriesValue == null) { + return; + } //don't create a rule for countries if null + + SqlStatement statement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), + EXPERT_RULE_VALUE_TABLE) + .addColumnValue("id", ruleId.toString()) + .addColumnValue(VALUE_COL, countriesValue); + statements.add(statement); + + } + createRuleStatement(statements, database, param); } - } - private void createNumericRuleStatements(JdbcConnection connection, List statements, - Database database, UUID parentRuleId, String numericId, String fieldValue) - throws SQLException, DatabaseException - { + private void createEnumRuleStatement(List statements, Database database, UUID parentRuleId, String value, + String fieldValue) { + + if (value != null) { + UUID ruleId = UUID.randomUUID(); + ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "ENUM", "EQUALS", fieldValue, parentRuleId.toString()); + createRuleStatement(statements, database, param); - if (numericId == null) { return; } - StringBuilder builder = new StringBuilder(""); - builder.append("select * from numeric_filter where id = ").append("'").append(numericId).append("'"); + // value table + InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), + database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) + .addColumnValue("id", ruleId.toString()) + .addColumnValue(VALUE_COL, value); + statements.add(ruleValueStatement); + } + } - try (ResultSet infosFromNumericFilter = connection.createStatement().executeQuery(builder.toString())) { - List values = new ArrayList<>(); - UUID ruleId = UUID.randomUUID(); - String operatorExpert = null; + private void createNumericRuleStatements(JdbcConnection connection, List statements, + Database database, UUID parentRuleId, String numericId, String fieldValue) + throws SQLException, DatabaseException { - // values - if (infosFromNumericFilter.next()) { - operatorExpert = convertOperator(infosFromNumericFilter.getString("range_type")); - // insert rule into expert_rule table (get id and then insert values - String valueTmp = infosFromNumericFilter.getString("value1"); - if (valueTmp != null) { - values.add(valueTmp); + if (numericId == null) { + return; } + StringBuilder builder = new StringBuilder(); + builder.append("select * from numeric_filter where id = ").append("'").append(numericId).append("'"); + + try (ResultSet infosFromNumericFilter = connection.createStatement().executeQuery(builder.toString())) { + List values = new ArrayList<>(); + UUID ruleId = UUID.randomUUID(); + String operatorExpert = null; + + // values + if (infosFromNumericFilter.next()) { + operatorExpert = convertOperator(infosFromNumericFilter.getString("range_type")); + // insert rule into expert_rule table (get id and then insert values + String valueTmp = infosFromNumericFilter.getString("value1"); + if (valueTmp != null) { + values.add(valueTmp); + } + + valueTmp = infosFromNumericFilter.getString("value2"); + if (valueTmp != null) { + values.add(valueTmp); + } + } + + if (values.isEmpty()) { + return; + } // No value don't add anything + + // insert in expert_rule + ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "NUMBER", operatorExpert, fieldValue, parentRuleId.toString()); + createRuleStatement(statements, database, param); + + // insert expert_rule_value + String value = String.join(",", values); + InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), + database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) + .addColumnValue("id", ruleId.toString()) + .addColumnValue(VALUE_COL, value); + statements.add(ruleValueStatement); - valueTmp = infosFromNumericFilter.getString("value2"); - if (valueTmp != null) { - values.add(valueTmp); } - } + } - if (values.isEmpty()) { return; } // No value don't add anything + @Override + public String getConfirmationMessage() { + return null; + } - // insert in expert_rule - ExpertRuleParam param = new ExpertRuleParam(ruleId.toString(), "NUMBER", operatorExpert, fieldValue, parentRuleId.toString()); - createRuleStatement(statements, database, param); + @Override + public void setUp() throws SetupException { + // implement + } - // insert expert_rule_value - String value = String.join(",", values); - InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), - database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) - .addColumnValue("id", ruleId.toString()) - .addColumnValue(VALUE_COL, value); - statements.add(ruleValueStatement); + @Override + public void setFileOpener(ResourceAccessor resourceAccessor) { + // implement + } + @Override + public ValidationErrors validate(Database database) { + return null; } - } - - @Override - public String getConfirmationMessage() - { - return null; - } - - @Override - public void setUp() throws SetupException - { - // implement - } - - @Override - public void setFileOpener(ResourceAccessor resourceAccessor) - { - // implement - } - - @Override - public ValidationErrors validate(Database database) - { - return null; - } } From dcffee401406c29a49976345a2f7d0b48e6facc1 Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 18 Nov 2024 16:40:47 +0100 Subject: [PATCH 04/27] Migration ok for transformers --- .../migrations/MigrateEquipmentFilter.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java index 0e15b033..68f41094 100644 --- a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java +++ b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java @@ -17,6 +17,8 @@ import liquibase.resource.ResourceAccessor; import liquibase.statement.SqlStatement; import liquibase.statement.core.InsertStatement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MigrateEquipmentFilter implements CustomSqlChange { private static final String EXPERT_RULE_TABLE = "expert_rule"; @@ -26,6 +28,8 @@ public class MigrateEquipmentFilter implements CustomSqlChange { private static final String NUMERIC_FILTER_ID = "numeric_filter_id_id"; private static final String VALUE_COL = "value_"; + private static final Logger LOGGER = LoggerFactory.getLogger(MigrateEquipmentFilter.class); + static class ExpertRuleParam { private final String id; private final String dataType; @@ -82,7 +86,7 @@ enum ColType { static class Column { private final String name; private final ColType type; - private String fieldValue; + private final String fieldValue; String name() { return name; @@ -140,7 +144,7 @@ private enum Equipment { @Override Column[] columns() { return new Column[]{new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES), new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES), new Column("energy_source", ColType.ENUM, "ENERGY_SOURCE")}; } @@ -190,7 +194,7 @@ Column[] columns() { return new Column[]{new Column("three_windings_transformer_numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), new Column("three_windings_transformer_numeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), new Column("three_windings_transformer_numeric_filter_id3_id", ColType.NUMERIC, "NOMINAL_VOLTAGE_3"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1)}; + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES)}; } }, TWO_WINDINGS_TRANSFORMER("two_windings_transformer_filter") { @@ -198,12 +202,13 @@ Column[] columns() { Column[] columns() { return new Column[]{new Column("numeric_filter_id1_id", ColType.NUMERIC, NOMINAL_VOLTAGE_1), new Column("two_windings_transformernumeric_filter_id2_id", ColType.NUMERIC, NOMINAL_VOLTAGE_2), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES_1), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES), new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES)}; } }, VOLTAGE_LEVEL("voltage_level_filter"); + public static final String SUBSTATION_PROPERTIES = "SUBSTATION_PROPERTIES"; private static final String NOMINAL_VOLTAGE_1 = "NOMINAL_VOLTAGE_1"; private static final String NOMINAL_VOLTAGE_2 = "NOMINAL_VOLTAGE_2"; private static final String SUBSTATION_PROPERTIES_1 = "SUBSTATION_PROPERTIES_1"; @@ -225,7 +230,7 @@ CountryTable[] countriesTables() { Column[] columns() { return new Column[]{new Column(NUMERIC_FILTER_ID, ColType.NUMERIC, "NOMINAL_VOLTAGE"), - new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, "SUBSTATION_PROPERTIES"), + new Column(SUB_FREE_PROPS_ID, ColType.SUBSTATION_PROPERTY, SUBSTATION_PROPERTIES), new Column(FREE_PROPS_ID, ColType.PROPERTY, FREE_PROPERTIES)}; } @@ -278,7 +283,7 @@ public SqlStatement[] generateStatements(Database database) throws CustomChangeE } } } catch (Exception throwables) { - throwables.printStackTrace(); + LOGGER.error(throwables.getMessage()); return new SqlStatement[0]; // If any exception occurs don't do any migration } } @@ -321,7 +326,7 @@ private UUID createParentRuleStatement(List statements, Database d private void createRuleStatement(List statements, Database database, ExpertRuleParam params) { InsertStatement ruleStatement = new InsertStatement(database.getDefaultCatalogName(), database.getDefaultSchemaName(), - EXPERT_RULE_TABLE); + EXPERT_RULE_TABLE); if (params.id() == null || params.dataType() == null) { return; @@ -356,7 +361,7 @@ private void createPropertiesStatements(List statements, Database StringBuilder builder = new StringBuilder(); builder.append("select free_property_filter_entities_id from free_properties_free_property_filter_entities") - .append(" where free_properties_filter_entity_id = ").append("'").append(propId).append("'"); + .append(" where free_properties_filter_entity_id = ").append("'").append(propId).append("'"); try (ResultSet propertyQuery = connection.createStatement().executeQuery(builder.toString())) { while (propertyQuery.next()) { @@ -418,8 +423,8 @@ private void createCountryStatement(JdbcConnection connection, List statements, Database dat // value table InsertStatement ruleValueStatement = new InsertStatement(database.getDefaultCatalogName(), - database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) + database.getDefaultSchemaName(), EXPERT_RULE_VALUE_TABLE) .addColumnValue("id", ruleId.toString()) .addColumnValue(VALUE_COL, value); statements.add(ruleValueStatement); @@ -506,7 +511,7 @@ private void createNumericRuleStatements(JdbcConnection connection, List Date: Mon, 18 Nov 2024 17:14:50 +0100 Subject: [PATCH 05/27] desactivate search for migrated tables --- .../filter/server/FilterService.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/server/FilterService.java b/src/main/java/org/gridsuite/filter/server/FilterService.java index 9bcf0a17..3e22abe2 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterService.java +++ b/src/main/java/org/gridsuite/filter/server/FilterService.java @@ -65,41 +65,17 @@ public class FilterService { private final FilterService self; public FilterService(final ScriptFilterRepository scriptFiltersRepository, - final LineFilterRepository lineFilterRepository, - final GeneratorFilterRepository generatorFilterRepository, - final LoadFilterRepository loadFilterRepository, - final ShuntCompensatorFilterRepository shuntCompensatorFilterRepository, - final StaticVarCompensatorFilterRepository staticVarCompensatorFilterRepository, - final BatteryFilterRepository batteryFilterRepository, final BusBarSectionFilterRepository busBarSectionFilterRepository, - final DanglingLineFilterRepository danglingLineFilterRepository, final LccConverterStationFilterRepository lccConverterStationFilterRepository, final VscConverterStationFilterRepository vscConverterStationFilterRepository, - final TwoWindingsTransformerFilterRepository twoWindingsTransformerFilterRepository, - final ThreeWindingsTransformerFilterRepository threeWindingsTransformerFilterRepository, - final HvdcLineFilterRepository hvdcLineFilterRepository, - final VoltageLevelFilterRepository voltageLevelFilterRepository, - final SubstationFilterRepository substationFilterRepository, final IdentifierListFilterRepository identifierListFilterRepository, final ExpertFilterRepository expertFilterRepository, NetworkStoreService networkStoreService, NotificationService notificationService, @Lazy FilterService self) { - filterRepositories.put(EquipmentType.LINE.name(), new LineFilterRepositoryProxy(lineFilterRepository)); - filterRepositories.put(EquipmentType.GENERATOR.name(), new GeneratorFilterRepositoryProxy(generatorFilterRepository)); - filterRepositories.put(EquipmentType.LOAD.name(), new LoadFilterRepositoryProxy(loadFilterRepository)); - filterRepositories.put(EquipmentType.SHUNT_COMPENSATOR.name(), new ShuntCompensatorFilterRepositoryProxy(shuntCompensatorFilterRepository)); - filterRepositories.put(EquipmentType.STATIC_VAR_COMPENSATOR.name(), new StaticVarCompensatorFilterRepositoryProxy(staticVarCompensatorFilterRepository)); - filterRepositories.put(EquipmentType.BATTERY.name(), new BatteryFilterRepositoryProxy(batteryFilterRepository)); filterRepositories.put(EquipmentType.BUSBAR_SECTION.name(), new BusBarSectionFilterRepositoryProxy(busBarSectionFilterRepository)); - filterRepositories.put(EquipmentType.DANGLING_LINE.name(), new DanglingLineFilterRepositoryProxy(danglingLineFilterRepository)); filterRepositories.put(EquipmentType.LCC_CONVERTER_STATION.name(), new LccConverterStationFilterRepositoryProxy(lccConverterStationFilterRepository)); filterRepositories.put(EquipmentType.VSC_CONVERTER_STATION.name(), new VscConverterStationFilterRepositoryProxy(vscConverterStationFilterRepository)); - filterRepositories.put(EquipmentType.TWO_WINDINGS_TRANSFORMER.name(), new TwoWindingsTransformerFilterRepositoryProxy(twoWindingsTransformerFilterRepository)); - filterRepositories.put(EquipmentType.THREE_WINDINGS_TRANSFORMER.name(), new ThreeWindingsTransformerFilterRepositoryProxy(threeWindingsTransformerFilterRepository)); - filterRepositories.put(EquipmentType.HVDC_LINE.name(), new HvdcLineFilterRepositoryProxy(hvdcLineFilterRepository)); - filterRepositories.put(EquipmentType.VOLTAGE_LEVEL.name(), new VoltageLevelFilterRepositoryProxy(voltageLevelFilterRepository)); - filterRepositories.put(EquipmentType.SUBSTATION.name(), new SubstationFilterRepositoryProxy(substationFilterRepository)); filterRepositories.put(FilterType.SCRIPT.name(), new ScriptFilterRepositoryProxy(scriptFiltersRepository)); From 03e5f84884a54a35e3536d1114cea36e041005fd Mon Sep 17 00:00:00 2001 From: basseche Date: Tue, 19 Nov 2024 15:48:13 +0100 Subject: [PATCH 06/27] delete TU on Criteria filters --- .../server/FilterEntityControllerTest.java | 837 ------------------ 1 file changed, 837 deletions(-) diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 5805d111..04222e16 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -22,7 +22,6 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import jakarta.servlet.ServletException; import org.apache.commons.collections4.OrderedMap; import org.apache.commons.collections4.map.LinkedMap; import org.gridsuite.filter.AbstractFilter; @@ -64,11 +63,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.util.CollectionUtils; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import java.util.*; -import java.util.stream.Stream; import static org.apache.commons.lang3.StringUtils.join; import static org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy.WRONG_FILTER_TYPE; @@ -220,241 +216,12 @@ public String joinWithComma(Object... array) { return join(array, ","); } - @Test - public void testLineFilter() throws Exception { - String userId = "userId"; - UUID filterId1 = UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"); - UUID filterId2 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"); - Date modificationDate = new Date(); - - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1") - .substationName1("P1") - .substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))) - .countries2(new TreeSet<>(Set.of("FR"))) - .freeProperties2(Map.of("region", List.of("north"))) - .freeProperties1(Map.of("region", List.of("south"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)) - .nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)) - .build(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - filterId1, - modificationDate, - lineFilter - ); - insertFilter(filterId1, lineCriteriaFilter); - checkFormFilter(filterId1, lineCriteriaFilter); - - // export - assertThrows("Network '" + NETWORK_NOT_FOUND_UUID + "' not found", ServletException.class, () -> mvc.perform(get(URL_TEMPLATE + "/" + filterId1 + "/export?networkUuid=" + NETWORK_NOT_FOUND_UUID) - .contentType(APPLICATION_JSON))); - - mvc.perform(get(URL_TEMPLATE + "/" + filterId1 + "/export").param("networkUuid", NETWORK_UUID.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json("[{\"id\":\"NHV1_NHV2_1\",\"type\":\"LINE\"}]")); - - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", filterId1.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - Date dateModification = filterAttributes.get(0).getModificationDate(); - - CriteriaFilter hvdcLineCriteriaFilter = new CriteriaFilter( - filterId1, - dateModification, - HvdcLineFilter.builder() - .equipmentID("equipmentID") - .equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2") - .countries1(COUNTRIES1) - .countries2(COUNTRIES2) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build() - ); - modifyFormFilter(filterId1, hvdcLineCriteriaFilter, userId); - checkFormFilter(filterId1, hvdcLineCriteriaFilter); - - var res = mvc.perform(get(URL_TEMPLATE)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(); - filterAttributes = objectMapper.readValue(res, new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - if (!filterAttributes.get(0).getId().equals(filterId1)) { - Collections.reverse(filterAttributes); - } - - matchFilterInfos(filterAttributes.get(0), filterId1, FilterType.CRITERIA, EquipmentType.HVDC_LINE, modificationDate); - - filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", filterId1.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - matchFilterInfos(filterAttributes.get(0), filterId1, FilterType.CRITERIA, EquipmentType.HVDC_LINE, modificationDate); - - // test replace line filter with other filter type - AbstractFilter generatorFormFilter = new CriteriaFilter( - filterId1, - modificationDate, - new GeneratorFilter("eqId1", "gen1", "s1", new TreeSet<>(Set.of("FR", "BE")), null, null, new NumericalFilter(RangeType.RANGE, 50., null), null) - ); - - modifyFormFilter(filterId1, generatorFormFilter, userId); - - filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", filterId1.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - matchFilterInfos(filterAttributes.get(0), filterId1, FilterType.CRITERIA, EquipmentType.GENERATOR, modificationDate); - - // update with same type filter - AbstractFilter generatorFormFilter2 = new CriteriaFilter( - filterId1, - modificationDate, - new GeneratorFilter("eqId2", "gen2", "s2", new TreeSet<>(Set.of("FR", "BE")), null, null, new NumericalFilter(RangeType.RANGE, 50., null), null) - ); - modifyFormFilter(filterId1, generatorFormFilter2, userId); - - // delete - mvc.perform(delete(URL_TEMPLATE + "/" + filterId2)).andExpect(status().isNotFound()); - - mvc.perform(get(URL_TEMPLATE + "/" + filterId2)).andExpect(status().isNotFound()); - - filterService.deleteAll(); - } - - @Test - public void testLineFilter2() throws Exception { - String userId = "userId"; - UUID filterId3 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300c"); - UUID filterId4 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300d"); - Date modificationDate = new Date(); - - // a 2-country network (one substation FR, one BE) - final double p2NominalVoltage = 63.; - network6.getLine("NHV1_NHV2_2").getTerminal2().getVoltageLevel().setNominalV(p2NominalVoltage); // patch just for better coverage - final String noMatch = "[]"; - final String bothMatch = "[{\"id\":\"NHV1_NHV2_1\",\"type\":\"LINE\"},{\"id\":\"NHV1_NHV2_2\",\"type\":\"LINE\"}]"; - - List rangeTypes = new ArrayList<>(); - rangeTypes.add(RangeType.EQUALITY); - List values1 = new ArrayList<>(); - values1.add(p2NominalVoltage); - List values2 = new ArrayList<>(); - values2.add(null); - - CriteriaFilter lineCriteriaFilterBEFR = insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("BE")), new TreeSet<>(Set.of("FR")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, bothMatch, false); - - // more country filters - rangeTypes.add(RangeType.GREATER_OR_EQUAL); - rangeTypes.set(0, RangeType.GREATER_OR_EQUAL); - values1.set(0, 0.); - values1.add(0.); - values2.add(null); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("BE")), new TreeSet<>(Set.of("FR")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, bothMatch, true); - - network6.getSubstation("P2").setCountry(Country.FR); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("IT")), new TreeSet<>(Set.of("FR")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, noMatch, true); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of()), new TreeSet<>(Set.of("IT")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, noMatch, true); - network6.getSubstation("P1").setCountry(Country.IT); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("IT")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, bothMatch, true); - - filterService.deleteAll(); - } - - @Test - public void testGeneratorFilter() throws Exception { - final String generatorUuid = "42b70a4d-e0c4-413a-8e3e-78e9027d300f"; - final String noMatch = "[]"; - final String oneMatch = "[{\"id\":\"GEN\",\"type\":\"GENERATOR\"}]"; - final String bothMatch = "[{\"id\":\"GEN\",\"type\":\"GENERATOR\"}, {\"id\":\"GEN2\",\"type\":\"GENERATOR\"}]"; - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, oneMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, oneMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "nameNotFound", "P1", null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", null, null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, oneMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "substationNameNotFound", null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.EQUALITY, 145., null, null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 19., 22., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 27., 30., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 34.30, 35.70, null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 14.55, 15.45, null, NETWORK_UUID, null, noMatch); - // no filter at all - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - null, null, null, null, null, 0., 0., null, NETWORK_UUID, null, bothMatch); - // no SOLAR generator - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - null, null, null, null, null, 0., 0., EnergySource.SOLAR, NETWORK_UUID, null, noMatch); - // 2 OTHER generators in our network - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - null, null, null, null, null, 0., 0., EnergySource.OTHER, NETWORK_UUID, null, bothMatch); - } - - @Test - public void testLoadFilter() throws Exception { - insertInjectionFilter(EquipmentType.LOAD, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "LOAD", null, "P2", Set.of("FR"), RangeType.RANGE, 144., 176., null, NETWORK_UUID, VARIANT_ID_1, "[{\"id\":\"LOAD\",\"type\":\"LOAD\"}]"); - } - - @Test - public void testShuntCompensatorFilter() throws Exception { - insertInjectionFilter(EquipmentType.SHUNT_COMPENSATOR, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "SHUNT", null, "S1", Set.of("FR"), RangeType.EQUALITY, 380., null, null, NETWORK_UUID_4, null, "[{\"id\":\"SHUNT\",\"type\":\"SHUNT_COMPENSATOR\"}]"); - } - - @Test - public void testStaticVarCompensatorFilter() throws Exception { - insertInjectionFilter(EquipmentType.STATIC_VAR_COMPENSATOR, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "SVC3", null, "S2", null, null, null, null, null, NETWORK_UUID_3, null, "[{\"id\":\"SVC3\",\"type\":\"STATIC_VAR_COMPENSATOR\"}]"); - } - - @Test - public void testBatteryFilter() throws Exception { - insertInjectionFilter(EquipmentType.BATTERY, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "batteryId1", "batteryName", null, Set.of("FR"), RangeType.RANGE, 45., 65., null, NETWORK_UUID, null, "[]"); - } - @Test public void testBusBarSectionFilter() throws Exception { insertInjectionFilter(EquipmentType.BUSBAR_SECTION, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), null, "batteryName", null, Set.of("DE"), RangeType.EQUALITY, 380., null, null, NETWORK_UUID, null, "[]"); } - @Test - public void testDanglingLineFilter() throws Exception { - insertInjectionFilter(EquipmentType.DANGLING_LINE, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "danglingLineId1", null, "s2", Set.of("FR"), RangeType.RANGE, 138., 162., null, NETWORK_UUID, null, "[]"); - } - @Test public void testLccConverterStationFilter() throws Exception { insertInjectionFilter(EquipmentType.LCC_CONVERTER_STATION, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), @@ -467,318 +234,6 @@ public void testVscConverterStationFilter() throws Exception { "vscId1", "vscName1", "s2", null, RangeType.EQUALITY, 225., null, null, NETWORK_UUID, null, "[]"); } - @Test - public void testHvdcLineFilter() throws Exception { - final String noMatch = "[]"; - final String matchHVDCLine = "[{\"id\":\"L\",\"type\":\"HVDC_LINE\"}]"; - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of("FR", "IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, matchHVDCLine); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "substationNameNotFound", new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of("FR", "IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "substationNameNotFound", "S1", new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of("FR", "IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("IT")), new TreeSet<>(Set.of("FR")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - network2.getSubstation("S1").setCountry(Country.IT); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, matchHVDCLine); - } - - @Test - public void testTwoWindingsTransformerFilter() throws Exception { - List rangeTypes = new ArrayList<>(); - rangeTypes.add(RangeType.EQUALITY); - rangeTypes.add(RangeType.RANGE); - List values1 = new ArrayList<>(); - values1.add(380.); - values1.add(142.5); - List values2 = new ArrayList<>(); - values2.add(null); - values2.add(157.5); - - // with this network (EurostagTutorialExample1Factory::create), we have 2 2WT Transfos: - // - NGEN_NHV1 term1: 24 kV term2: 380 kV - // - NHV2_NLOAD term1: 380 kV term2: 150 kV - final String noMatch = "[]"; - final String matchNHV2NLOAD = "[{\"id\":\"NHV2_NLOAD\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"}]"; - final String matchNGENNHV1 = "[{\"id\":\"NGEN_NHV1\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"}]"; - final String bothMatch = "[{\"id\":\"NHV2_NLOAD\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"},{\"id\":\"NGEN_NHV1\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"}]"; - - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "NHV2_NLOAD", null, "P2", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - // no eqpt/substation filter: only NHV2_NLOAD match because of RANGE filter - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - // bad substationName - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "NHV2_NLOAD", null, "substationNameNotFound", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, noMatch); - // this network has only FR substations: IT does not match: - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "NHV2_NLOAD", null, "P2", Set.of("IT"), rangeTypes, values1, values2, null, NETWORK_UUID, null, noMatch); - - // change RANGE into "> 24" - rangeTypes.set(1, RangeType.GREATER_THAN); - values1.set(1, 24.); - values2.set(1, null); - // NGEN_NHV1 still does not match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - - // change "> 24" into ">= 24" - rangeTypes.set(1, RangeType.GREATER_OR_EQUAL); - // both transfos now match both filters - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, bothMatch); - - // change "== 380" into ">= 0" - // change ">= 24" into "< 380" - rangeTypes.set(0, RangeType.GREATER_OR_EQUAL); - values1.set(0, 0.); - rangeTypes.set(1, RangeType.LESS_THAN); - values1.set(1, 380.); - // both match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, bothMatch); - // add substation filter on P1 => NGENNHV1 - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, "P1", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNGENNHV1); - // add substation filter on P2 => NHV2NLOAD - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, "P2", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - - // change "< 380" into "< 150" - values1.set(1, 150.); - // only NGEN_NHV1 match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNGENNHV1); - - // change "< 150" into "<= 150" - rangeTypes.set(1, RangeType.LESS_OR_EQUAL); - // both match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, bothMatch); - - // match second terminal property - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, Map.of("region", List.of("south")), NETWORK_UUID, null, matchNHV2NLOAD); - - // change ">=0" into "> 400" - rangeTypes.set(0, RangeType.GREATER_OR_EQUAL); - values1.set(0, 400.); - // [400..150] not possible - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, noMatch); - } - - @Test - public void testThreeWindingsTransformerFilter() throws Exception { - List rangeTypes = new ArrayList<>(); - rangeTypes.add(RangeType.RANGE); - rangeTypes.add(RangeType.EQUALITY); - rangeTypes.add(RangeType.EQUALITY); - List values1 = new ArrayList<>(); - values1.add(127.); - values1.add(33.); - values1.add(11.); - List values2 = new ArrayList<>(); - values2.add(134.); - values2.add(null); - values2.add(null); - - // with this network (ThreeWindingsTransformerNetworkFactory.create), we have a single 3WT: - // - 3WT term1: 132 kV term2: 33 kV term3: 11 kV - final String noMatch = "[]"; - final String match3WT = "[{\"id\":\"3WT\",\"type\":\"THREE_WINDINGS_TRANSFORMER\"}]"; - - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "3WT", null, "SUBSTATION", Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // same without eqpt / sybstation - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // bad substationName - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "3WT", null, "substationNameNotFound", Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - // IT does not match - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "3WT", null, "SUBSTATION", Set.of("IT"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Current filters have covered OR #1/6 in get3WTransformerList - - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #2/6 - values1.set(1, 11.); - values1.set(2, 33.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #3/6 - values1.set(0, 33.); - values2.set(0, 33.); - values1.set(1, 132.); - values1.set(2, 11.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #4/6 - values1.set(1, 11.); - values1.set(2, 132.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #5/6 - values1.set(0, 10.); - values2.set(0, 12.); - values1.set(1, 132.); - values1.set(2, 33.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #6/6 - values1.set(1, 33.); - values1.set(2, 132.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - } - - @Test - public void testVoltageLevelFilter() throws Exception { - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("FR", "IT"), RangeType.RANGE, 15., 30., NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", null, RangeType.RANGE, 15., 30., NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "nameNotFound", null, RangeType.RANGE, 15., 30., NETWORK_UUID, null, "[]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", null, RangeType.RANGE, 20., 27., NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", null, RangeType.RANGE, 29., 36., NETWORK_UUID, null, "[]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("FR", "IT"), RangeType.EQUALITY, 150., null, NETWORK_UUID, null, "[]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("FR", "IT"), RangeType.EQUALITY, 24., null, NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("ES", "PT"), null, null, null, NETWORK_UUID, null, "[]"); - } - - @Test - public void testSubstationFilter() throws Exception { - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "P1", Set.of("FR", "IT"), NETWORK_UUID, null, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"}]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "P1", null, NETWORK_UUID, null, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"}]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "nameNotFound", null, NETWORK_UUID, null, "[]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "P1", Set.of("ES", "PT"), NETWORK_UUID, null, "[]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P2", null, Set.of("FR", "IT"), NETWORK_UUID, null, "[{\"id\":\"P2\",\"type\":\"SUBSTATION\"}]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P2", null, Set.of("ES", "PT"), NETWORK_UUID, null, "[]"); - } - - @Test - public void testLineFilterCrud() throws Exception { - UUID filterId1 = UUID.fromString("99999999-e0c4-413a-8e3e-78e9027d300f"); - LineFilter lineFilter = LineFilter.builder().equipmentID("equipmentID").equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES1).countries2(COUNTRIES2) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 5., 8.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 6., null)) - .build(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - null, - new Date(), - lineFilter - ); - - // --- insert filter --- // - insertFilter(filterId1, lineCriteriaFilter); - - // check the inserted filter - lineCriteriaFilter.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter); - - // --- duplicate filter -- // - UUID newFilterId1 = duplicateFilter(filterId1); - - // check the duplicated filter whether it is matched to the original - lineCriteriaFilter.setId(newFilterId1); - checkFormFilter(newFilterId1, lineCriteriaFilter); - - // --- modify filter --- // - LineFilter lineFilter2 = LineFilter.builder().equipmentID("equipmentID").equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES2).countries2(COUNTRIES1) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 4., 9.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 5., null)) - .build(); - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - null, - new Date(), - lineFilter2 - ); - updateFilter(filterId1, lineCriteriaFilter2, "userId"); - - // check the modified filter - lineCriteriaFilter2.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter2); - - // --- modify filter with equipment type changed --- // - GeneratorFilter generatorFilter = GeneratorFilter.builder().equipmentID("eqId1").equipmentName("gen1") - .substationName("s1") - .countries(new TreeSet<>(Set.of("FR", "BE"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build(); - CriteriaFilter generatorCriteriaFilter = new CriteriaFilter( - null, - new Date(), - generatorFilter - ); - updateFilter(filterId1, generatorCriteriaFilter, "userId"); - - // check the modified filter - generatorCriteriaFilter.setId(filterId1); - checkFormFilter(filterId1, generatorCriteriaFilter); - - // --- delete filters --- // - deleteFilter(filterId1); - deleteFilter(newFilterId1); - - // check empty after delete all - List allFilters = getAllFilters(); - Assertions.assertThat(allFilters).isEmpty(); - } - @Test public void testIdentifierListFilter() throws Exception { UUID filterId = UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"); @@ -847,182 +302,6 @@ public void testIdentifierListFilter() throws Exception { checkIdentifierListFilterExportAndMetadata(substationFilterId, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"},{\"id\":\"P2\",\"type\":\"SUBSTATION\"}]\n", EquipmentType.SUBSTATION); } - @Test - public void testGetFiltersByIds() throws Exception { - UUID filterId3 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300c"); - UUID filterId4 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300d"); - - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - filterId3, - new Date(), - lineFilter - ); - insertFilter(filterId3, lineCriteriaFilter); - checkFormFilter(filterId3, lineCriteriaFilter); - - LineFilter lineFilter2 = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - filterId4, - new Date(), - lineFilter2 - ); - - insertFilter(filterId4, lineCriteriaFilter2); - checkFormFilter(filterId4, lineCriteriaFilter2); - } - - @Test - public void testExportFilters() throws Exception { - UUID filterId = UUID.randomUUID(); - UUID filterId2 = UUID.randomUUID(); - UUID filterId3 = UUID.randomUUID(); - - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - Date date = new Date(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - filterId2, - date, - lineFilter - ); - insertFilter(filterId2, lineCriteriaFilter); - checkFormFilter(filterId2, lineCriteriaFilter); - - LineFilter lineFilter2 = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - filterId3, - date, - lineFilter2 - ); - - insertFilter(filterId3, lineCriteriaFilter2); - checkFormFilter(filterId3, lineCriteriaFilter2); - - IdentifierListFilterEquipmentAttributes attribute1 = new IdentifierListFilterEquipmentAttributes("GEN", 1.0); - IdentifierListFilterEquipmentAttributes attribute2 = new IdentifierListFilterEquipmentAttributes("wrongId", 2.0); - IdentifierListFilterEquipmentAttributes attribute3 = new IdentifierListFilterEquipmentAttributes("wrongId2", 3.0); - - IdentifierListFilter identifierListFilter = new IdentifierListFilter(filterId, - date, - EquipmentType.GENERATOR, - List.of(attribute1, attribute2, attribute3)); - insertFilter(filterId, identifierListFilter); - checkIdentifierListFilter(filterId, identifierListFilter); - - List values = Arrays.asList(filterId.toString(), filterId2.toString(), filterId3.toString()); - MultiValueMap params = new LinkedMultiValueMap<>(); - params.addAll("ids", values); - params.add("networkUuid", NETWORK_UUID.toString()); - params.add("variantId", VARIANT_ID_1); - - List filterEquipments = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/export").params(params) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - IdentifiableAttributes identifiableAttributes = new IdentifiableAttributes("GEN", IdentifiableType.GENERATOR, 1.0); - IdentifiableAttributes identifiableAttributes4 = new IdentifiableAttributes("NHV1_NHV2_1", IdentifiableType.LINE, null); - - FilterEquipments filterEquipment1 = FilterEquipments.builder() - .filterId(filterId) - .identifiableAttributes(List.of(identifiableAttributes)) - .notFoundEquipments(List.of("wrongId", "wrongId2")) - .build(); - - FilterEquipments filterEquipment2 = FilterEquipments.builder() - .filterId(filterId2) - .identifiableAttributes(List.of(identifiableAttributes4)) - .build(); - - FilterEquipments filterEquipment3 = FilterEquipments.builder() - .filterId(filterId3) - .identifiableAttributes(List.of(identifiableAttributes4)) - .build(); - - assertEquals(3, filterEquipments.size()); - List expected = new ArrayList<>(List.of(filterEquipment1, filterEquipment2, filterEquipment3)); - checkFilterEquipments(expected, filterEquipments); - - } - - @Test - public void testGetIdentifiablesCount() throws Exception { - UUID filterId1 = UUID.randomUUID(); - UUID filterId2 = UUID.randomUUID(); - UUID filterId3 = UUID.randomUUID(); - - LineFilter lineFilter1 = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - CriteriaFilter lineCriteriaFilter1 = new CriteriaFilter( - filterId1, - new Date(), - lineFilter1 - ); - insertFilter(filterId1, lineCriteriaFilter1); - checkFormFilter(filterId1, lineCriteriaFilter1); - - LineFilter lineFilter2 = LineFilter.builder().equipmentID("NHV1_NHV2_2").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - filterId2, - new Date(), - lineFilter2 - ); - insertFilter(filterId2, lineCriteriaFilter2); - checkFormFilter(filterId2, lineCriteriaFilter2); - - Date modificationDate = new Date(); - CriteriaFilter hvdcLineFilter = new CriteriaFilter( - filterId3, - modificationDate, - HvdcLineFilter.builder().equipmentID("NHV1_NHV2_3").equipmentName("equipmentName_3") - .substationName1("substationName1").substationName2("substationName2") - .countries1(new TreeSet<>(Set.of("FR", "BE"))).countries2(new TreeSet<>(Set.of("FR", "IT"))) - .freeProperties2(Map.of("region", List.of("north"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 380., 420.)) - .build() - ); - insertFilter(filterId3, hvdcLineFilter); - checkFormFilter(filterId3, hvdcLineFilter); - - MultiValueMap params = new LinkedMultiValueMap<>(Map.of( - "networkUuid", List.of(NETWORK_UUID.toString()), - "variantId", List.of(VARIANT_ID_1), - "ids[g1]", List.of(filterId1.toString()), - "ids[g2]", List.of(filterId2.toString()), - "ids[g3]", List.of(filterId3.toString()), - "ids[g4]", List.of(UUID.randomUUID().toString()) - )); - Map identifiablesCount = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/identifiables-count") - .params(params) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - assertEquals(1, identifiablesCount.get("g1").longValue()); - assertEquals(1, identifiablesCount.get("g2").longValue()); - assertEquals(0, identifiablesCount.get("g3").longValue()); - assertEquals(0, identifiablesCount.get("g4").longValue()); - - assertEquals(4, identifiablesCount.size()); - } - private void checkFilterEquipments(List filterEquipments1, List filterEquipments2) { assertEquals(CollectionUtils.isEmpty(filterEquipments1), CollectionUtils.isEmpty(filterEquipments2)); assertEquals(filterEquipments1.size(), filterEquipments2.size()); @@ -2148,120 +1427,4 @@ public void testExpertFilterLoadLinkToOtherFilterWithIsPartOfOperator() throws E checkFilterEvaluating(expertFilter, expectedResultJson); } - @Test - public void testLineFiltersCrudInBatch() throws Exception { - UUID filterId1 = UUID.randomUUID(); - LineFilter lineFilter1 = LineFilter.builder().equipmentID("equipmentID1").equipmentName("equipmentName1") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES1).countries2(COUNTRIES2) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 5., 8.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 6., null)) - .build(); - CriteriaFilter lineCriteriaFilter1 = new CriteriaFilter( - null, - new Date(), - lineFilter1 - ); - - UUID filterId2 = UUID.randomUUID(); - LineFilter lineFilter2 = LineFilter.builder().equipmentID("equipmentID2").equipmentName("equipmentName2") - .substationName1("substationName3").countries1(COUNTRIES1).countries2(COUNTRIES2) - .substationName2("substationName4") - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 4., 9.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 5., null)) - .build(); - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - null, - new Date(), - lineFilter2 - ); - - Map filtersToCreateMap = Map.of( - filterId1, lineCriteriaFilter1, - filterId2, lineCriteriaFilter2 - ); - - // --- insert in batch --- // - insertFilters(filtersToCreateMap); - - // check inserted filters - lineCriteriaFilter1.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter1); - lineCriteriaFilter2.setId(filterId2); - checkFormFilter(filterId2, lineCriteriaFilter2); - - // --- duplicate in batch --- // - Map sourceAndNewUuidMap = duplicateFilters(List.of(filterId1, filterId2)); - - sourceAndNewUuidMap.forEach((sourceUuid, newUuid) -> filtersToCreateMap.get(sourceUuid).setId(newUuid)); - - // check each duplicated filter whether it is matched to the original - for (Map.Entry entry : sourceAndNewUuidMap.entrySet()) { - UUID sourceUuid = entry.getKey(); - UUID newUuid = entry.getValue(); - checkFormFilter(newUuid, (CriteriaFilter) filtersToCreateMap.get(sourceUuid)); - } - - // --- modify filters in batch --- // - LineFilter lineFilter3 = LineFilter.builder().equipmentID("equipmentID").equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES2).countries2(COUNTRIES1) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 3., 10.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 4., null)) - .build(); - CriteriaFilter lineCriteriaFilter3 = new CriteriaFilter( - null, - new Date(), - lineFilter3 - ); - GeneratorFilter generatorFilter = GeneratorFilter.builder().equipmentID("eqId1").equipmentName("gen1") - .substationName("s1") - .countries(new TreeSet<>(Set.of("FR", "BE"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build(); - CriteriaFilter generatorCriteriaFilter = new CriteriaFilter( - null, - new Date(), - generatorFilter - ); - Map filtersToUpdateMap = Map.of( - filterId1, lineCriteriaFilter3, - filterId2, generatorCriteriaFilter - ); - updateFilters(filtersToUpdateMap); - - // check modified filters - lineCriteriaFilter3.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter3); - generatorCriteriaFilter.setId(filterId2); - checkFormFilter(filterId2, generatorCriteriaFilter); - - // --- modify filters in batch with a none existing id --- // - GeneratorFilter generatorFilter2 = GeneratorFilter.builder().equipmentID("eqId1").equipmentName("gen1") - .substationName("s1") - .countries(new TreeSet<>(Set.of("FR", "BE"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 60., null)) - .build(); - CriteriaFilter generatorCriteriaFilter2 = new CriteriaFilter( - null, - new Date(), - generatorFilter2 - ); - - Map filtersToUpdateMap2 = Map.of( - UUID.randomUUID(), lineCriteriaFilter3, - filterId2, generatorCriteriaFilter2 - ); - updateFiltersWithNoneExistingId(filtersToUpdateMap2); - // check modified filters => filter with filterId2 should not be changed - checkFormFilter(filterId2, generatorCriteriaFilter); - - // --- delete filters in batch -- // - deleteFilters(Stream.concat(sourceAndNewUuidMap.keySet().stream(), sourceAndNewUuidMap.values().stream()).toList()); - - // check empty after delete all - List allFilters = getAllFilters(); - Assertions.assertThat(allFilters).isEmpty(); - } - } From 7de7207b0757227dab765c1544a6110d320cf1e0 Mon Sep 17 00:00:00 2001 From: basseche Date: Thu, 21 Nov 2024 13:59:58 +0100 Subject: [PATCH 07/27] exclude migrations from sonar coverage --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 12721a2d..d8f2712d 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,7 @@ 35 4.3.1 org.gridsuite.filter.server + **/migrations/**/* From 8807198ad78a392da0ac863124b6916c47fc3f22 Mon Sep 17 00:00:00 2001 From: basseche Date: Fri, 22 Nov 2024 15:53:36 +0100 Subject: [PATCH 08/27] review --- .../gridsuite/filter/server/FilterService.java | 11 ----------- ...igrateEquipmentFiltersToExpertFilters.java} | 4 ++-- .../changesets/changelog_20241105T114300Z.xml | 2 +- .../server/FilterEntityControllerTest.java | 18 ------------------ 4 files changed, 3 insertions(+), 32 deletions(-) rename src/main/java/org/gridsuite/filter/server/migrations/{MigrateEquipmentFilter.java => MigrateEquipmentFiltersToExpertFilters.java} (99%) diff --git a/src/main/java/org/gridsuite/filter/server/FilterService.java b/src/main/java/org/gridsuite/filter/server/FilterService.java index 3e22abe2..1e4ec486 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterService.java +++ b/src/main/java/org/gridsuite/filter/server/FilterService.java @@ -20,16 +20,13 @@ import org.gridsuite.filter.server.dto.IdsByGroup; import org.gridsuite.filter.server.entities.AbstractFilterEntity; import org.gridsuite.filter.server.repositories.FilterRepository; -import org.gridsuite.filter.server.repositories.criteriafilter.*; import org.gridsuite.filter.server.repositories.expertfilter.ExpertFilterRepository; import org.gridsuite.filter.server.repositories.identifierlistfilter.IdentifierListFilterRepository; import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.server.repositories.proxies.criteriafilter.*; import org.gridsuite.filter.server.repositories.proxies.expertfiler.ExpertFilterRepositoryProxy; import org.gridsuite.filter.server.repositories.proxies.identifierlistfilter.IdentifierListFilterRepositoryProxy; import org.gridsuite.filter.server.repositories.proxies.scriptfilter.ScriptFilterRepositoryProxy; import org.gridsuite.filter.server.repositories.scriptfilter.ScriptFilterRepository; -import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.filter.utils.FilterServiceUtils; import org.gridsuite.filter.utils.FilterType; import org.springframework.context.annotation.ComponentScan; @@ -65,20 +62,12 @@ public class FilterService { private final FilterService self; public FilterService(final ScriptFilterRepository scriptFiltersRepository, - final BusBarSectionFilterRepository busBarSectionFilterRepository, - final LccConverterStationFilterRepository lccConverterStationFilterRepository, - final VscConverterStationFilterRepository vscConverterStationFilterRepository, final IdentifierListFilterRepository identifierListFilterRepository, final ExpertFilterRepository expertFilterRepository, NetworkStoreService networkStoreService, NotificationService notificationService, @Lazy FilterService self) { - filterRepositories.put(EquipmentType.BUSBAR_SECTION.name(), new BusBarSectionFilterRepositoryProxy(busBarSectionFilterRepository)); - filterRepositories.put(EquipmentType.LCC_CONVERTER_STATION.name(), new LccConverterStationFilterRepositoryProxy(lccConverterStationFilterRepository)); - filterRepositories.put(EquipmentType.VSC_CONVERTER_STATION.name(), new VscConverterStationFilterRepositoryProxy(vscConverterStationFilterRepository)); - filterRepositories.put(FilterType.SCRIPT.name(), new ScriptFilterRepositoryProxy(scriptFiltersRepository)); - filterRepositories.put(FilterType.IDENTIFIER_LIST.name(), new IdentifierListFilterRepositoryProxy(identifierListFilterRepository)); filterRepositories.put(FilterType.EXPERT.name(), new ExpertFilterRepositoryProxy(expertFilterRepository)); diff --git a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java similarity index 99% rename from src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java rename to src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java index 68f41094..bd024985 100644 --- a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFilter.java +++ b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java @@ -20,7 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class MigrateEquipmentFilter implements CustomSqlChange { +public class MigrateEquipmentFiltersToExpertFilters implements CustomSqlChange { private static final String EXPERT_RULE_TABLE = "expert_rule"; private static final String EXPERT_RULE_VALUE_TABLE = "expert_rule_value"; private static final String FREE_PROPS_ID = "free_properties_id"; @@ -28,7 +28,7 @@ public class MigrateEquipmentFilter implements CustomSqlChange { private static final String NUMERIC_FILTER_ID = "numeric_filter_id_id"; private static final String VALUE_COL = "value_"; - private static final Logger LOGGER = LoggerFactory.getLogger(MigrateEquipmentFilter.class); + private static final Logger LOGGER = LoggerFactory.getLogger(MigrateEquipmentFiltersToExpertFilters.class); static class ExpertRuleParam { private final String id; diff --git a/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml index 324ecdc2..60e8b660 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20241105T114300Z.xml @@ -4,6 +4,6 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> - + \ No newline at end of file diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 04222e16..1b1022fa 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -216,24 +216,6 @@ public String joinWithComma(Object... array) { return join(array, ","); } - @Test - public void testBusBarSectionFilter() throws Exception { - insertInjectionFilter(EquipmentType.BUSBAR_SECTION, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "batteryName", null, Set.of("DE"), RangeType.EQUALITY, 380., null, null, NETWORK_UUID, null, "[]"); - } - - @Test - public void testLccConverterStationFilter() throws Exception { - insertInjectionFilter(EquipmentType.LCC_CONVERTER_STATION, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "lccId1", "lccName1", "s3", Set.of("FR", "BE", "NL", "DE", "IT"), RangeType.RANGE, 20., 400., null, NETWORK_UUID, null, "[]"); - } - - @Test - public void testVscConverterStationFilter() throws Exception { - insertInjectionFilter(EquipmentType.VSC_CONVERTER_STATION, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "vscId1", "vscName1", "s2", null, RangeType.EQUALITY, 225., null, null, NETWORK_UUID, null, "[]"); - } - @Test public void testIdentifierListFilter() throws Exception { UUID filterId = UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"); From 0ae3b24a5a3050ed0f7115c2679a71b1f2e0c9a5 Mon Sep 17 00:00:00 2001 From: basseche Date: Tue, 26 Nov 2024 16:25:25 +0100 Subject: [PATCH 09/27] little optimization --- .../migrations/MigrateEquipmentFiltersToExpertFilters.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java index bd024985..739f4e45 100644 --- a/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java +++ b/src/main/java/org/gridsuite/filter/server/migrations/MigrateEquipmentFiltersToExpertFilters.java @@ -240,13 +240,13 @@ Column[] columns() { @Override public SqlStatement[] generateStatements(Database database) throws CustomChangeException { List statements = new ArrayList<>(); + JdbcConnection connection = (JdbcConnection) database.getConnection(); for (Equipment equipment : Equipment.values()) { StringBuilder builder = new StringBuilder(); builder.append("select * from ").append(equipment.table()); try { - JdbcConnection connection = (JdbcConnection) database.getConnection(); // All filters to migrate in equipment filter table try (ResultSet filters = connection.createStatement().executeQuery(builder.toString())) { From 2a216bb1807b1e778c6f131cf08f0b8eb822432c Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 14:56:43 +0100 Subject: [PATCH 10/27] correct TU --- .../server/FilterEntityControllerTest.java | 326 ++++++++++++++++++ 1 file changed, 326 insertions(+) diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 1b1022fa..4b94c06f 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -63,8 +63,11 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.util.CollectionUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import java.util.*; +import java.util.stream.Stream; import static org.apache.commons.lang3.StringUtils.join; import static org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy.WRONG_FILTER_TYPE; @@ -284,6 +287,198 @@ public void testIdentifierListFilter() throws Exception { checkIdentifierListFilterExportAndMetadata(substationFilterId, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"},{\"id\":\"P2\",\"type\":\"SUBSTATION\"}]\n", EquipmentType.SUBSTATION); } + @Test + public void testGetFiltersByIds() throws Exception { + UUID filterId3 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300c"); + UUID filterId4 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300d"); + + ArrayList rules = new ArrayList<>(); + EnumExpertRule country1Filter = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules.add(country1Filter); + EnumExpertRule country2Filter = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules.add(country2Filter); + NumberExpertRule nominalVoltage1Filter = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(360., 400.))).build(); + rules.add(nominalVoltage1Filter); + NumberExpertRule nominalVoltage2Filter = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(356.25, 393.75))).build(); + rules.add(nominalVoltage2Filter); + CombinatorExpertRule parentRule = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); + ExpertFilter lineFilter = new ExpertFilter(filterId3, new Date(), EquipmentType.LINE, parentRule); + + insertFilter(filterId3, lineFilter); + checkExpertFilter(filterId3, lineFilter); + + ArrayList rules2 = new ArrayList<>(); + EnumExpertRule country1Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules2.add(country1Filter2); + EnumExpertRule country2Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules2.add(country2Filter2); + NumberExpertRule nominalVoltage1Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(360., 400.))).build(); + rules2.add(nominalVoltage1Filter2); + NumberExpertRule nominalVoltage2Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(356.25, 393.75))).build(); + rules2.add(nominalVoltage2Filter2); + CombinatorExpertRule parentRule2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); + ExpertFilter lineFilter2 = new ExpertFilter(filterId4, new Date(), EquipmentType.LINE, parentRule2); + + insertFilter(filterId4, lineFilter2); + checkExpertFilter(filterId4, lineFilter2); + } + + @Test + public void testExportFilters() throws Exception { + UUID filterId = UUID.randomUUID(); + UUID filterId2 = UUID.randomUUID(); + UUID filterId3 = UUID.randomUUID(); + + ArrayList rules = new ArrayList<>(); + EnumExpertRule country1Filter = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules.add(country1Filter); + EnumExpertRule country2Filter = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules.add(country2Filter); + NumberExpertRule nominalVoltage1Filter = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(360., 400.))).build(); + rules.add(nominalVoltage1Filter); + NumberExpertRule nominalVoltage2Filter = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(356.25, 393.75))).build(); + rules.add(nominalVoltage2Filter); + CombinatorExpertRule parentRule = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); + ExpertFilter lineFilter = new ExpertFilter(filterId2, new Date(), EquipmentType.LINE, parentRule); + + insertFilter(filterId2, lineFilter); + checkExpertFilter(filterId2, lineFilter); + + ArrayList rules2 = new ArrayList<>(); + EnumExpertRule country1Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules2.add(country1Filter2); + EnumExpertRule country2Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules2.add(country2Filter2); + NumberExpertRule nominalVoltage1Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(360., 400.))).build(); + rules2.add(nominalVoltage1Filter2); + NumberExpertRule nominalVoltage2Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(356.25, 393.75))).build(); + rules2.add(nominalVoltage2Filter2); + CombinatorExpertRule parentRule2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); + ExpertFilter lineFilter2 = new ExpertFilter(filterId3, new Date(), EquipmentType.LINE, parentRule2); + + insertFilter(filterId3, lineFilter2); + checkExpertFilter(filterId3, lineFilter2); + + IdentifierListFilterEquipmentAttributes attribute1 = new IdentifierListFilterEquipmentAttributes("GEN", 1.0); + IdentifierListFilterEquipmentAttributes attribute2 = new IdentifierListFilterEquipmentAttributes("wrongId", 2.0); + IdentifierListFilterEquipmentAttributes attribute3 = new IdentifierListFilterEquipmentAttributes("wrongId2", 3.0); + + Date date = new Date(); + IdentifierListFilter identifierListFilter = new IdentifierListFilter(filterId, + date, + EquipmentType.GENERATOR, + List.of(attribute1, attribute2, attribute3)); + insertFilter(filterId, identifierListFilter); + checkIdentifierListFilter(filterId, identifierListFilter); + + List values = Arrays.asList(filterId.toString(), filterId2.toString(), filterId3.toString()); + MultiValueMap params = new LinkedMultiValueMap<>(); + params.addAll("ids", values); + params.add("networkUuid", NETWORK_UUID.toString()); + params.add("variantId", VARIANT_ID_1); + } + + @Test + public void testGetIdentifiablesCount() throws Exception { + UUID filterId1 = UUID.randomUUID(); + UUID filterId2 = UUID.randomUUID(); + UUID filterId3 = UUID.randomUUID(); + + ArrayList rules = new ArrayList<>(); + EnumExpertRule country1Rule = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules.add(country1Rule); + EnumExpertRule country2Rule = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules.add(country2Rule); + NumberExpertRule voltageLevel1Rule1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(360., 400.))).build(); + rules.add(voltageLevel1Rule1); + NumberExpertRule voltageLevel2Rule1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(356.25, 393.7))).build(); + rules.add(voltageLevel2Rule1); + CombinatorExpertRule parentRule = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); + ExpertFilter expertFilter = new ExpertFilter(filterId1, new Date(), EquipmentType.LINE, parentRule); + + insertFilter(filterId1, expertFilter); + checkExpertFilter(filterId1, expertFilter); + + ArrayList rules2 = new ArrayList<>(); + EnumExpertRule country1Rule2 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules2.add(country1Rule2); + EnumExpertRule country2Rule2 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR"))).build(); + rules2.add(country2Rule2); + NumberExpertRule voltageLevel1Rule2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1).operator(OperatorType.BETWEEN) + .values(new TreeSet<>(Set.of(360., 400.))).build(); + rules2.add(voltageLevel1Rule2); + NumberExpertRule voltageLevel2Rule2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2).operator(OperatorType.BETWEEN) + .values(new TreeSet<>(Set.of(356.25, 393.7))).build(); + rules2.add(voltageLevel2Rule2); + CombinatorExpertRule parentRule2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); + ExpertFilter expertFilter2 = new ExpertFilter(filterId2, new Date(), EquipmentType.LINE, parentRule2); + + insertFilter(filterId2, expertFilter2); + checkExpertFilter(filterId2, expertFilter2); + + ArrayList rules3 = new ArrayList<>(); + EnumExpertRule country1Rule3 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR", "BE"))).build(); + rules3.add(country1Rule3); + EnumExpertRule country2Rule3 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR", "IT"))).build(); + rules3.add(country2Rule3); + NumberExpertRule voltageLevel1Rule3 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1).operator(OperatorType.BETWEEN) + .values(new TreeSet<>(Set.of(380., 420.))).build(); + rules3.add(voltageLevel1Rule3); + CombinatorExpertRule parentRule3 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules3).build(); + ExpertFilter expertFilter3 = new ExpertFilter(filterId3, new Date(), EquipmentType.HVDC_LINE, parentRule3); + + insertFilter(filterId3, expertFilter3); + checkExpertFilter(filterId3, expertFilter3); + + MultiValueMap params = new LinkedMultiValueMap<>(Map.of( + "networkUuid", List.of(NETWORK_UUID.toString()), + "variantId", List.of(VARIANT_ID_1), + "ids[g1]", List.of(filterId1.toString()), + "ids[g2]", List.of(filterId2.toString()), + "ids[g3]", List.of(filterId3.toString()), + "ids[g4]", List.of(UUID.randomUUID().toString()) + )); + Map identifiablesCount = objectMapper.readValue( + mvc.perform(get(URL_TEMPLATE + "/identifiables-count") + .params(params) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(), + new TypeReference<>() { + }); + + assertEquals(2, identifiablesCount.get("g1").longValue()); + assertEquals(2, identifiablesCount.get("g2").longValue()); + assertEquals(0, identifiablesCount.get("g3").longValue()); + assertEquals(0, identifiablesCount.get("g4").longValue()); + + assertEquals(4, identifiablesCount.size()); + } + private void checkFilterEquipments(List filterEquipments1, List filterEquipments2) { assertEquals(CollectionUtils.isEmpty(filterEquipments1), CollectionUtils.isEmpty(filterEquipments2)); assertEquals(filterEquipments1.size(), filterEquipments2.size()); @@ -1409,4 +1604,135 @@ public void testExpertFilterLoadLinkToOtherFilterWithIsPartOfOperator() throws E checkFilterEvaluating(expertFilter, expectedResultJson); } + @Test + public void testLineFiltersCrudInBatch() throws Exception { + UUID filterId1 = UUID.randomUUID(); + Date date = new Date(); + ArrayList rules = new ArrayList<>(); + EnumExpertRule country1Filter1 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(COUNTRIES1).build(); + rules.add(country1Filter1); + EnumExpertRule country2Filter1 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(COUNTRIES2).build(); + rules.add(country2Filter1); + NumberExpertRule nominalVoltage1Filter1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(5., 8.))).build(); + rules.add(nominalVoltage1Filter1); + NumberExpertRule nominalVoltage2Filter1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.EQUALS).value(6.).build(); + rules.add(nominalVoltage2Filter1); + + CombinatorExpertRule parentRule = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); + ExpertFilter expertFilter1 = new ExpertFilter(filterId1, date, EquipmentType.LINE, parentRule); + + UUID filterId2 = UUID.randomUUID(); + ArrayList rules2 = new ArrayList<>(); + EnumExpertRule country1Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(COUNTRIES1).build(); + rules2.add(country1Filter2); + EnumExpertRule country2Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(COUNTRIES2).build(); + rules2.add(country2Filter2); + NumberExpertRule nominalVoltage1Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(4., 9.))).build(); + rules2.add(nominalVoltage1Filter2); + NumberExpertRule nominalVoltage2Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.EQUALS).value(5.).build(); + rules2.add(nominalVoltage2Filter2); + + CombinatorExpertRule parentRule2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); + ExpertFilter expertFilter2 = new ExpertFilter(filterId2, date, EquipmentType.LINE, parentRule2); + + Map filtersToCreateMap = Map.of( + filterId1, expertFilter1, + filterId2, expertFilter2 + ); + + // --- insert in batch --- // + insertFilters(filtersToCreateMap); + + // check inserted filters + expertFilter1.setId(filterId1); + checkExpertFilter(filterId1, expertFilter1); + expertFilter2.setId(filterId2); + checkExpertFilter(filterId2, expertFilter2); + + // --- duplicate in batch --- // + Map sourceAndNewUuidMap = duplicateFilters(List.of(filterId1, filterId2)); + sourceAndNewUuidMap.forEach((sourceUuid, newUuid) -> filtersToCreateMap.get(sourceUuid).setId(newUuid)); + + // check each duplicated filter whether it is matched to the original + for (Map.Entry entry : sourceAndNewUuidMap.entrySet()) { + UUID sourceUuid = entry.getKey(); + UUID newUuid = entry.getValue(); + checkExpertFilter(newUuid, (ExpertFilter) filtersToCreateMap.get(sourceUuid)); + } + + // --- modify filters in batch --- // + ArrayList rules3 = new ArrayList<>(); + EnumExpertRule country1Filter3 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) + .values(COUNTRIES1).build(); + rules3.add(country1Filter3); + EnumExpertRule country2Filter3 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) + .values(COUNTRIES2).build(); + rules3.add(country2Filter3); + NumberExpertRule nominalVoltage1Filter3 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) + .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(3., 10.))).build(); + rules3.add(nominalVoltage1Filter3); + NumberExpertRule nominalVoltage2Filter3 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) + .operator(OperatorType.EQUALS).value(4.).build(); + rules3.add(nominalVoltage2Filter3); + CombinatorExpertRule parentRule3 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules3).build(); + ExpertFilter lineExpertFilter = new ExpertFilter(null, date, EquipmentType.LINE, parentRule3); + + ArrayList rules4 = new ArrayList<>(); + EnumExpertRule countryFilter4 = EnumExpertRule.builder().field(FieldType.COUNTRY).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR", "BE"))).build(); + rules4.add(countryFilter4); + NumberExpertRule nominalVoltageFilter4 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE) + .operator(OperatorType.EQUALS).value(50.).build(); + rules4.add(nominalVoltageFilter4); + CombinatorExpertRule parentRule4 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules4).build(); + ExpertFilter generatorExpertFilter = new ExpertFilter(null, date, EquipmentType.GENERATOR, parentRule4); + + Map filtersToUpdateMap = Map.of( + filterId1, lineExpertFilter, + filterId2, generatorExpertFilter + ); + updateFilters(filtersToUpdateMap); + + // check modified filters + lineExpertFilter.setId(filterId1); + checkExpertFilter(filterId1, lineExpertFilter); + generatorExpertFilter.setId(filterId2); + checkExpertFilter(filterId2, generatorExpertFilter); + + // --- modify filters in batch with a none existing id --- // + ArrayList rules5 = new ArrayList<>(); + EnumExpertRule countryFilter5 = EnumExpertRule.builder().field(FieldType.COUNTRY).operator(OperatorType.IN) + .values(new TreeSet<>(Set.of("FR", "BE"))).build(); + rules5.add(countryFilter5); + + NumberExpertRule nominalVoltageFilter5 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE) + .operator(OperatorType.EQUALS).value(60.).build(); + rules5.add(nominalVoltageFilter5); + CombinatorExpertRule parentRule5 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules5).build(); + ExpertFilter generatorExpertFilter2 = new ExpertFilter(null, new Date(), EquipmentType.GENERATOR, parentRule5); + + Map filtersToUpdateMap2 = Map.of( + UUID.randomUUID(), lineExpertFilter, + filterId2, generatorExpertFilter2 + ); + updateFiltersWithNoneExistingId(filtersToUpdateMap2); + // check modified filters => filter with filterId2 should not be changed + checkExpertFilter(filterId2, generatorExpertFilter); + + // --- delete filters in batch -- // + deleteFilters(Stream.concat(sourceAndNewUuidMap.keySet().stream(), sourceAndNewUuidMap.values().stream()).toList()); + + // check empty after delete all + List allFilters = getAllFilters(); + Assertions.assertThat(allFilters).isEmpty(); + } + } From 53d45a343e0219a728b7a57799196deb32acf25b Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 16:27:26 +0100 Subject: [PATCH 11/27] remove unused code --- .../server/FilterEntityControllerTest.java | 506 +----------------- 1 file changed, 6 insertions(+), 500 deletions(-) diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 4b94c06f..3a95ef8b 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -9,34 +9,25 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Option; import com.jayway.jsonpath.spi.json.JacksonJsonProvider; import com.jayway.jsonpath.spi.json.JsonProvider; import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; import com.jayway.jsonpath.spi.mapper.MappingProvider; -import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.test.*; import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import org.apache.commons.collections4.OrderedMap; -import org.apache.commons.collections4.map.LinkedMap; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.IFilterAttributes; -import org.gridsuite.filter.criteriafilter.DanglingLineFilter; import org.gridsuite.filter.criteriafilter.*; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.expertfilter.expertrule.*; -import org.gridsuite.filter.identifierlistfilter.FilterEquipments; -import org.gridsuite.filter.identifierlistfilter.IdentifiableAttributes; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.server.dto.FilterAttributes; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.server.utils.FieldsMatcher; import org.gridsuite.filter.server.utils.MatcherJson; import org.gridsuite.filter.server.utils.assertions.Assertions; import org.gridsuite.filter.utils.EquipmentType; @@ -49,20 +40,15 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.cloud.stream.binder.test.OutputDestination; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; -import org.springframework.messaging.Message; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -70,8 +56,6 @@ import java.util.stream.Stream; import static org.apache.commons.lang3.StringUtils.join; -import static org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy.WRONG_FILTER_TYPE; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.*; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -99,7 +83,6 @@ public class FilterEntityControllerTest { private Network network; private Network network2; private Network network6; - private ObjectWriter objectWriter; @Autowired private FilterService filterService; @@ -116,9 +99,6 @@ public class FilterEntityControllerTest { public static final SortedSet COUNTRIES1 = new TreeSet<>(Collections.singleton("France")); public static final SortedSet COUNTRIES2 = new TreeSet<>(Collections.singleton("Germany")); - public static final OrderedMap> FREE_PROPS = new LinkedMap<>( - Map.of("region", List.of("north", "south"))); - private static final UUID NETWORK_UUID = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); private static final UUID NETWORK_UUID_2 = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e5"); private static final UUID NETWORK_UUID_3 = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e6"); @@ -127,19 +107,16 @@ public class FilterEntityControllerTest { private static final UUID NETWORK_UUID_6 = UUID.fromString("11111111-7977-4592-2222-88027e4254e8"); private static final UUID NETWORK_NOT_FOUND_UUID = UUID.fromString("88888888-7977-3333-9999-88027e4254e7"); private static final String VARIANT_ID_1 = "variant_1"; - private static final String USER_ID_HEADER = "userId"; private String elementUpdateDestination = "element.update"; @Before public void setUp() { Configuration.defaultConfiguration(); - MockitoAnnotations.initMocks(this); - final ObjectMapper objectMapper = new ObjectMapper(); - objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); - objectMapper.enable(DeserializationFeature.USE_LONG_FOR_INTS); - objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); - objectMapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); + final ObjectMapper mapper = new ObjectMapper(); + mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS); + mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); + mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); network = EurostagTutorialExample1Factory.createWithMoreGenerators(new NetworkFactoryImpl()); network.getSubstation("P1").setProperty("region", "north"); @@ -172,8 +149,8 @@ public void setUp() { Configuration.setDefaults(new Configuration.Defaults() { - private final JsonProvider jsonProvider = new JacksonJsonProvider(objectMapper); - private final MappingProvider mappingProvider = new JacksonMappingProvider(objectMapper); + private final JsonProvider jsonProvider = new JacksonJsonProvider(mapper); + private final MappingProvider mappingProvider = new JacksonMappingProvider(mapper); @Override public JsonProvider jsonProvider() { @@ -479,41 +456,6 @@ public void testGetIdentifiablesCount() throws Exception { assertEquals(4, identifiablesCount.size()); } - private void checkFilterEquipments(List filterEquipments1, List filterEquipments2) { - assertEquals(CollectionUtils.isEmpty(filterEquipments1), CollectionUtils.isEmpty(filterEquipments2)); - assertEquals(filterEquipments1.size(), filterEquipments2.size()); - - filterEquipments1.sort(Comparator.comparing(filterEquipments -> filterEquipments.getFilterId().toString())); - filterEquipments2.sort(Comparator.comparing(filterEquipments -> filterEquipments.getFilterId().toString())); - - for (int index = 0; index < filterEquipments1.size(); index++) { - FilterEquipments filterEquipment1 = filterEquipments1.get(index); - FilterEquipments filterEquipment2 = filterEquipments2.get(index); - assertEquals(filterEquipment1.getFilterId(), filterEquipment2.getFilterId()); - assertEquals(CollectionUtils.isEmpty(filterEquipment1.getNotFoundEquipments()), CollectionUtils.isEmpty(filterEquipment2.getNotFoundEquipments())); - if (filterEquipment1.getNotFoundEquipments() != null) { - assertTrue(filterEquipment1.getNotFoundEquipments().containsAll(filterEquipment2.getNotFoundEquipments())); - } - checkIdentifiableAttributes(new ArrayList<>(filterEquipment1.getIdentifiableAttributes()), new ArrayList<>(filterEquipment2.getIdentifiableAttributes())); - } - } - - private void checkIdentifiableAttributes(List identifiableAttributes1, List identifiableAttributes2) { - assertEquals(CollectionUtils.isEmpty(identifiableAttributes1), CollectionUtils.isEmpty(identifiableAttributes2)); - assertEquals(identifiableAttributes1.size(), identifiableAttributes2.size()); - - identifiableAttributes1.sort(Comparator.comparing(IdentifiableAttributes::getId)); - identifiableAttributes2.sort(Comparator.comparing(IdentifiableAttributes::getId)); - - for (int index = 0; index < identifiableAttributes1.size(); index++) { - IdentifiableAttributes identifiableAttribute1 = identifiableAttributes1.get(index); - IdentifiableAttributes identifiableAttribute2 = identifiableAttributes2.get(index); - assertEquals(identifiableAttribute1.getId(), identifiableAttribute2.getId()); - assertEquals(identifiableAttribute1.getType(), identifiableAttribute2.getType()); - assertEquals(identifiableAttribute1.getDistributionKey(), identifiableAttribute2.getDistributionKey()); - } - } - private void checkIdentifierListFilterExportAndMetadata(UUID filterId, String expectedJson, EquipmentType equipmentType) throws Exception { mvc.perform(get(URL_TEMPLATE + "/" + filterId + "/export").param("networkUuid", NETWORK_UUID.toString()) .contentType(APPLICATION_JSON)) @@ -583,13 +525,6 @@ private List insertFilters(Map filtersToCr return objectMapper.readValue(response, new TypeReference<>() { }); } - private UUID duplicateFilter(UUID filterId) throws Exception { - String response = mvc.perform(post(URL_TEMPLATE).param("duplicateFrom", filterId.toString())) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(); - return objectMapper.readValue(response, UUID.class); - } - private Map duplicateFilters(List sourceFilterUuids) throws Exception { String response = mvc.perform(post(URL_TEMPLATE + "/duplicate/batch") .content(objectMapper.writeValueAsString(sourceFilterUuids)) @@ -598,15 +533,6 @@ private Map duplicateFilters(List sourceFilterUuids) throws Ex return objectMapper.readValue(response, new TypeReference<>() { }); } - private void updateFilter(UUID filterId, AbstractFilter filter, String userId) throws Exception { - mvc.perform(put(URL_TEMPLATE + "/" + filterId) - .content(objectMapper.writeValueAsString(filter)) - .contentType(APPLICATION_JSON) - .header(USER_ID_HEADER, userId)) - .andExpect(status().isOk()); - checkElementUpdatedMessageSent(filterId, userId); - } - private List updateFilters(Map filtersToUpdateMap) throws Exception { String response = mvc.perform(put(URL_TEMPLATE + "/batch") .content(objectMapper.writeValueAsString(filtersToUpdateMap)) @@ -640,404 +566,6 @@ private List getAllFilters() throws Exception { return objectMapper.readValue(response, new TypeReference<>() { }); } - private void modifyFormFilter(UUID filterId, AbstractFilter newFilter, String userId) throws Exception { - mvc.perform(put(URL_TEMPLATE + "/" + filterId) - .content(objectMapper.writeValueAsString(newFilter)) - .contentType(APPLICATION_JSON) - .header(USER_ID_HEADER, userId)) - .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); - - checkElementUpdatedMessageSent(filterId, userId); - - String modifiedFilterAsString = mvc.perform(get(URL_TEMPLATE + "/" + filterId)).andReturn().getResponse().getContentAsString(); - CriteriaFilter modifiedFilter = objectMapper.readValue(modifiedFilterAsString, CriteriaFilter.class); - checkFormFilter(filterId, modifiedFilter); - - mvc.perform(get(URL_TEMPLATE)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(); - MvcResult mockResponse = mvc.perform(get(URL_TEMPLATE + "/" + filterId)).andExpect(status().isOk()).andReturn(); - modifiedFilter = objectMapper.readValue(mockResponse.getResponse().getContentAsString(), CriteriaFilter.class); - checkFormFilter(filterId, modifiedFilter); - } - - private void insertInjectionFilter(EquipmentType equipmentType, UUID id, String equipmentID, String equipmentName, - String substationName, Set countries, - RangeType rangeType, Double value1, Double value2, EnergySource energySource, - UUID networkUuid, String variantId, String expectedJsonExport) throws Exception { - NumericalFilter numericalFilter = rangeType != null ? new NumericalFilter(rangeType, value1, value2) : null; - AbstractInjectionFilter abstractInjectionFilter; - Date modificationDate = new Date(); - SortedSet sortedCountries = AbstractFilterRepositoryProxy.setToSorterSet(countries); - // compensators are on powsybl networks without substation, so filtering on substation free props would prevent match. - OrderedMap> workAroundProps = - Set.of(EquipmentType.SHUNT_COMPENSATOR, EquipmentType.STATIC_VAR_COMPENSATOR).contains(equipmentType) ? null : FREE_PROPS; - InjectionFilterAttributes injectionFilterAttributes = new InjectionFilterAttributes(equipmentID, equipmentName, substationName, - sortedCountries, workAroundProps, workAroundProps, numericalFilter); - switch (equipmentType) { - case BATTERY: - abstractInjectionFilter = new BatteryFilter(injectionFilterAttributes); - break; - case BUSBAR_SECTION: - abstractInjectionFilter = new BusBarSectionFilter(injectionFilterAttributes); - break; - case DANGLING_LINE: - abstractInjectionFilter = new DanglingLineFilter(injectionFilterAttributes); - break; - case GENERATOR: - abstractInjectionFilter = new GeneratorFilter(injectionFilterAttributes.getEquipmentID(), - injectionFilterAttributes.getEquipmentName(), - injectionFilterAttributes.getSubstationName(), - injectionFilterAttributes.getCountries(), - injectionFilterAttributes.getSubstationFreeProperties(), - injectionFilterAttributes.getFreeProperties(), - injectionFilterAttributes.getNominalVoltage(), - energySource); - break; - case LCC_CONVERTER_STATION: - abstractInjectionFilter = new LccConverterStationFilter(injectionFilterAttributes); - break; - case LOAD: - abstractInjectionFilter = new LoadFilter(injectionFilterAttributes); - break; - case SHUNT_COMPENSATOR: - abstractInjectionFilter = new ShuntCompensatorFilter(injectionFilterAttributes); - break; - case STATIC_VAR_COMPENSATOR: - abstractInjectionFilter = new StaticVarCompensatorFilter(injectionFilterAttributes); - break; - case VSC_CONVERTER_STATION: - abstractInjectionFilter = new VscConverterStationFilter(injectionFilterAttributes); - break; - default: - throw new PowsyblException("Equipment type not allowed"); - } - CriteriaFilter injectionFilter = new CriteriaFilter( - id, - modificationDate, - abstractInjectionFilter - ); - - insertFilter(id, injectionFilter); - AbstractInjectionFilter injectionEquipment = (AbstractInjectionFilter) injectionFilter.getEquipmentFilterForm(); - injectionEquipment.setCountries(AbstractFilterRepositoryProxy.setToSorterSet(countries)); - injectionEquipment.setSubstationFreeProperties(workAroundProps); - injectionEquipment.setFreeProperties(workAroundProps); - checkFormFilter(id, injectionFilter); - - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(1, filterAttributes.size()); - assertEquals(id, filterAttributes.get(0).getId()); - assertEquals(FilterType.CRITERIA, filterAttributes.get(0).getType()); - assertEquals(equipmentType, filterAttributes.get(0).getEquipmentType()); - - MockHttpServletRequestBuilder requestBuilder = get(URL_TEMPLATE + "/" + id + "/export") - .param("networkUuid", networkUuid.toString()); - if (variantId != null) { - requestBuilder.param("variantId", variantId); - } - - mvc.perform(requestBuilder.contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json(expectedJsonExport)); - - deleteFilter(id); - } - - private void insertTransformerFilter(EquipmentType equipmentType, UUID id, String equipmentID, String equipmentName, - String substationName, Set countries, - List rangeTypes, List values1, List values2, Map> substationProperties, - UUID networkUuid, String variantId, String expectedJsonExport) throws Exception { - NumericalFilter numericalFilter1 = new NumericalFilter(rangeTypes.get(0), values1.get(0), values2.get(0)); - NumericalFilter numericalFilter2 = new NumericalFilter(rangeTypes.get(1), values1.get(1), values2.get(1)); - AbstractEquipmentFilterForm equipmentFilterForm; - if (equipmentType == EquipmentType.TWO_WINDINGS_TRANSFORMER) { - equipmentFilterForm = TwoWindingsTransformerFilter.builder().equipmentID(equipmentID).equipmentName(equipmentName).substationName(substationName) - .countries(AbstractFilterRepositoryProxy.setToSorterSet(countries)) - .substationFreeProperties(substationProperties) - .nominalVoltage1(numericalFilter1) - .nominalVoltage2(numericalFilter2) - .build(); - } else if (equipmentType == EquipmentType.THREE_WINDINGS_TRANSFORMER) { - NumericalFilter numericalFilter3 = new NumericalFilter(rangeTypes.get(2), values1.get(2), values2.get(2)); - equipmentFilterForm = ThreeWindingsTransformerFilter.builder().equipmentID(equipmentID).equipmentName(equipmentName).substationName(substationName) - .countries(AbstractFilterRepositoryProxy.setToSorterSet(countries)) - .nominalVoltage1(numericalFilter1) - .nominalVoltage2(numericalFilter2) - .nominalVoltage3(numericalFilter3) - .build(); - } else { - throw new PowsyblException(WRONG_FILTER_TYPE); - } - Date modificationDate = new Date(); - - CriteriaFilter transformerFilter = new CriteriaFilter( - id, - - modificationDate, - equipmentFilterForm - ); - - insertFilter(id, transformerFilter); - checkFormFilter(id, transformerFilter); - - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(1, filterAttributes.size()); - assertEquals(id, filterAttributes.get(0).getId()); - assertEquals(FilterType.CRITERIA, filterAttributes.get(0).getType()); - assertEquals(equipmentType, filterAttributes.get(0).getEquipmentType()); - - MockHttpServletRequestBuilder requestBuilder = get(URL_TEMPLATE + "/" + id + "/export") - .param("networkUuid", networkUuid.toString()); - if (variantId != null) { - requestBuilder.param("variantId", variantId); - } - - mvc.perform(requestBuilder.contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json(expectedJsonExport)); - - deleteFilter(id); - } - - private void insertHvdcLineFilter(UUID id, String equipmentID, String equipmentName, - String substationName1, String substationName2, SortedSet countries1, - SortedSet countries2, RangeType rangeType, Double value1, Double value2, - UUID networkUuid, String variantId, String expectedJsonExport) throws Exception { - Date modificationDate = new Date(); - CriteriaFilter hvdcLineFilter = new CriteriaFilter( - id, - modificationDate, - HvdcLineFilter.builder().equipmentID(equipmentID).equipmentName(equipmentName) - .substationName1(substationName1).substationName2(substationName2) - .countries1(countries1).countries2(countries2) - .freeProperties2(Map.of("region", List.of("north"))) - .nominalVoltage(new NumericalFilter(rangeType, value1, value2)) - .build() - ); - - insertFilter(id, hvdcLineFilter); - checkFormFilter(id, hvdcLineFilter); - - String filtersAsString = mvc.perform(get(URL_TEMPLATE)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(); - - List filterAttributes = objectMapper.readValue(filtersAsString, - new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - matchFilterInfos(filterAttributes.get(0), id, FilterType.CRITERIA, EquipmentType.HVDC_LINE, modificationDate); - - filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(1, filterAttributes.size()); - matchFilterInfos(filterAttributes.get(0), id, FilterType.CRITERIA, EquipmentType.HVDC_LINE, modificationDate); - - MockHttpServletRequestBuilder requestBuilder = get(URL_TEMPLATE + "/" + id + "/export") - .param("networkUuid", networkUuid.toString()); - if (variantId != null) { - requestBuilder.param("variantId", variantId); - } - - mvc.perform(requestBuilder.contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json(expectedJsonExport)); - - deleteFilter(id); - - filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(0, filterAttributes.size()); - } - - private CriteriaFilter insertLineFilter(UUID id, String equipmentID, String equipmentName, - String substationName, Set countries1, Set countries2, - List rangeTypes, List values1, List values2, - UUID networkUuid, String variantId, String expectedJsonExport, boolean delete) throws Exception { - NumericalFilter numericalFilter1 = null; - if (rangeTypes.size() >= 1) { - numericalFilter1 = new NumericalFilter(rangeTypes.get(0), values1.get(0), values2.get(0)); - } - NumericalFilter numericalFilter2 = null; - if (rangeTypes.size() == 2) { - numericalFilter2 = new NumericalFilter(rangeTypes.get(1), values1.get(1), values2.get(1)); - } - AbstractEquipmentFilterForm equipmentFilterForm = LineFilter.builder().equipmentID(equipmentID).equipmentName(equipmentName) - .substationName1(substationName) - .countries1(AbstractFilterRepositoryProxy.setToSorterSet(countries1)) - .countries2(AbstractFilterRepositoryProxy.setToSorterSet(countries2)) - .nominalVoltage1(numericalFilter1) - .nominalVoltage2(numericalFilter2) - .build(); - Date modificationDate = new Date(); - CriteriaFilter filter = new CriteriaFilter( - id, - - modificationDate, - equipmentFilterForm - ); - insertFilter(id, filter); - checkFormFilter(id, filter); - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(1, filterAttributes.size()); - assertEquals(id, filterAttributes.get(0).getId()); - assertEquals(FilterType.CRITERIA, filterAttributes.get(0).getType()); - assertEquals(EquipmentType.LINE, filterAttributes.get(0).getEquipmentType()); - - MockHttpServletRequestBuilder requestBuilder = get(URL_TEMPLATE + "/" + id + "/export") - .param("networkUuid", networkUuid.toString()); - if (variantId != null) { - requestBuilder.param("variantId", variantId); - } - - mvc.perform(requestBuilder.contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json(expectedJsonExport)); - if (delete) { - deleteFilter(id); - } - return filter; - } - - private void insertVoltageLevelFilter(UUID id, String equipmentID, String equipmentName, Set countries, - RangeType rangeType, Double value1, Double value2, - UUID networkUuid, String variantId, String expectedJsonExport) throws Exception { - NumericalFilter numericalFilter = rangeType != null ? new NumericalFilter(rangeType, value1, value2) : null; - SortedSet sortedCountries = AbstractFilterRepositoryProxy.setToSorterSet(countries); - VoltageLevelFilter voltageLevelFilter = VoltageLevelFilter.builder() - .equipmentID(equipmentID) - .equipmentName(equipmentName) - .countries(sortedCountries) - .nominalVoltage(numericalFilter) - .build(); - Date modificationDate = new Date(); - - CriteriaFilter filter = new CriteriaFilter( - id, - - modificationDate, - voltageLevelFilter - ); - - insertFilter(id, filter); - checkFormFilter(id, filter); - - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(1, filterAttributes.size()); - assertEquals(id, filterAttributes.get(0).getId()); - assertEquals(FilterType.CRITERIA, filterAttributes.get(0).getType()); - - MockHttpServletRequestBuilder requestBuilder = get(URL_TEMPLATE + "/" + id + "/export") - .param("networkUuid", networkUuid.toString()); - if (variantId != null) { - requestBuilder.param("variantId", variantId); - } - - mvc.perform(requestBuilder.contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json(expectedJsonExport)); - - deleteFilter(id); - } - - private void insertSubstationFilter(UUID id, String equipmentID, String equipmentName, Set countries, - UUID networkUuid, String variantId, String expectedJsonExport) throws Exception { - SortedSet sortedCountries = AbstractFilterRepositoryProxy.setToSorterSet(countries); - SubstationFilter substationFilter = SubstationFilter.builder() - .equipmentID(equipmentID) - .equipmentName(equipmentName) - .countries(sortedCountries) - .build(); - Date modificationDate = new Date(); - - CriteriaFilter filter = new CriteriaFilter( - id, - - modificationDate, - substationFilter - ); - - insertFilter(id, filter); - checkFormFilter(id, filter); - - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", id.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - assertEquals(1, filterAttributes.size()); - assertEquals(id, filterAttributes.get(0).getId()); - assertEquals(FilterType.CRITERIA, filterAttributes.get(0).getType()); - - MockHttpServletRequestBuilder requestBuilder = get(URL_TEMPLATE + "/" + id + "/export") - .param("networkUuid", networkUuid.toString()); - if (variantId != null) { - requestBuilder.param("variantId", variantId); - } - - mvc.perform(requestBuilder.contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json(expectedJsonExport)); - - deleteFilter(id); - } - - private void checkFormFilter(UUID filterId, CriteriaFilter criteriaFilter) throws Exception { - String foundFilterAsString = mvc.perform(get(URL_TEMPLATE + "/" + filterId)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); - CriteriaFilter foundFilter = objectMapper.readValue(foundFilterAsString, CriteriaFilter.class); - matchFormFilterInfos(foundFilter, criteriaFilter); - } - private void checkIdentifierListFilter(UUID filterId, IdentifierListFilter identifierListFilter) throws Exception { String foundFilterAsString = mvc.perform(get(URL_TEMPLATE + "/" + filterId)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); IdentifierListFilter foundFilter = objectMapper.readValue(foundFilterAsString, IdentifierListFilter.class); @@ -1057,22 +585,6 @@ private void matchFilterInfos(IFilterAttributes filter1, IFilterAttributes filte assertEquals(filter1.getEquipmentType(), filter2.getEquipmentType()); } - private void matchFilterInfos(IFilterAttributes filterAttribute, UUID id, FilterType type, EquipmentType equipmentType, Date modificationDate) { - assertEquals(filterAttribute.getId(), id); - assertEquals(filterAttribute.getType(), type); - assertTrue((modificationDate.getTime() - filterAttribute.getModificationDate().getTime()) < 2000); - assertEquals(filterAttribute.getEquipmentType(), equipmentType); - } - - private void matchFormFilterInfos(CriteriaFilter criteriaFilter1, CriteriaFilter criteriaFilter2) { - matchFilterInfos(criteriaFilter1, criteriaFilter2); - matchEquipmentFormFilter(criteriaFilter1.getEquipmentFilterForm(), criteriaFilter2.getEquipmentFilterForm()); - } - - private void matchEquipmentFormFilter(AbstractEquipmentFilterForm equipmentFilterForm1, AbstractEquipmentFilterForm equipmentFilterForm2) { - assertThat(equipmentFilterForm1, new FieldsMatcher<>(equipmentFilterForm2)); - } - private void matchIdentifierListFilterInfos(IdentifierListFilter identifierListFilter1, IdentifierListFilter identifierListFilter2) { matchFilterInfos(identifierListFilter1, identifierListFilter2); assertTrue(new MatcherJson<>(objectMapper, identifierListFilter2.getFilterEquipmentsAttributes()).matchesSafely(identifierListFilter1.getFilterEquipmentsAttributes())); @@ -1083,12 +595,6 @@ private void matchExpertFilterInfos(ExpertFilter expertFilter1, ExpertFilter exp Assertions.assertThat(expertFilter1).recursivelyEquals(expertFilter2, "topologyKind" /* not persisted field */); } - private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { - Message message = output.receive(TIMEOUT, elementUpdateDestination); - assertEquals(elementUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); - assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); - } - @Test public void testExpertFilterGenerator() throws Exception { UUID filterId = UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"); From 926e7bdb6943adf7476a689dcdfcc9f359a0867f Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Mon, 2 Dec 2024 16:34:37 +0100 Subject: [PATCH 12/27] for coverage Signed-off-by: Etienne Homer --- src/main/java/org/gridsuite/filter/server/FilterController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index c6ef88e5..d135e32e 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -172,6 +172,7 @@ public ResponseEntity> exportFilter(@PathVariable(" public ResponseEntity> getIdentifiablesCountByGroup(@RequestParam(value = "networkUuid") UUID networkUuid, @RequestParam(value = "variantId", required = false) String variantId, IdsByGroup idsByGroup) { + Logger.getLogger("export").info(() -> "test"); return ResponseEntity.ok() .contentType(MediaType.APPLICATION_JSON) .body(service.getIdentifiablesCountByGroup(idsByGroup, networkUuid, variantId)); From 2a4d7c0d1355edcde8f0e9c1977b8fefb67df47b Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Mon, 2 Dec 2024 16:49:19 +0100 Subject: [PATCH 13/27] Clean Signed-off-by: Etienne Homer --- src/main/java/org/gridsuite/filter/server/FilterController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index d135e32e..c6ef88e5 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -172,7 +172,6 @@ public ResponseEntity> exportFilter(@PathVariable(" public ResponseEntity> getIdentifiablesCountByGroup(@RequestParam(value = "networkUuid") UUID networkUuid, @RequestParam(value = "variantId", required = false) String variantId, IdsByGroup idsByGroup) { - Logger.getLogger("export").info(() -> "test"); return ResponseEntity.ok() .contentType(MediaType.APPLICATION_JSON) .body(service.getIdentifiablesCountByGroup(idsByGroup, networkUuid, variantId)); From 4d0a2ce853e1138df9e704b2ae500bbb62f2afd8 Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 17:03:31 +0100 Subject: [PATCH 14/27] delete code of criteria filters --- .../BatteryFilterRepository.java | 19 ---- .../BusBarSectionFilterRepository.java | 19 ---- .../DanglingLineFilterRepository.java | 19 ---- .../GeneratorFilterRepository.java | 19 ---- .../HvdcLineFilterRepository.java | 19 ---- .../LccConverterStationFilterRepository.java | 19 ---- .../criteriafilter/LineFilterRepository.java | 19 ---- .../criteriafilter/LoadFilterRepository.java | 19 ---- .../ShuntCompensatorFilterRepository.java | 19 ---- .../StaticVarCompensatorFilterRepository.java | 19 ---- .../SubstationFilterRepository.java | 19 ---- ...eeWindingsTransformerFilterRepository.java | 19 ---- ...woWindingsTransformerFilterRepository.java | 19 ---- .../VoltageLevelFilterRepository.java | 19 ---- .../VscConverterStationFilterRepository.java | 19 ---- .../BatteryFilterRepositoryProxy.java | 64 -------------- .../BusBarSectionFilterRepositoryProxy.java | 64 -------------- .../DanglingLineFilterRepositoryProxy.java | 64 -------------- .../GeneratorFilterRepositoryProxy.java | 75 ---------------- .../HvdcLineFilterRepositoryProxy.java | 84 ------------------ ...ConverterStationFilterRepositoryProxy.java | 64 -------------- .../LineFilterRepositoryProxy.java | 88 ------------------- .../LoadFilterRepositoryProxy.java | 64 -------------- ...ShuntCompensatorFilterRepositoryProxy.java | 64 -------------- ...icVarCompensatorFilterRepositoryProxy.java | 64 -------------- .../SubstationFilterRepositoryProxy.java | 74 ---------------- ...dingsTransformerFilterRepositoryProxy.java | 81 ----------------- ...dingsTransformerFilterRepositoryProxy.java | 81 ----------------- .../VoltageLevelFilterRepositoryProxy.java | 78 ---------------- ...ConverterStationFilterRepositoryProxy.java | 64 -------------- .../filter/server/FilterRepositoryTest.java | 66 -------------- 31 files changed, 1424 deletions(-) delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BatteryFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BusBarSectionFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/DanglingLineFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/GeneratorFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/HvdcLineFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LccConverterStationFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LineFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LoadFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ShuntCompensatorFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/StaticVarCompensatorFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/SubstationFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ThreeWindingsTransformerFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/TwoWindingsTransformerFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VoltageLevelFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VscConverterStationFilterRepository.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BatteryFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BusBarSectionFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/DanglingLineFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/GeneratorFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/HvdcLineFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LccConverterStationFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LineFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LoadFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ShuntCompensatorFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/StaticVarCompensatorFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/SubstationFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ThreeWindingsTransformerFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/TwoWindingsTransformerFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VoltageLevelFilterRepositoryProxy.java delete mode 100644 src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VscConverterStationFilterRepositoryProxy.java diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BatteryFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BatteryFilterRepository.java deleted file mode 100644 index 5b7fbd74..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BatteryFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.BatteryFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface BatteryFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BusBarSectionFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BusBarSectionFilterRepository.java deleted file mode 100644 index 934c50d4..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/BusBarSectionFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.BusBarSectionFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface BusBarSectionFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/DanglingLineFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/DanglingLineFilterRepository.java deleted file mode 100644 index f029fb6d..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/DanglingLineFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.DanglingLineFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface DanglingLineFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/GeneratorFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/GeneratorFilterRepository.java deleted file mode 100644 index 7c287071..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/GeneratorFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.GeneratorFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface GeneratorFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/HvdcLineFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/HvdcLineFilterRepository.java deleted file mode 100644 index 9bd0d95a..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/HvdcLineFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.HvdcLineFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface HvdcLineFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LccConverterStationFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LccConverterStationFilterRepository.java deleted file mode 100644 index bc4157f4..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LccConverterStationFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.LccConverterStationFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface LccConverterStationFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LineFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LineFilterRepository.java deleted file mode 100644 index a165d68b..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LineFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.LineFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Jacques Borsenberger - */ -@Repository -public interface LineFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LoadFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LoadFilterRepository.java deleted file mode 100644 index d60e67dc..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/LoadFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.LoadFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface LoadFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ShuntCompensatorFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ShuntCompensatorFilterRepository.java deleted file mode 100644 index d97bfa1d..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ShuntCompensatorFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.ShuntCompensatorFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface ShuntCompensatorFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/StaticVarCompensatorFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/StaticVarCompensatorFilterRepository.java deleted file mode 100644 index 1b4e46ba..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/StaticVarCompensatorFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.StaticVarCompensatorFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface StaticVarCompensatorFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/SubstationFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/SubstationFilterRepository.java deleted file mode 100644 index 7dde7ca4..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/SubstationFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2022, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.SubstationFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface SubstationFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ThreeWindingsTransformerFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ThreeWindingsTransformerFilterRepository.java deleted file mode 100644 index b9a7eb11..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/ThreeWindingsTransformerFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.ThreeWindingsTransformerFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface ThreeWindingsTransformerFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/TwoWindingsTransformerFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/TwoWindingsTransformerFilterRepository.java deleted file mode 100644 index 649c44f1..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/TwoWindingsTransformerFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.TwoWindingsTransformerFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface TwoWindingsTransformerFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VoltageLevelFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VoltageLevelFilterRepository.java deleted file mode 100644 index 8bbbdfc2..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VoltageLevelFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2022, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.VoltageLevelFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface VoltageLevelFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VscConverterStationFilterRepository.java b/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VscConverterStationFilterRepository.java deleted file mode 100644 index ba2632f4..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/criteriafilter/VscConverterStationFilterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, 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.repositories.criteriafilter; - -import org.gridsuite.filter.server.entities.criteriafilter.VscConverterStationFilterEntity; -import org.gridsuite.filter.server.repositories.FilterRepository; -import org.springframework.stereotype.Repository; - -/** - * @author Franck Lecuyer - */ -@Repository -public interface VscConverterStationFilterRepository extends FilterRepository { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BatteryFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BatteryFilterRepositoryProxy.java deleted file mode 100644 index 49382746..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BatteryFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.BatteryFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.BatteryFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.BatteryFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class BatteryFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final BatteryFilterRepository batteryFilterRepository; - - public BatteryFilterRepositoryProxy(BatteryFilterRepository batteryFilterRepository) { - this.batteryFilterRepository = batteryFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.BATTERY; - } - - @Override - public BatteryFilterRepository getRepository() { - return batteryFilterRepository; - } - - @Override - public AbstractFilter toDto(BatteryFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new BatteryFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public BatteryFilterEntity fromDto(AbstractFilter dto) { - var batteryFilterEntityBuilder = BatteryFilterEntity.builder(); - buildInjectionFilter(batteryFilterEntityBuilder, toFormFilter(dto, BatteryFilter.class)); - return batteryFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BusBarSectionFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BusBarSectionFilterRepositoryProxy.java deleted file mode 100644 index ed9865bf..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/BusBarSectionFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.BusBarSectionFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.BusBarSectionFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.BusBarSectionFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class BusBarSectionFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final BusBarSectionFilterRepository busBarSectionFilterRepository; - - public BusBarSectionFilterRepositoryProxy(BusBarSectionFilterRepository busBarSectionFilterRepository) { - this.busBarSectionFilterRepository = busBarSectionFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.BUSBAR_SECTION; - } - - @Override - public BusBarSectionFilterRepository getRepository() { - return busBarSectionFilterRepository; - } - - @Override - public AbstractFilter toDto(BusBarSectionFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new BusBarSectionFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public BusBarSectionFilterEntity fromDto(AbstractFilter dto) { - var busBarSectionFilterEntityBuilder = BusBarSectionFilterEntity.builder(); - buildInjectionFilter(busBarSectionFilterEntityBuilder, toFormFilter(dto, BusBarSectionFilter.class)); - return busBarSectionFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/DanglingLineFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/DanglingLineFilterRepositoryProxy.java deleted file mode 100644 index 5bcda820..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/DanglingLineFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.DanglingLineFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.DanglingLineFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.DanglingLineFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class DanglingLineFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final DanglingLineFilterRepository danglingLineFilterRepository; - - public DanglingLineFilterRepositoryProxy(DanglingLineFilterRepository danglingLineFilterRepository) { - this.danglingLineFilterRepository = danglingLineFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.DANGLING_LINE; - } - - @Override - public DanglingLineFilterRepository getRepository() { - return danglingLineFilterRepository; - } - - @Override - public AbstractFilter toDto(DanglingLineFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new DanglingLineFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public DanglingLineFilterEntity fromDto(AbstractFilter dto) { - var danglingLineFilterEntityBuilder = DanglingLineFilterEntity.builder(); - buildInjectionFilter(danglingLineFilterEntityBuilder, toFormFilter(dto, DanglingLineFilter.class)); - return danglingLineFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/GeneratorFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/GeneratorFilterRepositoryProxy.java deleted file mode 100644 index 46aad348..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/GeneratorFilterRepositoryProxy.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.GeneratorFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.GeneratorFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.GeneratorFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class GeneratorFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final GeneratorFilterRepository generatorFilterRepository; - - public GeneratorFilterRepositoryProxy(GeneratorFilterRepository generatorFilterRepository) { - this.generatorFilterRepository = generatorFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.GENERATOR; - } - - @Override - public GeneratorFilterRepository getRepository() { - return generatorFilterRepository; - } - - @Override - public AbstractFilter toDto(GeneratorFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - GeneratorFilterEntity generatorFilterEntity = (GeneratorFilterEntity) entity; - return new GeneratorFilter(generatorFilterEntity.getEquipmentId(), - generatorFilterEntity.getEquipmentName(), - generatorFilterEntity.getSubstationName(), - AbstractFilterRepositoryProxy.setToSorterSet(generatorFilterEntity.getCountries()), - AbstractFilterRepositoryProxy.convert(generatorFilterEntity.getSubstationFreeProperties()), - AbstractFilterRepositoryProxy.convert(generatorFilterEntity.getFreeProperties()), - AbstractFilterRepositoryProxy.convert(generatorFilterEntity.getNominalVoltage()), - generatorFilterEntity.getEnergySource()); - } - - @Override - public GeneratorFilterEntity fromDto(AbstractFilter dto) { - var generatorFilterEntityBuilder = GeneratorFilterEntity.builder(); - CriteriaFilter criteriaFilter = toFormFilter(dto, GeneratorFilter.class); - buildInjectionFilter(generatorFilterEntityBuilder, criteriaFilter); - GeneratorFilter generatorFilter = (GeneratorFilter) criteriaFilter.getEquipmentFilterForm(); - generatorFilterEntityBuilder.energySource(generatorFilter.getEnergySource()); - return generatorFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/HvdcLineFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/HvdcLineFilterRepositoryProxy.java deleted file mode 100644 index 2f38a885..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/HvdcLineFilterRepositoryProxy.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.HvdcLineFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.HvdcLineFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.HvdcLineFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class HvdcLineFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final HvdcLineFilterRepository hvdcLineFilterRepository; - - public HvdcLineFilterRepositoryProxy(HvdcLineFilterRepository hvdcLineFilterRepository) { - this.hvdcLineFilterRepository = hvdcLineFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.HVDC_LINE; - } - - @Override - public HvdcLineFilterRepository getRepository() { - return hvdcLineFilterRepository; - } - - @Override - public AbstractFilter toDto(HvdcLineFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - HvdcLineFilterEntity hvdcLineFilterEntity = (HvdcLineFilterEntity) entity; - return HvdcLineFilter.builder() - .equipmentID(hvdcLineFilterEntity.getEquipmentId()) - .equipmentName(hvdcLineFilterEntity.getEquipmentName()) - .substationName1(hvdcLineFilterEntity.getSubstationName1()) - .substationName2(hvdcLineFilterEntity.getSubstationName2()) - .countries1(setToSorterSet(hvdcLineFilterEntity.getCountries1())) - .countries2(setToSorterSet(hvdcLineFilterEntity.getCountries2())) - .nominalVoltage(convert(hvdcLineFilterEntity.getNominalVoltage())) - .freeProperties1(convert(hvdcLineFilterEntity.getSubstationFreeProperties1())) - .freeProperties2(convert(hvdcLineFilterEntity.getSubstationFreeProperties2())) - .build(); - } - - @Override - public HvdcLineFilterEntity fromDto(AbstractFilter dto) { - CriteriaFilter criteriaFilter = toFormFilter(dto, HvdcLineFilter.class); - HvdcLineFilter hvdcLineFilter = (HvdcLineFilter) criteriaFilter.getEquipmentFilterForm(); - var hvdcLineFilterEntityBuilder = HvdcLineFilterEntity.builder() - .countries1(hvdcLineFilter.getCountries1()) - .countries2(hvdcLineFilter.getCountries2()) - .nominalVoltage(convert(hvdcLineFilter.getNominalVoltage())) - .substationName1(hvdcLineFilter.getSubstationName1()) - .substationName2(hvdcLineFilter.getSubstationName2()) - .substationFreeProperties1(convert(hvdcLineFilter.getFreeProperties1())) - .substationFreeProperties2(convert(hvdcLineFilter.getFreeProperties2())); - buildGenericFilter(hvdcLineFilterEntityBuilder, criteriaFilter); - return hvdcLineFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LccConverterStationFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LccConverterStationFilterRepositoryProxy.java deleted file mode 100644 index 328edc21..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LccConverterStationFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.LccConverterStationFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.LccConverterStationFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.LccConverterStationFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class LccConverterStationFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final LccConverterStationFilterRepository lccConverterStationFilterRepository; - - public LccConverterStationFilterRepositoryProxy(LccConverterStationFilterRepository lccConverterStationFilterRepository) { - this.lccConverterStationFilterRepository = lccConverterStationFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.LCC_CONVERTER_STATION; - } - - @Override - public LccConverterStationFilterRepository getRepository() { - return lccConverterStationFilterRepository; - } - - @Override - public AbstractFilter toDto(LccConverterStationFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new LccConverterStationFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public LccConverterStationFilterEntity fromDto(AbstractFilter dto) { - var lccConverterStationFilterEntityBuilder = LccConverterStationFilterEntity.builder(); - buildInjectionFilter(lccConverterStationFilterEntityBuilder, toFormFilter(dto, LccConverterStationFilter.class)); - return lccConverterStationFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LineFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LineFilterRepositoryProxy.java deleted file mode 100644 index f71068bd..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LineFilterRepositoryProxy.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.LineFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.LineFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.LineFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Jacques Borsenberger - */ - -public class LineFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final LineFilterRepository lineFilterRepository; - - public LineFilterRepositoryProxy(LineFilterRepository lineFilterRepository) { - this.lineFilterRepository = lineFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.LINE; - } - - @Override - public LineFilterRepository getRepository() { - return lineFilterRepository; - } - - @Override - public AbstractFilter toDto(LineFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - LineFilterEntity lineFilterEntity = (LineFilterEntity) entity; - return LineFilter.builder() - .equipmentID(lineFilterEntity.getEquipmentId()) - .equipmentName(lineFilterEntity.getEquipmentName()) - .substationName1(lineFilterEntity.getSubstationName1()) - .substationName2(lineFilterEntity.getSubstationName2()) - .countries1(setToSorterSet(lineFilterEntity.getCountries1())) - .countries2(setToSorterSet(lineFilterEntity.getCountries2())) - .nominalVoltage1(convert(lineFilterEntity.getNominalVoltage1())) - .nominalVoltage2(convert(lineFilterEntity.getNominalVoltage2())) - .freeProperties1(convert(lineFilterEntity.getSubstationFreeProperties1())) - .freeProperties2(convert(lineFilterEntity.getSubstationFreeProperties2())) - .freeProperties(convert(lineFilterEntity.getFreeProperties())) - .build(); - } - - @Override - public LineFilterEntity fromDto(AbstractFilter dto) { - CriteriaFilter criteriaFilter = toFormFilter(dto, LineFilter.class); - LineFilter lineFilter = (LineFilter) criteriaFilter.getEquipmentFilterForm(); - var lineFilterEntityBuilder = LineFilterEntity.builder() - .countries1(lineFilter.getCountries1()) - .countries2(lineFilter.getCountries2()) - .nominalVoltage1(convert(lineFilter.getNominalVoltage1())) - .nominalVoltage2(convert(lineFilter.getNominalVoltage2())) - .substationName1(lineFilter.getSubstationName1()) - .substationName2(lineFilter.getSubstationName2()) - .substationFreeProperties1(convert(lineFilter.getFreeProperties1())) - .substationFreeProperties2(convert(lineFilter.getFreeProperties2())) - .freeProperties(convert(lineFilter.getFreeProperties())); - buildGenericFilter(lineFilterEntityBuilder, criteriaFilter); - return lineFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LoadFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LoadFilterRepositoryProxy.java deleted file mode 100644 index 394374a5..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/LoadFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.LoadFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.LoadFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.LoadFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class LoadFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final LoadFilterRepository loadFilterRepository; - - public LoadFilterRepositoryProxy(LoadFilterRepository loadFilterRepository) { - this.loadFilterRepository = loadFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.LOAD; - } - - @Override - public LoadFilterRepository getRepository() { - return loadFilterRepository; - } - - @Override - public AbstractFilter toDto(LoadFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new LoadFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public LoadFilterEntity fromDto(AbstractFilter dto) { - var loadFilterEntityBuilder = LoadFilterEntity.builder(); - buildInjectionFilter(loadFilterEntityBuilder, toFormFilter(dto, LoadFilter.class)); - return loadFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ShuntCompensatorFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ShuntCompensatorFilterRepositoryProxy.java deleted file mode 100644 index e89149e4..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ShuntCompensatorFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.ShuntCompensatorFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.ShuntCompensatorFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.ShuntCompensatorFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class ShuntCompensatorFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final ShuntCompensatorFilterRepository shuntCompensatorFilterRepository; - - public ShuntCompensatorFilterRepositoryProxy(ShuntCompensatorFilterRepository shuntCompensatorFilterRepository) { - this.shuntCompensatorFilterRepository = shuntCompensatorFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.SHUNT_COMPENSATOR; - } - - @Override - public ShuntCompensatorFilterRepository getRepository() { - return shuntCompensatorFilterRepository; - } - - @Override - public AbstractFilter toDto(ShuntCompensatorFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new ShuntCompensatorFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public ShuntCompensatorFilterEntity fromDto(AbstractFilter dto) { - var shuntCompensatorFilterEntityBuilder = ShuntCompensatorFilterEntity.builder(); - buildInjectionFilter(shuntCompensatorFilterEntityBuilder, toFormFilter(dto, ShuntCompensatorFilter.class)); - return shuntCompensatorFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/StaticVarCompensatorFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/StaticVarCompensatorFilterRepositoryProxy.java deleted file mode 100644 index 0cc9f846..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/StaticVarCompensatorFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.StaticVarCompensatorFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.StaticVarCompensatorFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.StaticVarCompensatorFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class StaticVarCompensatorFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final StaticVarCompensatorFilterRepository staticVarCompensatorFilterRepository; - - public StaticVarCompensatorFilterRepositoryProxy(StaticVarCompensatorFilterRepository staticVarCompensatorFilterRepository) { - this.staticVarCompensatorFilterRepository = staticVarCompensatorFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.STATIC_VAR_COMPENSATOR; - } - - @Override - public StaticVarCompensatorFilterRepository getRepository() { - return staticVarCompensatorFilterRepository; - } - - @Override - public AbstractFilter toDto(StaticVarCompensatorFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new StaticVarCompensatorFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public StaticVarCompensatorFilterEntity fromDto(AbstractFilter dto) { - var staticVarCompensatorFilterEntityBuilder = StaticVarCompensatorFilterEntity.builder(); - buildInjectionFilter(staticVarCompensatorFilterEntityBuilder, toFormFilter(dto, StaticVarCompensatorFilter.class)); - return staticVarCompensatorFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/SubstationFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/SubstationFilterRepositoryProxy.java deleted file mode 100644 index 557bf529..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/SubstationFilterRepositoryProxy.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2022, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.SubstationFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.SubstationFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.SubstationFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class SubstationFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final SubstationFilterRepository substationFilterRepository; - - public SubstationFilterRepositoryProxy(SubstationFilterRepository substationFilterRepository) { - this.substationFilterRepository = substationFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.SUBSTATION; - } - - @Override - public SubstationFilterRepository getRepository() { - return substationFilterRepository; - } - - @Override - public AbstractFilter toDto(SubstationFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - SubstationFilterEntity substationFilterEntity = (SubstationFilterEntity) entity; - return SubstationFilter.builder() - .equipmentID(substationFilterEntity.getEquipmentId()) - .equipmentName(substationFilterEntity.getEquipmentName()) - .countries(setToSorterSet(substationFilterEntity.getCountries())) - .freeProperties(convert(substationFilterEntity.getFreeProperties())) - .build(); - } - - @Override - public SubstationFilterEntity fromDto(AbstractFilter dto) { - CriteriaFilter criteriaFilter = toFormFilter(dto, SubstationFilter.class); - SubstationFilter substationFilter = (SubstationFilter) criteriaFilter.getEquipmentFilterForm(); - var substationFilterEntityBuilder = SubstationFilterEntity.builder() - .countries(substationFilter.getCountries()) - .freeProperties(convert(substationFilter.getFreeProperties())); - buildGenericFilter(substationFilterEntityBuilder, criteriaFilter); - return substationFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ThreeWindingsTransformerFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ThreeWindingsTransformerFilterRepositoryProxy.java deleted file mode 100644 index 2e8328b0..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/ThreeWindingsTransformerFilterRepositoryProxy.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.ThreeWindingsTransformerFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.ThreeWindingsTransformerFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.ThreeWindingsTransformerFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class ThreeWindingsTransformerFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final ThreeWindingsTransformerFilterRepository threeWindingsTransformerFilterRepository; - - public ThreeWindingsTransformerFilterRepositoryProxy(ThreeWindingsTransformerFilterRepository threeWindingsTransformerFilterRepository) { - this.threeWindingsTransformerFilterRepository = threeWindingsTransformerFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.THREE_WINDINGS_TRANSFORMER; - } - - @Override - public ThreeWindingsTransformerFilterRepository getRepository() { - return threeWindingsTransformerFilterRepository; - } - - @Override - public AbstractFilter toDto(ThreeWindingsTransformerFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - ThreeWindingsTransformerFilterEntity threeWindingsTransformerFilterEntity = (ThreeWindingsTransformerFilterEntity) entity; - return ThreeWindingsTransformerFilter.builder() - .equipmentID(threeWindingsTransformerFilterEntity.getEquipmentId()) - .equipmentName(threeWindingsTransformerFilterEntity.getEquipmentName()) - .substationName(threeWindingsTransformerFilterEntity.getSubstationName()) - .countries(setToSorterSet(threeWindingsTransformerFilterEntity.getCountries())) - .substationFreeProperties(convert(threeWindingsTransformerFilterEntity.getSubstationFreeProperties())) - .nominalVoltage1(convert(threeWindingsTransformerFilterEntity.getNominalVoltage1())) - .nominalVoltage2(convert(threeWindingsTransformerFilterEntity.getNominalVoltage2())) - .nominalVoltage3(convert(threeWindingsTransformerFilterEntity.getNominalVoltage3())).build(); - } - - @Override - public ThreeWindingsTransformerFilterEntity fromDto(AbstractFilter dto) { - CriteriaFilter criteriaFilter = toFormFilter(dto, ThreeWindingsTransformerFilter.class); - ThreeWindingsTransformerFilter threeWindingsTransformerFilter = (ThreeWindingsTransformerFilter) criteriaFilter.getEquipmentFilterForm(); - var threeWindingsTransformerFilterEntityBuilder = ThreeWindingsTransformerFilterEntity.builder() - .countries(threeWindingsTransformerFilter.getCountries()) - .substationName(threeWindingsTransformerFilter.getSubstationName()) - .nominalVoltage1(convert(threeWindingsTransformerFilter.getNominalVoltage1())) - .nominalVoltage2(convert(threeWindingsTransformerFilter.getNominalVoltage2())) - .nominalVoltage3(convert(threeWindingsTransformerFilter.getNominalVoltage3())) - .substationFreeProperties(convert(threeWindingsTransformerFilter.getSubstationFreeProperties())); - buildGenericFilter(threeWindingsTransformerFilterEntityBuilder, criteriaFilter); - return threeWindingsTransformerFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/TwoWindingsTransformerFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/TwoWindingsTransformerFilterRepositoryProxy.java deleted file mode 100644 index bf61f186..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/TwoWindingsTransformerFilterRepositoryProxy.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.TwoWindingsTransformerFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.TwoWindingsTransformerFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.TwoWindingsTransformerFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class TwoWindingsTransformerFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final TwoWindingsTransformerFilterRepository twoWindingsTransformerFilterRepository; - - public TwoWindingsTransformerFilterRepositoryProxy(TwoWindingsTransformerFilterRepository twoWindingsTransformerFilterRepository) { - this.twoWindingsTransformerFilterRepository = twoWindingsTransformerFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.TWO_WINDINGS_TRANSFORMER; - } - - @Override - public TwoWindingsTransformerFilterRepository getRepository() { - return twoWindingsTransformerFilterRepository; - } - - @Override - public AbstractFilter toDto(TwoWindingsTransformerFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - TwoWindingsTransformerFilterEntity twoWindingsTransformerFilterEntity = (TwoWindingsTransformerFilterEntity) entity; - return TwoWindingsTransformerFilter.builder().equipmentID(twoWindingsTransformerFilterEntity.getEquipmentId()) - .equipmentName(twoWindingsTransformerFilterEntity.getEquipmentName()) - .substationName(twoWindingsTransformerFilterEntity.getSubstationName()) - .countries(setToSorterSet(twoWindingsTransformerFilterEntity.getCountries())) - .substationFreeProperties(convert(twoWindingsTransformerFilterEntity.getSubstationFreeProperties())) - .freeProperties(convert(twoWindingsTransformerFilterEntity.getFreeProperties())) - .nominalVoltage1(convert(twoWindingsTransformerFilterEntity.getNominalVoltage1())) - .nominalVoltage2(convert(twoWindingsTransformerFilterEntity.getNominalVoltage2())) - .build(); - } - - @Override - public TwoWindingsTransformerFilterEntity fromDto(AbstractFilter dto) { - CriteriaFilter criteriaFilter = toFormFilter(dto, TwoWindingsTransformerFilter.class); - TwoWindingsTransformerFilter twoWindingsTransformerFilter = (TwoWindingsTransformerFilter) criteriaFilter.getEquipmentFilterForm(); - var twoWindingsTransformerFilterEntityBuilder = TwoWindingsTransformerFilterEntity.builder() - .countries(twoWindingsTransformerFilter.getCountries()) - .substationName(twoWindingsTransformerFilter.getSubstationName()) - .nominalVoltage1(convert(twoWindingsTransformerFilter.getNominalVoltage1())) - .nominalVoltage2(convert(twoWindingsTransformerFilter.getNominalVoltage2())) - .substationFreeProperties(convert(twoWindingsTransformerFilter.getSubstationFreeProperties())) - .freeProperties(convert(twoWindingsTransformerFilter.getFreeProperties())); - buildGenericFilter(twoWindingsTransformerFilterEntityBuilder, criteriaFilter); - return twoWindingsTransformerFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VoltageLevelFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VoltageLevelFilterRepositoryProxy.java deleted file mode 100644 index 2e865255..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VoltageLevelFilterRepositoryProxy.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2022, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.VoltageLevelFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.VoltageLevelFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.VoltageLevelFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class VoltageLevelFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final VoltageLevelFilterRepository voltageLevelFilterRepository; - - public VoltageLevelFilterRepositoryProxy(VoltageLevelFilterRepository voltageLevelFilterRepository) { - this.voltageLevelFilterRepository = voltageLevelFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.VOLTAGE_LEVEL; - } - - @Override - public VoltageLevelFilterRepository getRepository() { - return voltageLevelFilterRepository; - } - - @Override - public AbstractFilter toDto(VoltageLevelFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - VoltageLevelFilterEntity voltageLevelFilterEntity = (VoltageLevelFilterEntity) entity; - return VoltageLevelFilter.builder() - .equipmentID(voltageLevelFilterEntity.getEquipmentId()) - .equipmentName(voltageLevelFilterEntity.getEquipmentName()) - .countries(setToSorterSet(voltageLevelFilterEntity.getCountries())) - .freeProperties(convert(voltageLevelFilterEntity.getFreeProperties())) - .substationFreeProperties(convert(voltageLevelFilterEntity.getSubstationFreeProperties())) - .nominalVoltage(convert(voltageLevelFilterEntity.getNominalVoltage())) - .build(); - } - - @Override - public VoltageLevelFilterEntity fromDto(AbstractFilter dto) { - CriteriaFilter criteriaFilter = toFormFilter(dto, VoltageLevelFilter.class); - VoltageLevelFilter voltageLevelFilter = (VoltageLevelFilter) criteriaFilter.getEquipmentFilterForm(); - var voltageLevelFilterEntityBuilder = VoltageLevelFilterEntity.builder() - .countries(voltageLevelFilter.getCountries()) - .substationFreeProperties(convert(voltageLevelFilter.getSubstationFreeProperties())) - .nominalVoltage(convert(voltageLevelFilter.getNominalVoltage())) - .freeProperties(convert(voltageLevelFilter.getFreeProperties())); - buildGenericFilter(voltageLevelFilterEntityBuilder, criteriaFilter); - return voltageLevelFilterEntityBuilder.build(); - } -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VscConverterStationFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VscConverterStationFilterRepositoryProxy.java deleted file mode 100644 index 7b210fe5..00000000 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/criteriafilter/VscConverterStationFilterRepositoryProxy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021, 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.repositories.proxies.criteriafilter; - -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; -import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.VscConverterStationFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.VscConverterStationFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.VscConverterStationFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; -import org.gridsuite.filter.utils.EquipmentType; -import org.gridsuite.filter.utils.FilterType; - -/** - * @author Franck Lecuyer - */ - -public class VscConverterStationFilterRepositoryProxy extends AbstractFilterRepositoryProxy { - - private final VscConverterStationFilterRepository vscConverterStationFilterRepository; - - public VscConverterStationFilterRepositoryProxy(VscConverterStationFilterRepository vscConverterStationFilterRepository) { - this.vscConverterStationFilterRepository = vscConverterStationFilterRepository; - } - - @Override - public FilterType getFilterType() { - return FilterType.CRITERIA; - } - - @Override - public EquipmentType getEquipmentType() { - return EquipmentType.VSC_CONVERTER_STATION; - } - - @Override - public VscConverterStationFilterRepository getRepository() { - return vscConverterStationFilterRepository; - } - - @Override - public AbstractFilter toDto(VscConverterStationFilterEntity entity) { - return super.toFormFilterDto(entity); - } - - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return new VscConverterStationFilter(buildInjectionAttributesFromEntity((AbstractInjectionFilterEntity) entity)); - } - - @Override - public VscConverterStationFilterEntity fromDto(AbstractFilter dto) { - var vscConverterStationFilterEntityBuilder = VscConverterStationFilterEntity.builder(); - buildInjectionFilter(vscConverterStationFilterEntityBuilder, toFormFilter(dto, VscConverterStationFilter.class)); - return vscConverterStationFilterEntityBuilder.build(); - } -} diff --git a/src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java b/src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java index e8f0cf24..e69de29b 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2024, 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; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.powsybl.commons.PowsyblException; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; -import org.gridsuite.filter.criteriafilter.LineFilter; -import org.gridsuite.filter.criteriafilter.NumericalFilter; -import org.gridsuite.filter.server.entities.criteriafilter.AbstractInjectionFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.GeneratorFilterEntity; -import org.gridsuite.filter.server.repositories.criteriafilter.GeneratorFilterRepository; -import org.gridsuite.filter.server.repositories.proxies.criteriafilter.GeneratorFilterRepositoryProxy; -import org.gridsuite.filter.utils.RangeType; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.*; - -import static org.junit.Assert.assertThrows; - -/** - * @author Hugo Marcellin - */ -@RunWith(SpringRunner.class) -@SpringBootTest -public class FilterRepositoryTest { - - @Autowired - ObjectMapper objectMapper; - - @Autowired - GeneratorFilterRepository generatorFilterRepository; - GeneratorFilterRepositoryProxy generatorFilterRepositoryProxy; - - @Before - public void setUp() { - generatorFilterRepositoryProxy = new GeneratorFilterRepositoryProxy(generatorFilterRepository); - } - - @Test - public void buildWrongFilterType() throws Exception { - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1") - .substationName1("P1") - .substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))) - .countries2(new TreeSet<>(Set.of("FR"))) - .freeProperties2(Map.of("region", List.of("north"))) - .freeProperties1(Map.of("region", List.of("south"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)) - .nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)) - .build(); - - AbstractInjectionFilterEntity.AbstractInjectionFilterEntityBuilder builder = GeneratorFilterEntity.builder(); - CriteriaFilter criteriaFilter = CriteriaFilter.builder().equipmentFilterForm(lineFilter).build(); - assertThrows("Wrong filter type, should never happen", PowsyblException.class, () -> generatorFilterRepositoryProxy.buildInjectionFilter(builder, criteriaFilter)); - } -} From 3233cca14f34d2c73ed9e66315984b98cfd8ca3d Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 17:13:13 +0100 Subject: [PATCH 15/27] suppress criteria filter code - part 2 --- .../AbstractGenericFilterEntity.java | 36 -------- .../AbstractInjectionFilterEntity.java | 59 ------------ .../criteriafilter/BatteryFilterEntity.java | 26 ------ .../BusBarSectionFilterEntity.java | 26 ------ .../DanglingLineFilterEntity.java | 26 ------ .../FreePropertiesFilterEntity.java | 44 --------- .../FreePropertyFilterEntity.java | 40 -------- .../criteriafilter/GeneratorFilterEntity.java | 29 ------ .../criteriafilter/HvdcLineFilterEntity.java | 73 --------------- .../LccConverterStationFilterEntity.java | 26 ------ .../criteriafilter/LineFilterEntity.java | 76 --------------- .../criteriafilter/LoadFilterEntity.java | 26 ------ .../criteriafilter/NumericFilterEntity.java | 42 --------- .../ShuntCompensatorFilterEntity.java | 26 ------ .../StaticVarCompensatorFilterEntity.java | 26 ------ .../SubstationFilterEntity.java | 48 ---------- .../ThreeWindingsTransformerFilterEntity.java | 75 --------------- .../TwoWindingsTransformerFilterEntity.java | 73 --------------- .../VoltageLevelFilterEntity.java | 62 ------------- .../VscConverterStationFilterEntity.java | 26 ------ .../AbstractFilterRepositoryProxy.java | 92 ------------------- .../ExpertFilterRepositoryProxy.java | 6 -- .../IdentifierListFilterRepositoryProxy.java | 6 -- .../ScriptFilterRepositoryProxy.java | 7 -- .../filter/server/FilterRepositoryTest.java | 0 25 files changed, 976 deletions(-) delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractGenericFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractInjectionFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BatteryFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BusBarSectionFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/DanglingLineFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertiesFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertyFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/GeneratorFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/HvdcLineFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LccConverterStationFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LineFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LoadFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/NumericFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ShuntCompensatorFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/StaticVarCompensatorFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/SubstationFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ThreeWindingsTransformerFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/TwoWindingsTransformerFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VoltageLevelFilterEntity.java delete mode 100644 src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VscConverterStationFilterEntity.java delete mode 100644 src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractGenericFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractGenericFilterEntity.java deleted file mode 100644 index f7dce3f7..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractGenericFilterEntity.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.*; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; - -/** - * @author Jacques Borsenberger - * @author Franck Lecuyer - */ -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@MappedSuperclass -public abstract class AbstractGenericFilterEntity extends AbstractFilterEntity { - - @Column(name = "equipmentName") - private String equipmentName; - @Column(name = "equipmentId") - private String equipmentId; - -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractInjectionFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractInjectionFilterEntity.java deleted file mode 100644 index a555a3bb..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/AbstractInjectionFilterEntity.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import java.util.Set; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@MappedSuperclass -public abstract class AbstractInjectionFilterEntity extends AbstractGenericFilterEntity { - - /* as AbstractInjectionFilterEntity is a mapped superclass naming constraints gives to each child class the same name - for the constraint, liquibase only take one of these the others are discarded, so we let hibernate pick a name - */ - @Column(name = "countries") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey()) - Set countries; - - @Column(name = "substationName") - String substationName; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "numericFilterId_id", - referencedColumnName = "id", - /* as AbstractInjectionFilterEntity is a mapped superclass naming constraints gives to each child class the same name - for the constraint, liquibase only take one of these the others are discarded, so we let hibernate pick a name - */ - foreignKey = @ForeignKey(), nullable = true) - NumericFilterEntity nominalVoltage; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "freeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity freeProperties; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BatteryFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BatteryFilterEntity.java deleted file mode 100644 index 24703365..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BatteryFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "battery_filter") -public class BatteryFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BusBarSectionFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BusBarSectionFilterEntity.java deleted file mode 100644 index 50018d7e..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/BusBarSectionFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "busbar_section_filter") -public class BusBarSectionFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/DanglingLineFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/DanglingLineFilterEntity.java deleted file mode 100644 index 1cfd2eb5..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/DanglingLineFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "dangling_line_filter") -public class DanglingLineFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertiesFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertiesFilterEntity.java deleted file mode 100644 index 6bb4d269..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertiesFilterEntity.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2022, 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.entities.criteriafilter; - -import java.util.List; -import java.util.UUID; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OrderColumn; -import jakarta.persistence.Table; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author Laurent Garnier - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "free_properties") -public class FreePropertiesFilterEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - UUID id; - - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @OrderColumn(name = "pos") - List freePropertyFilterEntities; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertyFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertyFilterEntity.java deleted file mode 100644 index 9d5466d3..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/FreePropertyFilterEntity.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2022, 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.entities.criteriafilter; - -import jakarta.persistence.*; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import java.util.List; -import java.util.UUID; - -/** - * @author Laurent Garnier - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "free_property") -public class FreePropertyFilterEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - UUID id; - - @Column(name = "propName", nullable = false) - String propName; - - @Column(name = "prop_values") - @ElementCollection(fetch = FetchType.EAGER) - @CollectionTable(name = "prop_value") - @OrderColumn(name = "pos") - List propValues; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/GeneratorFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/GeneratorFilterEntity.java deleted file mode 100644 index bbe7cdc2..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/GeneratorFilterEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import com.powsybl.iidm.network.EnergySource; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.*; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "generator_filter") -public class GeneratorFilterEntity extends AbstractInjectionFilterEntity { - @Enumerated(EnumType.STRING) - @Column(name = "energySource") - EnergySource energySource; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/HvdcLineFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/HvdcLineFilterEntity.java deleted file mode 100644 index 139d2191..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/HvdcLineFilterEntity.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.Set; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Entity -@Table(name = "hvdc_line_filter") -public class HvdcLineFilterEntity extends AbstractGenericFilterEntity { - @Column(name = "countries1") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "hvdcLineFilterEntity_countries_fk1"), indexes = {@Index(name = "hvdcLineFilterEntity_countries_idx1", columnList = "hvdc_line_filter_entity_id")}) - Set countries1; - - @Column(name = "countries2") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "hvdcLineFilterEntity_countries_fk2"), indexes = {@Index(name = "hvdcLineFilterEntity_countries_idx2", columnList = "hvdc_line_filter_entity_id")}) - Set countries2; - - @Column(name = "substationName1") - String substationName1; - - @Column(name = "substationName2") - String substationName2; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "hvdcLineFilterEntity_numericFilterId_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "numericFilterId_id_fk" - ), nullable = true) - NumericFilterEntity nominalVoltage; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties1_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties1; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties2_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties2; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LccConverterStationFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LccConverterStationFilterEntity.java deleted file mode 100644 index c4a86854..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LccConverterStationFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "lcc_converter_station_filter") -public class LccConverterStationFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LineFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LineFilterEntity.java deleted file mode 100644 index 4a6ad105..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LineFilterEntity.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; -import jakarta.persistence.*; - -import java.util.Set; - -/** - * @author Jacques Borsenberger - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@AllArgsConstructor -@Entity -@Table(name = "line_filter") -public class LineFilterEntity extends AbstractGenericFilterEntity { - @Column(name = "countries1") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "lineFilterEntity_countries_fk1"), indexes = {@Index(name = "lineFilterEntity_countries_idx1", columnList = "line_filter_entity_id")}) - Set countries1; - - @Column(name = "countries2") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "lineFilterEntity_countries_fk2"), indexes = {@Index(name = "lineFilterEntity_countries_idx2", columnList = "line_filter_entity_id")}) - Set countries2; - - @Column(name = "substationName1") - String substationName1; - @Column(name = "substationName2") - String substationName2; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "numericFilterId1_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "line_numericFilterId_id_fk1" - ), nullable = true) - NumericFilterEntity nominalVoltage1; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "numericFilterId2_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "line_numericFilterId_id_fk2" - ), nullable = true) - NumericFilterEntity nominalVoltage2; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties1_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties1; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties2_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties2; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "freeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity freeProperties; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LoadFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LoadFilterEntity.java deleted file mode 100644 index e2b2fd6b..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/LoadFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "load_filter") -public class LoadFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/NumericFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/NumericFilterEntity.java deleted file mode 100644 index ce096018..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/NumericFilterEntity.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.gridsuite.filter.utils.RangeType; - -import jakarta.persistence.*; -import java.util.UUID; - -/** - * @author Jacques Borsenberger - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@Entity -@Table(name = "numericFilter") -public class NumericFilterEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private UUID id; - - @Enumerated(EnumType.STRING) - @Column(name = "rangeType") - RangeType filterType; - - @Column(name = "value1") - Double value1; - - @Column(name = "value2") - Double value2; - -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ShuntCompensatorFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ShuntCompensatorFilterEntity.java deleted file mode 100644 index 6f41749a..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ShuntCompensatorFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "shunt_compensator_filter") -public class ShuntCompensatorFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/StaticVarCompensatorFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/StaticVarCompensatorFilterEntity.java deleted file mode 100644 index dba90470..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/StaticVarCompensatorFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "static_var_compensator_filter") -public class StaticVarCompensatorFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/SubstationFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/SubstationFilterEntity.java deleted file mode 100644 index 2b0ea13a..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/SubstationFilterEntity.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2022, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.Set; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Entity -@Table(name = "substation_filter") -public class SubstationFilterEntity extends AbstractGenericFilterEntity { - @Column(name = "countries") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "substationFilterEntity_countries_fk"), indexes = {@Index(name = "substationFilterEntity_countries_idx", columnList = "substation_filter_entity_id")}) - Set countries; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "freeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity freeProperties; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ThreeWindingsTransformerFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ThreeWindingsTransformerFilterEntity.java deleted file mode 100644 index b1d7205b..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/ThreeWindingsTransformerFilterEntity.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.Set; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Entity -@Table(name = "three_windings_transformer_filter") -public class ThreeWindingsTransformerFilterEntity extends AbstractGenericFilterEntity { - @Column(name = "countries") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "threeWindingsTransformerFilterEntity_countries_fk"), indexes = {@Index(name = "threeWindingsTransformerFilterEntity_countries_idx", columnList = "three_windings_transformer_filter_entity_id")}) - Set countries; - - @Column(name = "substationName") - String substationName; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "threeWindingsTransformer_numericFilterId1_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "threeWindingsTransformer_numericFilterId_id_fk1" - ), nullable = true) - NumericFilterEntity nominalVoltage1; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "threeWindingsTransformer_numericFilterId2_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "threeWindingsTransformer_numericFilterId_id_fk2" - ), nullable = true) - NumericFilterEntity nominalVoltage2; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "threeWindingsTransformer_numericFilterId3_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "threeWindingsTransformer_numericFilterId_id_fk3" - ), nullable = true) - NumericFilterEntity nominalVoltage3; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/TwoWindingsTransformerFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/TwoWindingsTransformerFilterEntity.java deleted file mode 100644 index 1dce8984..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/TwoWindingsTransformerFilterEntity.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.Set; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Entity -@Table(name = "two_windings_transformer_filter") -public class TwoWindingsTransformerFilterEntity extends AbstractGenericFilterEntity { - @Column(name = "countries") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "twoWindingsTransformerFilterEntity_countries_fk"), indexes = {@Index(name = "twoWindingsTransformerFilterEntity_countries_idx", columnList = "two_windings_transformer_filter_entity_id")}) - Set countries; - - @Column(name = "substationName") - String substationName; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "numericFilterId1_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "twoWindingsTransformer_numericFilterId_id_fk1" - ), nullable = true) - NumericFilterEntity nominalVoltage1; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "twoWindingsTransformernumericFilterId2_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "twoWindingsTransformer_numericFilterId_id_fk2" - ), nullable = true) - NumericFilterEntity nominalVoltage2; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "freeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity freeProperties; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VoltageLevelFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VoltageLevelFilterEntity.java deleted file mode 100644 index a5ed0e02..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VoltageLevelFilterEntity.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2022, 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.entities.criteriafilter; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; -import java.util.Set; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Entity -@Table(name = "voltage_level_filter") -public class VoltageLevelFilterEntity extends AbstractGenericFilterEntity { - @Column(name = "countries") - @ElementCollection - @CollectionTable(foreignKey = @ForeignKey(name = "voltageLevelFilterEntity_countries_fk"), indexes = {@Index(name = "voltageLevelFilterEntity_countries_idx", columnList = "voltage_level_filter_entity_id")}) - Set countries; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "substationFreeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity substationFreeProperties; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "freeProperties_id", - referencedColumnName = "id", - foreignKey = @ForeignKey) - FreePropertiesFilterEntity freeProperties; - - @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "numericFilterId_id", - referencedColumnName = "id", - foreignKey = @ForeignKey( - name = "voltageLevel_numericFilterId_id_fk" - ), nullable = true) - NumericFilterEntity nominalVoltage; -} diff --git a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VscConverterStationFilterEntity.java b/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VscConverterStationFilterEntity.java deleted file mode 100644 index ff5b69db..00000000 --- a/src/main/java/org/gridsuite/filter/server/entities/criteriafilter/VscConverterStationFilterEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021, 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.entities.criteriafilter; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Franck Lecuyer - */ -@Getter -@NoArgsConstructor -@SuperBuilder -@Entity -@Table(name = "vsc_converter_station_filter") -public class VscConverterStationFilterEntity extends AbstractInjectionFilterEntity { -} diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/AbstractFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/AbstractFilterRepositoryProxy.java index a9c66139..caf7676d 100644 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/AbstractFilterRepositoryProxy.java +++ b/src/main/java/org/gridsuite/filter/server/repositories/proxies/AbstractFilterRepositoryProxy.java @@ -7,12 +7,9 @@ package org.gridsuite.filter.server.repositories.proxies; -import com.powsybl.commons.PowsyblException; import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.*; import org.gridsuite.filter.server.dto.FilterAttributes; import org.gridsuite.filter.server.entities.AbstractFilterEntity; -import org.gridsuite.filter.server.entities.criteriafilter.*; import org.gridsuite.filter.server.repositories.FilterMetadata; import org.gridsuite.filter.server.repositories.FilterRepository; import org.gridsuite.filter.utils.EquipmentType; @@ -38,49 +35,10 @@ static Set cloneIfNotEmptyOrNull(Set set) { return null; } - public static NumericalFilter convert(NumericFilterEntity entity) { - return entity != null ? new NumericalFilter(entity.getFilterType(), entity.getValue1(), entity.getValue2()) : null; - } - public static SortedSet setToSorterSet(Set set) { return CollectionUtils.isEmpty(set) ? null : new TreeSet<>(set); } - public static Map> convert(FreePropertiesFilterEntity entity) { - if (entity == null) { - return null; - } - - List freePropertyFilterEntities = entity.getFreePropertyFilterEntities(); - if (freePropertyFilterEntities == null) { - return null; - } - - // LinkedHashMap to keep order too - LinkedHashMap> ret = new LinkedHashMap<>(); - // can not use stream and Collectors.toMap which would go through an HashMap for the two arguments version - // and HashMap does not take care of order - freePropertyFilterEntities.forEach(p -> ret.put(p.getPropName(), p.getPropValues())); - return ret; - } - - public static NumericFilterEntity convert(NumericalFilter numericalFilter) { - return numericalFilter != null ? - new NumericFilterEntity(null, numericalFilter.getType(), numericalFilter.getValue1(), numericalFilter.getValue2()) - : null; - } - - public static FreePropertiesFilterEntity convert(Map> dto) { - if (dto == null) { - return null; - } - - List innerEntities = dto.entrySet().stream() - .map(p -> FreePropertyFilterEntity.builder() - .propName(p.getKey()).propValues(p.getValue()).build()).collect(Collectors.toList()); - return FreePropertiesFilterEntity.builder().freePropertyFilterEntities(innerEntities).build(); - } - public abstract R getRepository(); public abstract AbstractFilter toDto(F filterEntity); @@ -144,59 +102,9 @@ public void deleteAll() { getRepository().deleteAll(); } - public void buildGenericFilter(AbstractGenericFilterEntity.AbstractGenericFilterEntityBuilder builder, CriteriaFilter dto) { - buildAbstractFilter(builder, dto); - builder.equipmentId(dto.getEquipmentFilterForm().getEquipmentID()) - .equipmentName(dto.getEquipmentFilterForm().getEquipmentName()); - } - - public void buildInjectionFilter(AbstractInjectionFilterEntity.AbstractInjectionFilterEntityBuilder builder, CriteriaFilter dto) { - buildGenericFilter(builder, dto); - if (!(dto.getEquipmentFilterForm() instanceof AbstractInjectionFilter injectionFilter)) { - throw new PowsyblException(WRONG_FILTER_TYPE); - } - builder.substationName(injectionFilter.getSubstationName()) - .countries(AbstractFilterRepositoryProxy.cloneIfNotEmptyOrNull(injectionFilter.getCountries())) - .substationFreeProperties(convert(injectionFilter.getSubstationFreeProperties())) - .freeProperties(convert(injectionFilter.getFreeProperties())) - .nominalVoltage(AbstractFilterRepositoryProxy.convert(injectionFilter.getNominalVoltage())); - } - public void buildAbstractFilter(AbstractFilterEntity.AbstractFilterEntityBuilder builder, AbstractFilter dto) { /* modification date is managed by jpa, so we don't process it */ builder.id(dto.getId()); } - public AbstractFilter toFormFilterDto(AbstractGenericFilterEntity entity) { - return new CriteriaFilter( - entity.getId(), - entity.getModificationDate(), - buildEquipmentFormFilter(entity) - ); - } - - public abstract AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity); - - public InjectionFilterAttributes buildInjectionAttributesFromEntity(AbstractInjectionFilterEntity entity) { - return new InjectionFilterAttributes(entity.getEquipmentId(), - entity.getEquipmentName(), - entity.getSubstationName(), - setToSorterSet(entity.getCountries()), - convert(entity.getSubstationFreeProperties()), - convert(entity.getFreeProperties()), - convert(entity.getNominalVoltage()) - ); - } - - public static CriteriaFilter toFormFilter(AbstractFilter dto, Class clazz) { - if (!(dto instanceof CriteriaFilter)) { - throw new PowsyblException(WRONG_FILTER_TYPE); - } - CriteriaFilter criteriaFilter = (CriteriaFilter) dto; - - if (!(clazz.isInstance(criteriaFilter.getEquipmentFilterForm()))) { - throw new PowsyblException(WRONG_FILTER_TYPE); - } - return criteriaFilter; - } } diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/expertfiler/ExpertFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/expertfiler/ExpertFilterRepositoryProxy.java index 31169506..897ef7ca 100644 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/expertfiler/ExpertFilterRepositoryProxy.java +++ b/src/main/java/org/gridsuite/filter/server/repositories/proxies/expertfiler/ExpertFilterRepositoryProxy.java @@ -9,10 +9,8 @@ import com.powsybl.commons.PowsyblException; import org.gridsuite.filter.AbstractFilter; -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.expertfilter.expertrule.*; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; import org.gridsuite.filter.server.entities.expertfilter.ExpertFilterEntity; import org.gridsuite.filter.server.entities.expertfilter.ExpertRuleEntity; import org.gridsuite.filter.server.entities.expertfilter.ExpertRulePropertiesEntity; @@ -258,8 +256,4 @@ public EquipmentType getEquipmentType(UUID id) { .orElseThrow(() -> new PowsyblException("Identifier list filter " + id + " not found")); } - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return null; - } } diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/identifierlistfilter/IdentifierListFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/identifierlistfilter/IdentifierListFilterRepositoryProxy.java index 73cbc0e8..4596a2d1 100644 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/identifierlistfilter/IdentifierListFilterRepositoryProxy.java +++ b/src/main/java/org/gridsuite/filter/server/repositories/proxies/identifierlistfilter/IdentifierListFilterRepositoryProxy.java @@ -8,11 +8,9 @@ package org.gridsuite.filter.server.repositories.proxies.identifierlistfilter; import com.powsybl.commons.PowsyblException; -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; import org.gridsuite.filter.server.entities.identifierlistfilter.IdentifierListFilterEntity; import org.gridsuite.filter.server.entities.identifierlistfilter.IdentifierListFilterEquipmentEntity; import org.gridsuite.filter.server.repositories.identifierlistfilter.IdentifierListFilterRepository; @@ -89,8 +87,4 @@ public EquipmentType getEquipmentType(UUID id) { .orElseThrow(() -> new PowsyblException("Identifier list filter " + id + " not found")); } - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return null; - } } diff --git a/src/main/java/org/gridsuite/filter/server/repositories/proxies/scriptfilter/ScriptFilterRepositoryProxy.java b/src/main/java/org/gridsuite/filter/server/repositories/proxies/scriptfilter/ScriptFilterRepositoryProxy.java index 0fbff508..05bd5897 100644 --- a/src/main/java/org/gridsuite/filter/server/repositories/proxies/scriptfilter/ScriptFilterRepositoryProxy.java +++ b/src/main/java/org/gridsuite/filter/server/repositories/proxies/scriptfilter/ScriptFilterRepositoryProxy.java @@ -8,10 +8,8 @@ package org.gridsuite.filter.server.repositories.proxies.scriptfilter; import com.powsybl.commons.PowsyblException; -import org.gridsuite.filter.criteriafilter.AbstractEquipmentFilterForm; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.scriptfilter.ScriptFilter; -import org.gridsuite.filter.server.entities.AbstractFilterEntity; import org.gridsuite.filter.server.entities.scriptfilter.ScriptFilterEntity; import org.gridsuite.filter.server.repositories.scriptfilter.ScriptFilterRepository; import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; @@ -38,11 +36,6 @@ public EquipmentType getEquipmentType() { return null; } - @Override - public AbstractEquipmentFilterForm buildEquipmentFormFilter(AbstractFilterEntity entity) { - return null; - } - @Override public ScriptFilterRepository getRepository() { return scriptFiltersRepository; diff --git a/src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java b/src/test/java/org/gridsuite/filter/server/FilterRepositoryTest.java deleted file mode 100644 index e69de29b..00000000 From 4a863ab1ae739a10284972fb857ec56b816e6f1a Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Mon, 2 Dec 2024 17:24:42 +0100 Subject: [PATCH 16/27] Trigger coverage Signed-off-by: Etienne Homer --- src/main/java/org/gridsuite/filter/server/FilterController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index c6ef88e5..d135e32e 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -172,6 +172,7 @@ public ResponseEntity> exportFilter(@PathVariable(" public ResponseEntity> getIdentifiablesCountByGroup(@RequestParam(value = "networkUuid") UUID networkUuid, @RequestParam(value = "variantId", required = false) String variantId, IdsByGroup idsByGroup) { + Logger.getLogger("export").info(() -> "test"); return ResponseEntity.ok() .contentType(MediaType.APPLICATION_JSON) .body(service.getIdentifiablesCountByGroup(idsByGroup, networkUuid, variantId)); From 85ab4dc82b642af90283067519fe42a5fa4eafc9 Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 17:30:21 +0100 Subject: [PATCH 17/27] correction --- .../filter/server/FilterService.java | 6 +---- .../server/FilterEntityControllerTest.java | 26 ------------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/main/java/org/gridsuite/filter/server/FilterService.java b/src/main/java/org/gridsuite/filter/server/FilterService.java index 1e4ec486..77c093f3 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterService.java +++ b/src/main/java/org/gridsuite/filter/server/FilterService.java @@ -14,7 +14,6 @@ import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.FilterLoader; import org.gridsuite.filter.IFilterAttributes; -import org.gridsuite.filter.criteriafilter.CriteriaFilter; import org.gridsuite.filter.identifierlistfilter.FilterEquipments; import org.gridsuite.filter.identifierlistfilter.IdentifiableAttributes; import org.gridsuite.filter.server.dto.IdsByGroup; @@ -164,10 +163,7 @@ public Map duplicateFilters(List filterUuids) { private AbstractFilterRepositoryProxy> getRepository(AbstractFilter filter) { - if (!filter.getType().equals(FilterType.CRITERIA)) { - return filterRepositories.get(filter.getType().name()); - } - return filterRepositories.get(((CriteriaFilter) filter).getEquipmentFilterForm().getEquipmentType().name()); + return filterRepositories.get(filter.getType().name()); } @Transactional diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 3a95ef8b..4eca59c8 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -22,7 +22,6 @@ import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; import org.gridsuite.filter.AbstractFilter; import org.gridsuite.filter.IFilterAttributes; -import org.gridsuite.filter.criteriafilter.*; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.expertfilter.expertrule.*; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; @@ -32,7 +31,6 @@ import org.gridsuite.filter.server.utils.assertions.Assertions; import org.gridsuite.filter.utils.EquipmentType; import org.gridsuite.filter.utils.FilterType; -import org.gridsuite.filter.utils.RangeType; import org.gridsuite.filter.utils.expertfilter.CombinatorType; import org.gridsuite.filter.utils.expertfilter.FieldType; import org.gridsuite.filter.utils.expertfilter.OperatorType; @@ -1055,30 +1053,6 @@ public void testExpertFilterTwoWindingsTransformerWithInAndNotInOperator() throw // Build a filter AND with only an IN operator } - @Test - public void lineFilterIsEmpty() { - HvdcLineFilter hvdcFilter = HvdcLineFilter.builder() - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build(); - 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()); - } - @Test public void testExpertFilterLoadLinkToOtherFilterWithIsPartOfOperator() throws Exception { // Create identifier list filter for loads From 1f747e65860e09356f5b999d7e7d7d965955e272 Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Mon, 2 Dec 2024 17:32:23 +0100 Subject: [PATCH 18/27] Clean Signed-off-by: Etienne Homer --- src/main/java/org/gridsuite/filter/server/FilterController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index d135e32e..c6ef88e5 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -172,7 +172,6 @@ public ResponseEntity> exportFilter(@PathVariable(" public ResponseEntity> getIdentifiablesCountByGroup(@RequestParam(value = "networkUuid") UUID networkUuid, @RequestParam(value = "variantId", required = false) String variantId, IdsByGroup idsByGroup) { - Logger.getLogger("export").info(() -> "test"); return ResponseEntity.ok() .contentType(MediaType.APPLICATION_JSON) .body(service.getIdentifiablesCountByGroup(idsByGroup, networkUuid, variantId)); From 26cdf851aba05a70f10ba447894d688768126ea0 Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 17:37:05 +0100 Subject: [PATCH 19/27] changelog drop criteria base tables --- .../changesets/changelog_20241202T163604Z.xml | 327 ++++++++++++++++++ 1 file changed, 327 insertions(+) create mode 100644 src/main/resources/db/changelog/changesets/changelog_20241202T163604Z.xml diff --git a/src/main/resources/db/changelog/changesets/changelog_20241202T163604Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241202T163604Z.xml new file mode 100644 index 00000000..a758469b --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20241202T163604Z.xml @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 8c12164350cd5c70eae14e0e33ac42f1833b0496 Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 17:44:35 +0100 Subject: [PATCH 20/27] add changelog to master file --- src/main/resources/db/changelog/db.changelog-master.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index baef517b..2216d928 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -52,3 +52,7 @@ databaseChangeLog: - include: file: changesets/changelog_20241105T114300Z.xml relativeToChangelogFile: true + - include: + file: changesets/changelog_20241202T163604Z.xml + relativeToChangelogFile: true + From 1d369605f68557f488df149fd1990077a2786b4a Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 18:08:32 +0100 Subject: [PATCH 21/27] remove unused class --- .../filter/server/utils/FieldsMatcher.java | 404 ------------------ 1 file changed, 404 deletions(-) diff --git a/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java b/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java index 10e02194..fa935f86 100644 --- a/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java +++ b/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java @@ -6,33 +6,10 @@ */ package org.gridsuite.filter.server.utils; -import lombok.SneakyThrows; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.tuple.MutableTriple; -import org.apache.commons.lang3.tuple.Triple; import org.hamcrest.Description; -import org.hamcrest.StringDescription; import org.hamcrest.TypeSafeDiagnosingMatcher; -import org.hamcrest.TypeSafeMatcher; -import org.hamcrest.collection.ArrayMatching; -import org.hamcrest.collection.IsIterableContainingInOrder; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; import java.util.Objects; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.TreeSet; import static java.lang.String.format; @@ -61,384 +38,3 @@ public void describeTo(Description description) { } } -public class FieldsMatcher extends TypeSafeDiagnosingMatcher { - - private static final String SEP = "/"; - - private static final Set> CHEAP_EQUAL_CLASSES = Set.of(String.class, Boolean.class, - Integer.class, Float.class, Double.class, Long.class, Short.class, - Enum.class); - - T expected; - private Map> pathBasedMatchersMap; - private Map, TypeSafeMatcher> classBasedMatcherMap; - - public FieldsMatcher(T expected, - Map> pathBasedMatchersMap, - Map, TypeSafeMatcher> classBasedMatcherMap) { - - this.expected = expected; - this.pathBasedMatchersMap = pathBasedMatchersMap; - this.classBasedMatcherMap = classBasedMatcherMap; - } - - public FieldsMatcher(T expected) { - this(expected, null, null); - } - - @SneakyThrows - @Override - protected boolean matchesSafely(T actual, Description mismatch) { - return matchesRecurs(null, expected, SEP, actual, mismatch); - } - - protected TypeSafeDiagnosingMatcher getSloppyMatcher(String path, Object expected) { - return null; - } - - protected TypeSafeDiagnosingMatcher> makeMapSloppyMatcher(Map expected, String path) { - return new TypeSafeDiagnosingMatcher<>() { - protected boolean matchesSafely(Map actual, Description mismatch) { - Set expectedKeySet = expected.keySet(); - Set actualKeySet = actual.keySet(); - Collection keysUnion = CollectionUtils.union(expectedKeySet, actualKeySet); - Collection intersection = CollectionUtils.intersection(expectedKeySet, actualKeySet); - int mismatchCount = keysUnion.size() - intersection.size(); - if (mismatchCount != 0) { - Set onlyExpected = new TreeSet<>(keysUnion); - onlyExpected.removeAll(actualKeySet); - Set onlyActual = new TreeSet<>(keysUnion); - onlyActual.removeAll(expectedKeySet); - // tell problematic keys - mismatch.appendText("unfullfilled").appendValue(onlyExpected) - .appendText(" unexpected").appendValue(onlyActual); - } - - for (U k : intersection) { - V expectedValue = expected.get(k); - V actualValue = actual.get(k); - - boolean valueMatch = matchesRecurs(null, expectedValue, "{" + k + "}", actualValue, mismatch); - if (!valueMatch) { - mismatchCount += 1; - } - } - - return mismatchCount == 0; - } - - public void describeTo(Description description) { - description.appendText("map without order on keys"); - } - }; - } - - protected TypeSafeDiagnosingMatcher> makeListSloppyMatcher(List expected, String path) { - return new TypeSafeDiagnosingMatcher<>() { - protected boolean matchesSafely(List actual, Description mismatch) { - int expectedSize = expected.size(); - int actualSize = actual.size(); - - SortedMap actualToExpectedIndices = new TreeMap<>(); - SortedMap expectedToActualIndices = new TreeMap<>(); - for (int i = 0; i < expectedSize; i++) { - U expectedElement = expected.get(i); - boolean valueMatch = false; - int j = i; - while (!valueMatch && j < actualSize) { - U actualElement = actual.get(j); - valueMatch = matchesRecurs(null, expectedElement, path, actualElement, Description.NONE); - if (!valueMatch) { - j++; - } else { - actualToExpectedIndices.put(j, i); - expectedToActualIndices.put(i, j); - } - } - } - - for (int j = 0; j < actualSize; j++) { - if (actualToExpectedIndices.containsKey(j)) { - continue; - } - - U actualElement = actual.get(j); - boolean valueMatch = false; - int i = j + 1; // j would have been in actualToExpectedIndices otherwise - while (!valueMatch && i < expectedSize) { - if (expectedToActualIndices.containsKey(i)) { - i++; - continue; - } - U expectedElement = expected.get(i); - valueMatch = matchesRecurs(null, expectedElement, path, actualElement, Description.NONE); - if (!valueMatch) { - i++; - } else { - actualToExpectedIndices.put(j, i); - expectedToActualIndices.put(i, j); - } - } - } - - int mismatchCount = tellMismatches(mismatch, actual, actualToExpectedIndices, expectedToActualIndices); - return mismatchCount == 0; - } - - private int tellMismatches(Description mismatch, List actual, - SortedMap actualToExpectedIndices, - SortedMap expectedToActualIndices) { - - int mismatchCount = Math.abs(expected.size() - actual.size()); - if (mismatchCount != 0) { - mismatch.appendText("difference in size : expected " + expected.size() + " actual " + actual.size() + " "); - } - - List> triples = new ArrayList<>(); - for (int i = 0; i < expected.size(); i++) { - Integer actualIndex = expectedToActualIndices.get(i); - if (actualIndex == null) { - mismatchCount += 1; - triples.add(MutableTriple.of(i, null, null)); - } else if (actualIndex == i) { - triples.add(MutableTriple.of(i, 0, 0)); - } else { - mismatchCount += 1; - int delta = i - actualIndex; - MutableTriple last = triples.isEmpty() ? null : triples.get(triples.size() - 1); - if (last == null || last.getMiddle() == null || last.getMiddle() != delta) { - triples.add(MutableTriple.of(i, delta, 1)); - } else { - last.setRight(last.getRight() + 1); - } - } - } - for (Triple t : triples) { - Integer delta = t.getMiddle(); - if (delta == null) { - mismatch.appendText("[" + t.getLeft() + "!]"); - } else if (delta != 0) { - int expectedIndex = t.getLeft(); - int runLength = t.getRight(); - int actualIndex = expectedIndex - delta; - mismatch.appendText("[" + expectedIndex + "->" + actualIndex + "]"); - if (runLength > 2) { - mismatch.appendText(" -- "); - } - if (runLength > 1) { - int lastExpectedIndex = expectedIndex + runLength - 1; - mismatch.appendText("[" + lastExpectedIndex + "->" + (lastExpectedIndex - delta) + "]"); - } - } - } - - for (int j = 0; j < actual.size(); j++) { - Integer expectedIndex = actualToExpectedIndices.get(j); - if (expectedIndex == null) { - mismatch.appendText("[!" + j + "]"); - mismatchCount += 1; - } - } - - return mismatchCount; - } - - public void describeTo(Description description) { - description.appendText("ordered"); - } - }; - } - - protected TypeSafeDiagnosingMatcher> makeCollectionSloppyMatcher(Collection expected, String path) { - return new TypeSafeDiagnosingMatcher<>() { - protected boolean matchesSafely(Collection actual, Description mismatch) { - int mismatchCount = Math.abs(expected.size() - actual.size()); - - LinkedList shrinkingActuals = new LinkedList<>(actual); - List unfulfilled = new ArrayList<>(); - for (U expectedElement : expected) { - ListIterator actualIterator = shrinkingActuals.listIterator(); - ListIterator foundIt = null; - while (foundIt == null && actualIterator.hasNext()) { - U actualElement = actualIterator.next(); - boolean valueMatch = matchesRecurs(null, expectedElement, "*", actualElement, Description.NONE); - if (valueMatch) { - foundIt = actualIterator; - actualIterator.remove(); - } - } - if (foundIt == null) { - unfulfilled.add(expectedElement); - } - } - if (mismatchCount + unfulfilled.size() + shrinkingActuals.size() > 0) { - mismatch.appendText("*"); - } - if (mismatchCount != 0) { - mismatch.appendText(" difference in size : expected ").appendValue(expected.size()) - .appendText(" actual ").appendValue(actual.size()); - } - if (!unfulfilled.isEmpty()) { - mismatch.appendText(" unfulfilled").appendValue(unfulfilled); - } - if (!shrinkingActuals.isEmpty()) { - mismatch.appendText(" unexpected").appendValue(shrinkingActuals); - } - mismatchCount += shrinkingActuals.size() + unfulfilled.size(); - return mismatchCount == 0; - } - - public void describeTo(Description description) { - description.appendText("collection"); - } - }; - } - - protected TypeSafeDiagnosingMatcher getSloppyMatcher(Class clazz, S expected, String path) { - if (CHEAP_EQUAL_CLASSES.contains(clazz)) { - return new EqualDiagnosingMatcher(expected); - } - - if (clazz == Map.class) { - //noinspection unchecked,rawtypes - return makeMapSloppyMatcher((Map) expected, path); - } - - if (List.class.isAssignableFrom(clazz)) { - //noinspection unchecked,rawtypes - return makeListSloppyMatcher((List) expected, path); - } - - if (Collection.class.isAssignableFrom(clazz)) { - //noinspection unchecked,rawtypes - return makeCollectionSloppyMatcher((Collection) expected, path); - } - - if (Iterable.class.isAssignableFrom(clazz)) { - //noinspection unchecked - return (TypeSafeDiagnosingMatcher) - new IsIterableContainingInOrder<>(ArrayMatching.asEqualMatchers(((Set) expected).toArray())); - } - return null; - } - - private static Boolean mitigates(TypeSafeDiagnosingMatcher mitigater, - T expected, String path, T actual, Description mismatch) { - - assert expected != actual; // implies at least one is NOT null - - if (mitigater != null && mitigater.matches(actual)) { - return true; - } else if (mitigater != null) { - mismatch.appendText(path + " "); - mitigater.describeMismatch(actual, mismatch); - return false; - } else if (expected == null) { - mismatch.appendText(path + " " + "was not null"); - return false; - } - - return null; - } - - private static List getFieldsUpTo(@Nonnull Class startClass, @Nullable Class exclusiveParent) { - List classFields = new ArrayList<>(); - addFieldsTo(startClass, exclusiveParent, classFields); - return classFields; - } - - private static void addFieldsTo(@Nonnull Class startClass, @Nullable Class exclusiveParent, List fields) { - List declaredField = Arrays.asList(startClass.getDeclaredFields()); - declaredField.forEach(f -> f.setAccessible(true)); - fields.addAll(declaredField); - Class parentClass = startClass.getSuperclass(); - - if (parentClass != null && !parentClass.equals(exclusiveParent)) { - addFieldsTo(parentClass, exclusiveParent, fields); - } - } - - protected boolean matchesRecurs(Class clazz, S expected, String path, S actual, Description mismatch) { - if (expected == actual) { - return true; - } - - TypeSafeDiagnosingMatcher mitigater = getSloppyMatcher(path, expected); - Boolean resolves = mitigates(mitigater, expected, path, actual, mismatch); - if (resolves != null) { - return resolves; - } - - Class expectedClass = clazz != null ? clazz : expected.getClass(); - mitigater = getSloppyMatcher(expectedClass, expected, path); - resolves = mitigates(mitigater, expected, path, actual, mismatch); - if (resolves != null) { - return resolves; - } - - if (!expectedClass.isInstance(actual)) { - if (actual == null) { - mismatch.appendText(path + " was null"); - } else { - mismatch.appendText(path + " was ") - .appendText(actual.getClass().getSimpleName()) - .appendText(" ") - .appendValue(actual); - } - return false; - } - - Description localDescription = new StringDescription(); - int mismatchCount = 0; - List fields = getFieldsUpTo(expectedClass, null); - for (Field field : fields) { - if (Modifier.isStatic(field.getModifiers())) { - continue; - } - - final Object subActual = uncheckedGet(field, actual); - final Object subExpected = uncheckedGet(field, expected); - String subPath = path + field.getName() + SEP; - - Class subClazz = field.getType(); - - boolean localMatch = matchesRecurs(subClazz, subExpected, subPath, subActual, localDescription); - if (!localMatch) { - mismatchCount += 1; - } - } - - boolean returnValue; - if (0 != mismatchCount) { - // localDescription should not be empty - returnValue = false; - } else if (fields.isEmpty()) { - // uh uh, actual != expect but have no field comparable : better to alert - mismatch.appendText(path + " can not compare non identical").appendValue(expected) - .appendText("and").appendValue(actual); - returnValue = false; - } else { - returnValue = true; - } - if (!returnValue) { - mismatch.appendText(localDescription.toString()); - } - - return returnValue; - } - - private static U uncheckedGet(Field field, Object object) { - try { - //noinspection unchecked - return (U) field.get(object); - } catch (ClassCastException e) { - throw e; - } catch (Exception e) { - throw new AssertionError(format("IllegalAccess, reading field '%s' from %s", field.getName(), object)); - } - } - - public void describeTo(Description description) { - description.appendText("acyclic fields matcher"); - } -} From 7426e9cf8763203861750f76f758c618afe86de6 Mon Sep 17 00:00:00 2001 From: basseche Date: Mon, 2 Dec 2024 18:14:39 +0100 Subject: [PATCH 22/27] remove unused class 2 --- .../filter/server/utils/FieldsMatcher.java | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java diff --git a/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java b/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java deleted file mode 100644 index fa935f86..00000000 --- a/src/test/java/org/gridsuite/filter/server/utils/FieldsMatcher.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2022, 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.utils; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeDiagnosingMatcher; - -import java.util.Objects; - -import static java.lang.String.format; - -/** - * @author Laurent Garnier - */ - -class EqualDiagnosingMatcher extends TypeSafeDiagnosingMatcher { - - private final U expected; - - EqualDiagnosingMatcher(U expected) { - this.expected = expected; - } - - protected boolean matchesSafely(U actual, Description mismatchDescription) { - boolean equals = Objects.equals(expected, actual); - if (!equals) { - mismatchDescription.appendText("was not " + expected); - } - return equals; - } - - public void describeTo(Description description) { - description.appendText("Objects.equals"); - } -} - From bdb0afc6a0955971dfd4274828f3353b4166635e Mon Sep 17 00:00:00 2001 From: basseche Date: Tue, 3 Dec 2024 11:27:56 +0100 Subject: [PATCH 23/27] improve tests and suppress warnings --- .../server/FilterEntityControllerTest.java | 93 +++++++------------ 1 file changed, 31 insertions(+), 62 deletions(-) diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 3a95ef8b..daa633b6 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -371,25 +371,40 @@ public void testExportFilters() throws Exception { params.add("variantId", VARIANT_ID_1); } - @Test - public void testGetIdentifiablesCount() throws Exception { - UUID filterId1 = UUID.randomUUID(); - UUID filterId2 = UUID.randomUUID(); - UUID filterId3 = UUID.randomUUID(); + private void createExpertLineRules(ArrayList rules, Set countries1, Set countries2, + Set nominalVoltage1, Set nominalVoltage2) { - ArrayList rules = new ArrayList<>(); EnumExpertRule country1Rule = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) - .values(new TreeSet<>(Set.of("FR"))).build(); + .values(countries1).build(); rules.add(country1Rule); EnumExpertRule country2Rule = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) - .values(new TreeSet<>(Set.of("FR"))).build(); + .values(countries2).build(); rules.add(country2Rule); NumberExpertRule voltageLevel1Rule1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) - .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(360., 400.))).build(); + .operator(OperatorType.BETWEEN).values(nominalVoltage1).build(); rules.add(voltageLevel1Rule1); - NumberExpertRule voltageLevel2Rule1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) - .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(356.25, 393.7))).build(); + + NumberExpertRule voltageLevel2Rule1; + if (nominalVoltage2.size() == 1) { + voltageLevel2Rule1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2).operator(OperatorType.EQUALS) + .value(nominalVoltage2.stream().findFirst().isPresent() ? nominalVoltage2.stream().findFirst().get() : null) + .build(); + } else { + voltageLevel2Rule1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2).operator(OperatorType.BETWEEN) + .values(nominalVoltage2).build(); + } rules.add(voltageLevel2Rule1); + } + + @Test + public void testGetIdentifiablesCount() throws Exception { + UUID filterId1 = UUID.randomUUID(); + UUID filterId2 = UUID.randomUUID(); + UUID filterId3 = UUID.randomUUID(); + + ArrayList rules = new ArrayList<>(); + createExpertLineRules(rules, new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of(360., 400.)), + new TreeSet<>(Set.of(356.25, 393.7))); CombinatorExpertRule parentRule = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); ExpertFilter expertFilter = new ExpertFilter(filterId1, new Date(), EquipmentType.LINE, parentRule); @@ -397,18 +412,8 @@ public void testGetIdentifiablesCount() throws Exception { checkExpertFilter(filterId1, expertFilter); ArrayList rules2 = new ArrayList<>(); - EnumExpertRule country1Rule2 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) - .values(new TreeSet<>(Set.of("FR"))).build(); - rules2.add(country1Rule2); - EnumExpertRule country2Rule2 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) - .values(new TreeSet<>(Set.of("FR"))).build(); - rules2.add(country2Rule2); - NumberExpertRule voltageLevel1Rule2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1).operator(OperatorType.BETWEEN) - .values(new TreeSet<>(Set.of(360., 400.))).build(); - rules2.add(voltageLevel1Rule2); - NumberExpertRule voltageLevel2Rule2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2).operator(OperatorType.BETWEEN) - .values(new TreeSet<>(Set.of(356.25, 393.7))).build(); - rules2.add(voltageLevel2Rule2); + createExpertLineRules(rules2, new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of(360., 400.)), + new TreeSet<>(Set.of(356.25, 393.7))); CombinatorExpertRule parentRule2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); ExpertFilter expertFilter2 = new ExpertFilter(filterId2, new Date(), EquipmentType.LINE, parentRule2); @@ -422,9 +427,6 @@ public void testGetIdentifiablesCount() throws Exception { EnumExpertRule country2Rule3 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) .values(new TreeSet<>(Set.of("FR", "IT"))).build(); rules3.add(country2Rule3); - NumberExpertRule voltageLevel1Rule3 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1).operator(OperatorType.BETWEEN) - .values(new TreeSet<>(Set.of(380., 420.))).build(); - rules3.add(voltageLevel1Rule3); CombinatorExpertRule parentRule3 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules3).build(); ExpertFilter expertFilter3 = new ExpertFilter(filterId3, new Date(), EquipmentType.HVDC_LINE, parentRule3); @@ -1115,36 +1117,14 @@ public void testLineFiltersCrudInBatch() throws Exception { UUID filterId1 = UUID.randomUUID(); Date date = new Date(); ArrayList rules = new ArrayList<>(); - EnumExpertRule country1Filter1 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) - .values(COUNTRIES1).build(); - rules.add(country1Filter1); - EnumExpertRule country2Filter1 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) - .values(COUNTRIES2).build(); - rules.add(country2Filter1); - NumberExpertRule nominalVoltage1Filter1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) - .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(5., 8.))).build(); - rules.add(nominalVoltage1Filter1); - NumberExpertRule nominalVoltage2Filter1 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) - .operator(OperatorType.EQUALS).value(6.).build(); - rules.add(nominalVoltage2Filter1); + createExpertLineRules(rules, COUNTRIES1, COUNTRIES2, new TreeSet<>(Set.of(5., 8.)), new TreeSet<>(Set.of(6.))); CombinatorExpertRule parentRule = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); ExpertFilter expertFilter1 = new ExpertFilter(filterId1, date, EquipmentType.LINE, parentRule); UUID filterId2 = UUID.randomUUID(); ArrayList rules2 = new ArrayList<>(); - EnumExpertRule country1Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) - .values(COUNTRIES1).build(); - rules2.add(country1Filter2); - EnumExpertRule country2Filter2 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) - .values(COUNTRIES2).build(); - rules2.add(country2Filter2); - NumberExpertRule nominalVoltage1Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) - .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(4., 9.))).build(); - rules2.add(nominalVoltage1Filter2); - NumberExpertRule nominalVoltage2Filter2 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) - .operator(OperatorType.EQUALS).value(5.).build(); - rules2.add(nominalVoltage2Filter2); + createExpertLineRules(rules2, COUNTRIES1, COUNTRIES2, new TreeSet<>(Set.of(4., 9.)), new TreeSet<>(Set.of(5.))); CombinatorExpertRule parentRule2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); ExpertFilter expertFilter2 = new ExpertFilter(filterId2, date, EquipmentType.LINE, parentRule2); @@ -1176,18 +1156,7 @@ public void testLineFiltersCrudInBatch() throws Exception { // --- modify filters in batch --- // ArrayList rules3 = new ArrayList<>(); - EnumExpertRule country1Filter3 = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) - .values(COUNTRIES1).build(); - rules3.add(country1Filter3); - EnumExpertRule country2Filter3 = EnumExpertRule.builder().field(FieldType.COUNTRY_2).operator(OperatorType.IN) - .values(COUNTRIES2).build(); - rules3.add(country2Filter3); - NumberExpertRule nominalVoltage1Filter3 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_1) - .operator(OperatorType.BETWEEN).values(new TreeSet<>(Set.of(3., 10.))).build(); - rules3.add(nominalVoltage1Filter3); - NumberExpertRule nominalVoltage2Filter3 = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2) - .operator(OperatorType.EQUALS).value(4.).build(); - rules3.add(nominalVoltage2Filter3); + createExpertLineRules(rules3, COUNTRIES1, COUNTRIES2, new TreeSet<>(Set.of(3., 10.)), new TreeSet<>(Set.of(4.))); CombinatorExpertRule parentRule3 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules3).build(); ExpertFilter lineExpertFilter = new ExpertFilter(null, date, EquipmentType.LINE, parentRule3); From 6c21a33f22024f425d02b99896f86e566c423ea9 Mon Sep 17 00:00:00 2001 From: basseche Date: Tue, 3 Dec 2024 15:37:33 +0100 Subject: [PATCH 24/27] add tests --- .../server/FilterEntityControllerTest.java | 108 ++++++++++++++++-- 1 file changed, 101 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index daa633b6..f87b1f57 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -46,6 +46,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.cloud.stream.binder.test.OutputDestination; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; +import org.springframework.messaging.Message; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -107,6 +108,7 @@ public class FilterEntityControllerTest { private static final UUID NETWORK_UUID_6 = UUID.fromString("11111111-7977-4592-2222-88027e4254e8"); private static final UUID NETWORK_NOT_FOUND_UUID = UUID.fromString("88888888-7977-3333-9999-88027e4254e7"); private static final String VARIANT_ID_1 = "variant_1"; + private static final String USER_ID_HEADER = "userId"; private String elementUpdateDestination = "element.update"; @@ -264,6 +266,81 @@ public void testIdentifierListFilter() throws Exception { checkIdentifierListFilterExportAndMetadata(substationFilterId, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"},{\"id\":\"P2\",\"type\":\"SUBSTATION\"}]\n", EquipmentType.SUBSTATION); } + private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { + Message message = output.receive(TIMEOUT, elementUpdateDestination); + assertEquals(elementUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); + assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); + } + + private void updateFilter(UUID filterId, AbstractFilter filter, String userId) throws Exception { + mvc.perform(put(URL_TEMPLATE + "/" + filterId) + .content(objectMapper.writeValueAsString(filter)) + .contentType(APPLICATION_JSON) + .header(USER_ID_HEADER, userId)) + .andExpect(status().isOk()); + checkElementUpdatedMessageSent(filterId, userId); + } + + private UUID duplicateFilter(UUID filterId) throws Exception { + String response = mvc.perform(post(URL_TEMPLATE).param("duplicateFrom", filterId.toString())) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + return objectMapper.readValue(response, UUID.class); + } + + @Test + public void testLineFilterCrud() throws Exception { + UUID filterId1 = UUID.fromString("99999999-e0c4-413a-8e3e-78e9027d300f"); + List rules = new ArrayList<>(); + createExpertLineRules(rules, COUNTRIES1, COUNTRIES2, new TreeSet<>(Set.of(5., 8.)), new TreeSet<>(Set.of(6.))); + CombinatorExpertRule combinator = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules).build(); + ExpertFilter lineFilter = new ExpertFilter(null, new Date(), EquipmentType.LINE, combinator); + + // --- insert filter --- // + insertFilter(filterId1, lineFilter); + + // check the inserted filter + lineFilter.setId(filterId1); + checkExpertFilter(filterId1, lineFilter); + + // --- duplicate filter -- // + UUID newFilterId1 = duplicateFilter(filterId1); + + // check the duplicated filter whether it is matched to the original + lineFilter.setId(newFilterId1); + checkExpertFilter(newFilterId1, lineFilter); + + // --- modify filter --- // + List rules2 = new ArrayList<>(); + createExpertLineRules(rules2, COUNTRIES2, COUNTRIES1, new TreeSet<>(Set.of(4., 9.)), new TreeSet<>(Set.of(5.))); + CombinatorExpertRule combinator2 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules2).build(); + ExpertFilter lineFilter2 = new ExpertFilter(null, new Date(), EquipmentType.LINE, combinator2); + updateFilter(filterId1, lineFilter2, "userId"); + + // check the modified filter + lineFilter2.setId(filterId1); + checkExpertFilter(filterId1, lineFilter2); + + // --- modify filter with equipment type changed --- // + List rules3 = new ArrayList<>(); + createExpertRules(rules3, new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of(50.))); + CombinatorExpertRule combinator3 = CombinatorExpertRule.builder().combinator(CombinatorType.AND).rules(rules3).build(); + ExpertFilter generatorFilter = new ExpertFilter(null, new Date(), EquipmentType.GENERATOR, combinator3); + updateFilter(filterId1, generatorFilter, "userId"); + + // check the modified filter + generatorFilter.setId(filterId1); + checkExpertFilter(filterId1, generatorFilter); + + // --- delete filters --- // + deleteFilter(filterId1); + deleteFilter(newFilterId1); + + // check empty after delete all + List allFilters = getAllFilters(); + Assertions.assertThat(allFilters).isEmpty(); + } + @Test public void testGetFiltersByIds() throws Exception { UUID filterId3 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300c"); @@ -371,7 +448,24 @@ public void testExportFilters() throws Exception { params.add("variantId", VARIANT_ID_1); } - private void createExpertLineRules(ArrayList rules, Set countries1, Set countries2, + private void createExpertRules(List rules, Set countries, Set nominalVoltages) { + EnumExpertRule country1Rule = EnumExpertRule.builder().field(FieldType.COUNTRY).operator(OperatorType.IN) + .values(countries).build(); + rules.add(country1Rule); + + NumberExpertRule nominalVoltage2Rule; + if (nominalVoltages.size() == 1) { + nominalVoltage2Rule = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE).operator(OperatorType.EQUALS) + .value(nominalVoltages.stream().findFirst().isPresent() ? nominalVoltages.stream().findFirst().get() : null) + .build(); + } else { + nominalVoltage2Rule = NumberExpertRule.builder().field(FieldType.NOMINAL_VOLTAGE_2).operator(OperatorType.BETWEEN) + .values(nominalVoltages).build(); + } + rules.add(nominalVoltage2Rule); + } + + private void createExpertLineRules(List rules, Set countries1, Set countries2, Set nominalVoltage1, Set nominalVoltage2) { EnumExpertRule country1Rule = EnumExpertRule.builder().field(FieldType.COUNTRY_1).operator(OperatorType.IN) @@ -380,20 +474,20 @@ private void createExpertLineRules(ArrayList rules, Set Date: Tue, 3 Dec 2024 15:43:29 +0100 Subject: [PATCH 25/27] Trigger coverage Signed-off-by: Etienne Homer --- src/main/java/org/gridsuite/filter/server/FilterController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index c6ef88e5..fe54ce9f 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -139,6 +139,7 @@ public ResponseEntity deleteFilter(@PathVariable("id") UUID id) { @Operation(summary = "delete the filters") @ApiResponse(responseCode = "200", description = "The filters have been deleted") public ResponseEntity deleteFilters(@RequestBody List ids) { + Logger.getLogger("export").info(() -> "test"); service.deleteFilters(ids); return ResponseEntity.ok().build(); } From a8c110d1a2a52a5a8f18a3701eba722bd84b0ce3 Mon Sep 17 00:00:00 2001 From: basseche Date: Tue, 3 Dec 2024 16:36:08 +0100 Subject: [PATCH 26/27] add tests --- .../server/FilterEntityControllerTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index f87b1f57..80e0a6b4 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -25,6 +25,8 @@ import org.gridsuite.filter.criteriafilter.*; import org.gridsuite.filter.expertfilter.ExpertFilter; import org.gridsuite.filter.expertfilter.expertrule.*; +import org.gridsuite.filter.identifierlistfilter.FilterEquipments; +import org.gridsuite.filter.identifierlistfilter.IdentifiableAttributes; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter; import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes; import org.gridsuite.filter.server.dto.FilterAttributes; @@ -50,6 +52,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -385,6 +388,41 @@ public void testGetFiltersByIds() throws Exception { checkExpertFilter(filterId4, lineFilter2); } + private void checkFilterEquipments(List filterEquipments1, List filterEquipments2) { + assertEquals(CollectionUtils.isEmpty(filterEquipments1), CollectionUtils.isEmpty(filterEquipments2)); + assertEquals(filterEquipments1.size(), filterEquipments2.size()); + + filterEquipments1.sort(Comparator.comparing(filterEquipments -> filterEquipments.getFilterId().toString())); + filterEquipments2.sort(Comparator.comparing(filterEquipments -> filterEquipments.getFilterId().toString())); + + for (int index = 0; index < filterEquipments1.size(); index++) { + FilterEquipments filterEquipment1 = filterEquipments1.get(index); + FilterEquipments filterEquipment2 = filterEquipments2.get(index); + assertEquals(filterEquipment1.getFilterId(), filterEquipment2.getFilterId()); + assertEquals(CollectionUtils.isEmpty(filterEquipment1.getNotFoundEquipments()), CollectionUtils.isEmpty(filterEquipment2.getNotFoundEquipments())); + if (filterEquipment1.getNotFoundEquipments() != null) { + assertTrue(filterEquipment1.getNotFoundEquipments().containsAll(filterEquipment2.getNotFoundEquipments())); + checkIdentifiableAttributes(new ArrayList<>(filterEquipment1.getIdentifiableAttributes()), new ArrayList<>(filterEquipment2.getIdentifiableAttributes())); + } + } + } + + private void checkIdentifiableAttributes(List identifiableAttributes1, List identifiableAttributes2) { + assertEquals(CollectionUtils.isEmpty(identifiableAttributes1), CollectionUtils.isEmpty(identifiableAttributes2)); + assertEquals(identifiableAttributes1.size(), identifiableAttributes2.size()); + + identifiableAttributes1.sort(Comparator.comparing(IdentifiableAttributes::getId)); + identifiableAttributes2.sort(Comparator.comparing(IdentifiableAttributes::getId)); + + for (int index = 0; index < identifiableAttributes1.size(); index++) { + IdentifiableAttributes identifiableAttribute1 = identifiableAttributes1.get(index); + IdentifiableAttributes identifiableAttribute2 = identifiableAttributes2.get(index); + assertEquals(identifiableAttribute1.getId(), identifiableAttribute2.getId()); + assertEquals(identifiableAttribute1.getType(), identifiableAttribute2.getType()); + assertEquals(identifiableAttribute1.getDistributionKey(), identifiableAttribute2.getDistributionKey()); + } + } + @Test public void testExportFilters() throws Exception { UUID filterId = UUID.randomUUID(); @@ -446,6 +484,37 @@ public void testExportFilters() throws Exception { params.addAll("ids", values); params.add("networkUuid", NETWORK_UUID.toString()); params.add("variantId", VARIANT_ID_1); + + List filterEquipments = objectMapper.readValue( + mvc.perform(get(URL_TEMPLATE + "/export").params(params) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(), + new TypeReference<>() { + }); + + IdentifiableAttributes identifiableAttributes = new IdentifiableAttributes("GEN", IdentifiableType.GENERATOR, 1.0); + IdentifiableAttributes identifiableAttributes4 = new IdentifiableAttributes("NHV1_NHV2_1", IdentifiableType.LINE, null); + + FilterEquipments filterEquipment1 = FilterEquipments.builder() + .filterId(filterId) + .identifiableAttributes(List.of(identifiableAttributes)) + .notFoundEquipments(List.of("wrongId", "wrongId2")) + .build(); + + FilterEquipments filterEquipment2 = FilterEquipments.builder() + .filterId(filterId2) + .identifiableAttributes(List.of(identifiableAttributes4)) + .build(); + + FilterEquipments filterEquipment3 = FilterEquipments.builder() + .filterId(filterId3) + .identifiableAttributes(List.of(identifiableAttributes4)) + .build(); + + assertEquals(3, filterEquipments.size()); + List expected = new ArrayList<>(List.of(filterEquipment1, filterEquipment2, filterEquipment3)); + checkFilterEquipments(expected, filterEquipments); } private void createExpertRules(List rules, Set countries, Set nominalVoltages) { From a29e1491851d4f205705340527ca6e2ce6898853 Mon Sep 17 00:00:00 2001 From: Etienne Homer Date: Tue, 3 Dec 2024 16:54:15 +0100 Subject: [PATCH 27/27] Clean Signed-off-by: Etienne Homer --- src/main/java/org/gridsuite/filter/server/FilterController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/gridsuite/filter/server/FilterController.java b/src/main/java/org/gridsuite/filter/server/FilterController.java index fe54ce9f..c6ef88e5 100644 --- a/src/main/java/org/gridsuite/filter/server/FilterController.java +++ b/src/main/java/org/gridsuite/filter/server/FilterController.java @@ -139,7 +139,6 @@ public ResponseEntity deleteFilter(@PathVariable("id") UUID id) { @Operation(summary = "delete the filters") @ApiResponse(responseCode = "200", description = "The filters have been deleted") public ResponseEntity deleteFilters(@RequestBody List ids) { - Logger.getLogger("export").info(() -> "test"); service.deleteFilters(ids); return ResponseEntity.ok().build(); }