Skip to content

Commit bc2dbc5

Browse files
authored
Rework global filter model (#51)
Signed-off-by: Hugo Marcellin <[email protected]>
1 parent 27ae1f8 commit bc2dbc5

File tree

9 files changed

+176
-59
lines changed

9 files changed

+176
-59
lines changed

src/main/java/org/gridsuite/studyconfig/server/dto/GlobalFilterInfos.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,28 @@
1717
@Schema(name = "GlobalFilterDto", description = "Global filter configuration")
1818
public record GlobalFilterInfos(
1919

20-
@Schema(description = "Global filter UUID")
21-
UUID uuid,
20+
@Schema(description = "Global filter UUID")
21+
UUID id,
2222

23-
@NotNull(message = "Filter ID is mandatory")
24-
@Schema(description = "Filter ID")
25-
UUID filterId,
23+
@Schema(description = "Generic filter ID")
24+
UUID uuid,
2625

27-
@NotNull(message = "Filter name is mandatory")
28-
@Schema(description = "Filter name")
29-
String name
30-
) { }
26+
@NotNull(message = "Filter type is mandatory")
27+
@Schema(description = "Filter type")
28+
String filterType,
29+
30+
@NotNull(message = "Filter label is mandatory")
31+
@Schema(description = "Filter label")
32+
String label,
33+
34+
@Schema(description = "Was filter recently applied")
35+
boolean recent,
36+
37+
@Schema(description = "Generic filter related equipment type")
38+
String equipmentType,
39+
40+
@Schema(description = "Generic filter path")
41+
String path
42+
43+
) {
44+
}

src/main/java/org/gridsuite/studyconfig/server/entities/GlobalFilterEntity.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,25 @@ public class GlobalFilterEntity {
2525

2626
@Id
2727
@GeneratedValue(strategy = GenerationType.AUTO)
28+
@Column(name = "id")
29+
private UUID id;
30+
31+
@Column(name = "filter_type", nullable = false)
32+
private String filterType;
33+
34+
@Column(name = "label", nullable = false)
35+
private String label;
36+
37+
@Column(name = "recent")
38+
private boolean recent;
39+
2840
@Column(name = "uuid")
2941
private UUID uuid;
3042

31-
@Column(name = "filter_id", nullable = false)
32-
private UUID filterId;
43+
@Column(name = "equipment_type")
44+
private String equipmentType;
3345

34-
@Column(name = "name", nullable = false, columnDefinition = "varchar(255)")
35-
private String name;
46+
@Column(name = "path")
47+
private String path;
3648

3749
}

src/main/java/org/gridsuite/studyconfig/server/mapper/SpreadsheetConfigMapper.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,24 @@ public static ColumnEntity toColumnEntity(ColumnInfos dto) {
9494

9595
public static GlobalFilterInfos toGlobalFilterDto(GlobalFilterEntity entity) {
9696
return new GlobalFilterInfos(
97+
entity.getId(),
9798
entity.getUuid(),
98-
entity.getFilterId(),
99-
entity.getName()
99+
entity.getFilterType(),
100+
entity.getLabel(),
101+
entity.isRecent(),
102+
entity.getEquipmentType(),
103+
entity.getPath()
100104
);
101105
}
102106

103107
public static GlobalFilterEntity toGlobalFilterEntity(GlobalFilterInfos dto) {
104108
return GlobalFilterEntity.builder()
105-
.filterId(dto.filterId())
106-
.name(dto.name())
109+
.filterType(dto.filterType())
110+
.uuid(dto.uuid())
111+
.label(dto.label())
112+
.recent(dto.recent())
113+
.equipmentType(dto.equipmentType())
114+
.path(dto.path())
107115
.build();
108116
}
109117
}

src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ private SpreadsheetConfigEntity duplicateSpreadsheetConfigEntity(UUID id) {
8383
if (entity.getGlobalFilters() != null) {
8484
duplicate.setGlobalFilters(entity.getGlobalFilters().stream()
8585
.map(globalFilter -> GlobalFilterEntity.builder()
86-
.filterId(globalFilter.getFilterId())
87-
.name(globalFilter.getName())
86+
.filterType(globalFilter.getFilterType())
87+
.label(globalFilter.getLabel())
88+
.uuid(globalFilter.getUuid())
89+
.equipmentType(globalFilter.getEquipmentType())
90+
.recent(globalFilter.isRecent())
91+
.path(globalFilter.getPath())
8892
.build())
8993
.toList());
9094
}
@@ -277,8 +281,12 @@ public UUID duplicateSpreadsheetConfigCollection(UUID id) {
277281
.toList());
278282
configDuplicate.setGlobalFilters(config.getGlobalFilters().stream()
279283
.map(globalFilter -> GlobalFilterEntity.builder()
280-
.filterId(globalFilter.getFilterId())
281-
.name(globalFilter.getName())
284+
.filterType(globalFilter.getFilterType())
285+
.label(globalFilter.getLabel())
286+
.uuid(globalFilter.getUuid())
287+
.equipmentType(globalFilter.getEquipmentType())
288+
.recent(globalFilter.isRecent())
289+
.path(globalFilter.getPath())
282290
.build())
283291
.toList());
284292
return configDuplicate;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
4+
xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
6+
<changeSet author="marcelinhug" id="rename-uuid-to-id">
7+
<dropPrimaryKey tableName="spreadsheet_global_filter" constraintName="spreadsheet_global_filterPK"/>
8+
<renameColumn tableName="spreadsheet_global_filter"
9+
oldColumnName="uuid"
10+
newColumnName="id"
11+
columnDataType="uuid"/>
12+
<addPrimaryKey tableName="spreadsheet_global_filter"
13+
columnNames="id"
14+
constraintName="spreadsheet_global_filterPK"/>
15+
</changeSet>
16+
<changeSet author="marcelinhug" id="rename-name-to-label">
17+
<renameColumn tableName="spreadsheet_global_filter"
18+
oldColumnName="name"
19+
newColumnName="label"
20+
columnDataType="varchar(255)"/>
21+
</changeSet>
22+
<changeSet author="marcelinhug" id="rename-filterId-to-filterUuid">
23+
<renameColumn tableName="spreadsheet_global_filter"
24+
oldColumnName="filter_id"
25+
newColumnName="uuid"
26+
columnDataType="uuid"/>
27+
<dropNotNullConstraint
28+
tableName="spreadsheet_global_filter"
29+
columnName="uuid"
30+
columnDataType="uuid"/>
31+
</changeSet>
32+
<changeSet author="marcelinhug" id="add-equipment-type">
33+
<addColumn tableName="spreadsheet_global_filter">
34+
<column name="equipment_type" type="varchar(255)"/>
35+
</addColumn>
36+
</changeSet>
37+
<changeSet author="marcelinhug" id="add-filter-type">
38+
<addColumn tableName="spreadsheet_global_filter">
39+
<column name="filter_type" type="varchar(255)"/>
40+
</addColumn>
41+
</changeSet>
42+
<changeSet author="marcelinhug" id="add-path">
43+
<addColumn tableName="spreadsheet_global_filter">
44+
<column name="path" type="varchar(255)"/>
45+
</addColumn>
46+
</changeSet>
47+
<changeSet author="marcelinhug" id="add-recent-default-false">
48+
<addColumn tableName="spreadsheet_global_filter">
49+
<column name="recent" type="boolean" defaultValueBoolean="false">
50+
<constraints nullable="false"/>
51+
</column>
52+
</addColumn>
53+
</changeSet>
54+
<!-- Set default values for existing rows -->
55+
<changeSet author="marcelinhug" id="update-existing-filter-type">
56+
<update tableName="spreadsheet_global_filter">
57+
<column name="filter_type" value="genericFilter"/>
58+
<where>filter_type IS NULL</where>
59+
</update>
60+
</changeSet>
61+
<changeSet author="marcelinhug" id="init-equipment-type-from-sheet-type">
62+
<sql>
63+
UPDATE spreadsheet_global_filter
64+
SET equipment_type = (
65+
SELECT sheet_type
66+
FROM spreadsheet_config
67+
WHERE spreadsheet_config.id = spreadsheet_global_filter.spreadsheet_config_id
68+
)
69+
WHERE equipment_type IS NULL;
70+
</sql>
71+
</changeSet>
72+
</databaseChangeLog>

src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ databaseChangeLog:
4444
- include:
4545
file: changesets/changelog_20250522T225500Z.xml
4646
relativeToChangelogFile: true
47+
- include:
48+
file: changesets/changelog_20250519T134047Z.xml
49+
relativeToChangelogFile: true

src/test/java/org/gridsuite/studyconfig/server/DtoConverterTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ void testConversionToDtoOfSpreadsheetConfig() {
5050
))
5151
.globalFilters(Arrays.asList(
5252
GlobalFilterEntity.builder()
53-
.filterId(UUID.randomUUID())
54-
.name("GlobalFilter1")
53+
.uuid(UUID.randomUUID())
54+
.label("GlobalFilter1")
5555
.build(),
5656
GlobalFilterEntity.builder()
57-
.filterId(UUID.randomUUID())
58-
.name("GlobalFilter2")
57+
.uuid(UUID.randomUUID())
58+
.label("GlobalFilter2")
5959
.build()
6060
))
6161
.build();
@@ -84,11 +84,11 @@ void testConversionToDtoOfSpreadsheetConfig() {
8484
assertThat(d.columns().get(1).filterValue()).isNull();
8585
// Global filters assertions
8686
assertThat(d.globalFilters()).hasSize(2);
87-
assertThat(d.globalFilters().get(0).filterId()).isNotNull();
88-
assertThat(d.globalFilters().get(0).name()).isEqualTo("GlobalFilter1");
87+
assertThat(d.globalFilters().get(0).uuid()).isNotNull();
88+
assertThat(d.globalFilters().get(0).label()).isEqualTo("GlobalFilter1");
8989

90-
assertThat(d.globalFilters().get(1).filterId()).isNotNull();
91-
assertThat(d.globalFilters().get(1).name()).isEqualTo("GlobalFilter2");
90+
assertThat(d.globalFilters().get(1).uuid()).isNotNull();
91+
assertThat(d.globalFilters().get(1).label()).isEqualTo("GlobalFilter2");
9292
});
9393
}
9494

@@ -107,7 +107,7 @@ void testConversionToEntityOfSpreadsheetConfig() {
107107
null, null, null, null)
108108
),
109109
List.of(
110-
new GlobalFilterInfos(null, filterId, "GlobalFilter1")
110+
new GlobalFilterInfos(null, filterId, "country", "GlobalFilter1", false, null, null)
111111
)
112112
);
113113

@@ -141,8 +141,8 @@ void testConversionToEntityOfSpreadsheetConfig() {
141141

142142
// Global filter assertions
143143
assertThat(e.getGlobalFilters()).hasSize(1);
144-
assertThat(e.getGlobalFilters().get(0).getFilterId()).isEqualTo(filterId);
145-
assertThat(e.getGlobalFilters().get(0).getName()).isEqualTo("GlobalFilter1");
144+
assertThat(e.getGlobalFilters().get(0).getUuid()).isEqualTo(filterId);
145+
assertThat(e.getGlobalFilters().get(0).getLabel()).isEqualTo("GlobalFilter1");
146146
});
147147
}
148148
}
@@ -239,35 +239,35 @@ void testConversionToDtoOfGlobalFilter() {
239239
UUID uuid = UUID.randomUUID();
240240
UUID filterId = UUID.randomUUID();
241241
GlobalFilterEntity entity = GlobalFilterEntity.builder()
242-
.uuid(uuid)
243-
.filterId(filterId)
244-
.name("TestGlobalFilter")
242+
.id(uuid)
243+
.uuid(filterId)
244+
.label("TestGlobalFilter")
245245
.build();
246246

247247
GlobalFilterInfos dto = SpreadsheetConfigMapper.toGlobalFilterDto(entity);
248248

249249
assertThat(dto)
250250
.as("DTO conversion result")
251251
.satisfies(d -> {
252-
assertThat(d.uuid()).isEqualTo(uuid);
253-
assertThat(d.filterId()).isEqualTo(filterId);
254-
assertThat(d.name()).isEqualTo("TestGlobalFilter");
252+
assertThat(d.id()).isEqualTo(uuid);
253+
assertThat(d.uuid()).isEqualTo(filterId);
254+
assertThat(d.label()).isEqualTo("TestGlobalFilter");
255255
});
256256
}
257257

258258
@Test
259259
void testConversionToEntityOfGlobalFilter() {
260260
UUID uuid = UUID.randomUUID();
261261
UUID filterId = UUID.randomUUID();
262-
GlobalFilterInfos dto = new GlobalFilterInfos(uuid, filterId, "TestGlobalFilter");
262+
GlobalFilterInfos dto = new GlobalFilterInfos(uuid, filterId, "country", "TestGlobalFilter", false, null, null);
263263

264264
GlobalFilterEntity entity = SpreadsheetConfigMapper.toGlobalFilterEntity(dto);
265265

266266
assertThat(entity)
267267
.as("Entity conversion result")
268268
.satisfies(e -> {
269-
assertThat(e.getFilterId()).isEqualTo(filterId);
270-
assertThat(e.getName()).isEqualTo("TestGlobalFilter");
269+
assertThat(e.getUuid()).isEqualTo(filterId);
270+
assertThat(e.getLabel()).isEqualTo("TestGlobalFilter");
271271
});
272272
}
273273
}

src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigCollectionIntegrationTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithFilters() {
425425
);
426426

427427
List<GlobalFilterInfos> globalFiltersConfig1 = Arrays.asList(
428-
new GlobalFilterInfos(null, UUID.randomUUID(), "Global Filter 1"),
429-
new GlobalFilterInfos(null, UUID.randomUUID(), "Global Filter 2")
428+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Global Filter 1", false, null, null),
429+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Global Filter 2", false, null, null)
430430
);
431431

432432
List<ColumnInfos> columnsConfig2 = Arrays.asList(
@@ -439,7 +439,7 @@ private List<SpreadsheetConfigInfos> createSpreadsheetConfigsWithFilters() {
439439
);
440440

441441
List<GlobalFilterInfos> globalFiltersConfig2 = List.of(
442-
new GlobalFilterInfos(null, UUID.randomUUID(), "Another Global Filter")
442+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Another Global Filter", false, null, null)
443443
);
444444

445445
return List.of(
@@ -472,9 +472,9 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
472472
);
473473

474474
List<GlobalFilterInfos> globalFiltersConfig1 = Arrays.asList(
475-
new GlobalFilterInfos(null, UUID.randomUUID(), "Updated Filter 1"),
476-
new GlobalFilterInfos(null, UUID.randomUUID(), "Updated Filter 2"),
477-
new GlobalFilterInfos(null, UUID.randomUUID(), "Updated Filter 3")
475+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Updated Filter 1", false, null, null),
476+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Updated Filter 2", false, null, null),
477+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Updated Filter 3", false, null, null)
478478
);
479479

480480
List<ColumnInfos> columnsConfig2 = Arrays.asList(
@@ -485,7 +485,7 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
485485
);
486486

487487
List<GlobalFilterInfos> globalFiltersConfig2 = List.of(
488-
new GlobalFilterInfos(null, UUID.randomUUID(), "Updated Other Filter")
488+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Updated Other Filter", false, null, null)
489489
);
490490

491491
List<ColumnInfos> columnsConfig3 = Arrays.asList(
@@ -496,7 +496,7 @@ private List<SpreadsheetConfigInfos> createUpdatedSpreadsheetConfigsWithFilters(
496496
);
497497

498498
List<GlobalFilterInfos> globalFiltersConfig3 = List.of(
499-
new GlobalFilterInfos(null, UUID.randomUUID(), "Third Config Filter")
499+
new GlobalFilterInfos(null, UUID.randomUUID(), "country", "Third Config Filter", false, null, null)
500500
);
501501

502502
return List.of(

0 commit comments

Comments
 (0)