Coverage Report - org.kuali.rice.kim.service.impl.ResponsibilityInternalServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponsibilityInternalServiceImpl
0%
0/34
0%
0/8
1.857
 
 1  
 /*
 2  
  * Copyright 2007-2009 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 java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.HashSet;
 21  
 import java.util.List;
 22  
 import java.util.Set;
 23  
 
 24  
 import javax.xml.namespace.QName;
 25  
 
 26  
 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
 27  
 import org.kuali.rice.kew.messaging.MessageServiceNames;
 28  
 import org.kuali.rice.kew.responsibility.ResponsibilityChangeProcessor;
 29  
 import org.kuali.rice.kim.bo.role.dto.RoleResponsibilityInfo;
 30  
 import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl;
 31  
 import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl;
 32  
 import org.kuali.rice.kim.service.ResponsibilityInternalService;
 33  
 import org.kuali.rice.kim.util.KimConstants;
 34  
 import org.kuali.rice.kns.service.BusinessObjectService;
 35  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 36  
 import org.kuali.rice.ksb.messaging.service.KSBXMLService;
 37  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 38  
 
 39  
 /**
 40  
  * This is a description of what this class does - Garey don't forget to fill this in.
 41  
  *
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class ResponsibilityInternalServiceImpl implements ResponsibilityInternalService {
 46  
 
 47  
         private BusinessObjectService businessObjectService;
 48  
 
 49  
         public void saveRoleMember(RoleMemberImpl roleMember){
 50  
 
 51  
                 //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 52  0
             List<RoleResponsibilityInfo> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 53  
 
 54  
             // add row to member table
 55  0
             getBusinessObjectService().save( roleMember );
 56  
 
 57  
             //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 58  
             // the new member has been added
 59  0
             List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 60  
 
 61  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
 62  0
         }
 63  
 
 64  
         public void removeRoleMember(RoleMemberImpl roleMember){
 65  
                 //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 66  0
             List<RoleResponsibilityInfo> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 67  
 
 68  
             // add row to member table
 69  0
             getBusinessObjectService().delete( roleMember );
 70  
 
 71  
             //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 72  
             // the new member has been added
 73  0
             List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 74  
 
 75  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
 76  0
         }
 77  
 
 78  
         @SuppressWarnings("unchecked")
 79  
         public void updateActionRequestsForRoleChange(String roleId) {
 80  0
             List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleId);
 81  
                 
 82  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(Collections.EMPTY_LIST, newRoleResp));
 83  0
         }
 84  
         
 85  
 
 86  
         /**
 87  
          * This overridden method ...
 88  
          *
 89  
          * @see org.kuali.rice.kim.service.ResponsibilityInternalService#updateActionRequestsForResponsibilityChange(java.util.Set)
 90  
          */
 91  
         public void updateActionRequestsForResponsibilityChange(Set<String> responsibilityIds) {
 92  
 
 93  0
                 KSBXMLService responsibilityChangeProcessor = (KSBXMLService) KSBServiceLocator.getMessageHelper()
 94  
         .getServiceAsynchronously(new QName(MessageServiceNames.RESPONSIBILITY_CHANGE_SERVICE));
 95  
         try {
 96  0
                 responsibilityChangeProcessor.invoke(ResponsibilityChangeProcessor.getResponsibilityChangeContents(responsibilityIds));
 97  
 
 98  0
         } catch (Exception e) {
 99  0
             throw new WorkflowRuntimeException(e);
 100  0
         }
 101  
 
 102  0
         }
 103  
 
 104  
         @SuppressWarnings("unchecked")
 105  
         public List<RoleResponsibilityInfo> getRoleResponsibilities(String roleId){                
 106  0
                 List<RoleResponsibilityImpl> roleResponsibilities = 
 107  
                                 (List<RoleResponsibilityImpl>)getBusinessObjectService()
 108  
                                 .findMatching(RoleResponsibilityImpl.class, Collections.singletonMap(KimConstants.PrimaryKeyConstants.ROLE_ID, roleId));
 109  0
                 List<RoleResponsibilityInfo> result = new ArrayList<RoleResponsibilityInfo>( roleResponsibilities.size() );
 110  0
                 for ( RoleResponsibilityImpl roleResp : roleResponsibilities ) {
 111  0
                         result.add( roleResp.toSimpleInfo() );
 112  
                 }
 113  
 
 114  0
                 return result;
 115  
     }
 116  
 
 117  
          /**
 118  
     *
 119  
     * This method compares the two lists of responsibilitiy IDs and does a union.  returns a unique list of responsibility ids.
 120  
     *
 121  
     * @param oldRespList
 122  
     * @param newRespList
 123  
     * @return
 124  
     */
 125  
    protected Set<String> getChangedRoleResponsibilityIds(
 126  
                         List<RoleResponsibilityInfo> oldRespList,
 127  
                         List<RoleResponsibilityInfo> newRespList) {
 128  0
                 Set<String> lRet = new HashSet<String>();
 129  
 
 130  0
                 for (RoleResponsibilityInfo resp : oldRespList) {
 131  0
                         lRet.add(resp.getResponsibilityId());
 132  
                 }
 133  0
                 for (RoleResponsibilityInfo resp : newRespList) {
 134  0
                         lRet.add(resp.getResponsibilityId());
 135  
                 }
 136  
 
 137  0
                 return lRet;
 138  
         }
 139  
 
 140  
         protected BusinessObjectService getBusinessObjectService() {
 141  0
                 if ( businessObjectService == null ) {
 142  0
                         businessObjectService = KNSServiceLocator.getBusinessObjectService();
 143  
                 }
 144  0
                 return businessObjectService;
 145  
         }
 146  
 
 147  
 }