Changeset 5552 for ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
- Timestamp:
- 08/13/14 16:55:59 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r5551 r5552 189 189 "Releasing {} registered components into the world ({} millisecs)", 190 190 result.size(), (System.currentTimeMillis() - start)); 191 191 192 return result; 192 193 } catch (AuthenticationFailException e) { … … 214 215 215 216 long start = System.currentTimeMillis(); 216 217 217 218 if (!checkRegistrySpaceString(registrySpace)) { 218 219 response.sendError(Status.NOT_FOUND.getStatusCode(), "illegal registry space"); … … 225 226 "Releasing {} registered components into the world ({} millisecs)", 226 227 result.size(), (System.currentTimeMillis() - start)); 228 227 229 return result; 228 230 } catch (AuthenticationFailException e) { … … 418 420 public List<Comment> getCommentsFromProfile( 419 421 @PathParam("profileId") String profileId) 420 throws ComponentRegistryException,IOException {422 throws IOException { 421 423 long start = System.currentTimeMillis(); 422 424 try { … … 426 428 comments.size(), (System.currentTimeMillis() - start)); 427 429 return comments; 430 } catch (ComponentRegistryException e) { 431 response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); 432 return new ArrayList<Comment>(); 428 433 } catch (ItemNotFoundException e) { 429 response.sendError(Status.NOT_FOUND.getStatusCode() );434 response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage()); 430 435 return new ArrayList<Comment>(); 431 432 436 } catch (UserUnauthorizedException e) { 433 response.sendError(Status.FORBIDDEN.getStatusCode() );437 response.sendError(Status.FORBIDDEN.getStatusCode(), e.getMessage()); 434 438 return new ArrayList<Comment>(); 435 439 } catch (AuthenticationFailException e1) { 436 response.sendError(Status.UNAUTHORIZED.getStatusCode() );440 response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage()); 437 441 return new ArrayList<Comment>(); 438 442 } … … 446 450 public List<Comment> getCommentsFromComponent( 447 451 @PathParam("componentId") String componentId) 448 throws ComponentRegistryException,IOException {452 throws IOException { 449 453 long start = System.currentTimeMillis(); 450 454 try { … … 454 458 comments.size(), (System.currentTimeMillis() - start)); 455 459 return comments; 460 } catch (ComponentRegistryException e) { 461 response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); 462 return new ArrayList<Comment>(); 456 463 } catch (ItemNotFoundException e) { 457 response.sendError(Status.NOT_FOUND.getStatusCode() );464 response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage()); 458 465 return new ArrayList<Comment>(); 459 466 } catch (UserUnauthorizedException e1) { 460 response.sendError(Status.FORBIDDEN.getStatusCode() );467 response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage()); 461 468 return new ArrayList<Comment>(); 462 469 } catch (AuthenticationFailException e1) { 463 response.sendError(Status.UNAUTHORIZED.getStatusCode() );470 response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage()); 464 471 return new ArrayList<Comment>(); 465 472 } … … 474 481 @PathParam("profileId") String profileId, 475 482 @PathParam("commentId") String commentId) 476 throws ComponentRegistryException,IOException {483 throws IOException { 477 484 478 485 LOG.debug("Comments of profile with id {} are requested.", commentId); … … 480 487 481 488 return this.getBaseRegistry().getSpecifiedCommentInProfile(profileId, commentId); 489 } catch (ComponentRegistryException e) { 490 response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); 491 return new Comment(); 482 492 } catch (ItemNotFoundException e) { 483 response.sendError(Status.NOT_FOUND.getStatusCode() );493 response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage()); 484 494 return new Comment(); 485 495 } catch (UserUnauthorizedException e1) { 486 response.sendError(Status.FORBIDDEN.getStatusCode() );496 response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage()); 487 497 return new Comment(); 488 498 } catch (AuthenticationFailException e1) { 489 response.sendError(Status.UNAUTHORIZED.getStatusCode() );499 response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage()); 490 500 return new Comment(); 491 501 } … … 500 510 @PathParam("componentId") String componentId, 501 511 @PathParam("commentId") String commentId) 502 throws ComponentRegistryException,IOException {512 throws IOException { 503 513 LOG.debug("Comments of component with id {} are requested.", commentId); 504 514 try { 505 515 506 516 return this.getBaseRegistry().getSpecifiedCommentInComponent(componentId, commentId); 517 } catch (ComponentRegistryException e) { 518 response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); 519 return new Comment(); 507 520 } catch (ItemNotFoundException e) { 508 response.sendError(Status.NOT_FOUND.getStatusCode() );521 response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage()); 509 522 return new Comment(); 510 523 } catch (UserUnauthorizedException e1) { 511 response.sendError(Status.FORBIDDEN.getStatusCode() );524 response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage()); 512 525 return new Comment(); 513 526 } catch (AuthenticationFailException e1) { 514 response.sendError(Status.UNAUTHORIZED.getStatusCode() );527 response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage()); 515 528 return new Comment(); 516 529 } … … 540 553 } 541 554 542 // TODO: test via POSTMAN555 543 556 @Override 544 557 @POST … … 555 568 } 556 569 557 // TODO: test via POSTMAN570 558 571 @Override 559 572 @POST … … 848 861 .build(); 849 862 } catch (ItemNotFoundException e) { 850 LOG.warn("Component with id " + componentId + " is not found.", 851 e); 863 LOG.warn("Component with id " + componentId + " is not found."); 852 864 return Response.serverError().status(Status.NOT_FOUND) 853 865 .build(); … … 869 881 870 882 LOG.info("Component with id: {} deleted.", componentId); 871 return Response.ok( ).build();883 return Response.ok("Component with id" + componentId+" deleted.").build(); 872 884 } 873 885 … … 1736 1748 @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, 1737 1749 MediaType.APPLICATION_JSON}) 1738 public StringtransferItemOwnershipToGroup(@PathParam("itemId") String itemId,1750 public Response transferItemOwnershipToGroup(@PathParam("itemId") String itemId, 1739 1751 @QueryParam("groupId") long groupId) throws IOException { 1740 1752 Principal principal = security.getUserPrincipal(); 1741 1753 try { 1742 1754 groupService.transferItemOwnershipFromUserToGroupId(principal.getName(), groupId, itemId); 1743 return "No exceptions happen, the item shoul be transferred";1755 return Response.ok("Ownership transferred").build(); 1744 1756 } catch (UserUnauthorizedException e) { 1745 response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString()); 1746 return e.toString(); 1757 return Response.status(Status.FORBIDDEN).build(); 1747 1758 } 1748 1759 } … … 1757 1768 try { 1758 1769 ComponentRegistry cr = this.getBaseRegistry(); 1759 try { 1760 BaseDescription description = cr.getComponentDescriptionAccessControlled(itemId); 1770 BaseDescription description; 1771 if (itemId.startsWith(ComponentDescription.COMPONENT_PREFIX)) { 1772 description = cr.getComponentDescriptionAccessControlled(itemId); 1761 1773 return description; 1762 } catch (UserUnauthorizedException ex1) { 1763 try { 1764 BaseDescription description = cr.getProfileDescriptionAccessControlled(itemId); 1765 return description; 1766 } catch (UserUnauthorizedException ex2) { 1767 response.sendError(Status.FORBIDDEN.getStatusCode(), "User \'" + security.getUserPrincipal().getName() + "\' does not have access to the item with the given id or the item with the given id does not exist."); 1768 return new BaseDescription(); 1769 } 1770 } 1774 }; 1775 if (itemId.startsWith(ProfileDescription.PROFILE_PREFIX)) { 1776 description = cr.getProfileDescriptionAccessControlled(itemId); 1777 return description; 1778 }; 1779 response.sendError(Status.BAD_REQUEST.getStatusCode()); 1780 return new BaseDescription(); 1781 1782 1783 } catch (UserUnauthorizedException ex2) { 1784 response.sendError(Status.FORBIDDEN.getStatusCode(), ex2.getMessage()); 1785 return new BaseDescription(); 1771 1786 } catch (ItemNotFoundException e) { 1772 response.sendError(Status.NOT_FOUND.getStatusCode() );1787 response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage()); 1773 1788 return new BaseDescription(); 1774 1789 } catch (AuthenticationFailException e) {
Note: See TracChangeset
for help on using the changeset viewer.