Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,15 @@ public ResponseEntity<Void> 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<Void> resetFilters(
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id) {
spreadsheetConfigService.resetSpreadsheetConfigFilters(id);
return ResponseEntity.noContent().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> nodeAliases;

public void resetFilters() {
this.globalFilters.clear();
getColumns().forEach(ColumnEntity::resetFilter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,9 @@ public void renameSpreadsheetConfig(UUID id, String name) {
entity.setName(name);
}

@Transactional
public void resetSpreadsheetConfigFilters(UUID id) {
findEntityById(id).resetFilters();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,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().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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());

// Verify the filters (global or column based) were reset
SpreadsheetConfigInfos updatedConfig = getSpreadsheetConfig(configId);
assertThat(updatedConfig.globalFilters()).isEmpty();
assertThat(updatedConfig.columns().getFirst()).hasFieldOrPropertyWithValue("filterValue", null);
}

@Test
void testSetGlobalFiltersToNonExistentConfig() throws Exception {
UUID nonExistentConfigId = UUID.randomUUID();
Expand Down