Project

General

Profile

« Previous | Next » 

Revision 47226

Exception handling

View differences:

modules/uoa-openaire-connector/branches/newClaimAPI/src/main/java/eu/dnetlib/openaire/rest/HelloWorldService.java
9 9
import eu.dnetlib.data.claims.migration.handler.DirectIndexHandler;
10 10
import eu.dnetlib.data.claims.migration.handler.FetchClaimHandler;
11 11
import eu.dnetlib.data.claims.migration.handler.FetchProjectHandler;
12
import eu.dnetlib.data.claimsDemo.SQLStoreException;
12 13
import eu.dnetlib.openaire.rest.authorization.Authorization;
13 14
import eu.dnetlib.openaire.rest.inputHandler.UserHandler;
14 15
import eu.dnetlib.openaire.rest.security.JWTValidator;
......
93 94
                claims = fetchClaimHandler.fetchClaimsByProject(projectId, limit, offset, keyword, orderby, descending, listTypes,false);
94 95
                total = fetchClaimHandler.countClaimsByProject(projectId, keyword, listTypes);
95 96

  
96
            } catch (Exception e) {
97
            } catch (SQLStoreException|Exception e) {  //TODO check this with exception
97 98
                logger.error("Could not fetch claims for project with id " + projectId, e);
98 99
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
99 100
                        " for projects with id " + projectId + ".", e)).type(MediaType.APPLICATION_JSON).build();
101

  
100 102
            }
101 103

  
102 104
            return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
......
153 155
                    claims = fetchClaimHandler.fetchClaimsByProject(projectId, limit, offset, keyword, orderby, descending, listTypes,true);
154 156
                    total = fetchClaimHandler.countClaimsByProject(projectId, keyword, listTypes);
155 157
                    return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
156

  
157 158
                }
158 159

  
159

  
160

  
161
            } catch (Exception e) {
160
            } catch (SQLStoreException|Exception e) {
162 161
                logger.error("Could not fetch claims for project token " + projectToken, e);
163 162
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
164 163
                        " for projects with token " + projectToken + ".", e)).type(MediaType.APPLICATION_JSON).build();
......
210 209
                claims = fetchClaimHandler.fetchClaimsByContext(contextId, limit, offset, keyword, orderby, descending, listTypes,false);
211 210
                total = fetchClaimHandler.countClaimsByContext(contextId, keyword, listTypes);
212 211

  
213
            } catch (Exception e) {
212
            } catch (SQLStoreException|Exception e) {
214 213
                logger.error("Could not fetch claims for context with id " + contextId, e);
215 214
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
216 215
                        " for context with id " + contextId + ".", e)).type(MediaType.APPLICATION_JSON).build();
......
264 263
                claims = fetchClaimHandler.fetchClaimsByResult(resultId, limit, offset, keyword, orderby, descending, listTypes,false);
265 264
                total = fetchClaimHandler.countClaimsByResult(resultId, keyword, listTypes);
266 265

  
267
            } catch (Exception e) {
266
            } catch (SQLStoreException|Exception e) {
268 267
                logger.error("Could not fetch claims for result with id " + resultId, e);
269 268
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
270 269
                        " for result with id " + resultId + ".", e)).type(MediaType.APPLICATION_JSON).build();
......
325 324
                claims = fetchClaimHandler.fetchClaimsByUser(userMail, limit, offset, keyword, orderby, descending, listTypes,false);
326 325
                total = fetchClaimHandler.countClaimsByUser(userMail, keyword, listTypes);
327 326

  
328
            } catch (Exception e) {
327
            } catch (SQLStoreException|Exception e) {
329 328
                logger.error("Could not fetch claims for result with id " + userMail, e);
330 329
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
331 330
                        " for user with e-mail " + userMail + ".", e)).type(MediaType.APPLICATION_JSON).build();
......
364 363

  
365 364
                    return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).type(MediaType.APPLICATION_JSON).build();
366 365

  
367
                } catch (Exception e) {
366
                } catch (SQLStoreException|Exception e) {
368 367
                    logger.error("Could not fetch claims.", e);
369 368
                    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims.", e))
370 369
                            .type(MediaType.APPLICATION_JSON).build();
......
380 379

  
381 380
                return Response.status(200).entity(composeDataResponse(claim)).build();
382 381

  
383
            } catch (Exception e) {
382
            } catch (SQLStoreException|Exception e) {
384 383
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claim " +
385 384
                        "with id " + claimId + " id.", e)).type(MediaType.APPLICATION_JSON).build();
386 385
            }
......
426 425

  
427 426
                return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
428 427

  
429
            } catch (Exception e) {
428
            } catch (SQLStoreException|Exception e) {
430 429
                logger.error("Could not fetch claims.", e);
431 430
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims.", e))
432 431
                        .type(MediaType.APPLICATION_JSON).build();
......
558 557
                            .type(MediaType.APPLICATION_JSON)
559 558
                            .build();
560 559
                }
561
            } catch (Exception e) {
560
            } catch (SQLStoreException|Exception e) {
562 561
                logger.error("Fail to delete claim with id " + claimId + ".", e);
563 562
                notFoundIds.add(claimId);
564 563
            }
......
631 630
                return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("The given ids are wrong.", ve))
632 631
                        .type(MediaType.APPLICATION_JSON).build();
633 632

  
634
            } catch (Exception e) {
633
            } catch (SQLStoreException|Exception e) {
635 634
                logger.error("Fail to add new claim.", e);
636 635
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to add new claim.", e))
637 636
                        .type(MediaType.APPLICATION_JSON).build();
......
717 716
                    errorInClaims.add(jsonObject);
718 717
                    code400++;
719 718

  
720
                } catch (Exception e) {
719
                } catch (SQLStoreException|Exception e) {
721 720
                    //                logger.error("Fail to add new claim.", e);
722 721
                    //                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to add new claim.", e))
723 722
                    //                        .type(MediaType.APPLICATION_JSON).build();
......
779 778
                    errorInClaims.add(jsonObject);
780 779
                }
781 780

  
782

  
783 781
                try {
784 782
                    claimHandler.updateClaimCurationInfo(curatedBy,id, approved);
785 783
                    insertedIds.add(id);
786 784
                    code200++;
787 785

  
788
                } catch (Exception e) {
789

  
786
                } catch (SQLStoreException|Exception e) {
790 787
                    jsonObject.addProperty("error", "insertion");
791 788
                    errorInClaims.add(jsonObject);
792 789
                    code500++;
......
969 966
        return  "{ \"status\" : \"error\", \"code\" : \"400\", \"message\" : \"  " + message +" \""+  ", \"insertedIds\" : " + new Gson().toJson(insertedIds) +","+  "\"errorInClaims\" : " + new Gson().toJson(errorInClaims) + " }";
970 967
    }
971 968

  
972
    private String compose500Message(String message, Exception exception) {
969
    private String compose500Message(String message, Throwable throwable) {
973 970
        return  "{ \"status\" : \"fail\", \"code\" : \"500\", \"message\" : \"  " + message + "\", " +
974
                "\"description\" : \""+  exception.getMessage() +"\" }";
971
                "\"description\" : \""+  throwable.getMessage() +"\" }";
975 972
    }
976 973

  
977 974
    private String compose500BulkInsertMessage(String message,  List<String> insertedIds, JsonArray errorInClaims) {
modules/uoa-openaire-connector/branches/newClaimAPI/pom.xml
88 88
                </plugin>
89 89
            </plugins>
90 90
        </pluginManagement> -->
91

  
91
        <plugins>
92
            <plugin>
93
                <groupId>org.apache.maven.plugins</groupId>
94
                <artifactId>maven-compiler-plugin</artifactId>
95
                <configuration>
96
                    <source>1.7</source>
97
                    <target>1.7</target>
98
                </configuration>
99
            </plugin>
100
        </plugins>
92 101
    </build>
93 102
    <dependencies>
94 103
        <dependency>

Also available in: Unified diff