Skip to content

Commit c9cf5a0

Browse files
authored
feat: duplicate spreadsheet column (#805)
Signed-off-by: Abdelsalem <[email protected]>
1 parent bbe6353 commit c9cf5a0

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

src/main/java/org/gridsuite/study/server/RestResponseEntityExceptionHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ protected ResponseEntity<Object> handleStudyException(StudyException exception)
122122
RUN_DYNAMIC_SECURITY_ANALYSIS_FAILED,
123123
INVALIDATE_DYNAMIC_SECURITY_ANALYSIS_FAILED,
124124
UPDATE_DYNAMIC_SECURITY_ANALYSIS_PARAMETERS_FAILED,
125-
DUPLICATE_DYNAMIC_SECURITY_ANALYSIS_PARAMETERS_FAILED
125+
DUPLICATE_DYNAMIC_SECURITY_ANALYSIS_PARAMETERS_FAILED,
126+
UPDATE_SPREADSHEET_CONFIG_FAILED
126127
-> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage());
127128
case SVG_NOT_FOUND,
128129
NO_VOLTAGE_INIT_RESULTS_FOR_NODE,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ public ResponseEntity<Void> deleteColumn(
8484
return ResponseEntity.noContent().build();
8585
}
8686

87+
@PostMapping("/{id}/columns/{columnUuid}/duplicate")
88+
@Operation(summary = "duplicate a column", description = "duplicate an existing column")
89+
@ApiResponse(responseCode = "204", description = "Column duplicated")
90+
public ResponseEntity<Void> duplicateColumn(
91+
@PathVariable("studyUuid") UUID studyUuid,
92+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
93+
@Parameter(description = "ID of the column to duplicate") @PathVariable UUID columnUuid) {
94+
studyService.duplicateColumn(studyUuid, id, columnUuid);
95+
return ResponseEntity.noContent().build();
96+
}
97+
8798
@PutMapping("/{id}/columns/reorder")
8899
@Operation(summary = "Reorder columns", description = "Reorders the columns of a spreadsheet configuration")
89100
@ApiResponse(responseCode = "204", description = "Columns reordered")

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ public void deleteColumn(UUID configUuid, UUID columnUuid) {
346346
restTemplate.delete(studyConfigServerBaseUri + path);
347347
}
348348

349+
public void duplicateColumn(UUID configUuid, UUID columnUuid) {
350+
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_WITH_ID_URI + "/columns/{colId}/duplicate");
351+
String path = uriBuilder.buildAndExpand(configUuid, columnUuid).toUriString();
352+
HttpHeaders headers = new HttpHeaders();
353+
headers.setContentType(MediaType.APPLICATION_JSON);
354+
HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
355+
try {
356+
restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, httpEntity, Void.class);
357+
} catch (HttpStatusCodeException e) {
358+
throw handleHttpError(e, UPDATE_SPREADSHEET_CONFIG_FAILED);
359+
}
360+
}
361+
349362
public void renameSpreadsheetConfig(UUID configUuid, String newName) {
350363
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + STUDY_CONFIG_API_VERSION + SPREADSHEET_CONFIG_WITH_ID_URI + "/name");
351364
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
@@ -3363,6 +3363,11 @@ public void deleteColumn(UUID studyUuid, UUID configUuid, UUID columnUuid) {
33633363
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
33643364
}
33653365

3366+
public void duplicateColumn(UUID studyUuid, UUID configUuid, UUID columnUuid) {
3367+
studyConfigService.duplicateColumn(configUuid, columnUuid);
3368+
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);
3369+
}
3370+
33663371
public void reorderColumns(UUID studyUuid, UUID configUuid, List<UUID> columnOrder) {
33673372
studyConfigService.reorderColumns(configUuid, columnOrder);
33683373
notificationService.emitSpreadsheetConfigChanged(studyUuid, configUuid);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ void testDeleteColumn() throws Exception {
158158
wireMockUtils.verifyDeleteRequest(stubId, configServerUrl, false, Map.of());
159159
}
160160

161+
@Test
162+
void testDuplicateColumn() throws Exception {
163+
StudyEntity studyEntity = insertStudy();
164+
String configServerUrl = "/v1/spreadsheet-configs/" + SPREADSHEET_CONFIG_UUID + "/columns/" + SPREADSHEET_CONFIG_COLUMN_UUID + "/duplicate";
165+
166+
UUID stubId = wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(configServerUrl))
167+
.willReturn(WireMock.noContent())).getId();
168+
169+
mockMvc.perform(post("/v1/studies/{studyUuid}/spreadsheet-config/{configUuid}/columns/{columnUuid}/duplicate", studyEntity.getId(), SPREADSHEET_CONFIG_UUID, SPREADSHEET_CONFIG_COLUMN_UUID)
170+
.header("content-type", "application/json"))
171+
.andExpect(status().isNoContent())
172+
.andReturn();
173+
174+
checkSpreadsheetTabUpdateMessageReceived(studyEntity.getId());
175+
wireMockUtils.verifyPostRequest(stubId, configServerUrl, Map.of(), 1);
176+
}
177+
161178
@Test
162179
void testUpdateColumn() throws Exception {
163180
StudyEntity studyEntity = insertStudy();

0 commit comments

Comments
 (0)