Coverage Report - org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponsibilityInternalServiceImpl
0%
0/42
0%
0/14
1.9
 
 1  
 /**
 2  
  * Copyright 2005-2011 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 org.kuali.rice.kew.api.KewApiServiceLocator;
 19  
 import org.kuali.rice.kim.api.KimConstants;
 20  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 21  
 import org.kuali.rice.kim.api.responsibility.ResponsibilityService;
 22  
 import org.kuali.rice.kim.api.role.RoleResponsibility;
 23  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 24  
 import org.kuali.rice.kim.impl.role.RoleMemberBo;
 25  
 import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
 26  
 import org.kuali.rice.krad.service.BusinessObjectService;
 27  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.Collections;
 31  
 import java.util.HashSet;
 32  
 import java.util.List;
 33  
 import java.util.Map;
 34  
 import java.util.Set;
 35  
 
 36  0
 public class ResponsibilityInternalServiceImpl implements ResponsibilityInternalService {
 37  
 
 38  
         private BusinessObjectService businessObjectService;
 39  
     private ResponsibilityService responsibilityService;
 40  
 
 41  
     @Override
 42  
         public RoleMemberBo saveRoleMember(RoleMemberBo roleMember){
 43  
 
 44  
                 //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 45  0
             List<RoleResponsibility> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 46  
 
 47  
             // add row to member table
 48  0
             RoleMemberBo member = getBusinessObjectService().save( roleMember );
 49  
 
 50  
             //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 51  
             // the new member has been added
 52  0
             List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 53  
 
 54  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
 55  
 
 56  0
         return member;
 57  
         }
 58  
     @Override
 59  
         public void removeRoleMember(RoleMemberBo roleMember){
 60  
                 //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 61  0
             List<RoleResponsibility> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 62  
 
 63  
             // add row to member table
 64  0
             getBusinessObjectService().delete( roleMember );
 65  
 
 66  
             //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 67  
             // the new member has been added
 68  0
             List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 69  
 
 70  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
 71  0
         }
 72  
 
 73  
     @Override
 74  
         @SuppressWarnings("unchecked")
 75  
         public void updateActionRequestsForRoleChange(String roleId) {
 76  0
             List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleId);
 77  
                 
 78  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(Collections.EMPTY_LIST, newRoleResp));
 79  0
         }
 80  
         
 81  
 
 82  
         /**
 83  
          * This overridden method ...
 84  
          *
 85  
          * @see ResponsibilityInternalService#updateActionRequestsForResponsibilityChange(java.util.Set)
 86  
          */
 87  
     @Override
 88  
         public void updateActionRequestsForResponsibilityChange(Set<String> responsibilityIds) {
 89  0
         KewApiServiceLocator.getResponsibilityChangeQueue().responsibilitiesChanged(responsibilityIds);
 90  0
         }
 91  
 
 92  
         @SuppressWarnings("unchecked")
 93  
         public List<RoleResponsibility> getRoleResponsibilities(String roleId){
 94  0
                 List<RoleResponsibilityBo> rrBoList =
 95  
                                 (List<RoleResponsibilityBo>)getBusinessObjectService()
 96  
                                 .findMatching(RoleResponsibilityBo.class, Collections.singletonMap(KimConstants.PrimaryKeyConstants.ROLE_ID, roleId));
 97  0
                 List<RoleResponsibility> result = new ArrayList<RoleResponsibility>( rrBoList.size() );
 98  0
                 for ( RoleResponsibilityBo bo : rrBoList ) {
 99  0
                         result.add( RoleResponsibilityBo.to(bo) );
 100  
                 }
 101  0
                 return result;
 102  
     }
 103  
 
 104  
          /**
 105  
     *
 106  
     * This method compares the two lists of responsibilitiy IDs and does a union.  returns a unique list of responsibility ids.
 107  
     *
 108  
     * @param oldRespList
 109  
     * @param newRespList
 110  
     * @return
 111  
     */
 112  
    protected Set<String> getChangedRoleResponsibilityIds(
 113  
                         List<RoleResponsibility> oldRespList,
 114  
                         List<RoleResponsibility> newRespList) {
 115  0
                 Set<String> lRet = new HashSet<String>();
 116  
 
 117  0
                 for (RoleResponsibility resp : oldRespList) {
 118  0
                         lRet.add(resp.getResponsibilityId());
 119  
                 }
 120  0
                 for (RoleResponsibility resp : newRespList) {
 121  0
                         lRet.add(resp.getResponsibilityId());
 122  
                 }
 123  
 
 124  0
                 return lRet;
 125  
         }
 126  
 
 127  
         protected BusinessObjectService getBusinessObjectService() {
 128  0
                 if ( businessObjectService == null ) {
 129  0
                         businessObjectService = KRADServiceLocator.getBusinessObjectService();
 130  
                 }
 131  0
                 return businessObjectService;
 132  
         }
 133  
 
 134  
     protected ResponsibilityService getResponsibilityService() {
 135  0
                 if ( responsibilityService == null ) {
 136  0
                         responsibilityService = KimApiServiceLocator.getResponsibilityService();
 137  
                 }
 138  0
                 return responsibilityService;
 139  
         }
 140  
 
 141  
     @Override
 142  
     public boolean areActionsAtAssignmentLevel(Responsibility responsibility ) {
 143  0
             Map<String, String> details = responsibility.getAttributes();
 144  0
             if ( details == null ) {
 145  0
                     return false;
 146  
             }
 147  0
             String actionDetailsAtRoleMemberLevel = details.get( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL );
 148  0
             return Boolean.valueOf(actionDetailsAtRoleMemberLevel);
 149  
     }
 150  
 
 151  
     @Override
 152  
     public boolean areActionsAtAssignmentLevelById( String responsibilityId ) {
 153  0
             Responsibility responsibility = getResponsibilityService().getResponsibility(responsibilityId);
 154  0
             if ( responsibility == null ) {
 155  0
                     return false;
 156  
             }
 157  0
             return areActionsAtAssignmentLevel(responsibility);
 158  
     }
 159  
 
 160  
 }