|
| 1 | +package org.gridsuite.shortcircuit.server; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | +import io.swagger.v3.oas.annotations.Operation; |
| 5 | +import io.swagger.v3.oas.annotations.Parameter; |
| 6 | +import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 8 | +import org.gridsuite.shortcircuit.server.dto.ShortCircuitParametersInfos; |
| 9 | +import org.gridsuite.shortcircuit.server.service.ShortCircuitService; |
| 10 | +import org.springframework.http.MediaType; |
| 11 | +import org.springframework.http.ResponseEntity; |
| 12 | +import org.springframework.web.bind.annotation.*; |
| 13 | + |
| 14 | +import java.util.UUID; |
| 15 | + |
| 16 | +import static org.gridsuite.shortcircuit.server.util.Utils.APPLICATION_JSON_PATCH_VALUE; |
| 17 | +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; |
| 18 | +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; |
| 19 | +import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; |
| 20 | + |
| 21 | +@RestController |
| 22 | +@RequestMapping(value = "/" + ShortCircuitApi.API_VERSION + "/parameters", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) |
| 23 | +@Tag(name = "Short circuit server analysis parameters") |
| 24 | +public class ParametersController { |
| 25 | + private final ShortCircuitService shortCircuitService; |
| 26 | + |
| 27 | + public ParametersController(ShortCircuitService shortCircuitService) { |
| 28 | + this.shortCircuitService = shortCircuitService; |
| 29 | + } |
| 30 | + |
| 31 | + @GetMapping(value = "/{parametersUuid}") |
| 32 | + @Operation(summary = "Get the parameters for an analysis") |
| 33 | + @ApiResponse(responseCode = "200", description = "The parameters asked") |
| 34 | + public ResponseEntity<ShortCircuitParametersInfos> getParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid) { |
| 35 | + return ResponseEntity.of(shortCircuitService.getParameters(parametersUuid)); |
| 36 | + } |
| 37 | + |
| 38 | + @PostMapping(produces = TEXT_PLAIN_VALUE, consumes = {APPLICATION_JSON_VALUE, APPLICATION_JSON_PATCH_VALUE}) |
| 39 | + @Operation(summary = "Create a new set of parameters for an analysis using default parameters as base") |
| 40 | + public ResponseEntity<UUID> createParameters(@RequestHeader(value = CONTENT_TYPE, required = false) MediaType contentType, |
| 41 | + @RequestBody(required = false) String parametersPatch) { |
| 42 | + return ResponseEntity.ok(shortCircuitService.createParameters(contentType, parametersPatch)); |
| 43 | + } |
| 44 | + |
| 45 | + @PostMapping(value = "/parameters", produces = TEXT_PLAIN_VALUE) |
| 46 | + @Operation(summary = "Duplicate the parameters of an analysis") |
| 47 | + public ResponseEntity<UUID> duplicateParameters(@Parameter(description = "UUID of parameters to duplicate") @RequestParam(name = "duplicateFrom") UUID sourceParametersUuid) { |
| 48 | + return ResponseEntity.of(shortCircuitService.duplicateParameters(sourceParametersUuid)); |
| 49 | + } |
| 50 | + |
| 51 | + @DeleteMapping(value = "/parameters/{parametersUuid}") |
| 52 | + @Operation(summary = "Delete a set of parameters") |
| 53 | + public ResponseEntity<Void> deleteParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid) { |
| 54 | + shortCircuitService.deleteParameters(parametersUuid); |
| 55 | + return ResponseEntity.ok().build(); |
| 56 | + } |
| 57 | + |
| 58 | + @PutMapping(value = "/parameters/{parametersUuid}", consumes = {APPLICATION_JSON_VALUE, APPLICATION_JSON_PATCH_VALUE}) |
| 59 | + @Operation(summary = "Update a set of parameters for an analysis or reset them to default ones") |
| 60 | + public ResponseEntity<Void> updateParameters(@Parameter(description = "UUID of parameters") @PathVariable("parametersUuid") UUID parametersUuid, |
| 61 | + @RequestHeader(value = CONTENT_TYPE, required = false) MediaType contentType, @RequestBody(required = false) String parametersPatch) throws JsonProcessingException { |
| 62 | + if (shortCircuitService.updateParameters(parametersUuid, contentType, parametersPatch)) { |
| 63 | + return ResponseEntity.noContent().build(); |
| 64 | + } else { |
| 65 | + return ResponseEntity.notFound().build(); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments