Coverage Report - org.kuali.rice.kew.role.service.impl.ActionRequestDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionRequestDerivedRoleTypeServiceImpl
0%
0/32
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 org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 19  
 import org.kuali.rice.kew.api.KewApiServiceLocator;
 20  
 import org.kuali.rice.kew.api.action.ActionRequest;
 21  
 import org.kuali.rice.kew.api.action.ActionRequestStatus;
 22  
 import org.kuali.rice.kew.util.KEWConstants;
 23  
 import org.kuali.rice.kim.api.role.Role;
 24  
 import org.kuali.rice.kim.api.role.RoleMembership;
 25  
 import org.kuali.rice.kim.framework.type.KimDelegationTypeService;
 26  
 import org.kuali.rice.kim.framework.type.KimRoleTypeService;
 27  
 import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase;
 28  
 import org.kuali.rice.kim.util.KimConstants;
 29  
 
 30  
 import java.util.ArrayList;
 31  
 import java.util.List;
 32  
 import java.util.Map;
 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  
 
 46  
         {
 47  0
                 requiredAttributes.add( KimConstants.AttributeConstants.DOCUMENT_NUMBER );
 48  0
                 checkRequiredAttributes = true;
 49  0
         }
 50  
         
 51  
         @Override
 52  
     public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 53  0
                 List<RoleMembership> members = new ArrayList<RoleMembership>();
 54  0
                 if ( qualification != null && !qualification.isEmpty() ) {
 55  0
                     String principalId = qualification.get(KimConstants.AttributeConstants.PRINCIPAL_ID);
 56  0
                         if (qualification.containsKey(KimConstants.AttributeConstants.PRINCIPAL_ID)
 57  
                                         && hasApplicationRole(principalId, null, namespaceCode,
 58  
                                                         roleName, qualification)) {
 59  0
                 members.add(RoleMembership.Builder.create(null/*roleId*/, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null).build());
 60  
                         }
 61  
                 }
 62  0
                 return members;
 63  
         }
 64  
 
 65  
         @Override
 66  
         public boolean hasApplicationRole(String principalId,
 67  
                         List<String> groupIds, String namespaceCode, String roleName,
 68  
                         Map<String, String> qualification) {
 69  0
                 validateRequiredAttributesAgainstReceived(qualification);
 70  
                 try {
 71  0
                         if ( (qualification != null && !qualification.isEmpty()))  {
 72  0
                                 List<ActionRequest> actionRequests = KewApiServiceLocator.getWorkflowDocumentService().getActionRequests(qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER), null, principalId);
 73  0
                 if (APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) {
 74  0
                                         for ( ActionRequest ar : actionRequests ) {
 75  0
                                                 if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_APPROVE_REQ )
 76  
                                                                 && ar.getStatus().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) {
 77  0
                                                         return APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || (NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) && !ar.isAdHocRequest());
 78  
                                                 }
 79  
                                         }
 80  0
                                         return false;
 81  
                                 }
 82  0
                                 if (ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) {
 83  0
                                         for ( ActionRequest ar : actionRequests ) {
 84  0
                                                 if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ ) 
 85  
                                                         && ar.getStatus().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) {
 86  0
                                                         return true;
 87  
                                                 }
 88  
                                         }
 89  0
                                         return false;
 90  
                                 }
 91  0
                                 if (FYI_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) {
 92  0
                                         for ( ActionRequest ar : actionRequests ) {
 93  0
                                                 if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_FYI_REQ ) 
 94  
                                                         && ar.getStatus().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) {
 95  0
                                                         return true;
 96  
                                                 }
 97  
                                         }
 98  0
                                         return false;
 99  
                                 }
 100  
                         }
 101  0
                         return false;
 102  0
                 } catch (RiceIllegalArgumentException e) {
 103  0
                         throw new RuntimeException("Unable to load route header", e);
 104  
                 }
 105  
         }
 106  
 
 107  
         /**
 108  
          * Returns false, as action requests change quite often so membership in this role is highly volatile
 109  
          * 
 110  
          * @see org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase#shouldCacheRoleMembershipResults(java.lang.String, java.lang.String)
 111  
          */
 112  
         @Override
 113  
         public boolean shouldCacheRoleMembershipResults(String namespaceCode,
 114  
                         String roleName) {
 115  0
                 return false;
 116  
         }
 117  
         
 118  
 }