Skip to content

Commit ef09f12

Browse files
authored
Add endpoint to reset spreadsheet config filters (#815)
Signed-off-by: Hugo Marcellin <[email protected]>
1 parent f15e59b commit ef09f12

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,16 @@ public ResponseEntity<Void> renameSpreadsheetConfig(
130130
studyService.renameSpreadsheetConfig(studyUuid, id, name);
131131
return ResponseEntity.noContent().build();
132132
}
133+
134+
@PutMapping("/{id}/reset-filters")
135+
@Operation(summary = "Reset global and column filters",
136+
description = "Reset all columns filters in a spreadsheet configuration as well as the global filter")
137+
@ApiResponse(responseCode = "204", description = "Filters reset successfully")
138+
@ApiResponse(responseCode = "404", description = "Spreadsheet configuration not found")
139+
public ResponseEntity<Void> resetFilters(
140+
@PathVariable("studyUuid") UUID studyUuid,
141+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id) {
142+
studyService.resetFilters(studyUuid, id);
143+
return ResponseEntity.noContent().build();
144+
}
133145
}

src/main/java/org/gridsuite/study/server/service/StudyConfigService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ public void setGlobalFilters(UUID configUuid, String globalFilters) {
389389
}
390390
}
391391

392+
public void resetFilters(UUID configUuid) {
393+
String path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_WITH_ID_URI + "/reset-filters")
394+
.buildAndExpand(configUuid).toUriString();
395+
try {
396+
restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.PUT, null, UUID.class);
397+
} catch (HttpStatusCodeException e) {
398+
throw handleHttpError(e, UPDATE_SPREADSHEET_CONFIG_FAILED);
399+
}
400+
}
401+
392402
public DiagramGridLayout getDiagramGridLayout(UUID diagramGridLayoutUuid) {
393403
Objects.requireNonNull(diagramGridLayoutUuid);
394404
String path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + DIAGRAM_GRID_LAYOUT_WITH_ID_URI)

src/main/java/org/gridsuite/study/server/service/StudyService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,6 +3422,11 @@ public void reorderSpreadsheetConfigs(UUID studyUuid, UUID collectionUuid, List<
34223422
notificationService.emitSpreadsheetCollectionChanged(studyUuid, collectionUuid);
34233423
}
34243424

3425+
public void resetFilters(UUID studyUuid, UUID configUuid) {
3426+
studyConfigService.resetFilters(configUuid);
3427+
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
3428+
}
3429+
34253430
@Transactional(readOnly = true)
34263431
public String getVoltageInitResult(UUID nodeUuid, UUID rootNetworkUuid, String globalFilters) {
34273432
UUID networkuuid = rootNetworkService.getNetworkUuid(rootNetworkUuid);

src/test/java/org/gridsuite/study/server/SpreadsheetConfigTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.github.tomakehurst.wiremock.WireMockServer;
55
import com.github.tomakehurst.wiremock.client.WireMock;
6+
import mockwebserver3.MockWebServer;
67
import mockwebserver3.junit5.internal.MockWebServerExtension;
78
import org.gridsuite.study.server.notification.NotificationService;
89
import org.gridsuite.study.server.repository.StudyEntity;
@@ -35,9 +36,9 @@
3536

3637
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
3738
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
3840
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
3941
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
40-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
4142
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4243

4344
/**
@@ -238,6 +239,23 @@ void testSetGlobalFilters() throws Exception {
238239
wireMockUtils.verifyPostRequest(stubId, configServerUrl, false, Map.of(), globalFilters);
239240
}
240241

242+
@Test
243+
void testResetFilters(final MockWebServer server) throws Exception {
244+
StudyEntity studyEntity = insertStudy();
245+
final String configServerUrl = "/v1/spreadsheet-configs/" + SPREADSHEET_CONFIG_UUID + "/reset-filters";
246+
247+
UUID stubId = wireMockServer.stubFor(WireMock.put(WireMock.urlPathEqualTo(configServerUrl))
248+
.willReturn(WireMock.noContent())).getId();
249+
250+
mockMvc.perform(put("/v1/studies/{studyUuid}/spreadsheet-config/{configUuid}/reset-filters", studyEntity.getId(), SPREADSHEET_CONFIG_UUID)
251+
.header("content-type", "application/json"))
252+
.andExpect(status().isNoContent())
253+
.andReturn();
254+
255+
checkSpreadsheetTabUpdateMessageReceived(studyEntity.getId());
256+
wireMockUtils.verifyPutRequest(stubId, configServerUrl, false, Map.of(), null);
257+
}
258+
241259
private StudyEntity insertStudy() {
242260
StudyEntity studyEntity = TestUtils.createDummyStudy(NETWORK_UUID, "netId", CASE_UUID, "", "", SPREADSHEET_CONFIG_UUID);
243261
var study = studyRepository.save(studyEntity);

0 commit comments

Comments
 (0)