Skip to content

Commit 250a8e3

Browse files
Add endpoint to update a spreadsheet config (#827)
Signed-off-by: Franck LECUYER <[email protected]>
1 parent f77e6b9 commit 250a8e3

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,17 @@ public ResponseEntity<Void> resetFilters(
142142
studyService.resetFilters(studyUuid, id);
143143
return ResponseEntity.noContent().build();
144144
}
145+
146+
@PutMapping("/{id}")
147+
@Operation(summary = "Update a spreadsheet configuration",
148+
description = "Updates an existing spreadsheet configuration")
149+
@ApiResponse(responseCode = "204", description = "Configuration updated")
150+
@ApiResponse(responseCode = "404", description = "Configuration not found")
151+
public ResponseEntity<Void> updateSpreadsheetConfig(
152+
@PathVariable("studyUuid") UUID studyUuid,
153+
@Parameter(description = "ID of the configuration to update") @PathVariable UUID id,
154+
@Valid @RequestBody String spreadsheetConfigInfos) {
155+
studyService.updateSpreadsheetConfig(studyUuid, id, spreadsheetConfigInfos);
156+
return ResponseEntity.noContent().build();
157+
}
145158
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ public void renameSpreadsheetConfig(UUID configUuid, String newName) {
376376
}
377377
}
378378

379+
public void updateSpreadsheetConfig(UUID configUuid, String spreadsheetConfigInfos) {
380+
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_WITH_ID_URI);
381+
String path = uriBuilder.buildAndExpand(configUuid).toUriString();
382+
HttpHeaders headers = new HttpHeaders();
383+
headers.setContentType(MediaType.APPLICATION_JSON);
384+
HttpEntity<String> httpEntity = new HttpEntity<>(spreadsheetConfigInfos, headers);
385+
try {
386+
restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class);
387+
} catch (HttpStatusCodeException e) {
388+
throw handleHttpError(e, UPDATE_SPREADSHEET_CONFIG_FAILED);
389+
}
390+
}
391+
379392
public void setGlobalFilters(UUID configUuid, String globalFilters) {
380393
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_WITH_ID_URI + "/global-filters");
381394
String path = uriBuilder.buildAndExpand(configUuid).toUriString();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,11 @@ public void renameSpreadsheetConfig(UUID studyUuid, UUID configUuid, String newN
34153415
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
34163416
}
34173417

3418+
public void updateSpreadsheetConfig(UUID studyUuid, UUID configUuid, String spreadsheetConfigInfos) {
3419+
studyConfigService.updateSpreadsheetConfig(configUuid, spreadsheetConfigInfos);
3420+
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
3421+
}
3422+
34183423
public UUID addSpreadsheetConfigToCollection(UUID studyUuid, UUID collectionUuid, String configurationDto) {
34193424
UUID newConfigId = studyConfigService.addSpreadsheetConfigToCollection(collectionUuid, configurationDto);
34203425
notificationService.emitSpreadsheetCollectionChanged(studyUuid, collectionUuid);

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,36 @@ void testResetFilters(final MockWebServer server) throws Exception {
256256
wireMockUtils.verifyPutRequest(stubId, configServerUrl, false, Map.of(), null);
257257
}
258258

259+
@Test
260+
void testUpdateConfig() throws Exception {
261+
StudyEntity studyEntity = insertStudy();
262+
String configServerUrl = "/v1/spreadsheet-configs/" + SPREADSHEET_CONFIG_UUID;
263+
264+
UUID stubId = wireMockServer.stubFor(WireMock.put(WireMock.urlPathEqualTo(configServerUrl))
265+
.willReturn(WireMock.noContent())).getId();
266+
267+
String spreadsheetConfig = "{\"id\": \"" + SPREADSHEET_CONFIG_UUID + "\"," +
268+
"\"name\": \"name\"" + "," +
269+
"\"sheetType\": \"SUBSTATION\"" + "," +
270+
"\"columns\": [{" +
271+
"\"uuid\": \"" + UUID.randomUUID() + "\"," +
272+
"\"id\": \"id\"" + "," +
273+
"\"name\": \"columnName\"" + "," +
274+
"\"type\": \"TEXT\"" + "," +
275+
"\"formula\": \"id\"" +
276+
"}]" +
277+
"}";
278+
279+
mockMvc.perform(put("/v1/studies/{studyUuid}/spreadsheet-config/{configUuid}", studyEntity.getId(), SPREADSHEET_CONFIG_UUID)
280+
.header("content-type", "application/json")
281+
.content(spreadsheetConfig))
282+
.andExpect(status().isNoContent())
283+
.andReturn();
284+
285+
checkSpreadsheetTabUpdateMessageReceived(studyEntity.getId());
286+
wireMockUtils.verifyPutRequest(stubId, configServerUrl, false, Map.of(), spreadsheetConfig);
287+
}
288+
259289
private StudyEntity insertStudy() {
260290
StudyEntity studyEntity = TestUtils.createDummyStudy(NETWORK_UUID, "netId", CASE_UUID, "", "", SPREADSHEET_CONFIG_UUID);
261291
var study = studyRepository.save(studyEntity);

0 commit comments

Comments
 (0)