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 org.kuali.rice.kew.api.WorkflowRuntimeException;
 19  
 import org.kuali.rice.kew.messaging.MessageServiceNames;
 20  
 import org.kuali.rice.kew.responsibility.ResponsibilityChangeProcessor;
 21  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 22  
 import org.kuali.rice.kim.api.responsibility.ResponsibilityService;
 23  
 import org.kuali.rice.kim.api.role.RoleResponsibility;
 24  
 import org.kuali.rice.kim.impl.role.RoleMemberBo;
 25  
 import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
 26  
 import org.kuali.rice.kim.util.KimConstants;
 27  
 import org.kuali.rice.krad.service.BusinessObjectService;
 28  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 29  
 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
 30  
 import org.kuali.rice.ksb.messaging.service.KSBXMLService;
 31  
 
 32  
 import javax.xml.namespace.QName;
 33  
 import java.util.ArrayList;
 34  
 import java.util.Collections;
 35  
 import java.util.HashSet;
 36  
 import java.util.List;
 37  
 import java.util.Map;
 38  
 import java.util.Set;
 39  
 
 40  0
 public class ResponsibilityInternalServiceImpl implements ResponsibilityInternalService {
 41  
 
 42  
         private BusinessObjectService businessObjectService;
 43  
     private ResponsibilityService responsibilityService;
 44  
 
 45  
         public void saveRoleMember(RoleMemberBo roleMember){
 46  
 
 47  
                 //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 48  0
             List<RoleResponsibility> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 49  
 
 50  
             // add row to member table
 51  0
             getBusinessObjectService().save( roleMember );
 52  
 
 53  
             //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 54  
             // the new member has been added
 55  0
             List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 56  
 
 57  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
 58  0
         }
 59  
 
 60  
         public void removeRoleMember(RoleMemberBo roleMember){
 61  
                 //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 62  0
             List<RoleResponsibility> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 63  
 
 64  
             // add row to member table
 65  0
             getBusinessObjectService().delete( roleMember );
 66  
 
 67  
             //need to find what responsibilities changed so we can notify interested clients.  Like workflow.
 68  
             // the new member has been added
 69  0
             List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
 70  
 
 71  0
             updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
 72  0
         }
 73  
 
 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  
         public void updateActionRequestsForResponsibilityChange(Set<String> responsibilityIds) {
 88  
 
 89  0
                 KSBXMLService responsibilityChangeProcessor = (KSBXMLService) KsbApiServiceLocator.getMessageHelper()
 90  
         .getServiceAsynchronously(new QName(MessageServiceNames.RESPONSIBILITY_CHANGE_SERVICE));
 91  
         try {
 92  0
                 responsibilityChangeProcessor.invoke(ResponsibilityChangeProcessor.getResponsibilityChangeContents(responsibilityIds));
 93  
 
 94  0
         } catch (Exception e) {
 95  0
             throw new WorkflowRuntimeException(e);
 96  0
         }
 97  
 
 98  0
         }
 99  
 
 100  
         @SuppressWarnings("unchecked")
 101  
         public List<RoleResponsibility> getRoleResponsibilities(String roleId){
 102  0
                 List<RoleResponsibilityBo> rrBoList =
 103  
                                 (List<RoleResponsibilityBo>)getBusinessObjectService()
 104  
                                 .findMatching(RoleResponsibilityBo.class, Collections.singletonMap(KimConstants.PrimaryKeyConstants.ROLE_ID, roleId));
 105  0
                 List<RoleResponsibility> result = new ArrayList<RoleResponsibility>( rrBoList.size() );
 106  0
                 for ( RoleResponsibilityBo bo : rrBoList ) {
 107  0
                         result.add( RoleResponsibilityBo.to(bo) );
 108  
                 }
 109  0
                 return result;
 110  
     }
 111  
 
 112  
          /**
 113  
     *
 114  
     * This method compares the two lists of responsibilitiy IDs and does a union.  returns a unique list of responsibility ids.
 115  
     *
 116  
     * @param oldRespList
 117  
     * @param newRespList
 118  
     * @return
 119  
     */
 120  
    protected Set<String> getChangedRoleResponsibilityIds(
 121  
                         List<RoleResponsibility> oldRespList,
 122  
                         List<RoleResponsibility> newRespList) {
 123  0
                 Set<String> lRet = new HashSet<String>();
 124  
 
 125  0
                 for (RoleResponsibility resp : oldRespList) {
 126  0
                         lRet.add(resp.getResponsibilityId());
 127  
                 }
 128  0
                 for (RoleResponsibility resp : newRespList) {
 129  0
                         lRet.add(resp.getResponsibilityId());
 130  
                 }
 131  
 
 132  0
                 return lRet;
 133  
         }
 134  
 
 135  
         protected BusinessObjectService getBusinessObjectService() {
 136  0
                 if ( businessObjectService == null ) {
 137  0
                         businessObjectService = KRADServiceLocator.getBusinessObjectService();
 138  
                 }
 139  0
                 return businessObjectService;
 140  
         }
 141  
 
 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  
     public boolean areActionsAtAssignmentLevelById( String responsibilityId ) {
 152  0
             Responsibility responsibility = responsibilityService.getResponsibility(responsibilityId);
 153  0
             if ( responsibility == null ) {
 154  0
                     return false;
 155  
             }
 156  0
             return areActionsAtAssignmentLevel(responsibility);
 157  
     }
 158  
 
 159  
 }