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