Changeset 5549 for ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/GroupServiceImpl.java
- Timestamp:
- 08/11/14 16:07:55 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/GroupServiceImpl.java
r4169 r5549 1 1 package clarin.cmdi.componentregistry.impl.database; 2 2 3 import clarin.cmdi.componentregistry.UserUnauthorizedException; 3 4 import java.util.ArrayList; 4 5 import java.util.Collections; … … 235 236 ownerships.addAll(ownershipDao.findOwnershipByComponentId(itemId)); 236 237 Set<Group> groups = new HashSet<Group>(); 237 for (Ownership ownership : ownerships) 238 for (Ownership ownership : ownerships) { 238 239 groups.add(groupDao.findOne(ownership.getGroupId())); 240 } 239 241 List<Group> groupList = new ArrayList<Group>(groups); 240 242 Collections.sort(groupList, new Comparator<Group>() { … … 247 249 return groupList; 248 250 } 251 252 249 253 250 254 @ManagedOperation(description = "Make a component owned by a group instead of a user") … … 254 258 @ManagedOperationParameter(name = "componentId", description = "Id of component") }) 255 259 @Override 256 public void transferItemOwnershipFromUserToGroup(String principal, String groupName, String itemId) { 257 260 public void transferItemOwnershipFromUserToGroup(String principal, String groupName, String itemId) throws UserUnauthorizedException{ 261 262 258 263 BaseDescription item = null; 259 264 item = componentDao.getByCmdId(itemId); 260 if (item == null) 265 if (item == null) { 261 266 throw new ValidationException("No profile or component found with ID " + itemId); 267 } 262 268 Group group = groupDao.findGroupByName(groupName); 263 if (group == null) 269 if (group == null) { 264 270 throw new ValidationException("No group found with name " + groupName); 271 } 272 273 if (!this.userGroupMember(principal, String.valueOf(group.getId()))) { 274 throw new UserUnauthorizedException("User " + principal+ " is not a member of group "+groupName); 275 } 276 277 String creatorName = item.getCreatorName(); 278 if (!creatorName.equals(principal)) { 279 throw new UserUnauthorizedException("User " + principal+ " is not creator of the item "+item.getName()); 280 } 281 282 265 283 Ownership ownership = null; 266 284 List<Ownership> oldOwnerships = ownershipDao.findOwnershipByComponentId(itemId); … … 273 291 274 292 @Override 275 public void transferItemOwnershipFromUserToGroupId(String principal, long groupId, String componentId) {293 public void transferItemOwnershipFromUserToGroupId(String principal, long groupId, String componentId) throws UserUnauthorizedException{ 276 294 Group group = groupDao.findOne(groupId); 277 if (group == null) 295 if (group == null) { 278 296 throw new ValidationException("No group found with id " + groupId); 279 transferItemOwnershipFromUserToGroup(principal, group.getName(), componentId); 280 } 281 297 } 298 this.transferItemOwnershipFromUserToGroup(principal, group.getName(), componentId); 299 } 300 301 @Override 302 public boolean userGroupMember(String principalName, String groupId) { 303 RegistryUser user = userDao.getByPrincipalName(principalName); 304 GroupMembership gm = groupMembershipDao.findMembership(user.getId(), Long.parseLong(groupId)); 305 return gm != null; 306 } 282 307 }
Note: See TracChangeset
for help on using the changeset viewer.