Skip to content

Commit 9536ba7

Browse files
committed
refactor: for parameter servers, update existing parameters instead of creating new and deleting old
Added forgotten ShortCircuit parameter deletion on study deletion Use DTO for updating LoadFlow parameters Refactored createOrUpdate methods for parameters to better handle the creation of new parameters or update of existing parameters and removed the return in the middle of the method Updated tests to work with updated code
1 parent 272b4b6 commit 9536ba7

13 files changed

Lines changed: 323 additions & 218 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.gridsuite.study.server.StudyApi;
2121
import org.gridsuite.study.server.StudyConstants.ModificationsActionType;
2222
import org.gridsuite.study.server.dto.modification.NetworkModificationMetadata;
23+
import org.gridsuite.study.server.dto.securityanalysis.SecurityAnalysisParametersValues;
2324
import org.gridsuite.study.server.error.StudyException;
2425
import org.gridsuite.study.server.dto.*;
2526
import org.gridsuite.study.server.dto.computation.LoadFlowComputationInfos;
@@ -1079,7 +1080,7 @@ public ResponseEntity<List<String>> getResultEnumValues(@Parameter(description =
10791080
@ApiResponse(responseCode = "204", description = "Reset with user profile cannot be done")})
10801081
public ResponseEntity<Void> setLoadflowParameters(
10811082
@PathVariable("studyUuid") UUID studyUuid,
1082-
@RequestBody(required = false) String lfParameter,
1083+
@RequestBody(required = false) LoadFlowParametersInfos lfParameter,
10831084
@RequestHeader(HEADER_USER_ID) String userId) {
10841085
studyService.assertNoBlockedNodeInStudy(studyUuid, networkModificationTreeService.getStudyRootNodeUuid(studyUuid));
10851086
return studyService.setLoadFlowParameters(studyUuid, lfParameter, userId) ? ResponseEntity.noContent().build() : ResponseEntity.ok().build();
@@ -2071,7 +2072,7 @@ public ResponseEntity<String> getDynamicSecurityAnalysisStatus(@Parameter(descri
20712072
@GetMapping(value = "/studies/{studyUuid}/security-analysis/parameters")
20722073
@Operation(summary = "Get security analysis parameters on study")
20732074
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis parameters")})
2074-
public ResponseEntity<String> getSecurityAnalysisParametersValues(
2075+
public ResponseEntity<SecurityAnalysisParametersValues> getSecurityAnalysisParametersValues(
20752076
@PathVariable("studyUuid") UUID studyUuid) {
20762077
return ResponseEntity.ok().body(studyService.getSecurityAnalysisParametersValues(studyUuid));
20772078
}
@@ -2082,7 +2083,7 @@ public ResponseEntity<String> getSecurityAnalysisParametersValues(
20822083
@ApiResponse(responseCode = "204", description = "Reset with user profile cannot be done")})
20832084
public ResponseEntity<Void> setSecurityAnalysisParametersValues(
20842085
@PathVariable("studyUuid") UUID studyUuid,
2085-
@RequestBody(required = false) String securityAnalysisParametersValues,
2086+
@RequestBody(required = false) SecurityAnalysisParametersValues securityAnalysisParametersValues,
20862087
@RequestHeader(HEADER_USER_ID) String userId) {
20872088
return studyService.setSecurityAnalysisParametersValues(studyUuid, securityAnalysisParametersValues, userId) ? ResponseEntity.noContent().build() : ResponseEntity.ok().build();
20882089
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.gridsuite.study.server.dto.securityanalysis;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import org.gridsuite.study.server.dto.LimitReductionsByVoltageLevel;
8+
9+
import java.util.List;
10+
11+
/**
12+
* This DTO is a copy of Security Analysis Server's SecurityAnalysisParametersValues DTO and require updates when original DTO is updated
13+
*
14+
* @author Kamil MARUT {@literal <kamil.marut at rte-france.com>}
15+
*/
16+
17+
@Getter
18+
@AllArgsConstructor
19+
@Builder
20+
@NoArgsConstructor
21+
public class SecurityAnalysisParametersValues {
22+
23+
private String provider;
24+
25+
private double lowVoltageAbsoluteThreshold;
26+
27+
private double lowVoltageProportionalThreshold;
28+
29+
private double highVoltageAbsoluteThreshold;
30+
31+
private double highVoltageProportionalThreshold;
32+
33+
private double flowProportionalThreshold;
34+
35+
private List<LimitReductionsByVoltageLevel> limitReductions;
36+
37+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ public LoadFlowParametersInfos getLoadFlowParameters(UUID parametersUuid) {
241241
return restTemplate.getForObject(loadFlowServerBaseUri + path, LoadFlowParametersInfos.class);
242242
}
243243

244-
public UUID createLoadFlowParameters(String parameters) {
244+
public UUID createLoadFlowParameters(LoadFlowParametersInfos lfParameters) {
245245

246-
Objects.requireNonNull(parameters);
246+
Objects.requireNonNull(lfParameters);
247247

248248
var path = UriComponentsBuilder
249249
.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/parameters")
@@ -253,7 +253,7 @@ public UUID createLoadFlowParameters(String parameters) {
253253
HttpHeaders headers = new HttpHeaders();
254254
headers.setContentType(MediaType.APPLICATION_JSON);
255255

256-
HttpEntity<String> httpEntity = new HttpEntity<>(parameters, headers);
256+
HttpEntity<LoadFlowParametersInfos> httpEntity = new HttpEntity<>(lfParameters, headers);
257257

258258
return restTemplate.postForObject(loadFlowServerBaseUri + path, httpEntity, UUID.class);
259259
}
@@ -270,7 +270,7 @@ public UUID duplicateLoadFlowParameters(UUID sourceParametersUuid) {
270270
return restTemplate.postForObject(loadFlowServerBaseUri + path, null, UUID.class);
271271
}
272272

273-
public void updateLoadFlowParameters(UUID parametersUuid, @Nullable String parameters) {
273+
public void updateLoadFlowParameters(UUID parametersUuid, @Nullable LoadFlowParametersInfos lfParameters) {
274274
var path = UriComponentsBuilder
275275
.fromPath(DELIMITER + LOADFLOW_API_VERSION + PARAMETERS_URI)
276276
.buildAndExpand(parametersUuid)
@@ -279,7 +279,7 @@ public void updateLoadFlowParameters(UUID parametersUuid, @Nullable String param
279279
HttpHeaders headers = new HttpHeaders();
280280
headers.setContentType(MediaType.APPLICATION_JSON);
281281

282-
HttpEntity<String> httpEntity = new HttpEntity<>(parameters, headers);
282+
HttpEntity<LoadFlowParametersInfos> httpEntity = new HttpEntity<>(lfParameters, headers);
283283

284284
restTemplate.put(loadFlowServerBaseUri + path, httpEntity);
285285
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lombok.Setter;
1212
import org.apache.commons.lang3.StringUtils;
1313
import org.gridsuite.study.server.RemoteServicesProperties;
14+
import org.gridsuite.study.server.dto.securityanalysis.SecurityAnalysisParametersValues;
1415
import org.gridsuite.study.server.error.StudyException;
1516
import org.gridsuite.study.server.dto.NodeReceiver;
1617
import org.gridsuite.study.server.dto.ReportInfos;
@@ -225,13 +226,13 @@ public void assertSecurityAnalysisNotRunning(UUID resultUuid) {
225226
}
226227
}
227228

228-
public void updateSecurityAnalysisParameters(UUID parametersUuid, @Nullable String parameters) {
229+
public void updateSecurityAnalysisParameters(UUID parametersUuid, @Nullable SecurityAnalysisParametersValues saParameters) {
229230
var uriBuilder = UriComponentsBuilder.fromPath(DELIMITER + SECURITY_ANALYSIS_API_VERSION + "/parameters/{uuid}");
230231
String path = uriBuilder.buildAndExpand(parametersUuid).toUriString();
231232

232233
HttpHeaders headers = new HttpHeaders();
233234
headers.setContentType(MediaType.APPLICATION_JSON);
234-
HttpEntity<String> httpEntity = new HttpEntity<>(parameters, headers);
235+
HttpEntity<SecurityAnalysisParametersValues> httpEntity = new HttpEntity<>(saParameters, headers);
235236

236237
restTemplate.put(securityAnalysisServerBaseUri + path, httpEntity);
237238
}
@@ -250,13 +251,13 @@ public UUID duplicateSecurityAnalysisParameters(UUID sourceParametersUuid) {
250251
return restTemplate.exchange(securityAnalysisServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody();
251252
}
252253

253-
public String getSecurityAnalysisParameters(UUID parametersUuid) {
254+
public SecurityAnalysisParametersValues getSecurityAnalysisParameters(UUID parametersUuid) {
254255
Objects.requireNonNull(parametersUuid);
255256

256257
String path = UriComponentsBuilder.fromPath(DELIMITER + SECURITY_ANALYSIS_API_VERSION + PARAMETERS_URI)
257258
.buildAndExpand(parametersUuid).toUriString();
258259

259-
return restTemplate.getForObject(securityAnalysisServerBaseUri + path, String.class);
260+
return restTemplate.getForObject(securityAnalysisServerBaseUri + path, SecurityAnalysisParametersValues.class);
260261
}
261262

262263
public UUID getSecurityAnalysisParametersUuidOrElseCreateDefaults(StudyEntity studyEntity) {
@@ -286,15 +287,15 @@ public UUID createDefaultSecurityAnalysisParameters() {
286287
return restTemplate.exchange(securityAnalysisServerBaseUri + path, HttpMethod.POST, null, UUID.class).getBody();
287288
}
288289

289-
public UUID createSecurityAnalysisParameters(String parameters) {
290+
public UUID createSecurityAnalysisParameters(SecurityAnalysisParametersValues saParameters) {
290291
var path = UriComponentsBuilder
291292
.fromPath(DELIMITER + SECURITY_ANALYSIS_API_VERSION + "/parameters")
292293
.buildAndExpand()
293294
.toUriString();
294295

295296
HttpHeaders headers = new HttpHeaders();
296297
headers.setContentType(MediaType.APPLICATION_JSON);
297-
HttpEntity<String> httpEntity = new HttpEntity<>(parameters, headers);
298+
HttpEntity<SecurityAnalysisParametersValues> httpEntity = new HttpEntity<>(saParameters, headers);
298299

299300
return restTemplate.exchange(securityAnalysisServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody();
300301
}

0 commit comments

Comments
 (0)