|
| 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 | +} |
0 commit comments