Coverage Report - org.kuali.rice.kim.service.impl.RoleManagementServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleManagementServiceImpl
0%
0/142
0%
0/26
1.291
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.service.impl;
 17  
 
 18  
 import org.apache.commons.lang.exception.ExceptionUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.kim.api.common.delegate.DelegateMember;
 21  
 import org.kuali.rice.kim.api.common.delegate.DelegateType;
 22  
 import org.kuali.rice.kim.api.role.Role;
 23  
 import org.kuali.rice.kim.api.role.RoleManagementService;
 24  
 import org.kuali.rice.kim.api.role.RoleMember;
 25  
 import org.kuali.rice.kim.api.role.RoleMembership;
 26  
 import org.kuali.rice.kim.api.role.RoleResponsibility;
 27  
 import org.kuali.rice.kim.api.role.RoleResponsibilityAction;
 28  
 import org.kuali.rice.kim.api.role.RoleService;
 29  
 import org.kuali.rice.kim.api.role.RoleUpdateService;
 30  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 31  
 
 32  
 import java.sql.Date;
 33  
 import java.util.Collection;
 34  
 import java.util.HashMap;
 35  
 import java.util.List;
 36  
 import java.util.Map;
 37  
 
 38  
 /**
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  0
 public class RoleManagementServiceImpl implements RoleManagementService {
 42  0
     private static final Logger LOG = Logger.getLogger(RoleManagementServiceImpl.class);
 43  
 
 44  
     private RoleService roleService;
 45  
     private RoleUpdateService roleUpdateService;
 46  
 
 47  
     @Override
 48  
     public void flushRoleCaches() {
 49  0
         flushInternalRoleCache();
 50  0
         flushInternalRoleMemberCache();
 51  0
         flushInternalDelegationCache();
 52  0
         flushInternalDelegationMemberCache();
 53  0
     }
 54  
 
 55  
     @Override
 56  
     public void flushRoleMemberCaches() {
 57  0
         flushInternalRoleMemberCache();
 58  0
     }
 59  
 
 60  
     @Override
 61  
     public void flushDelegationCaches() {
 62  0
         flushInternalDelegationCache();
 63  0
         flushInternalDelegationMemberCache();
 64  0
     }
 65  
 
 66  
     @Override
 67  
     public void flushDelegationMemberCaches() {
 68  0
         flushInternalDelegationMemberCache();
 69  0
     }
 70  
 
 71  
     @Override
 72  
     public void removeCacheEntries(String roleId, String principalId) {
 73  
 
 74  0
     }
 75  
 
 76  
     @Override
 77  
     public Collection<String> getRoleMemberPrincipalIds(String namespaceCode, String roleName, Map<String, String> qualification) {
 78  0
         return getRoleService().getRoleMemberPrincipalIds(namespaceCode, roleName, qualification);
 79  
     }
 80  
 
 81  
     @Override
 82  
     public Role getRole(String roleId) {
 83  0
         return getRoleService().getRole(roleId);
 84  
     }
 85  
 
 86  
     @Override
 87  
     public Role getRoleByName(String namespaceCode, String roleName) {
 88  0
         return getRoleService().getRoleByName(namespaceCode, roleName);
 89  
     }
 90  
 
 91  
     @Override
 92  
     public String getRoleIdByName(String namespaceCode, String roleName) {
 93  0
         Role role = getRoleByName(namespaceCode, roleName);
 94  0
         if (role == null) {
 95  0
             return null;
 96  
         }
 97  0
         return role.getId();
 98  
     }
 99  
 
 100  
     @Override
 101  
     public List<Role> getRoles(List<String> roleIds) {
 102  0
         return getRoleService().getRoles(roleIds);
 103  
     }
 104  
 
 105  
     @Override
 106  
     public List<RoleMembership> getRoleMembers(List<String> roleIds, Map<String, String> qualification) {
 107  0
         return getRoleService().getRoleMembers(roleIds, qualification);
 108  
     }
 109  
 
 110  
     @Override
 111  
     public List<Map<String, String>> getRoleQualifiersForPrincipal(String principalId, List<String> roleIds, Map<String, String> qualification) {
 112  0
         return getRoleService().getRoleQualifiersForPrincipal(principalId, roleIds, qualification);
 113  
     }
 114  
 
 115  
     @Override
 116  
     public List<Map<String, String>> getRoleQualifiersForPrincipal(String principalId, String namespaceCode, String roleName, Map<String, String> qualification) {
 117  0
         return getRoleService().getRoleQualifiersForPrincipal(principalId, namespaceCode, roleName, qualification);
 118  
     }
 119  
 
 120  
     @Override
 121  
     public boolean isRoleActive(String roleId) {
 122  0
         Role role = getRole(roleId);
 123  0
         return role != null && role.isActive();
 124  
     }
 125  
 
 126  
     @Override
 127  
     public boolean principalHasRole(String principalId, List<String> roleIds, Map<String, String> qualification) {
 128  0
         if (LOG.isDebugEnabled()) {
 129  0
             logPrincipalHasRoleCheck(principalId, roleIds, qualification);
 130  
         }
 131  0
         boolean hasRole =  getRoleService().principalHasRole(principalId, roleIds, qualification);
 132  0
             if (LOG.isDebugEnabled()) {
 133  0
                 LOG.debug("Result: " + hasRole);
 134  
             }
 135  0
         return hasRole;
 136  
     }
 137  
 
 138  
     @Override
 139  
     public List<String> getPrincipalIdSubListWithRole(
 140  
             List<String> principalIds, String roleNamespaceCode,
 141  
             String roleName, Map<String, String> qualification) {
 142  0
         return getRoleService().getPrincipalIdSubListWithRole(principalIds,
 143  
                 roleNamespaceCode, roleName, qualification);
 144  
     }
 145  
 
 146  
     @Override
 147  
     public List<Map<String, String>> getNestedRoleQualifiersForPrincipal(String principalId, List<String> roleIds, Map<String, String> qualification) {
 148  0
         return getRoleService().getNestedRoleQualifiersForPrincipal(principalId, roleIds, qualification);
 149  
     }
 150  
 
 151  
     @Override
 152  
     public List<Map<String, String>> getNestedRoleQualifiersForPrincipal(String principalId, String namespaceCode, String roleName, Map<String, String> qualification) {
 153  0
         return getRoleService().getNestedRoleQualifiersForPrincipal(principalId, namespaceCode, roleName, qualification);
 154  
     }
 155  
 
 156  
     @Override
 157  
     public void assignGroupToRole(String groupId, String namespaceCode, String roleName,
 158  
                                   Map<String, String> qualifications) {
 159  0
         getRoleUpdateService().assignGroupToRole(groupId, namespaceCode, roleName, qualifications);
 160  0
         Role role = getRoleByName(namespaceCode, roleName);
 161  0
         removeCacheEntries(role.getId(), null);
 162  0
     }
 163  
 
 164  
     @Override
 165  
     public void assignPrincipalToRole(String principalId, String namespaceCode, String roleName,
 166  
                                       Map<String, String> qualifications) {
 167  0
         Role role = getRoleByName(namespaceCode, roleName);
 168  0
         getRoleUpdateService().assignPrincipalToRole(principalId, namespaceCode, roleName, qualifications);
 169  0
         removeCacheEntries(role.getId(), principalId);
 170  0
     }
 171  
 
 172  
     @Override
 173  
     public void removeGroupFromRole(String groupId, String namespaceCode, String roleName,
 174  
                                     Map<String, String> qualifications) {
 175  0
         getRoleUpdateService().removeGroupFromRole(groupId, namespaceCode, roleName, qualifications);
 176  0
         Role role = getRoleByName(namespaceCode, roleName);
 177  0
         removeCacheEntries(role.getId(), null);
 178  0
     }
 179  
 
 180  
     @Override
 181  
     public void removePrincipalFromRole(String principalId, String namespaceCode, String roleName,
 182  
                                         Map<String, String> qualifications) {
 183  0
         Role role = getRoleByName(namespaceCode, roleName);
 184  0
         getRoleUpdateService().removePrincipalFromRole(principalId, namespaceCode, roleName, qualifications);
 185  0
         removeCacheEntries(role.getId(), principalId);
 186  0
     }
 187  
 
 188  
     @Override
 189  
     public List<Role> getRolesSearchResults(
 190  
             Map<String, String> fieldValues) {
 191  0
         return getRoleService().getRolesSearchResults(fieldValues);
 192  
     }
 193  
 
 194  
     protected void logPrincipalHasRoleCheck(String principalId, List<String> roleIds, Map<String, String> roleQualifiers) {
 195  0
         StringBuilder sb = new StringBuilder();
 196  0
         sb.append('\n');
 197  0
         sb.append("Has Role     : ").append(roleIds).append('\n');
 198  0
         if (roleIds != null) {
 199  0
             for (String roleId : roleIds) {
 200  0
                 Role role = getRole(roleId);
 201  0
                 if (role != null) {
 202  0
                     sb.append("        Name : ").append(role.getNamespaceCode()).append('/').append(role.getName());
 203  0
                     sb.append(" (").append(roleId).append(')');
 204  0
                     sb.append('\n');
 205  
                 }
 206  0
             }
 207  
         }
 208  0
         sb.append("   Principal : ").append(principalId);
 209  0
         sb.append('\n');
 210  0
         sb.append("     Details :\n");
 211  0
         if (roleQualifiers != null) {
 212  0
             sb.append(new HashMap<String, String>(roleQualifiers));
 213  
         } else {
 214  0
             sb.append("               [null]\n");
 215  
         }
 216  0
         if (LOG.isTraceEnabled()) {
 217  0
             LOG.trace(sb.append(ExceptionUtils.getStackTrace(new Throwable())));
 218  
         } else {
 219  0
             LOG.debug(sb.toString());
 220  
         }
 221  0
     }
 222  
 
 223  
     @Override
 224  
     public void principalInactivated(String principalId) {
 225  0
         getRoleService().principalInactivated(principalId);
 226  0
         removeCacheEntries(null, principalId);
 227  0
     }
 228  
 
 229  
     @Override
 230  
     public void roleInactivated(String roleId) {
 231  0
         getRoleService().roleInactivated(roleId);
 232  0
         removeCacheEntries(roleId, null);
 233  0
     }
 234  
 
 235  
     @Override
 236  
     public void groupInactivated(String groupId) {
 237  0
         getRoleService().groupInactivated(groupId);
 238  0
     }
 239  
 
 240  
     @Override
 241  
     public List<RoleMembership> getFirstLevelRoleMembers(List<String> roleIds) {
 242  0
         return getRoleService().getFirstLevelRoleMembers(roleIds);
 243  
     }
 244  
 
 245  
     @Override
 246  
     public List<RoleMember> findRoleMembers(Map<String, String> fieldValues) {
 247  0
         return getRoleService().findRoleMembers(fieldValues);
 248  
     }
 249  
 
 250  
     @Override
 251  
     public List<RoleMembership> findRoleMemberships(Map<String, String> fieldValues) {
 252  0
         return getRoleService().findRoleMemberships(fieldValues);
 253  
     }
 254  
 
 255  
     @Override
 256  
     public void assignRoleToRole(String roleId, String namespaceCode, String roleName,
 257  
                                  Map<String, String> qualifications) {
 258  0
         getRoleUpdateService().assignRoleToRole(
 259  
                 roleId, namespaceCode, roleName, qualifications);
 260  0
         Role role = getRoleByName(namespaceCode, roleName);
 261  0
         removeCacheEntries(role.getId(), null);
 262  0
     }
 263  
 
 264  
     @Override
 265  
     public void saveDelegationMemberForRole(String delegationMemberId, String roleMemberId, String memberId, String memberTypeCode,
 266  
                                             String delegationTypeCode, String roleId, Map<String, String> qualifications,
 267  
                                             Date activeFromDate, Date activeToDate) throws UnsupportedOperationException {
 268  0
         getRoleUpdateService().saveDelegationMemberForRole(delegationMemberId, roleMemberId, memberId, memberTypeCode, delegationTypeCode, roleId, qualifications, activeFromDate, activeToDate);
 269  0
         Role role = getRole(roleId);
 270  0
         removeCacheEntries(role.getId(), null);
 271  0
     }
 272  
 
 273  
     @Override
 274  
     public RoleMember saveRoleMemberForRole(String roleMemberId, String memberId, String memberTypeCode,
 275  
                                             String roleId, Map<String, String> qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException {
 276  0
         Role role = getRole(roleId);
 277  0
         RoleMember roleMember = getRoleUpdateService().saveRoleMemberForRole(roleMemberId, memberId, memberTypeCode, roleId, qualifications, activeFromDate, activeToDate);
 278  0
         removeCacheEntries(role.getId(), memberId);
 279  0
         return roleMember;
 280  
     }
 281  
 
 282  
     @Override
 283  
     public void removeRoleFromRole(String roleId, String namespaceCode, String roleName,
 284  
                                    Map<String, String> qualifications) {
 285  0
         getRoleUpdateService().removeRoleFromRole(roleId, namespaceCode, roleName, qualifications);
 286  0
         Role role = getRoleByName(namespaceCode, roleName);
 287  0
         removeCacheEntries(role.getId(), null);
 288  0
     }
 289  
 
 290  
     @Override
 291  
     public List<DelegateMember> findDelegateMembers(Map<String, String> fieldValues) {
 292  0
         return getRoleService().findDelegateMembers(fieldValues);
 293  
     }
 294  
 
 295  
     @Override
 296  
     public List<DelegateMember> getDelegationMembersByDelegationId(String delegationId) {
 297  0
         return getRoleService().getDelegationMembersByDelegationId(delegationId);
 298  
     }
 299  
 
 300  
     @Override
 301  
     public DelegateMember getDelegationMemberByDelegationAndMemberId(String delegationId, String memberId) {
 302  0
         return getRoleService().getDelegationMemberByDelegationAndMemberId(delegationId, memberId);
 303  
     }
 304  
 
 305  
     @Override
 306  
     public DelegateMember getDelegationMemberById(String delegationMemberId) {
 307  0
         return getRoleService().getDelegationMemberById(delegationMemberId);
 308  
     }
 309  
 
 310  
     @Override
 311  
     public List<RoleResponsibilityAction> getRoleMemberResponsibilityActions(String roleMemberId) {
 312  0
         return getRoleService().getRoleMemberResponsibilityActions(roleMemberId);
 313  
     }
 314  
 
 315  
     @Override
 316  
     public DelegateType getDelegateTypeInfo(String roleId, String delegationTypeCode) {
 317  0
         return getRoleService().getDelegateTypeInfo(roleId, delegationTypeCode);
 318  
     }
 319  
 
 320  
     @Override
 321  
     public DelegateType getDelegateTypeInfoById(String delegationId) {
 322  0
         return getRoleService().getDelegateTypeInfoById(delegationId);
 323  
     }
 324  
 
 325  
     @Override
 326  
     public void saveRoleRspActions(String roleResponsibilityActionId, String roleId, String roleResponsibilityId, String roleMemberId,
 327  
                                    String actionTypeCode, String actionPolicyCode, Integer priorityNumber, Boolean forceAction) {
 328  0
         getRoleUpdateService().saveRoleRspActions(roleResponsibilityActionId, roleId, roleResponsibilityId, roleMemberId, actionTypeCode, actionPolicyCode, priorityNumber, forceAction);
 329  0
         removeCacheEntries(roleId, null);
 330  0
     }
 331  
 
 332  
     @Override
 333  
     public List<RoleResponsibility> getRoleResponsibilities(String roleId) {
 334  0
         return getRoleService().getRoleResponsibilities(roleId);
 335  
     }
 336  
 
 337  
     @Override
 338  
     public void applicationRoleMembershipChanged(String roleId) {
 339  0
         removeCacheEntries(roleId, null);
 340  0
         getRoleService().applicationRoleMembershipChanged(roleId);
 341  0
     }
 342  
 
 343  
     // Spring and injection methods
 344  
 
 345  
     public RoleService getRoleService() {
 346  0
         if (roleService == null) {
 347  0
             roleService = KimApiServiceLocator.getRoleService();
 348  
         }
 349  0
         return roleService;
 350  
     }
 351  
 
 352  
     public RoleUpdateService getRoleUpdateService() {
 353  
         try {
 354  0
             if (roleUpdateService == null) {
 355  0
                 roleUpdateService = KimApiServiceLocator.getRoleUpdateService();
 356  0
                 if (roleUpdateService == null) {
 357  0
                     throw new UnsupportedOperationException("null returned for RoleUpdateService, unable to update role data");
 358  
                 }
 359  
             }
 360  0
         } catch (Exception ex) {
 361  0
             throw new UnsupportedOperationException("unable to obtain a RoleUpdateService, unable to update role data", ex);
 362  0
         }
 363  0
         return roleUpdateService;
 364  
     }
 365  
 
 366  
     /**
 367  
      * This overridden method looks up roles based on criteria.  If you want
 368  
      * to return all roles pass in an empty map.
 369  
      */
 370  
     @Override
 371  
     public List<Role> lookupRoles(Map<String, String> searchCriteria) {
 372  0
         return getRoleService().lookupRoles(searchCriteria);
 373  
     }
 374  
 
 375  
     @Override
 376  
     public void flushInternalRoleCache() {
 377  0
         getRoleService().flushInternalRoleCache();
 378  0
     }
 379  
 
 380  
     @Override
 381  
     public void flushInternalRoleMemberCache() {
 382  0
         getRoleService().flushInternalRoleMemberCache();
 383  0
     }
 384  
 
 385  
     @Override
 386  
     public void flushInternalDelegationCache() {
 387  0
         getRoleService().flushInternalDelegationCache();
 388  0
     }
 389  
 
 390  
     @Override
 391  
     public void flushInternalDelegationMemberCache() {
 392  0
         getRoleService().flushInternalDelegationMemberCache();
 393  0
     }
 394  
 
 395  
     @Override
 396  
     public void assignPermissionToRole(String permissionId, String roleId) throws UnsupportedOperationException {
 397  0
         getRoleUpdateService().assignPermissionToRole(permissionId, roleId);
 398  0
     }
 399  
 
 400  
     @Override
 401  
     public String getNextAvailableRoleId() throws UnsupportedOperationException {
 402  0
         return getRoleUpdateService().getNextAvailableRoleId();
 403  
     }
 404  
 
 405  
     @Override
 406  
     public void saveRole(String roleId, String roleName, String roleDescription, boolean active, String kimTypeId, String namespaceCode) throws UnsupportedOperationException {
 407  0
         getRoleUpdateService().saveRole(roleId, roleName, roleDescription, active, kimTypeId, namespaceCode);
 408  0
     }
 409  
 
 410  
     @Override
 411  
     public List<String> getMemberParentRoleIds(String memberType,
 412  
                                                String memberId) {
 413  0
         return getRoleService().getMemberParentRoleIds(memberType, memberId);
 414  
     }
 415  
 }