diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index d4a4e5730..5d69af5c9 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -11,7 +11,6 @@ import com.powsybl.timeseries.DoubleTimeSeries; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; @@ -908,7 +907,6 @@ public ResponseEntity getDynamicSimulationProvider(@PathVariable("studyU @PostMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "set short-circuit analysis parameters on study, reset to default ones if empty body") - //@io.swagger.v3.oas.annotations.parameters.RequestBody(required = false, content = @Content(schema = @Schema(implementation = ShortCircuitParametersInfos.class))) @ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters are set") public ResponseEntity setShortCircuitParameters( @PathVariable("studyUuid") UUID studyUuid, @@ -918,12 +916,11 @@ public ResponseEntity setShortCircuitParameters( return ResponseEntity.ok().build(); } - @GetMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters") + @GetMapping(value = "/studies/{studyUuid}/short-circuit-analysis/parameters", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get short-circuit analysis parameters on study") - @ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters", content = { - @Content(mediaType = MediaType.APPLICATION_JSON_VALUE /*, schema = ...*/)}) + @ApiResponse(responseCode = "200", description = "The short-circuit analysis parameters return by shortcircuit-server") public ResponseEntity getShortCircuitParameters(@PathVariable("studyUuid") UUID studyUuid) { - return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getShortCircuitParametersInfo(studyUuid)); + return ResponseEntity.ok().body(studyService.getShortCircuitParametersInfo(studyUuid)); } @GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network/substations/{substationId}/svg") @@ -1766,7 +1763,7 @@ public ResponseEntity invalidateShortCircuitStatus(@Parameter(description return ResponseEntity.ok().build(); } - @PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run", produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run") @Operation(summary = "run sensitivity analysis non evacuated energy on study") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The sensitivity analysis non evacuated energy has started")}) public ResponseEntity runNonEvacuatedEnergy(@Parameter(description = "studyUuid") @PathVariable("studyUuid") UUID studyUuid, diff --git a/src/main/java/org/gridsuite/study/server/converter/UuidHttpConverter.java b/src/main/java/org/gridsuite/study/server/converter/UuidHttpConverter.java deleted file mode 100644 index 52c397d3a..000000000 --- a/src/main/java/org/gridsuite/study/server/converter/UuidHttpConverter.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.gridsuite.study.server.converter; - -import lombok.NonNull; -import org.jetbrains.annotations.NotNull; -import org.springframework.boot.context.properties.bind.Binder; -import org.springframework.boot.web.servlet.server.Encoding; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpInputMessage; -import org.springframework.http.HttpOutputMessage; -import org.springframework.http.MediaType; -import org.springframework.http.converter.AbstractHttpMessageConverter; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.lang.Nullable; -import org.springframework.stereotype.Component; -import org.springframework.util.MimeType; -import org.springframework.util.StreamUtils; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; - -/** - * Implementation of {@link HttpMessageConverter} that can read and write {@link UUID} to/from strings. - * - * @since 2.0 - */ -@Component -public class UuidHttpConverter extends AbstractHttpMessageConverter { - private final Encoding encoding; - private final List availableCharsets = List.copyOf(Charset.availableCharsets().values()); - - protected UuidHttpConverter(@NonNull final Environment environment) { - super(StandardCharsets.UTF_8, MediaType.TEXT_PLAIN); - encoding = Binder.get(environment).bindOrCreate("server.servlet.encoding", Encoding.class); - } - - /** - * {@inheritDoc} - */ - @Override - @NotNull - public Charset getDefaultCharset() { - return Objects.requireNonNullElse(encoding.getCharset(), super.getDefaultCharset()); - } - - /** - * {@inheritDoc} - */ - @Override - protected boolean supports(final Class clazz) { - return UUID.class == clazz; - } - - /** - * {@inheritDoc} - */ - @Override - @NotNull - protected Long getContentLength(UUID uuid, MediaType contentType) throws IOException { - return (long) uuid.toString().getBytes(getContentTypeCharset(contentType)).length; - - } - - /** - * {@inheritDoc} - */ - @Override - @NotNull - protected UUID readInternal(final Class clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { - return UUID.fromString(StreamUtils.copyToString(inputMessage.getBody(), getContentTypeCharset(inputMessage.getHeaders().getContentType()))); - } - - /** - * {@inheritDoc} - */ - @Override - protected void writeInternal(final UUID uuid, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { - final HttpHeaders headers = outputMessage.getHeaders(); - if (headers.get(HttpHeaders.ACCEPT_CHARSET) == null) { - headers.setAcceptCharset(this.availableCharsets); - } - StreamUtils.copy(uuid.toString(), this.getContentTypeCharset(headers.getContentType()), outputMessage.getBody()); - } - - @NotNull - private Charset getContentTypeCharset(@Nullable final MediaType contentType) { - return Objects.requireNonNull(Optional.ofNullable(contentType) - .map(MimeType::getCharset) - .orElseGet(this::getDefaultCharset), "No default charset"); - } -} diff --git a/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java b/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java index 9cb2d012f..338ffd70f 100644 --- a/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java +++ b/src/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java @@ -89,7 +89,7 @@ public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, Optional busI HttpHeaders headers = new HttpHeaders(); headers.set(HEADER_USER_ID, userId); headers.setAccept(List.of(MediaType.TEXT_PLAIN)); - return UUID.fromString(restTemplate.postForObject(path, new HttpEntity<>(headers), String.class)); + return restTemplate.postForObject(path, new HttpEntity<>(headers), UUID.class); } private String getShortCircuitAnalysisResultResourcePath(UUID nodeUuid, ShortcircuitAnalysisType type) { @@ -281,18 +281,16 @@ public List getEnumValues(String enumName, UUID resultUuid) { } public UUID createParameters(@Nullable final String parametersInfos) { - final URI uri = UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri) - .pathSegment(SHORT_CIRCUIT_API_VERSION, "parameters") - .build() - .toUri(); + final UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri) + .pathSegment(SHORT_CIRCUIT_API_VERSION, "parameters"); try { HttpHeaders headers = new HttpHeaders(); headers.setAccept(List.of(MediaType.TEXT_PLAIN)); if (StringUtils.isBlank(parametersInfos)) { - return UUID.fromString(restTemplate.postForObject(uri, new HttpEntity<>(headers), String.class)); + return restTemplate.postForObject(uri.pathSegment("default").build().toUri(), new HttpEntity<>(headers), UUID.class); } else { headers.setContentType(MediaType.APPLICATION_JSON); - return UUID.fromString(restTemplate.postForObject(uri, new HttpEntity<>(parametersInfos, headers), String.class)); + return restTemplate.postForObject(uri.build().toUri(), new HttpEntity<>(parametersInfos, headers), UUID.class); } } catch (final HttpStatusCodeException e) { throw handleHttpError(e, CREATE_SHORTCIRCUIT_PARAMETERS_FAILED); @@ -329,11 +327,11 @@ public UUID duplicateParameters(UUID parametersUuid) { try { HttpHeaders headers = new HttpHeaders(); headers.setAccept(List.of(MediaType.TEXT_PLAIN)); - return UUID.fromString(restTemplate.postForObject(UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri) + return restTemplate.postForObject(UriComponentsBuilder.fromUriString(shortCircuitServerBaseUri) .pathSegment(SHORT_CIRCUIT_API_VERSION, "parameters") .queryParam("duplicateFrom", parametersUuid) - .buildAndExpand() - .toUri(), new HttpEntity<>(headers), String.class)); + .build() + .toUri(), new HttpEntity<>(headers), UUID.class); } catch (final HttpStatusCodeException e) { throw handleHttpError(e, CREATE_SHORTCIRCUIT_PARAMETERS_FAILED); }