Skip to content

Commit 0c7888e

Browse files
authored
Persist columns and global filters in spreadsheets (#47)
Signed-off-by: achour94 <[email protected]>
1 parent be138c0 commit 0c7888e

14 files changed

+679
-60
lines changed

src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import lombok.RequiredArgsConstructor;
1717
import org.gridsuite.studyconfig.server.StudyConfigApi;
1818
import org.gridsuite.studyconfig.server.dto.ColumnInfos;
19+
import org.gridsuite.studyconfig.server.dto.GlobalFilterInfos;
1920
import org.gridsuite.studyconfig.server.dto.MetadataInfos;
2021
import org.gridsuite.studyconfig.server.dto.SpreadsheetConfigInfos;
2122
import org.gridsuite.studyconfig.server.service.SpreadsheetConfigService;
@@ -178,4 +179,16 @@ public ResponseEntity<Void> reorderColumns(
178179
return ResponseEntity.noContent().build();
179180
}
180181

182+
@PostMapping("/{id}/global-filters")
183+
@Operation(summary = "Set global filters",
184+
description = "Replaces all existing global filters with the provided list for a spreadsheet configuration")
185+
@ApiResponse(responseCode = "204", description = "Global filters set successfully")
186+
@ApiResponse(responseCode = "404", description = "Spreadsheet configuration not found")
187+
public ResponseEntity<Void> setGlobalFiltersForSpreadsheetConfig(
188+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
189+
@Valid @RequestBody List<GlobalFilterInfos> filters) {
190+
spreadsheetConfigService.setGlobalFiltersForSpreadsheetConfig(id, filters);
191+
return ResponseEntity.noContent().build();
192+
}
193+
181194
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,17 @@ public record ColumnInfos(
3939
String dependencies,
4040

4141
@Schema(description = "Column id")
42-
String id
42+
String id,
43+
44+
@Schema(description = "Filter data type")
45+
String filterDataType,
46+
47+
@Schema(description = "Filter type")
48+
String filterType,
49+
50+
@Schema(description = "Filter value")
51+
String filterValue,
52+
53+
@Schema(description = "Filter tolerance for numeric comparisons")
54+
Double filterTolerance
4355
) { }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.studyconfig.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import jakarta.validation.constraints.NotNull;
11+
12+
import java.util.UUID;
13+
14+
/**
15+
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
16+
*/
17+
@Schema(name = "GlobalFilterDto", description = "Global filter configuration")
18+
public record GlobalFilterInfos(
19+
20+
@Schema(description = "Global filter UUID")
21+
UUID uuid,
22+
23+
@NotNull(message = "Filter ID is mandatory")
24+
@Schema(description = "Filter ID")
25+
UUID filterId,
26+
27+
@NotNull(message = "Filter name is mandatory")
28+
@Schema(description = "Filter name")
29+
String name
30+
) { }

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ public record SpreadsheetConfigInfos(
3030
SheetType sheetType,
3131

3232
@Schema(description = "Columns")
33-
List<ColumnInfos> columns
33+
List<ColumnInfos> columns,
34+
35+
@Schema(description = "Global filters")
36+
List<GlobalFilterInfos> globalFilters
3437
) { }

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,17 @@ public class ColumnEntity {
4848

4949
@Column(name = "columnId", nullable = false, columnDefinition = "varchar(255)")
5050
private String id;
51+
52+
@Column(name = "filter_data_type", columnDefinition = "varchar(255)")
53+
private String filterDataType;
54+
55+
@Column(name = "filter_type", columnDefinition = "varchar(255)")
56+
private String filterType;
57+
58+
@Column(name = "filter_value", columnDefinition = "CLOB")
59+
private String filterValue;
60+
61+
@Column(name = "filter_tolerance")
62+
private Double filterTolerance;
63+
5164
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.studyconfig.server.entities;
8+
9+
import jakarta.persistence.*;
10+
import lombok.*;
11+
12+
import java.util.UUID;
13+
14+
/**
15+
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
16+
*/
17+
@Entity
18+
@Table(name = "spreadsheet_global_filter")
19+
@Getter
20+
@Setter
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
@Builder
24+
public class GlobalFilterEntity {
25+
26+
@Id
27+
@GeneratedValue(strategy = GenerationType.AUTO)
28+
@Column(name = "uuid")
29+
private UUID uuid;
30+
31+
@Column(name = "filter_id", nullable = false)
32+
private UUID filterId;
33+
34+
@Column(name = "name", nullable = false, columnDefinition = "varchar(255)")
35+
private String name;
36+
37+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ public class SpreadsheetConfigEntity {
4444
@Builder.Default
4545
private List<ColumnEntity> columns = new ArrayList<>();
4646

47+
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
48+
@JoinColumn(name = "spreadsheet_config_id", foreignKey = @ForeignKey(name = "fk_global_filter_spreadsheet_config"))
49+
@Builder.Default
50+
private List<GlobalFilterEntity> globalFilters = new ArrayList<>();
51+
4752
}

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
*/
77
package org.gridsuite.studyconfig.server.mapper;
88

9+
import org.gridsuite.studyconfig.server.dto.GlobalFilterInfos;
910
import org.gridsuite.studyconfig.server.dto.MetadataInfos;
1011
import org.gridsuite.studyconfig.server.dto.SpreadsheetConfigInfos;
1112
import org.gridsuite.studyconfig.server.dto.ColumnInfos;
1213
import org.gridsuite.studyconfig.server.entities.ColumnEntity;
14+
import org.gridsuite.studyconfig.server.entities.GlobalFilterEntity;
1315
import org.gridsuite.studyconfig.server.entities.SpreadsheetConfigEntity;
1416

1517
/**
@@ -27,6 +29,9 @@ public static SpreadsheetConfigInfos toDto(SpreadsheetConfigEntity entity) {
2729
entity.getSheetType(),
2830
entity.getColumns().stream()
2931
.map(SpreadsheetConfigMapper::toColumnDto)
32+
.toList(),
33+
entity.getGlobalFilters().stream()
34+
.map(SpreadsheetConfigMapper::toGlobalFilterDto)
3035
.toList()
3136
);
3237
}
@@ -47,11 +52,29 @@ public static SpreadsheetConfigEntity toEntity(SpreadsheetConfigInfos dto) {
4752
.toList());
4853
}
4954

55+
if (dto.globalFilters() != null) {
56+
entity.setGlobalFilters(dto.globalFilters().stream()
57+
.map(SpreadsheetConfigMapper::toGlobalFilterEntity)
58+
.toList());
59+
}
60+
5061
return entity;
5162
}
5263

5364
public static ColumnInfos toColumnDto(ColumnEntity entity) {
54-
return new ColumnInfos(entity.getUuid(), entity.getName(), entity.getType(), entity.getPrecision(), entity.getFormula(), entity.getDependencies(), entity.getId());
65+
return new ColumnInfos(
66+
entity.getUuid(),
67+
entity.getName(),
68+
entity.getType(),
69+
entity.getPrecision(),
70+
entity.getFormula(),
71+
entity.getDependencies(),
72+
entity.getId(),
73+
entity.getFilterDataType(),
74+
entity.getFilterType(),
75+
entity.getFilterValue(),
76+
entity.getFilterTolerance()
77+
);
5578
}
5679

5780
public static ColumnEntity toColumnEntity(ColumnInfos dto) {
@@ -62,6 +85,25 @@ public static ColumnEntity toColumnEntity(ColumnInfos dto) {
6285
.formula(dto.formula())
6386
.dependencies(dto.dependencies())
6487
.id(dto.id())
88+
.filterDataType(dto.filterDataType())
89+
.filterType(dto.filterType())
90+
.filterValue(dto.filterValue())
91+
.filterTolerance(dto.filterTolerance())
92+
.build();
93+
}
94+
95+
public static GlobalFilterInfos toGlobalFilterDto(GlobalFilterEntity entity) {
96+
return new GlobalFilterInfos(
97+
entity.getUuid(),
98+
entity.getFilterId(),
99+
entity.getName()
100+
);
101+
}
102+
103+
public static GlobalFilterEntity toGlobalFilterEntity(GlobalFilterInfos dto) {
104+
return GlobalFilterEntity.builder()
105+
.filterId(dto.filterId())
106+
.name(dto.name())
65107
.build();
66108
}
67109
}

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
import jakarta.persistence.EntityNotFoundException;
1010
import lombok.RequiredArgsConstructor;
11-
import org.gridsuite.studyconfig.server.dto.ColumnInfos;
12-
import org.gridsuite.studyconfig.server.dto.MetadataInfos;
13-
import org.gridsuite.studyconfig.server.dto.SpreadsheetConfigCollectionInfos;
14-
import org.gridsuite.studyconfig.server.dto.SpreadsheetConfigInfos;
11+
import org.gridsuite.studyconfig.server.dto.*;
1512
import org.gridsuite.studyconfig.server.entities.ColumnEntity;
13+
import org.gridsuite.studyconfig.server.entities.GlobalFilterEntity;
1614
import org.gridsuite.studyconfig.server.entities.SpreadsheetConfigCollectionEntity;
1715
import org.gridsuite.studyconfig.server.entities.SpreadsheetConfigEntity;
1816
import org.gridsuite.studyconfig.server.mapper.SpreadsheetConfigMapper;
@@ -73,9 +71,23 @@ private SpreadsheetConfigEntity duplicateSpreadsheetConfigEntity(UUID id) {
7371
.formula(column.getFormula())
7472
.dependencies(column.getDependencies())
7573
.id(column.getId())
74+
.filterDataType(column.getFilterDataType())
75+
.filterType(column.getFilterType())
76+
.filterValue(column.getFilterValue())
77+
.filterTolerance(column.getFilterTolerance())
7678
.build())
7779
.toList();
7880
duplicate.setColumns(columns);
81+
82+
// Copy global filters if needed
83+
if (entity.getGlobalFilters() != null) {
84+
duplicate.setGlobalFilters(entity.getGlobalFilters().stream()
85+
.map(globalFilter -> GlobalFilterEntity.builder()
86+
.filterId(globalFilter.getFilterId())
87+
.name(globalFilter.getName())
88+
.build())
89+
.toList());
90+
}
7991
return duplicate;
8092
}
8193

@@ -113,6 +125,12 @@ public void updateSpreadsheetConfig(UUID id, SpreadsheetConfigInfos dto) {
113125
.map(SpreadsheetConfigMapper::toColumnEntity)
114126
.toList());
115127
}
128+
entity.getGlobalFilters().clear();
129+
if (dto.globalFilters() != null) {
130+
entity.getGlobalFilters().addAll(dto.globalFilters().stream()
131+
.map(SpreadsheetConfigMapper::toGlobalFilterEntity)
132+
.toList());
133+
}
116134
}
117135

118136
@Transactional
@@ -244,6 +262,16 @@ public UUID duplicateSpreadsheetConfigCollection(UUID id) {
244262
.formula(column.getFormula())
245263
.dependencies(column.getDependencies())
246264
.id(column.getId())
265+
.filterDataType(column.getFilterDataType())
266+
.filterType(column.getFilterType())
267+
.filterValue(column.getFilterValue())
268+
.filterTolerance(column.getFilterTolerance())
269+
.build())
270+
.toList());
271+
configDuplicate.setGlobalFilters(config.getGlobalFilters().stream()
272+
.map(globalFilter -> GlobalFilterEntity.builder()
273+
.filterId(globalFilter.getFilterId())
274+
.name(globalFilter.getName())
247275
.build())
248276
.toList());
249277
return configDuplicate;
@@ -286,6 +314,10 @@ public void updateColumn(UUID id, UUID columnId, ColumnInfos dto) {
286314
columnEntity.setFormula(dto.formula());
287315
columnEntity.setDependencies(dto.dependencies());
288316
columnEntity.setId(dto.id());
317+
columnEntity.setFilterDataType(dto.filterDataType());
318+
columnEntity.setFilterType(dto.filterType());
319+
columnEntity.setFilterValue(dto.filterValue());
320+
columnEntity.setFilterTolerance(dto.filterTolerance());
289321

290322
spreadsheetConfigRepository.save(entity);
291323
}
@@ -318,6 +350,15 @@ private SpreadsheetConfigCollectionInfos readDefaultSpreadsheetConfigCollection(
318350
}
319351
}
320352

353+
@Transactional
354+
public void setGlobalFiltersForSpreadsheetConfig(UUID id, List<GlobalFilterInfos> globalFilters) {
355+
SpreadsheetConfigEntity entity = findEntityById(id);
356+
entity.getGlobalFilters().clear();
357+
entity.getGlobalFilters().addAll(globalFilters.stream()
358+
.map(SpreadsheetConfigMapper::toGlobalFilterEntity)
359+
.toList());
360+
}
361+
321362
public UUID createDefaultSpreadsheetConfigCollection() {
322363
try {
323364
SpreadsheetConfigCollectionInfos defaultCollection = readDefaultSpreadsheetConfigCollection();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
3+
<changeSet author="berrahmaach (generated)" id="1745258752443-1">
4+
<createTable tableName="spreadsheet_global_filter">
5+
<column name="uuid" type="UUID">
6+
<constraints nullable="false" primaryKey="true" primaryKeyName="spreadsheet_global_filterPK"/>
7+
</column>
8+
<column name="filter_id" type="UUID">
9+
<constraints nullable="false"/>
10+
</column>
11+
<column name="name" type="VARCHAR(255)">
12+
<constraints nullable="false"/>
13+
</column>
14+
<column name="spreadsheet_config_id" type="UUID"/>
15+
</createTable>
16+
</changeSet>
17+
<changeSet author="berrahmaach (generated)" id="1745258752443-2">
18+
<addColumn tableName="spreadsheet_column">
19+
<column name="filter_data_type" type="varchar(255)"/>
20+
</addColumn>
21+
</changeSet>
22+
<changeSet author="berrahmaach (generated)" id="1745258752443-3">
23+
<addColumn tableName="spreadsheet_column">
24+
<column name="filter_tolerance" type="float(53)"/>
25+
</addColumn>
26+
</changeSet>
27+
<changeSet author="berrahmaach (generated)" id="1745258752443-4">
28+
<addColumn tableName="spreadsheet_column">
29+
<column name="filter_type" type="varchar(255)"/>
30+
</addColumn>
31+
</changeSet>
32+
<changeSet author="berrahmaach (generated)" id="1745258752443-5">
33+
<addColumn tableName="spreadsheet_column">
34+
<column name="filter_value" type="CLOB"/>
35+
</addColumn>
36+
</changeSet>
37+
<changeSet author="berrahmaach (generated)" id="1745258752443-6">
38+
<addForeignKeyConstraint baseColumnNames="spreadsheet_config_id" baseTableName="spreadsheet_global_filter" constraintName="fk_global_filter_spreadsheet_config" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="spreadsheet_config" validate="true"/>
39+
</changeSet>
40+
</databaseChangeLog>

0 commit comments

Comments
 (0)