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