Ignore:
Timestamp:
08/18/14 09:50:16 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Unit test for getting profiles and components from groups. A little bug is fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r5553 r5556  
    155155        }
    156156    }
    157    
    158     @Override
    159     public Number makeGroupMember(String principalName, String groupName) throws  UserUnauthorizedException, ItemNotFoundException{
     157
     158    @Override
     159    public Number makeGroupMember(String principalName, String groupName) throws UserUnauthorizedException, ItemNotFoundException {
    160160        RegistryUser regOwner = userDao.getPrincipalNameById(registryOwner.getId());
    161         if  (groupService.isUserOwnerOfGroup(groupName, regOwner.getPrincipalName()) ||
    162                 configuration.isAdminUser(regOwner.getPrincipalName())) {
    163         return groupService.makeMember(principalName, groupName);
     161        if (groupService.isUserOwnerOfGroup(groupName, regOwner.getPrincipalName())
     162                || configuration.isAdminUser(regOwner.getPrincipalName())) {
     163            return groupService.makeMember(principalName, groupName);
    164164        } else {
    165165            throw new UserUnauthorizedException("The registry owner is not the admin or not the owner of the group and cannot add users to the group");
    166166        }
    167167    }
    168    
     168
    169169//    @Override
    170170//    public long removeGroupMember(String principalName, String groupName) throws  UserUnauthorizedException, ItemNotFoundException{
     
    177177//        }
    178178//    }
    179    
    180    
    181     @Override
    182     public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException {
     179    @Override
     180    public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException {
    183181        try {
    184182            switch (registrySpace) {
     
    234232
    235233    @Override
    236     public List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException, UserUnauthorizedException {
     234    public List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException {
    237235        try {
    238236            switch (registrySpace) {
     
    861859
    862860    private List<ComponentDescription> getComponentDescriptionsInGroup(Number groupId)
    863             throws ComponentRegistryException, UserUnauthorizedException {
     861            throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException {
    864862
    865863        String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName();
    866 
    867         if (!groupService.userGroupMember(principalName, groupId.toString())) {
     864        String groupName = groupService.getGroupNameById(groupId.longValue());
     865        if (!groupService.userGroupMember(principalName, groupId.toString())
     866                && !groupService.isUserOwnerOfGroup(groupName, principalName)) {
    868867            throw new UserUnauthorizedException("The user \'" + principalName + "\' does not have access to components of the group " + groupId);
    869868        }
     
    880879    }
    881880
    882     private List<ProfileDescription> getProfileDescriptionsInGroup(Number groupId) throws ComponentRegistryException, UserUnauthorizedException {
     881    private List<ProfileDescription> getProfileDescriptionsInGroup(Number groupId) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException {
    883882
    884883        String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName();
    885 
    886         if (!groupService.userGroupMember(principalName, groupId.toString())) {
     884        String groupName = groupService.getGroupNameById(groupId.longValue());
     885        if (!groupService.userGroupMember(principalName, groupId.toString())
     886                && !groupService.isUserOwnerOfGroup(groupName, principalName)) {
    887887            throw new UserUnauthorizedException("The user \'" + principalName + "\' does not have access to profiles of the group " + groupId);
    888888        }
     
    900900
    901901    @Override
    902     public List<ProfileDescription> getProfileDescriptionsForMetadaEditor(Number groupId) throws UserUnauthorizedException,
    903             ComponentRegistryException {
     902    public List<ProfileDescription> getProfileDescriptionsForMetadaEditor(Number groupId) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException {
    904903        return this.getProfileDescriptionsInGroup(groupId.longValue());
    905904    }
     
    984983        }
    985984    }
    986    
    987    
    988985}
Note: See TracChangeset for help on using the changeset viewer.