Skip to content

Commit 94ccf8e

Browse files
author
Hugo Marcellin
committed
Add endpoint to reset spreadsheet config filters
1 parent 73af9a2 commit 94ccf8e

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,15 @@ public ResponseEntity<Void> setGlobalFiltersForSpreadsheetConfig(
213213
return ResponseEntity.noContent().build();
214214
}
215215

216+
@DeleteMapping("/{id}/columns/filters")
217+
@Operation(summary = "Reset global and column filters",
218+
description = "Reset all columns filters in a spreadsheet configuration as well as the global filter")
219+
@ApiResponse(responseCode = "204", description = "Filters reset successfully")
220+
@ApiResponse(responseCode = "404", description = "Spreadsheet configuration not found")
221+
public ResponseEntity<Void> resetFilters(
222+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id) {
223+
spreadsheetConfigService.resetSpreadsheetConfigFilters(id);
224+
return ResponseEntity.noContent().build();
225+
}
226+
216227
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public class ColumnEntity {
6464
@Column(name = "visible", nullable = false)
6565
@Builder.Default
6666
private boolean visible = true;
67+
68+
public void resetFilter() {
69+
this.filterDataType = null;
70+
this.filterType = null;
71+
this.filterTolerance = null;
72+
this.filterValue = null;
73+
}
6774
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ public class SpreadsheetConfigEntity {
5252
@ElementCollection(fetch = FetchType.EAGER)
5353
@CollectionTable(name = "config_node_aliases", foreignKey = @ForeignKey(name = "fk_spreadsheet_config_node_aliases"))
5454
private List<String> nodeAliases;
55+
56+
public void resetFilters() {
57+
this.globalFilters.clear();
58+
getColumns().forEach(ColumnEntity::resetFilter);
59+
}
5560
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,9 @@ public void renameSpreadsheetConfig(UUID id, String name) {
486486
entity.setName(name);
487487
}
488488

489+
@Transactional
490+
public void resetSpreadsheetConfigFilters(UUID id) {
491+
findEntityById(id).resetFilters();
492+
}
493+
489494
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,29 @@ void testSetGlobalFiltersForSpreadsheetConfig() throws Exception {
537537
.containsExactly("Replacement Filter");
538538
}
539539

540+
@Test
541+
void testResetFiltersForSpreadsheetConfig() throws Exception {
542+
// Create a spreadsheet config with existing global filters
543+
SpreadsheetConfigInfos configWithFilters = new SpreadsheetConfigInfos(
544+
null, "ConfigWithFilters", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of());
545+
UUID configId = saveAndReturnId(configWithFilters);
546+
547+
// Initial config should have filters set
548+
SpreadsheetConfigInfos initialConfig = getSpreadsheetConfig(configId);
549+
assertThat(initialConfig.globalFilters()).hasSize(2);
550+
assertThat(initialConfig.columns().get(0)).hasFieldOrPropertyWithValue("filterValue", "test-value");
551+
552+
// Call the endpoint to reset the filters
553+
mockMvc.perform(delete(URI_SPREADSHEET_CONFIG_GET_PUT + configId + URI_COLUMN_BASE + "/filters")
554+
.contentType(MediaType.APPLICATION_JSON))
555+
.andExpect(status().isNoContent());
556+
557+
// Verify the filters (global or column based) were reset
558+
SpreadsheetConfigInfos updatedConfig = getSpreadsheetConfig(configId);
559+
assertThat(updatedConfig.globalFilters()).hasSize(0);
560+
assertThat(updatedConfig.columns().get(0)).hasFieldOrPropertyWithValue("filterValue", null);
561+
}
562+
540563
@Test
541564
void testSetGlobalFiltersToNonExistentConfig() throws Exception {
542565
UUID nonExistentConfigId = UUID.randomUUID();

0 commit comments

Comments
 (0)