Skip to content

Commit 85ff59b

Browse files
feat: remove wrapping over rest calls with StudyException
Signed-off-by: Joris Mancini <[email protected]>
1 parent 9815d09 commit 85ff59b

40 files changed

+390
-1357
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import java.util.*;
6767

6868
import static org.gridsuite.study.server.error.StudyBusinessErrorCode.MOVE_NETWORK_MODIFICATION_FORBIDDEN;
69-
import static org.gridsuite.study.server.error.StudyBusinessErrorCode.UNKNOWN_ACTION_TYPE;
7069
import static org.gridsuite.study.server.StudyConstants.*;
7170
import static org.gridsuite.study.server.dto.ComputationType.LOAD_FLOW;
7271

@@ -689,8 +688,6 @@ public ResponseEntity<Void> moveOrCopyModifications(@PathVariable("studyUuid") U
689688
}
690689
handleMoveNetworkModifications(studyUuid, nodeUuid, originNodeUuid, modificationsToCopyUuidList, userId);
691690
break;
692-
default:
693-
throw new StudyException(UNKNOWN_ACTION_TYPE);
694691
}
695692
return ResponseEntity.ok().build();
696693
}
@@ -1750,11 +1747,9 @@ public ResponseEntity<Void> reindexRootNetwork(@Parameter(description = "study u
17501747
@Operation(summary = "Create study related notification")
17511748
@ApiResponses(value = {
17521749
@ApiResponse(responseCode = "200", description = "The notification has been sent"),
1753-
@ApiResponse(responseCode = "400", description = "The notification type is unknown")
17541750
})
1755-
public ResponseEntity<Void> notify(@PathVariable("studyUuid") UUID studyUuid,
1756-
@RequestParam("type") String notificationType) {
1757-
studyService.notify(notificationType, studyUuid);
1751+
public ResponseEntity<Void> notify(@PathVariable("studyUuid") UUID studyUuid) {
1752+
studyService.notify(studyUuid);
17581753
return ResponseEntity.ok().build();
17591754
}
17601755

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.springframework.beans.factory.annotation.Value;
1818
import org.springframework.http.HttpMethod;
1919
import org.springframework.stereotype.Service;
20-
import org.springframework.web.client.RestClientException;
2120
import org.springframework.web.client.RestTemplate;
2221
import org.springframework.web.util.UriComponentsBuilder;
2322

@@ -66,11 +65,7 @@ public void deleteCase(UUID caseUuid) {
6665
.buildAndExpand(caseUuid)
6766
.toUriString();
6867

69-
try {
70-
restTemplate.exchange(caseServerBaseUri + path, HttpMethod.DELETE, null, Void.class, caseUuid);
71-
} catch (RestClientException e) {
72-
LOGGER.error(String.format("Error while deleting case '%s' : %s", caseUuid, e.getMessage()), e);
73-
}
68+
restTemplate.exchange(caseServerBaseUri + path, HttpMethod.DELETE, null, Void.class, caseUuid);
7469
}
7570

7671
public UUID duplicateCase(UUID caseUuid, Boolean withExpiration) {

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

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
import org.gridsuite.filter.globalfilter.GlobalFilter;
1414
import org.gridsuite.filter.utils.EquipmentType;
1515
import org.gridsuite.study.server.RemoteServicesProperties;
16-
import org.gridsuite.study.server.error.StudyException;
1716
import org.springframework.beans.factory.annotation.Autowired;
1817
import org.springframework.core.ParameterizedTypeReference;
1918
import org.springframework.http.*;
2019
import org.springframework.stereotype.Service;
21-
import org.springframework.web.client.HttpStatusCodeException;
2220
import org.springframework.web.client.RestTemplate;
2321
import org.springframework.web.util.UriComponents;
2422
import org.springframework.web.util.UriComponentsBuilder;
@@ -33,9 +31,6 @@
3331
import static org.gridsuite.study.server.StudyConstants.NETWORK_UUID;
3432
import static org.gridsuite.study.server.StudyConstants.QUERY_PARAM_EQUIPMENT_TYPES;
3533
import static org.gridsuite.study.server.StudyConstants.QUERY_PARAM_VARIANT_ID;
36-
import static org.gridsuite.study.server.error.StudyBusinessErrorCode.EVALUATE_FILTER_FAILED;
37-
import static org.gridsuite.study.server.error.StudyBusinessErrorCode.NETWORK_NOT_FOUND;
38-
import static org.gridsuite.study.server.utils.StudyUtils.handleHttpError;
3934

4035
/**
4136
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
@@ -74,16 +69,7 @@ public String evaluateFilter(UUID networkUuid, String variantId, String filter)
7469
headers.setContentType(MediaType.APPLICATION_JSON);
7570
HttpEntity<String> request = new HttpEntity<>(filter, headers);
7671

77-
// call filter-server REST API
78-
try {
79-
return restTemplate.postForObject(uriComponent.toUriString(), request, String.class);
80-
} catch (HttpStatusCodeException e) {
81-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
82-
throw new StudyException(NETWORK_NOT_FOUND);
83-
} else {
84-
throw handleHttpError(e, EVALUATE_FILTER_FAILED);
85-
}
86-
}
72+
return restTemplate.postForObject(uriComponent.toUriString(), request, String.class);
8773
}
8874

8975
public List<String> evaluateGlobalFilter(@NonNull final UUID networkUuid, @NonNull final String variantId,
@@ -96,16 +82,12 @@ public List<String> evaluateGlobalFilter(@NonNull final UUID networkUuid, @NonNu
9682
.build();
9783
HttpHeaders headers = new HttpHeaders();
9884
headers.setContentType(MediaType.APPLICATION_JSON);
99-
try {
100-
return restTemplate.exchange(uriComponent.toUri(), HttpMethod.POST, new HttpEntity<>(filter, headers), new ParameterizedTypeReference<List<String>>() { })
101-
.getBody();
102-
} catch (final HttpStatusCodeException ex) {
103-
if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) {
104-
throw new StudyException(NETWORK_NOT_FOUND);
105-
} else {
106-
throw handleHttpError(ex, EVALUATE_FILTER_FAILED);
107-
}
108-
}
85+
return restTemplate.exchange(
86+
uriComponent.toUri(),
87+
HttpMethod.POST,
88+
new HttpEntity<>(filter, headers),
89+
new ParameterizedTypeReference<List<String>>() { }
90+
).getBody();
10991
}
11092

11193
public String exportFilter(UUID networkUuid, UUID filterUuid) {

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

Lines changed: 17 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.springframework.http.*;
2121
import org.springframework.lang.Nullable;
2222
import org.springframework.stereotype.Service;
23-
import org.springframework.web.client.HttpStatusCodeException;
2423
import org.springframework.web.client.RestTemplate;
2524
import org.springframework.web.util.UriComponentsBuilder;
2625

@@ -34,7 +33,6 @@
3433

3534
import static org.gridsuite.study.server.StudyConstants.*;
3635
import static org.gridsuite.study.server.error.StudyBusinessErrorCode.*;
37-
import static org.gridsuite.study.server.utils.StudyUtils.handleHttpError;
3836

3937
/**
4038
* @author Kevin Le Saulnier <kevin.lesaulnier at rte-france.com>
@@ -111,8 +109,6 @@ public Integer getLoadFlowResultsCount() {
111109
}
112110

113111
public String getLoadFlowResult(UUID resultUuid, String filters, Sort sort) {
114-
String result;
115-
116112
if (resultUuid == null) {
117113
return null;
118114
}
@@ -126,15 +122,7 @@ public String getLoadFlowResult(UUID resultUuid, String filters, Sort sort) {
126122
}
127123
String path = uriComponentsBuilder.buildAndExpand(resultUuid).toUriString();
128124

129-
try {
130-
result = restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
131-
} catch (HttpStatusCodeException e) {
132-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
133-
throw new StudyException(LOADFLOW_NOT_FOUND);
134-
}
135-
throw e;
136-
}
137-
return result;
125+
return restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
138126
}
139127

140128
public String getLoadFlowModifications(UUID resultUuid) {
@@ -143,15 +131,7 @@ public String getLoadFlowModifications(UUID resultUuid) {
143131
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/results/{resultUuid}/modifications");
144132
String path = uriComponentsBuilder.buildAndExpand(resultUuid).toUriString();
145133

146-
try {
147-
result = restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
148-
} catch (HttpStatusCodeException e) {
149-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
150-
throw new StudyException(LOADFLOW_NOT_FOUND);
151-
}
152-
throw e;
153-
}
154-
return result;
134+
return restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
155135
}
156136

157137
public LoadFlowStatus getLoadFlowStatus(UUID resultUuid) {
@@ -164,15 +144,7 @@ public LoadFlowStatus getLoadFlowStatus(UUID resultUuid) {
164144
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/results/{resultUuid}/status");
165145
String path = uriComponentsBuilder.buildAndExpand(resultUuid).toUriString();
166146

167-
try {
168-
result = restTemplate.getForObject(loadFlowServerBaseUri + path, LoadFlowStatus.class);
169-
} catch (HttpStatusCodeException e) {
170-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
171-
throw new StudyException(LOADFLOW_NOT_FOUND);
172-
}
173-
throw e;
174-
}
175-
return result;
147+
return restTemplate.getForObject(loadFlowServerBaseUri + path, LoadFlowStatus.class);
176148
}
177149

178150
public void stopLoadFlow(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, UUID resultUuid, String userId) {
@@ -249,47 +221,24 @@ public List<LimitViolationInfos> getLimitViolations(UUID resultUuid, String filt
249221
sort.forEach(order -> uriComponentsBuilder.queryParam("sort", order.getProperty() + "," + order.getDirection()));
250222
}
251223
String path = uriComponentsBuilder.buildAndExpand(resultUuid).toUriString();
252-
try {
253-
ResponseEntity<List<LimitViolationInfos>> responseEntity = restTemplate.exchange(loadFlowServerBaseUri + path, HttpMethod.GET, null, new ParameterizedTypeReference<>() {
254-
});
255-
result = responseEntity.getBody();
256-
} catch (HttpStatusCodeException e) {
257-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
258-
throw new StudyException(LOADFLOW_NOT_FOUND);
259-
}
260-
throw e;
261-
}
224+
return restTemplate.exchange(loadFlowServerBaseUri + path, HttpMethod.GET, null, new ParameterizedTypeReference<List<LimitViolationInfos>>() {
225+
}).getBody();
262226
}
263227
return result;
264228
}
265229

266230
public List<LimitViolationInfos> getCurrentLimitViolations(UUID resultUuid) {
267231
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/results/{resultUuid}/current-limit-violations");
268232
String path = uriComponentsBuilder.buildAndExpand(resultUuid).toUriString();
269-
try {
270-
ResponseEntity<List<LimitViolationInfos>> responseEntity = restTemplate.exchange(loadFlowServerBaseUri + path, HttpMethod.GET, null, new ParameterizedTypeReference<>() {
271-
});
272-
return responseEntity.getBody();
273-
} catch (HttpStatusCodeException e) {
274-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
275-
throw new StudyException(LOADFLOW_NOT_FOUND);
276-
}
277-
throw e;
278-
}
233+
return restTemplate.exchange(loadFlowServerBaseUri + path, HttpMethod.GET, null, new ParameterizedTypeReference<List<LimitViolationInfos>>() {
234+
}).getBody();
279235
}
280236

281237
public LoadFlowParametersInfos getLoadFlowParameters(UUID parametersUuid) {
282238

283239
String path = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + PARAMETERS_URI)
284240
.buildAndExpand(parametersUuid).toUriString();
285-
try {
286-
return restTemplate.getForObject(loadFlowServerBaseUri + path, LoadFlowParametersInfos.class);
287-
} catch (HttpStatusCodeException e) {
288-
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
289-
throw new StudyException(LOADFLOW_PARAMETERS_NOT_FOUND);
290-
}
291-
throw handleHttpError(e, GET_LOADFLOW_PARAMETERS_FAILED);
292-
}
241+
return restTemplate.getForObject(loadFlowServerBaseUri + path, LoadFlowParametersInfos.class);
293242
}
294243

295244
public UUID createLoadFlowParameters(String parameters) {
@@ -306,11 +255,7 @@ public UUID createLoadFlowParameters(String parameters) {
306255

307256
HttpEntity<String> httpEntity = new HttpEntity<>(parameters, headers);
308257

309-
try {
310-
return restTemplate.postForObject(loadFlowServerBaseUri + path, httpEntity, UUID.class);
311-
} catch (HttpStatusCodeException e) {
312-
throw handleHttpError(e, CREATE_LOADFLOW_PARAMETERS_FAILED);
313-
}
258+
return restTemplate.postForObject(loadFlowServerBaseUri + path, httpEntity, UUID.class);
314259
}
315260

316261
public UUID duplicateLoadFlowParameters(UUID sourceParametersUuid) {
@@ -322,11 +267,7 @@ public UUID duplicateLoadFlowParameters(UUID sourceParametersUuid) {
322267
.queryParam("duplicateFrom", sourceParametersUuid)
323268
.buildAndExpand(sourceParametersUuid).toUriString();
324269

325-
try {
326-
return restTemplate.postForObject(loadFlowServerBaseUri + path, null, UUID.class);
327-
} catch (HttpStatusCodeException e) {
328-
throw handleHttpError(e, CREATE_LOADFLOW_PARAMETERS_FAILED);
329-
}
270+
return restTemplate.postForObject(loadFlowServerBaseUri + path, null, UUID.class);
330271
}
331272

332273
public void updateLoadFlowParameters(UUID parametersUuid, @Nullable String parameters) {
@@ -340,11 +281,7 @@ public void updateLoadFlowParameters(UUID parametersUuid, @Nullable String param
340281

341282
HttpEntity<String> httpEntity = new HttpEntity<>(parameters, headers);
342283

343-
try {
344-
restTemplate.put(loadFlowServerBaseUri + path, httpEntity);
345-
} catch (HttpStatusCodeException e) {
346-
throw handleHttpError(e, UPDATE_LOADFLOW_PARAMETERS_FAILED);
347-
}
284+
restTemplate.put(loadFlowServerBaseUri + path, httpEntity);
348285
}
349286

350287
public void deleteLoadFlowParameters(UUID uuid) {
@@ -353,11 +290,7 @@ public void deleteLoadFlowParameters(UUID uuid) {
353290
.buildAndExpand(uuid)
354291
.toUriString();
355292

356-
try {
357-
restTemplate.delete(loadFlowServerBaseUri + path);
358-
} catch (HttpStatusCodeException e) {
359-
throw handleHttpError(e, DELETE_LOADFLOW_PARAMETERS_FAILED);
360-
}
293+
restTemplate.delete(loadFlowServerBaseUri + path);
361294
}
362295

363296
public void updateLoadFlowProvider(UUID parameterUuid, String provider) {
@@ -372,11 +305,7 @@ public void updateLoadFlowProvider(UUID parameterUuid, String provider) {
372305

373306
HttpEntity<String> httpEntity = new HttpEntity<>(provider, headers);
374307

375-
try {
376-
restTemplate.exchange(loadFlowServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class);
377-
} catch (HttpStatusCodeException e) {
378-
throw handleHttpError(e, UPDATE_LOADFLOW_PROVIDER_FAILED);
379-
}
308+
restTemplate.exchange(loadFlowServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class);
380309
}
381310

382311
public String getLoadFlowDefaultProvider() {
@@ -385,11 +314,7 @@ public String getLoadFlowDefaultProvider() {
385314
.buildAndExpand()
386315
.toUriString();
387316

388-
try {
389-
return restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
390-
} catch (HttpStatusCodeException e) {
391-
throw handleHttpError(e, GET_LOADFLOW_DEFAULT_PROVIDER_FAILED);
392-
}
317+
return restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
393318
}
394319

395320
public UUID createDefaultLoadFlowParameters() {
@@ -399,11 +324,7 @@ public UUID createDefaultLoadFlowParameters() {
399324
.buildAndExpand()
400325
.toUriString();
401326

402-
try {
403-
return restTemplate.postForObject(loadFlowServerBaseUri + path, null, UUID.class);
404-
} catch (HttpStatusCodeException e) {
405-
throw handleHttpError(e, CREATE_LOADFLOW_PARAMETERS_FAILED);
406-
}
327+
return restTemplate.postForObject(loadFlowServerBaseUri + path, null, UUID.class);
407328
}
408329

409330
public UUID getLoadFlowParametersOrDefaultsUuid(StudyEntity studyEntity) {
@@ -418,15 +339,11 @@ public String getLoadFlowProvider(UUID parametersUuid) {
418339
String path = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + PARAMETERS_URI + "/provider")
419340
.buildAndExpand(parametersUuid).toUriString();
420341

421-
try {
422-
return restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
423-
} catch (HttpStatusCodeException e) {
424-
throw handleHttpError(e, GET_LOADFLOW_PROVIDER_FAILED);
425-
}
342+
return restTemplate.getForObject(loadFlowServerBaseUri + path, String.class);
426343
}
427344

428345
@Override
429346
public List<String> getEnumValues(String enumName, UUID resultUuid) {
430-
return getEnumValues(enumName, resultUuid, LOADFLOW_API_VERSION, loadFlowServerBaseUri, LOADFLOW_NOT_FOUND, restTemplate);
347+
return getEnumValues(enumName, resultUuid, LOADFLOW_API_VERSION, loadFlowServerBaseUri, restTemplate);
431348
}
432349
}

0 commit comments

Comments
 (0)