Changeset 5552 for ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.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/impl/database/ComponentRegistryDbImpl.java
r5550 r5552 84 84 private GroupService groupService; 85 85 86 87 86 // 88 87 /** 89 88 * Default constructor, to use this as a (spring) bean. The public registry 90 * by default. Use setRegistryStatus(), setRegistryOwner(), setGroupId() to make it another kind of91 * registry.89 * by default. Use setRegistryStatus(), setRegistryOwner(), setGroupId() to 90 * make it another kind of registry. 92 91 * 93 * 92 * 94 93 */ 95 94 public ComponentRegistryDbImpl() throws TransformerException { … … 97 96 } 98 97 99 100 98 @Override 101 99 public Owner getRegistryOwner() { 102 100 return this.registryOwner; 103 101 } 104 102 105 103 @Override 106 104 public void setRegistryOwner(Owner registryOwner) { 107 105 this.registryOwner = registryOwner; 108 106 } 109 110 107 111 108 @Override 112 109 public RegistrySpace getRegistrySpace() { … … 123 120 return this.groupId; 124 121 } 125 122 126 123 @Override 127 124 public void setGroupId(Number groupId) { 128 125 this.groupId = groupId; 129 126 } 130 131 @Override 132 public Number getBaseDescriptionOwnerId(String cmdId) {127 128 @Override 129 public Number getBaseDescriptionOwnerId(String cmdId) { 133 130 BaseDescription bd = componentDao.getByCmdId(cmdId); 134 131 return bd.getDbUserId(); 135 132 } 136 137 @Override 138 public List<Number> getItemGroups(String cmdId){133 134 @Override 135 public List<Number> getItemGroups(String cmdId) { 139 136 List<Group> groups = groupService.getGroupsTheItemIsAMemberOf(cmdId); 140 137 List<Number> result = new ArrayList<Number>(); 141 138 if (groups != null) { 142 for (Group group : groups) {139 for (Group group : groups) { 143 140 result.add(group.getId()); 144 141 } … … 146 143 return result; 147 144 } 148 145 149 146 /** 150 147 * @return The user id, or null if there is no owner or it is not a user. … … 157 154 } 158 155 } 159 156 160 157 @Override 161 158 public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException { … … 180 177 181 178 @Override 182 public Boolean isItemPublic(String id) throws ItemNotFoundException {179 public Boolean isItemPublic(String id) throws ItemNotFoundException { 183 180 BaseDescription desc = componentDao.getByCmdId(id); 184 181 if (desc == null) { 185 182 String idS = (id == null) ? "null" : id; 186 throw new ItemNotFoundException("The component with the id " + idS + "is not found in the database.");183 throw new ItemNotFoundException("The component with the id " + idS + "is not found in the database."); 187 184 } 188 185 return desc.isPublic(); … … 284 281 return comment; 285 282 } else { 286 throw new ComponentRegistryException("Comment " + commentId + "for the profile "+profileId);283 throw new ItemNotFoundException("Comment " + commentId + " for the profile " + profileId + " is not found."); 287 284 } 288 285 } catch (DataAccessException ex) { … … 322 319 return comment; 323 320 } else { 324 throw new ComponentRegistryException("Comment " + commentId + "for the profile "+componentId);321 throw new ItemNotFoundException("Comment " + commentId + " for the component " + componentId + " is not found."); 325 322 } 326 323 } catch (DataAccessException ex) { … … 437 434 public int registerComment(Comment comment, String principalName) throws ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException { 438 435 try { 439 if (comment.getComponentId() != null) { 440 if (this.canCurrentUserAccessDescription(comment.getComponentId())) 441 { 442 // Convert principal name to user record id 443 Number uid = convertUserIdInComment(comment, principalName); 444 // Set date to current date 445 comment.setCommentDate(new Date()); 446 comment.setUserId(uid.longValue()); 447 commentsDao.saveAndFlush(comment); 448 436 if (comment.getComponentId() != null) { 437 if (this.canCurrentUserAccessDescription(comment.getComponentId())) { 438 // Convert principal name to user record id 439 Number uid = convertUserIdInComment(comment, principalName); 440 // Set date to current date 441 comment.setCommentDate(new Date()); 442 comment.setUserId(uid.longValue()); 443 commentsDao.saveAndFlush(comment); 444 445 } else { 446 throw new UserUnauthorizedException("The logged-in user cannot access the component/profile with id " + comment.getComponentId()); 447 } 449 448 } else { 450 throw new UserUnauthorizedException("The logged-in user cannot access the component/profile with id "+comment.getComponentId()); 451 } 452 } else { 453 throw new ComponentRegistryException("The component/profile id for this comment is null."); 449 throw new ComponentRegistryException("The component/profile id for this comment is null."); 454 450 } 455 451 return 0; … … 623 619 public void deleteMDComponent(String componentId, boolean forceDelete) 624 620 throws UserUnauthorizedException, DeleteFailedException, ComponentRegistryException, ItemNotFoundException { 625 BaseDescription desc = componentDao.getByCmdId(componentId);621 BaseDescription desc = getComponentDescriptionAccessControlled(componentId); 626 622 if (desc != null) { 627 623 try { … … 639 635 } 640 636 } 641 642 643 637 644 638 private void invalidateCache(BaseDescription description) { … … 704 698 705 699 private void checkAuthorisation(BaseDescription desc) throws UserUnauthorizedException, ItemNotFoundException { 706 if (!this.canCurrentUserAccessDescription(desc.getId())) { 700 if (!this.canCurrentUserAccessDescription(desc.getId())) { 707 701 String principalName = (registryOwner != null) ? userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName() : "null"; 708 702 throw new UserUnauthorizedException("Unauthorized operation user '" + principalName … … 715 709 String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName(); 716 710 if (!(this.isOwnerOfComment(desc, principalName) || configuration.isAdminUser(principalName))) { 717 throw new UserUnauthorizedException("Unauthorized operation user '" + principalName718 + "' is not the creator (nor a member of the group, nor an administrator) of the " + (desc.getId()) + "(" + desc + ").");711 throw new UserUnauthorizedException("Unauthorized operation: user '" + principalName 712 + "' is not the creator (nor the Administrator) of the comment " + (desc.getId())); 719 713 } 720 714 } … … 741 735 throw new DeleteFailedException( 742 736 "The " 743 + (desc.isProfile() ? " Profile" : "Component")744 + " is more th en a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");737 + (desc.isProfile() ? "profile" : "Ccomponent") 738 + " is more than a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata."); 745 739 } 746 740 } … … 766 760 } 767 761 768 private boolean canCurrentUserAccessDescription(String cmdId) throws ItemNotFoundException {762 private boolean canCurrentUserAccessDescription(String cmdId) throws ItemNotFoundException { 769 763 if (cmdId == null) { 770 764 throw new ItemNotFoundException("Item with the null cmdIdentifier."); 771 765 } 772 766 773 767 BaseDescription description = componentDao.getByCmdId(cmdId); 774 768 if (description == null) { 775 throw new ItemNotFoundException("Item with the id " +cmdId+" is not found.");776 } 777 778 769 throw new ItemNotFoundException("Item with the id " + cmdId + " is not found."); 770 } 771 772 779 773 Number userId = getUserId(); 780 774 if (userId == null) { … … 785 779 return false; 786 780 } 787 781 788 782 789 783 if (configuration.isAdminUser(user.getPrincipalName())) { … … 805 799 806 800 @Override 807 public void deleteComment(String commentId) throws IOException, 801 public void deleteComment(String commentId) throws IOException, 808 802 UserUnauthorizedException, DeleteFailedException, ItemNotFoundException { 809 803 try { … … 826 820 } 827 821 } 828 829 830 822 831 823 @Override … … 857 849 for (String id : componentIds) { 858 850 BaseDescription description = componentDao.getByCmdId(id); 859 components.add(ComponentUtils.toComponent(description)); 851 if (description != null) { 852 components.add(ComponentUtils.toComponent(description)); 853 } 860 854 } 861 855 return components;
Note: See TracChangeset
for help on using the changeset viewer.