Coverage Report - org.kuali.rice.kew.role.service.impl.ActionRequestDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionRequestDerivedRoleTypeServiceImpl
0%
0/33
0%
0/44
11
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.kew.role.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.util.AttributeSet;
 22  
 import org.kuali.rice.kew.dto.ActionRequestDTO;
 23  
 import org.kuali.rice.kew.exception.WorkflowException;
 24  
 import org.kuali.rice.kew.service.WorkflowInfo;
 25  
 import org.kuali.rice.kew.util.KEWConstants;
 26  
 import org.kuali.rice.kim.bo.Role;
 27  
 import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
 28  
 import org.kuali.rice.kim.framework.type.KimDelegationTypeService;
 29  
 import org.kuali.rice.kim.framework.type.KimRoleTypeService;
 30  
 import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase;
 31  
 import org.kuali.rice.kim.util.KimConstants;
 32  
 
 33  
 /**
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  * 
 37  
  */
 38  0
 public class ActionRequestDerivedRoleTypeServiceImpl extends
 39  
                 KimDerivedRoleTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService {
 40  
         private static final String NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME = "Non-Ad Hoc Approve Request Recipient";
 41  
         private static final String APPROVE_REQUEST_RECIPIENT_ROLE_NAME = "Approve Request Recipient";
 42  
         private static final String ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME = "Acknowledge Request Recipient";
 43  
         private static final String FYI_REQUEST_RECIPIENT_ROLE_NAME = "FYI Request Recipient";
 44  0
         protected WorkflowInfo workflowInfo = new WorkflowInfo();
 45  
 
 46  
         {
 47  0
                 requiredAttributes.add( KimConstants.AttributeConstants.DOCUMENT_NUMBER );
 48  0
                 checkRequiredAttributes = true;
 49  0
         }
 50  
         
 51  
         /**
 52  
          * @see org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase#getRoleMembersFromApplicationRole(java.lang.String, java.lang.String, org.kuali.rice.core.util.AttributeSet)
 53  
          */
 54  
         @Override
 55  
     public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet qualification) {
 56  0
                 List<RoleMembershipInfo> members = new ArrayList<RoleMembershipInfo>();
 57  0
                 if ( qualification != null && !qualification.isEmpty() ) {
 58  0
                     String principalId = qualification.get(KimConstants.AttributeConstants.PRINCIPAL_ID);
 59  0
                         if (qualification.containsKey(KimConstants.AttributeConstants.PRINCIPAL_ID)
 60  
                                         && hasApplicationRole(principalId, null, namespaceCode,
 61  
                                                         roleName, qualification)) {
 62  0
                 members.add( new RoleMembershipInfo(null/*roleId*/, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) );
 63  
                         }
 64  
                 }
 65  0
                 return members;
 66  
         }
 67  
 
 68  
         /**
 69  
          * @see org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase#hasApplicationRole(java.lang.String, java.util.List, java.lang.String, java.lang.String, org.kuali.rice.core.util.AttributeSet)
 70  
          */
 71  
         @Override
 72  
         public boolean hasApplicationRole(String principalId,
 73  
                         List<String> groupIds, String namespaceCode, String roleName,
 74  
                         AttributeSet qualification) {
 75  0
                 validateRequiredAttributesAgainstReceived(qualification);
 76  
                 try {
 77  0
                         if ( (qualification != null && !qualification.isEmpty()))  {
 78  0
                                 ActionRequestDTO[] actionRequests = workflowInfo.getActionRequests(qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER), null, principalId);
 79  0
                                 if (APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) {
 80  0
                                         for ( ActionRequestDTO ar : actionRequests ) {
 81  0
                                                 if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_APPROVE_REQ )
 82  
                                                                 && ar.getStatus().equals( KEWConstants.ACTION_REQUEST_ACTIVATED ) ) {
 83  0
                                                         return APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || (NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) && !ar.isAdHocRequest());
 84  
                                                 }
 85  
                                         }
 86  0
                                         return false;
 87  
                                 }
 88  0
                                 if (ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) {
 89  0
                                         for ( ActionRequestDTO ar : actionRequests ) {
 90  0
                                                 if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ ) 
 91  
                                                         && ar.getStatus().equals( KEWConstants.ACTION_REQUEST_ACTIVATED ) ) {
 92  0
                                                         return true;
 93  
                                                 }
 94  
                                         }
 95  0
                                         return false;
 96  
                                 }
 97  0
                                 if (FYI_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) {
 98  0
                                         for ( ActionRequestDTO ar : actionRequests ) {
 99  0
                                                 if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_FYI_REQ ) 
 100  
                                                         && ar.getStatus().equals( KEWConstants.ACTION_REQUEST_ACTIVATED ) ) {
 101  0
                                                         return true;
 102  
                                                 }
 103  
                                         }
 104  0
                                         return false;
 105  
                                 }
 106  
                         }
 107  0
                         return false;
 108  0
                 } catch (WorkflowException e) {
 109  0
                         throw new RuntimeException("Unable to load route header", e);
 110  
                 }
 111  
         }
 112  
 
 113  
         /**
 114  
          * Returns false, as action requests change quite often so membership in this role is highly volatile
 115  
          * 
 116  
          * @see org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase#shouldCacheRoleMembershipResults(java.lang.String, java.lang.String)
 117  
          */
 118  
         @Override
 119  
         public boolean shouldCacheRoleMembershipResults(String namespaceCode,
 120  
                         String roleName) {
 121  0
                 return false;
 122  
         }
 123  
         
 124  
 }