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