2020import org .springframework .http .*;
2121import org .springframework .lang .Nullable ;
2222import org .springframework .stereotype .Service ;
23- import org .springframework .web .client .HttpStatusCodeException ;
2423import org .springframework .web .client .RestTemplate ;
2524import org .springframework .web .util .UriComponentsBuilder ;
2625
3433
3534import static org .gridsuite .study .server .StudyConstants .*;
3635import 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