Coverage Report - org.kuali.rice.kim.service.impl.RoleUpdateServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleUpdateServiceImpl
0%
0/232
0%
0/94
4.438
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.collections.CollectionUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.rice.core.util.AttributeSet;
 22  
 import org.kuali.rice.kim.bo.Role;
 23  
 import org.kuali.rice.kim.bo.impl.RoleImpl;
 24  
 import org.kuali.rice.kim.bo.role.dto.RoleMemberCompleteInfo;
 25  
 import org.kuali.rice.kim.bo.role.impl.KimDelegationImpl;
 26  
 import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberAttributeDataImpl;
 27  
 import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberImpl;
 28  
 import org.kuali.rice.kim.bo.role.impl.RoleMemberAttributeDataImpl;
 29  
 import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl;
 30  
 import org.kuali.rice.kim.bo.role.impl.RolePermissionImpl;
 31  
 import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityActionImpl;
 32  
 import org.kuali.rice.kim.service.RoleUpdateService;
 33  
 import org.kuali.rice.kim.util.KIMWebServiceConstants;
 34  
 import org.kuali.rice.kim.util.KimConstants;
 35  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 36  
 import org.kuali.rice.kns.service.SequenceAccessorService;
 37  
 
 38  
 import javax.jws.WebService;
 39  
 import java.sql.Date;
 40  
 import java.util.ArrayList;
 41  
 import java.util.HashMap;
 42  
 import java.util.List;
 43  
 import java.util.Map;
 44  
 
 45  
 /**
 46  
  * 
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  *
 49  
  */
 50  
 @WebService(endpointInterface = KIMWebServiceConstants.RoleUpdateService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.RoleUpdateService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.RoleUpdateService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE)
 51  0
 public class RoleUpdateServiceImpl extends RoleServiceBase implements RoleUpdateService {
 52  0
         private static final Logger LOG = Logger.getLogger( RoleUpdateServiceImpl.class );
 53  
         
 54  
         public void assignGroupToRole(String groupId, String namespaceCode, String roleName, AttributeSet qualifier) {
 55  
             // look up the role
 56  0
             RoleImpl role = getRoleImplByName( namespaceCode, roleName );
 57  
             // check that identical member does not already exist
 58  0
             if ( doAnyMemberRecordsMatch( role.getMembers(), groupId, Role.GROUP_MEMBER_TYPE, qualifier ) ) {
 59  0
                     return;
 60  
             }
 61  
             // create the new role member object
 62  0
             RoleMemberImpl newRoleMember = new RoleMemberImpl();
 63  
             // get a new ID from the sequence
 64  0
             SequenceAccessorService sas = getSequenceAccessorService();
 65  0
             Long nextSeq = sas.getNextAvailableSequenceNumber(
 66  
                             KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class);
 67  0
             newRoleMember.setRoleMemberId( nextSeq.toString() );
 68  
 
 69  0
             newRoleMember.setRoleId( role.getRoleId() );
 70  0
             newRoleMember.setMemberId( groupId );
 71  0
             newRoleMember.setMemberTypeCode( Role.GROUP_MEMBER_TYPE );
 72  
 
 73  
             // build role member attribute objects from the given AttributeSet
 74  0
             addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() );
 75  
 
 76  
             // When members are added to roles, clients must be notified.
 77  0
             getResponsibilityInternalService().saveRoleMember(newRoleMember);
 78  0
             getIdentityManagementNotificationService().roleUpdated();
 79  0
     }
 80  
 
 81  
         public void assignPrincipalToRole(String principalId, String namespaceCode, String roleName, AttributeSet qualifier) {
 82  
             // look up the role
 83  0
             RoleImpl role = getRoleImplByName( namespaceCode, roleName );
 84  0
             role.refreshReferenceObject("members");
 85  
             
 86  
             // check that identical member does not already exist
 87  0
             if ( doAnyMemberRecordsMatch( role.getMembers(), principalId, Role.PRINCIPAL_MEMBER_TYPE, qualifier ) ) {
 88  0
                     return;
 89  
             }
 90  
             // create the new role member object
 91  0
             RoleMemberImpl newRoleMember = new RoleMemberImpl();
 92  
             // get a new ID from the sequence
 93  0
             SequenceAccessorService sas = getSequenceAccessorService();
 94  0
             Long nextSeq = sas.getNextAvailableSequenceNumber( 
 95  
                             KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class );            
 96  0
             newRoleMember.setRoleMemberId( nextSeq.toString() );
 97  
 
 98  0
             newRoleMember.setRoleId( role.getRoleId() );
 99  0
             newRoleMember.setMemberId( principalId );
 100  0
             newRoleMember.setMemberTypeCode( Role.PRINCIPAL_MEMBER_TYPE );
 101  
 
 102  
             // build role member attribute objects from the given AttributeSet
 103  0
             addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() );
 104  
 
 105  
             // add row to member table
 106  
             // When members are added to roles, clients must be notified.
 107  0
             getResponsibilityInternalService().saveRoleMember(newRoleMember);
 108  0
             getIdentityManagementNotificationService().roleUpdated();
 109  0
     }
 110  
 
 111  
         public void assignRoleToRole(String roleId, String namespaceCode, String roleName, AttributeSet qualifier) {
 112  
             // look up the role
 113  0
             RoleImpl role = getRoleImplByName( namespaceCode, roleName );
 114  
             // check that identical member does not already exist
 115  0
             if ( doAnyMemberRecordsMatch( role.getMembers(), roleId, Role.ROLE_MEMBER_TYPE, qualifier ) ) {
 116  0
                     return;
 117  
             }
 118  
             // Check to make sure this doesn't create a circular membership
 119  0
             if ( !checkForCircularRoleMembership( roleId, role) ){
 120  0
             throw new IllegalArgumentException("Circular role reference.");
 121  
             }
 122  
             // create the new role member object
 123  0
             RoleMemberImpl newRoleMember = new RoleMemberImpl();
 124  
             // get a new ID from the sequence
 125  0
             SequenceAccessorService sas = getSequenceAccessorService();
 126  0
             Long nextSeq = sas.getNextAvailableSequenceNumber(
 127  
                             KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class);
 128  0
             newRoleMember.setRoleMemberId( nextSeq.toString() );
 129  
 
 130  0
             newRoleMember.setRoleId( role.getRoleId() );
 131  0
             newRoleMember.setMemberId( roleId );
 132  0
             newRoleMember.setMemberTypeCode( Role.ROLE_MEMBER_TYPE );
 133  
             // build role member attribute objects from the given AttributeSet
 134  0
             addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() );
 135  
 
 136  
             // When members are added to roles, clients must be notified.
 137  0
             getResponsibilityInternalService().saveRoleMember(newRoleMember);
 138  0
             getIdentityManagementNotificationService().roleUpdated();
 139  0
     }
 140  
 
 141  
         public void removeGroupFromRole(String groupId, String namespaceCode, String roleName, AttributeSet qualifier) {
 142  
             // look up the role
 143  0
             RoleImpl role = getRoleImplByName( namespaceCode, roleName );
 144  
             // pull all the group role members
 145  
             // look for an exact qualifier match
 146  0
                 for ( RoleMemberImpl rm : role.getMembers() ) {
 147  0
                         if ( doesMemberMatch( rm, groupId, Role.GROUP_MEMBER_TYPE, qualifier ) ) {
 148  
                             // if found, remove
 149  
                                 // When members are removed from roles, clients must be notified.
 150  0
                             getResponsibilityInternalService().removeRoleMember(rm);
 151  
                         }
 152  
                 }
 153  0
                 getIdentityManagementNotificationService().roleUpdated();
 154  0
     }
 155  
 
 156  
         public void removePrincipalFromRole(String principalId, String namespaceCode, String roleName, AttributeSet qualifier ) {
 157  
             // look up the role
 158  0
             RoleImpl role = getRoleImplByName( namespaceCode, roleName );
 159  
             // pull all the principal members
 160  0
             role.refreshReferenceObject("members");
 161  
             // look for an exact qualifier match
 162  0
                 for ( RoleMemberImpl rm : role.getMembers() ) {
 163  0
                         if ( doesMemberMatch( rm, principalId, Role.PRINCIPAL_MEMBER_TYPE, qualifier ) ) {
 164  
                             // if found, remove
 165  
                                 // When members are removed from roles, clients must be notified.
 166  0
                             getResponsibilityInternalService().removeRoleMember(rm);
 167  
                         }
 168  
                 }
 169  0
                 getIdentityManagementNotificationService().roleUpdated();
 170  0
     }
 171  
 
 172  
         public void removeRoleFromRole(String roleId, String namespaceCode, String roleName, AttributeSet qualifier) {
 173  
             // look up the role
 174  0
             RoleImpl role = getRoleImplByName( namespaceCode, roleName );
 175  
             // pull all the group role members
 176  
             // look for an exact qualifier match
 177  0
                 for ( RoleMemberImpl rm : role.getMembers() ) {
 178  0
                         if ( doesMemberMatch( rm, roleId, Role.ROLE_MEMBER_TYPE, qualifier ) ) {
 179  
                             // if found, remove
 180  
                                 // When members are removed from roles, clients must be notified.
 181  0
                             getResponsibilityInternalService().removeRoleMember(rm);
 182  
                         }
 183  
                 }
 184  0
                 getIdentityManagementNotificationService().roleUpdated();
 185  0
     }
 186  
 
 187  
         /**
 188  
      * 
 189  
      * This overridden method ...
 190  
      * 
 191  
      * @see org.kuali.rice.kim.service.RoleUpdateService#assignRoleAsDelegationMemberToRole(java.lang.String, java.lang.String, java.lang.String, org.kuali.rice.core.util.AttributeSet)
 192  
      */
 193  
     public void saveDelegationMemberForRole(String delegationMemberId,
 194  
                             String roleMemberId, String memberId, String memberTypeCode, String delegationTypeCode, 
 195  
                             String roleId, AttributeSet qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException{
 196  0
             if(StringUtils.isEmpty(delegationMemberId) && StringUtils.isEmpty(memberId) && StringUtils.isEmpty(roleId)){
 197  0
                     throw new IllegalArgumentException("Either Delegation member ID or a combination of member ID and role ID must be passed in.");
 198  
             }
 199  
             // look up the role
 200  0
             RoleImpl role = getRoleImpl(roleId);
 201  0
             KimDelegationImpl delegation = getDelegationOfType(role.getRoleId(), delegationTypeCode);
 202  
             // create the new role member object
 203  0
             KimDelegationMemberImpl newDelegationMember = new KimDelegationMemberImpl();
 204  
 
 205  0
             KimDelegationMemberImpl origDelegationMember = null;
 206  0
             if(StringUtils.isNotEmpty(delegationMemberId)){
 207  0
                     origDelegationMember = getKimDelegationMemberImpl(delegationMemberId);
 208  
             } else{
 209  0
                     List<KimDelegationMemberImpl> origDelegationMembers =
 210  
                             getKimDelegationMemberImplListByMemberAndDelegationId(memberId, delegation.getDelegationId());
 211  0
                     origDelegationMember = 
 212  
                             (origDelegationMembers!=null && origDelegationMembers.size()>0) ? origDelegationMembers.get(0) : null;
 213  
             }
 214  0
             if(origDelegationMember!=null){
 215  0
                     newDelegationMember.setDelegationMemberId(origDelegationMember.getDelegationMemberId());
 216  0
                     newDelegationMember.setVersionNumber(origDelegationMember.getVersionNumber());
 217  
             } else{
 218  0
                     newDelegationMember.setDelegationMemberId(getNewDelegationMemberId());
 219  
             }
 220  0
             newDelegationMember.setMemberId(memberId);
 221  0
             newDelegationMember.setDelegationId(delegation.getDelegationId());
 222  0
             newDelegationMember.setRoleMemberId(roleMemberId);
 223  0
             newDelegationMember.setMemberTypeCode(memberTypeCode);
 224  0
                 if (activeFromDate != null) {
 225  0
                         newDelegationMember.setActiveFromDate(new java.sql.Timestamp(activeFromDate.getTime()));
 226  
                 }
 227  0
                 if (activeToDate != null) {
 228  0
                         newDelegationMember.setActiveToDate(new java.sql.Timestamp(activeToDate.getTime()));
 229  
                 }
 230  
 
 231  
             // build role member attribute objects from the given AttributeSet
 232  0
             addDelegationMemberAttributeData( newDelegationMember, qualifications, role.getKimTypeId() );
 233  
 
 234  0
             List<KimDelegationMemberImpl> delegationMembers = new ArrayList<KimDelegationMemberImpl>();
 235  0
             delegationMembers.add(newDelegationMember);
 236  0
             delegation.setMembers(delegationMembers);
 237  
 
 238  0
             getBusinessObjectService().save(delegation);
 239  0
             for(KimDelegationMemberImpl delegationMember: delegation.getMembers()){
 240  0
                     deleteNullDelegationMemberAttributeData(delegationMember.getAttributes());
 241  
             }
 242  0
             getIdentityManagementNotificationService().roleUpdated();
 243  0
     }
 244  
 
 245  
     public RoleMemberCompleteInfo saveRoleMemberForRole(String roleMemberId, String memberId, String memberTypeCode, String roleId, 
 246  
                     AttributeSet qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException{
 247  0
             if(StringUtils.isEmpty(roleMemberId) && StringUtils.isEmpty(memberId) && StringUtils.isEmpty(roleId)){
 248  0
                     throw new IllegalArgumentException("Either Role member ID or a combination of member ID and role ID must be passed in.");
 249  
             }
 250  0
             RoleMemberImpl origRoleMember = null;
 251  
             RoleImpl role;
 252  
             // create the new role member object
 253  0
             RoleMemberImpl newRoleMember = new RoleMemberImpl();
 254  0
             if(StringUtils.isEmpty(roleMemberId)){
 255  
                     // look up the role
 256  0
                     role = getRoleImpl(roleId);
 257  
                     // check that identical member does not already exist
 258  0
                     origRoleMember = matchingMemberRecord( role.getMembers(), memberId, memberTypeCode, qualifications );
 259  
             } else{
 260  0
                     origRoleMember = getRoleMemberImpl(roleMemberId);
 261  0
                     role = getRoleImpl(origRoleMember.getRoleId());
 262  
             }
 263  
             
 264  0
             if(origRoleMember !=null){
 265  0
                     newRoleMember.setRoleMemberId(origRoleMember.getRoleMemberId());
 266  0
                     newRoleMember.setVersionNumber(origRoleMember.getVersionNumber());
 267  
             } else {
 268  
                     // get a new ID from the sequence
 269  0
                     SequenceAccessorService sas = getSequenceAccessorService();
 270  0
                     Long nextSeq = sas.getNextAvailableSequenceNumber(
 271  
                                     KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class);
 272  0
                     newRoleMember.setRoleMemberId( nextSeq.toString() );
 273  
             }
 274  0
             newRoleMember.setRoleId(role.getRoleId());
 275  0
             newRoleMember.setMemberId( memberId );
 276  0
             newRoleMember.setMemberTypeCode( memberTypeCode );
 277  0
                 if (activeFromDate != null) {
 278  0
                         newRoleMember.setActiveFromDate(new java.sql.Timestamp(activeFromDate.getTime()));
 279  
                 }
 280  0
                 if (activeToDate != null) {
 281  0
                         newRoleMember.setActiveToDate(new java.sql.Timestamp(activeToDate.getTime()));
 282  
                 }
 283  
             // build role member attribute objects from the given AttributeSet
 284  0
             addMemberAttributeData( newRoleMember, qualifications, role.getKimTypeId() );
 285  
 
 286  
             // When members are added to roles, clients must be notified.
 287  0
             getResponsibilityInternalService().saveRoleMember(newRoleMember);
 288  0
             deleteNullMemberAttributeData(newRoleMember.getAttributes());    
 289  0
             getIdentityManagementNotificationService().roleUpdated();
 290  
             
 291  0
             return findRoleMemberCompleteInfo(newRoleMember.getRoleMemberId());
 292  
     }
 293  
 
 294  
     public void saveRoleRspActions(String roleResponsibilityActionId, String roleId, String roleResponsibilityId, String roleMemberId, 
 295  
                         String actionTypeCode, String actionPolicyCode, Integer priorityNumber, Boolean forceAction){
 296  0
                 RoleResponsibilityActionImpl newRoleRspAction = new RoleResponsibilityActionImpl();
 297  0
                 newRoleRspAction.setActionPolicyCode(actionPolicyCode);
 298  0
                 newRoleRspAction.setActionTypeCode(actionTypeCode);
 299  0
                 newRoleRspAction.setPriorityNumber(priorityNumber);
 300  0
                 newRoleRspAction.setForceAction(forceAction);
 301  0
                 newRoleRspAction.setRoleMemberId(roleMemberId);
 302  0
                 newRoleRspAction.setRoleResponsibilityId(roleResponsibilityId);
 303  0
                 if(StringUtils.isEmpty(roleResponsibilityActionId)){
 304  
                         //If there is an existing one
 305  0
                         Map<String, String> criteria = new HashMap<String, String>(1);                
 306  0
                         criteria.put(KimConstants.PrimaryKeyConstants.ROLE_RESPONSIBILITY_ID, roleResponsibilityId);
 307  0
                         criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId);
 308  0
                         List<RoleResponsibilityActionImpl> roleResponsibilityActionImpls = (List<RoleResponsibilityActionImpl>)
 309  
                                 getBusinessObjectService().findMatching(RoleResponsibilityActionImpl.class, criteria);
 310  0
                         if(roleResponsibilityActionImpls!=null && roleResponsibilityActionImpls.size()>0){
 311  0
                                 newRoleRspAction.setRoleResponsibilityActionId(roleResponsibilityActionImpls.get(0).getRoleResponsibilityActionId());
 312  0
                                 newRoleRspAction.setVersionNumber(roleResponsibilityActionImpls.get(0).getVersionNumber());
 313  
                         } else{
 314  
         //                         get a new ID from the sequence
 315  0
                             SequenceAccessorService sas = getSequenceAccessorService();
 316  0
                             Long nextSeq = sas.getNextAvailableSequenceNumber(
 317  
                                             KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S, RoleResponsibilityActionImpl.class);
 318  0
                             newRoleRspAction.setRoleResponsibilityActionId(nextSeq.toString());
 319  
                         }
 320  0
                 } else{
 321  0
                         Map<String, String> criteria = new HashMap<String, String>(1);                
 322  0
                         criteria.put(KimConstants.PrimaryKeyConstants.ROLE_RESPONSIBILITY_ACTION_ID, roleResponsibilityActionId);
 323  0
                         List<RoleResponsibilityActionImpl> roleResponsibilityActionImpls = (List<RoleResponsibilityActionImpl>)
 324  
                                 getBusinessObjectService().findMatching(RoleResponsibilityActionImpl.class, criteria);
 325  0
                         if(CollectionUtils.isNotEmpty(roleResponsibilityActionImpls) && roleResponsibilityActionImpls.size()>0){
 326  0
                                 newRoleRspAction.setRoleResponsibilityActionId(roleResponsibilityActionImpls.get(0).getRoleResponsibilityActionId());
 327  0
                                 newRoleRspAction.setVersionNumber(roleResponsibilityActionImpls.get(0).getVersionNumber());
 328  
                         }
 329  
                 }
 330  0
                 getBusinessObjectService().save(newRoleRspAction);
 331  0
                 getIdentityManagementNotificationService().roleUpdated();
 332  0
         }
 333  
     
 334  
     // --------------------
 335  
     // Persistence Methods
 336  
     // --------------------
 337  
 
 338  
         private void deleteNullMemberAttributeData(List<RoleMemberAttributeDataImpl> attributes) {
 339  0
                 List<RoleMemberAttributeDataImpl> attributesToDelete = new ArrayList<RoleMemberAttributeDataImpl>();
 340  0
                 for(RoleMemberAttributeDataImpl attribute: attributes){
 341  0
                         if(attribute.getAttributeValue()==null){
 342  0
                                 attributesToDelete.add(attribute);
 343  
                         }
 344  
                 }
 345  0
                 getBusinessObjectService().delete(attributesToDelete);
 346  0
         }
 347  
         
 348  
         private void deleteNullDelegationMemberAttributeData(List<KimDelegationMemberAttributeDataImpl> attributes) {
 349  0
                 List<KimDelegationMemberAttributeDataImpl> attributesToDelete = new ArrayList<KimDelegationMemberAttributeDataImpl>();
 350  0
                 for(KimDelegationMemberAttributeDataImpl attribute: attributes){
 351  0
                         if(attribute.getAttributeValue()==null){
 352  0
                                 attributesToDelete.add(attribute);
 353  
                         }
 354  
                 }
 355  0
                 getBusinessObjectService().delete(attributesToDelete);
 356  0
         }
 357  
         
 358  
     protected void addMemberAttributeData( RoleMemberImpl roleMember, AttributeSet qualifier, String kimTypeId ) {
 359  0
                 List<RoleMemberAttributeDataImpl> attributes = new ArrayList<RoleMemberAttributeDataImpl>();
 360  0
                 for ( String attributeName : qualifier.keySet() ) {
 361  0
                         RoleMemberAttributeDataImpl a = new RoleMemberAttributeDataImpl();
 362  0
                         a.setAttributeValue( qualifier.get( attributeName ) );
 363  0
                         a.setKimTypeId( kimTypeId );
 364  0
                         a.setAssignedToId(roleMember.getRoleMemberId());
 365  
                         // look up the attribute ID
 366  0
                         a.setKimAttributeId( getKimAttributeId( attributeName ) );
 367  
                         
 368  0
                     Map<String, String> criteria = new HashMap<String, String>();
 369  0
                     criteria.put(KimConstants.PrimaryKeyConstants.KIM_ATTRIBUTE_ID, a.getKimAttributeId());
 370  0
                     criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMember.getRoleMemberId());
 371  0
                         List<RoleMemberAttributeDataImpl> origRoleMemberAttributes = 
 372  
                             (List<RoleMemberAttributeDataImpl>)getBusinessObjectService().findMatching(RoleMemberAttributeDataImpl.class, criteria);
 373  0
                         RoleMemberAttributeDataImpl origRoleMemberAttribute = 
 374  
                             (origRoleMemberAttributes!=null && origRoleMemberAttributes.size()>0) ? origRoleMemberAttributes.get(0) : null;
 375  0
                     if(origRoleMemberAttribute!=null){
 376  0
                             a.setId(origRoleMemberAttribute.getId());
 377  0
                             a.setVersionNumber(origRoleMemberAttribute.getVersionNumber());
 378  
                     } else{
 379  
                                 // pull the next sequence number for the data ID
 380  0
                                 a.setId(getNewAttributeDataId());
 381  
                     }
 382  0
                         attributes.add( a );
 383  0
                 }
 384  0
                 roleMember.setAttributes( attributes );
 385  0
         }
 386  
     
 387  
     protected void addDelegationMemberAttributeData( KimDelegationMemberImpl delegationMember, AttributeSet qualifier, String kimTypeId ) {
 388  0
                 List<KimDelegationMemberAttributeDataImpl> attributes = new ArrayList<KimDelegationMemberAttributeDataImpl>();
 389  0
                 for ( String attributeName : qualifier.keySet() ) {
 390  0
                         KimDelegationMemberAttributeDataImpl a = new KimDelegationMemberAttributeDataImpl();
 391  0
                         a.setAttributeValue( qualifier.get( attributeName ) );
 392  0
                         a.setKimTypeId( kimTypeId );
 393  0
                         a.setAssignedToId(delegationMember.getDelegationMemberId());
 394  
                         // look up the attribute ID
 395  0
                         a.setKimAttributeId( getKimAttributeId( attributeName ) );
 396  0
                     Map<String, String> criteria = new HashMap<String, String>();
 397  0
                     criteria.put(KimConstants.PrimaryKeyConstants.KIM_ATTRIBUTE_ID, a.getKimAttributeId());
 398  0
                     criteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_MEMBER_ID, delegationMember.getDelegationMemberId());
 399  0
                         List<KimDelegationMemberAttributeDataImpl> origDelegationMemberAttributes = 
 400  
                             (List<KimDelegationMemberAttributeDataImpl>)getBusinessObjectService().findMatching(KimDelegationMemberAttributeDataImpl.class, criteria);
 401  0
                         KimDelegationMemberAttributeDataImpl origDelegationMemberAttribute = 
 402  
                             (origDelegationMemberAttributes!=null && origDelegationMemberAttributes.size()>0) ? origDelegationMemberAttributes.get(0) : null;
 403  0
                     if(origDelegationMemberAttribute!=null){
 404  0
                             a.setId(origDelegationMemberAttribute.getId());
 405  0
                             a.setVersionNumber(origDelegationMemberAttribute.getVersionNumber());
 406  
                     } else{
 407  
                                 // pull the next sequence number for the data ID
 408  0
                                 a.setId(getNewAttributeDataId());
 409  
                     }
 410  0
                         attributes.add( a );
 411  0
                 }
 412  0
                 delegationMember.setAttributes( attributes );
 413  0
         }
 414  
 
 415  
     public void saveRole(String roleId, String roleName, String roleDescription, boolean active, String kimTypeId, String namespaceCode) throws UnsupportedOperationException {
 416  
         // look for existing role
 417  0
         RoleImpl role = getBusinessObjectService().findBySinglePrimaryKey(RoleImpl.class, roleId);
 418  0
         if (role == null) {
 419  0
             role = new RoleImpl();
 420  0
             role.setRoleId(roleId);
 421  
         }
 422  
 
 423  0
         role.setRoleName(roleName);
 424  0
         role.setRoleDescription(roleDescription);
 425  0
         role.setActive(active);
 426  0
         role.setKimTypeId(kimTypeId);
 427  0
         role.setNamespaceCode(namespaceCode);
 428  
 
 429  0
         getBusinessObjectService().save(role);
 430  0
     }
 431  
 
 432  
     public String getNextAvailableRoleId() throws UnsupportedOperationException {
 433  0
         Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleImpl.class);
 434  
 
 435  0
         if (nextSeq == null) {
 436  0
             LOG.error("Unable to get new role id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S);
 437  0
             throw new RuntimeException("Unable to get new role id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S);
 438  
         }
 439  
 
 440  0
         return nextSeq.toString();
 441  
     }
 442  
 
 443  
     public void assignPermissionToRole(String permissionId, String roleId) throws UnsupportedOperationException {
 444  0
         RolePermissionImpl newRolePermission = new RolePermissionImpl();
 445  
 
 446  0
         Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S, RolePermissionImpl.class);
 447  
 
 448  0
         if (nextSeq == null) {
 449  0
             LOG.error("Unable to get new role permission id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S);
 450  0
             throw new RuntimeException("Unable to get new role permission id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S);
 451  
         }
 452  
 
 453  0
         newRolePermission.setRolePermissionId(nextSeq.toString());
 454  0
         newRolePermission.setRoleId(roleId);
 455  0
         newRolePermission.setPermissionId(permissionId);
 456  0
         newRolePermission.setActive(true);
 457  
 
 458  0
         getBusinessObjectService().save(newRolePermission);
 459  0
         getIdentityManagementNotificationService().roleUpdated();
 460  0
     }
 461  
 }