Skip to content

Commit 72b8c45

Browse files
committed
Merge branch 'main' of https://github.com/gridsuite/study-server into refacto-invalidate-node
2 parents da673de + cba5fd0 commit 72b8c45

23 files changed

+806
-120
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
1111
*/
1212

13-
final class StudyApi {
13+
public final class StudyApi {
1414

1515
private StudyApi() {
1616
}
1717

18-
static final String API_VERSION = "v1";
18+
public static final String API_VERSION = "v1";
1919
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public enum Type {
151151
GET_SPREADSHEET_CONFIG_COLLECTION_FAILED,
152152
CREATE_SPREADSHEET_CONFIG_COLLECTION_FAILED,
153153
UPDATE_SPREADSHEET_CONFIG_COLLECTION_FAILED,
154+
UPDATE_SPREADSHEET_CONFIG_FAILED,
154155
NETWORK_EXPORT_FAILED
155156
}
156157

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.study.server.controller;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
12+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
13+
import io.swagger.v3.oas.annotations.tags.Tag;
14+
import jakarta.validation.Valid;
15+
import org.gridsuite.study.server.StudyApi;
16+
import org.gridsuite.study.server.service.*;
17+
import org.springframework.http.HttpStatus;
18+
import org.springframework.http.ResponseEntity;
19+
import org.springframework.web.bind.annotation.*;
20+
21+
import java.util.List;
22+
import java.util.UUID;
23+
24+
import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID;
25+
26+
@RestController
27+
@RequestMapping(value = "/" + StudyApi.API_VERSION + "/studies/{studyUuid}/spreadsheet-config-collection")
28+
@Tag(name = "Study server - Spreadsheet collections")
29+
public class SpreadsheetConfigCollectionController {
30+
private final StudyService studyService;
31+
32+
public SpreadsheetConfigCollectionController(StudyService studyService) {
33+
this.studyService = studyService;
34+
}
35+
36+
@GetMapping()
37+
@Operation(summary = "Get study's spreadsheet config collection")
38+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The spreadsheet config collection")})
39+
public ResponseEntity<String> getSpreadsheetConfigCollection(
40+
@PathVariable("studyUuid") UUID studyUuid) {
41+
return ResponseEntity.ok().body(studyService.getSpreadsheetConfigCollection(studyUuid));
42+
}
43+
44+
@PutMapping()
45+
@Operation(summary = "Update study's spreadsheet config collection, with replace or append mode")
46+
@ApiResponses(value = {
47+
@ApiResponse(responseCode = "200", description = "The updated spreadsheet config collection"),
48+
@ApiResponse(responseCode = "404", description = "The study or the collection doesn't exist")
49+
})
50+
public ResponseEntity<String> updateSpreadsheetConfigCollection(
51+
@PathVariable("studyUuid") UUID studyUuid,
52+
@RequestParam("collectionUuid") UUID collectionUuid,
53+
@RequestParam(value = "append", required = false, defaultValue = "false") Boolean appendMode) {
54+
return ResponseEntity.ok().body(studyService.updateSpreadsheetConfigCollection(studyUuid, collectionUuid, appendMode));
55+
}
56+
57+
@PostMapping()
58+
@Operation(summary = "Set spreadsheet config collection on study, reset to default one if empty body")
59+
@ApiResponses(value = {
60+
@ApiResponse(responseCode = "200", description = "The spreadsheet config collection is set"),
61+
@ApiResponse(responseCode = "204", description = "Reset with user profile cannot be done")
62+
})
63+
public ResponseEntity<Void> setSpreadsheetConfigCollection(
64+
@PathVariable("studyUuid") UUID studyUuid,
65+
@RequestBody(required = false) String configCollection,
66+
@RequestHeader(HEADER_USER_ID) String userId) {
67+
return studyService.setSpreadsheetConfigCollection(studyUuid, configCollection, userId) ?
68+
ResponseEntity.noContent().build() : ResponseEntity.ok().build();
69+
}
70+
71+
@PostMapping("/{id}/spreadsheet-configs")
72+
@Operation(summary = "Add a spreadsheet configuration to a collection",
73+
description = "Adds a new spreadsheet configuration to a collection")
74+
@ApiResponse(responseCode = "201", description = "Configuration added")
75+
@ApiResponse(responseCode = "404", description = "Configuration collection not found")
76+
public ResponseEntity<UUID> addSpreadsheetConfigToCollection(
77+
@PathVariable("studyUuid") UUID studyUuid,
78+
@Parameter(description = "ID of the configuration collection") @PathVariable UUID id,
79+
@Parameter(description = "Configuration to add") @Valid @RequestBody String configurationDto) {
80+
return ResponseEntity.status(HttpStatus.CREATED).body(studyService.addSpreadsheetConfigToCollection(studyUuid, id, configurationDto));
81+
}
82+
83+
@DeleteMapping("/{id}/spreadsheet-configs/{configId}")
84+
@Operation(summary = "Remove a spreadsheet configuration from a collection",
85+
description = "Removes an existing spreadsheet configuration from a collection")
86+
@ApiResponse(responseCode = "204", description = "Configuration removed")
87+
@ApiResponse(responseCode = "404", description = "Configuration collection or configuration not found")
88+
public ResponseEntity<Void> removeSpreadsheetConfigFromCollection(
89+
@PathVariable("studyUuid") UUID studyUuid,
90+
@Parameter(description = "ID of the configuration collection") @PathVariable UUID id,
91+
@Parameter(description = "ID of the configuration to remove") @PathVariable UUID configId) {
92+
studyService.removeSpreadsheetConfigFromCollection(studyUuid, id, configId);
93+
return ResponseEntity.noContent().build();
94+
}
95+
96+
@PutMapping("/{id}/reorder")
97+
@Operation(summary = "Reorder spreadsheet configs in a collection",
98+
description = "Updates the order of spreadsheet configs within a collection")
99+
@ApiResponse(responseCode = "204", description = "Order updated")
100+
@ApiResponse(responseCode = "404", description = "Collection not found")
101+
public ResponseEntity<Void> reorderSpreadsheetConfigs(
102+
@PathVariable("studyUuid") UUID studyUuid,
103+
@Parameter(description = "ID of the configuration collection") @PathVariable UUID id,
104+
@Valid @RequestBody List<UUID> newOrder) {
105+
studyService.reorderSpreadsheetConfigs(studyUuid, id, newOrder);
106+
return ResponseEntity.noContent().build();
107+
}
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.study.server.controller;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
13+
import jakarta.validation.Valid;
14+
import org.gridsuite.study.server.StudyApi;
15+
import org.gridsuite.study.server.service.StudyService;
16+
import org.springframework.http.HttpStatus;
17+
import org.springframework.http.ResponseEntity;
18+
import org.springframework.web.bind.annotation.DeleteMapping;
19+
import org.springframework.web.bind.annotation.PatchMapping;
20+
import org.springframework.web.bind.annotation.PathVariable;
21+
import org.springframework.web.bind.annotation.PostMapping;
22+
import org.springframework.web.bind.annotation.PutMapping;
23+
import org.springframework.web.bind.annotation.RequestBody;
24+
import org.springframework.web.bind.annotation.RequestMapping;
25+
import org.springframework.web.bind.annotation.RestController;
26+
27+
import java.util.List;
28+
import java.util.UUID;
29+
30+
@RestController
31+
@RequestMapping(value = "/" + StudyApi.API_VERSION + "/studies/{studyUuid}/spreadsheet-config")
32+
@Tag(name = "Study server - Spreadsheet configurations")
33+
public class SpreadsheetConfigController {
34+
private final StudyService studyService;
35+
36+
public SpreadsheetConfigController(StudyService studyService) {
37+
this.studyService = studyService;
38+
}
39+
40+
@PostMapping("/{id}/columns")
41+
@Operation(summary = "Create a column", description = "Creates a new column")
42+
@ApiResponse(responseCode = "201", description = "Column created")
43+
public ResponseEntity<UUID> createColumn(
44+
@PathVariable("studyUuid") UUID studyUuid,
45+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
46+
@Valid @RequestBody String columnInfos) {
47+
UUID newColumnId = studyService.createColumn(studyUuid, id, columnInfos);
48+
return ResponseEntity.status(HttpStatus.CREATED).body(newColumnId);
49+
}
50+
51+
@PutMapping("/{id}/columns/{columnUuid}")
52+
@Operation(summary = "Update a column", description = "Updates an existing column")
53+
@ApiResponse(responseCode = "204", description = "Column updated")
54+
public ResponseEntity<Void> updateColumn(
55+
@PathVariable("studyUuid") UUID studyUuid,
56+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
57+
@Parameter(description = "ID of the column to update") @PathVariable UUID columnUuid,
58+
@Valid @RequestBody String columnInfos) {
59+
studyService.updateColumn(studyUuid, id, columnUuid, columnInfos);
60+
return ResponseEntity.noContent().build();
61+
}
62+
63+
@DeleteMapping("/{id}/columns/{columnUuid}")
64+
@Operation(summary = "Delete a column", description = "Deletes an existing column")
65+
@ApiResponse(responseCode = "204", description = "Column deleted")
66+
@ApiResponse(responseCode = "404", description = "Column not found")
67+
public ResponseEntity<Void> deleteColumn(
68+
@PathVariable("studyUuid") UUID studyUuid,
69+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
70+
@Parameter(description = "ID of the column to delete") @PathVariable UUID columnUuid) {
71+
studyService.deleteColumn(studyUuid, id, columnUuid);
72+
return ResponseEntity.noContent().build();
73+
}
74+
75+
@PutMapping("/{id}/columns/reorder")
76+
@Operation(summary = "Reorder columns", description = "Reorders the columns of a spreadsheet configuration")
77+
@ApiResponse(responseCode = "204", description = "Columns reordered")
78+
public ResponseEntity<Void> reorderColumns(
79+
@PathVariable("studyUuid") UUID studyUuid,
80+
@Parameter(description = "ID of the spreadsheet config") @PathVariable UUID id,
81+
@Parameter(description = "New order of column IDs") @RequestBody List<UUID> columnOrder) {
82+
studyService.reorderColumns(studyUuid, id, columnOrder);
83+
return ResponseEntity.noContent().build();
84+
}
85+
86+
@PatchMapping("/{id}/name")
87+
@Operation(summary = "Rename a spreadsheet configuration",
88+
description = "Updates the name of an existing spreadsheet configuration")
89+
@ApiResponse(responseCode = "204", description = "Configuration renamed")
90+
@ApiResponse(responseCode = "404", description = "Configuration not found")
91+
public ResponseEntity<Void> renameSpreadsheetConfig(
92+
@PathVariable("studyUuid") UUID studyUuid,
93+
@Parameter(description = "ID of the configuration to rename") @PathVariable UUID id,
94+
@Parameter(description = "New name for the configuration") @RequestBody String name) {
95+
studyService.renameSpreadsheetConfig(studyUuid, id, name);
96+
return ResponseEntity.noContent().build();
97+
}
98+
}

0 commit comments

Comments
 (0)