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