From 94ccf8eecfaf19110b77d285fcb2e3a685da97ee Mon Sep 17 00:00:00 2001 From: Hugo Marcellin Date: Fri, 1 Aug 2025 15:24:14 +0200 Subject: [PATCH 1/3] Add endpoint to reset spreadsheet config filters --- .../SpreadsheetConfigController.java | 11 +++++++++ .../server/entities/ColumnEntity.java | 7 ++++++ .../entities/SpreadsheetConfigEntity.java | 5 ++++ .../service/SpreadsheetConfigService.java | 5 ++++ .../SpreadsheetConfigIntegrationTest.java | 23 +++++++++++++++++++ 5 files changed, 51 insertions(+) diff --git a/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java b/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java index 02946ac..aee86ed 100644 --- a/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java +++ b/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java @@ -213,4 +213,15 @@ public ResponseEntity setGlobalFiltersForSpreadsheetConfig( return ResponseEntity.noContent().build(); } + @DeleteMapping("/{id}/columns/filters") + @Operation(summary = "Reset global and column filters", + description = "Reset all columns filters in a spreadsheet configuration as well as the global filter") + @ApiResponse(responseCode = "204", description = "Filters reset successfully") + @ApiResponse(responseCode = "404", description = "Spreadsheet configuration not found") + public ResponseEntity resetFilters( + @Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id) { + spreadsheetConfigService.resetSpreadsheetConfigFilters(id); + return ResponseEntity.noContent().build(); + } + } diff --git a/src/main/java/org/gridsuite/studyconfig/server/entities/ColumnEntity.java b/src/main/java/org/gridsuite/studyconfig/server/entities/ColumnEntity.java index 884a329..d0166bb 100644 --- a/src/main/java/org/gridsuite/studyconfig/server/entities/ColumnEntity.java +++ b/src/main/java/org/gridsuite/studyconfig/server/entities/ColumnEntity.java @@ -64,4 +64,11 @@ public class ColumnEntity { @Column(name = "visible", nullable = false) @Builder.Default private boolean visible = true; + + public void resetFilter() { + this.filterDataType = null; + this.filterType = null; + this.filterTolerance = null; + this.filterValue = null; + } } diff --git a/src/main/java/org/gridsuite/studyconfig/server/entities/SpreadsheetConfigEntity.java b/src/main/java/org/gridsuite/studyconfig/server/entities/SpreadsheetConfigEntity.java index 7bbd872..911edae 100644 --- a/src/main/java/org/gridsuite/studyconfig/server/entities/SpreadsheetConfigEntity.java +++ b/src/main/java/org/gridsuite/studyconfig/server/entities/SpreadsheetConfigEntity.java @@ -52,4 +52,9 @@ public class SpreadsheetConfigEntity { @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "config_node_aliases", foreignKey = @ForeignKey(name = "fk_spreadsheet_config_node_aliases")) private List nodeAliases; + + public void resetFilters() { + this.globalFilters.clear(); + getColumns().forEach(ColumnEntity::resetFilter); + } } diff --git a/src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java b/src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java index 31d3863..2a51026 100644 --- a/src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java +++ b/src/main/java/org/gridsuite/studyconfig/server/service/SpreadsheetConfigService.java @@ -486,4 +486,9 @@ public void renameSpreadsheetConfig(UUID id, String name) { entity.setName(name); } + @Transactional + public void resetSpreadsheetConfigFilters(UUID id) { + findEntityById(id).resetFilters(); + } + } diff --git a/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java b/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java index b41b8d4..ce331c3 100644 --- a/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java +++ b/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java @@ -537,6 +537,29 @@ void testSetGlobalFiltersForSpreadsheetConfig() throws Exception { .containsExactly("Replacement Filter"); } + @Test + void testResetFiltersForSpreadsheetConfig() throws Exception { + // Create a spreadsheet config with existing global filters + SpreadsheetConfigInfos configWithFilters = new SpreadsheetConfigInfos( + null, "ConfigWithFilters", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of()); + UUID configId = saveAndReturnId(configWithFilters); + + // Initial config should have filters set + SpreadsheetConfigInfos initialConfig = getSpreadsheetConfig(configId); + assertThat(initialConfig.globalFilters()).hasSize(2); + assertThat(initialConfig.columns().get(0)).hasFieldOrPropertyWithValue("filterValue", "test-value"); + + // Call the endpoint to reset the filters + mockMvc.perform(delete(URI_SPREADSHEET_CONFIG_GET_PUT + configId + URI_COLUMN_BASE + "/filters") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNoContent()); + + // Verify the filters (global or column based) were reset + SpreadsheetConfigInfos updatedConfig = getSpreadsheetConfig(configId); + assertThat(updatedConfig.globalFilters()).hasSize(0); + assertThat(updatedConfig.columns().get(0)).hasFieldOrPropertyWithValue("filterValue", null); + } + @Test void testSetGlobalFiltersToNonExistentConfig() throws Exception { UUID nonExistentConfigId = UUID.randomUUID(); From 09b23a080fb06cda2c5aa1bc9c1d8506ac86ff20 Mon Sep 17 00:00:00 2001 From: Hugo Marcellin Date: Fri, 1 Aug 2025 15:30:05 +0200 Subject: [PATCH 2/3] Sonar issues --- .../server/SpreadsheetConfigIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java b/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java index ce331c3..dfecbee 100644 --- a/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java +++ b/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java @@ -547,7 +547,7 @@ void testResetFiltersForSpreadsheetConfig() throws Exception { // Initial config should have filters set SpreadsheetConfigInfos initialConfig = getSpreadsheetConfig(configId); assertThat(initialConfig.globalFilters()).hasSize(2); - assertThat(initialConfig.columns().get(0)).hasFieldOrPropertyWithValue("filterValue", "test-value"); + assertThat(initialConfig.columns().getFirst()).hasFieldOrPropertyWithValue("filterValue", "test-value"); // Call the endpoint to reset the filters mockMvc.perform(delete(URI_SPREADSHEET_CONFIG_GET_PUT + configId + URI_COLUMN_BASE + "/filters") @@ -556,8 +556,8 @@ void testResetFiltersForSpreadsheetConfig() throws Exception { // Verify the filters (global or column based) were reset SpreadsheetConfigInfos updatedConfig = getSpreadsheetConfig(configId); - assertThat(updatedConfig.globalFilters()).hasSize(0); - assertThat(updatedConfig.columns().get(0)).hasFieldOrPropertyWithValue("filterValue", null); + assertThat(updatedConfig.globalFilters()).isEmpty(); + assertThat(updatedConfig.columns().getFirst()).hasFieldOrPropertyWithValue("filterValue", null); } @Test From 56ef2c0fb2fdd7c3c15aaf9ee6bf9026c98fbb7f Mon Sep 17 00:00:00 2001 From: Hugo Marcellin Date: Tue, 12 Aug 2025 09:51:39 +0200 Subject: [PATCH 3/3] Swap delete for put and update URI --- .../server/controller/SpreadsheetConfigController.java | 2 +- .../studyconfig/server/SpreadsheetConfigIntegrationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java b/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java index aee86ed..b2da8a3 100644 --- a/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java +++ b/src/main/java/org/gridsuite/studyconfig/server/controller/SpreadsheetConfigController.java @@ -213,7 +213,7 @@ public ResponseEntity setGlobalFiltersForSpreadsheetConfig( return ResponseEntity.noContent().build(); } - @DeleteMapping("/{id}/columns/filters") + @PutMapping("/{id}/reset-filters") @Operation(summary = "Reset global and column filters", description = "Reset all columns filters in a spreadsheet configuration as well as the global filter") @ApiResponse(responseCode = "204", description = "Filters reset successfully") diff --git a/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java b/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java index 3fc4b1a..9925f5c 100644 --- a/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java +++ b/src/test/java/org/gridsuite/studyconfig/server/SpreadsheetConfigIntegrationTest.java @@ -561,7 +561,7 @@ void testResetFiltersForSpreadsheetConfig() throws Exception { assertThat(initialConfig.columns().getFirst()).hasFieldOrPropertyWithValue("filterValue", "test-value"); // Call the endpoint to reset the filters - mockMvc.perform(delete(URI_SPREADSHEET_CONFIG_GET_PUT + configId + URI_COLUMN_BASE + "/filters") + mockMvc.perform(put(URI_SPREADSHEET_CONFIG_GET_PUT + configId + "/reset-filters") .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isNoContent());