Skip to content

Commit 9c034be

Browse files
authored
Merge branch 'main' into nad-custom-coordinates
2 parents 6b198d2 + 9113f2e commit 9c034be

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+
@PutMapping("/{id}/reset-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
@@ -519,4 +519,9 @@ public void renameSpreadsheetConfig(UUID id, String name) {
519519
entity.setName(name);
520520
}
521521

522+
@Transactional
523+
public void resetSpreadsheetConfigFilters(UUID id) {
524+
findEntityById(id).resetFilters();
525+
}
526+
522527
}

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

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

551+
@Test
552+
void testResetFiltersForSpreadsheetConfig() throws Exception {
553+
// Create a spreadsheet config with existing global filters
554+
SpreadsheetConfigInfos configWithFilters = new SpreadsheetConfigInfos(
555+
null, "ConfigWithFilters", SheetType.BATTERY, createColumnsWithFilters(), createGlobalFilters(), List.of());
556+
UUID configId = saveAndReturnId(configWithFilters);
557+
558+
// Initial config should have filters set
559+
SpreadsheetConfigInfos initialConfig = getSpreadsheetConfig(configId);
560+
assertThat(initialConfig.globalFilters()).hasSize(2);
561+
assertThat(initialConfig.columns().getFirst()).hasFieldOrPropertyWithValue("filterValue", "test-value");
562+
563+
// Call the endpoint to reset the filters
564+
mockMvc.perform(put(URI_SPREADSHEET_CONFIG_GET_PUT + configId + "/reset-filters")
565+
.contentType(MediaType.APPLICATION_JSON))
566+
.andExpect(status().isNoContent());
567+
568+
// Verify the filters (global or column based) were reset
569+
SpreadsheetConfigInfos updatedConfig = getSpreadsheetConfig(configId);
570+
assertThat(updatedConfig.globalFilters()).isEmpty();
571+
assertThat(updatedConfig.columns().getFirst()).hasFieldOrPropertyWithValue("filterValue", null);
572+
}
573+
551574
@Test
552575
void testSetGlobalFiltersToNonExistentConfig() throws Exception {
553576
UUID nonExistentConfigId = UUID.randomUUID();

0 commit comments

Comments
 (0)