Coverage Report - org.kuali.rice.kew.role.service.impl.RouteLogDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteLogDerivedRoleTypeServiceImpl
0%
0/45
0%
0/26
6.667
 
 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.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kew.api.KewApiServiceLocator;
 20  
 import org.kuali.rice.kew.api.document.WorkflowDocumentService;
 21  
 import org.kuali.rice.kew.exception.WorkflowException;
 22  
 import org.kuali.rice.kew.service.WorkflowInfo;
 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 RouteLogDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService {
 40  
     public static final String INITIATOR_ROLE_NAME = "Initiator";
 41  
     public static final String INITIATOR_OR_REVIEWER_ROLE_NAME = "Initiator or Reviewer";
 42  
     public static final String ROUTER_ROLE_NAME = "Router";
 43  
 
 44  0
         protected WorkflowInfo workflowInfo = new WorkflowInfo();
 45  
     
 46  
         {
 47  
                 //KFSMI-4938 - document number needs to be optional for this role type, 
 48  
                 //since this is also used for inquiries
 49  
                 //requiredAttributes.add(KimAttributes.DOCUMENT_NUMBER);
 50  0
                 checkRequiredAttributes = true;
 51  0
         }
 52  
         
 53  
         /**
 54  
          *        - qualifier is document number
 55  
          *        - the roles that will be of this type are KR-WKFLW Initiator and KR-WKFLW Initiator or Reviewer, KR-WKFLW Router
 56  
          *        - only the initiator of the document in question gets the KR-WKFLW Initiator role
 57  
          *        - user who routed the document according to the route log should get the KR-WKFLW Router role
 58  
          *        - users who are authorized by the route log, 
 59  
          *                i.e. initiators, people who have taken action, people with a pending action request, 
 60  
          *                or people who will receive an action request for the document in question get the KR-WKFLW Initiator or Reviewer Role 
 61  
          *
 62  
          */
 63  
         @Override
 64  
     public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 65  0
                 validateRequiredAttributesAgainstReceived(qualification);
 66  0
                 List<RoleMembership> members = new ArrayList<RoleMembership>();
 67  0
                 if(qualification!=null && !qualification.isEmpty()){
 68  0
                         String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER);
 69  0
                         if (StringUtils.isNotBlank(documentId)) {
 70  
                                 try{
 71  0
                     WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService();
 72  0
                                         if (INITIATOR_ROLE_NAME.equals(roleName)) {
 73  0
                                             String principalId = KewApiServiceLocator.getWorkflowDocumentService().getDocumentInitiatorPrincipalId(
 74  
                                 documentId);
 75  0
                         RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, Role.PRINCIPAL_MEMBER_TYPE,null).build();
 76  0
                             members.add(roleMembership);
 77  0
                                         } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) {
 78  0
                                             List<String> ids = workflowInfo.getPrincipalIdsInRouteLog(documentId, true);
 79  0
                                             for ( String id : ids ) {
 80  0
                                                     if ( StringUtils.isNotBlank(id) ) {
 81  0
                                 RoleMembership roleMembership = RoleMembership.Builder.create(null,null,id, Role.PRINCIPAL_MEMBER_TYPE,null).build();
 82  0
                                                             members.add(roleMembership );
 83  0
                                                     }
 84  
                                             }
 85  0
                                         } else if(ROUTER_ROLE_NAME.equals(roleName)) {
 86  0
                         String principalId = workflowDocumentService.getDocumentRoutedByPrincipalId(documentId);
 87  0
                         RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, Role.PRINCIPAL_MEMBER_TYPE,null).build();
 88  0
                             members.add(roleMembership);
 89  
                                         }
 90  0
                                 } catch(WorkflowException wex){
 91  0
                                         throw new RuntimeException(
 92  
                                         "Error in getting principal Ids in route log for document id: "+ documentId +" :"+wex.getLocalizedMessage(),wex);
 93  0
                                 }
 94  
                         }
 95  
                 }
 96  
 
 97  0
                 return members;
 98  
         }
 99  
 
 100  
         @Override
 101  
         public boolean hasApplicationRole(
 102  
                         String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){
 103  0
                 validateRequiredAttributesAgainstReceived(qualification);
 104  0
         boolean isUserInRouteLog = false;
 105  0
                 if(qualification!=null && !qualification.isEmpty()){
 106  0
                         String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER);
 107  0
             WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService();
 108  
                         try {
 109  0
                                 if (INITIATOR_ROLE_NAME.equals(roleName)){
 110  0
                                         isUserInRouteLog = principalId.equals(workflowDocumentService.getDocumentInitiatorPrincipalId(documentId));
 111  0
                                 } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){
 112  0
                                         isUserInRouteLog = workflowInfo.isUserAuthenticatedByRouteLog(documentId, principalId, true);
 113  0
                                 } else if(ROUTER_ROLE_NAME.equals(roleName)){
 114  0
                                         isUserInRouteLog = principalId.equals(workflowDocumentService.getDocumentRoutedByPrincipalId(documentId));
 115  
                                 }
 116  0
                         } catch (WorkflowException wex) {
 117  0
                                 throw new RuntimeException("Error in determining whether the principal Id: " + principalId + " is in route log " +
 118  
                                                 "for document id: " + documentId + " :"+wex.getLocalizedMessage(),wex);
 119  0
                         }
 120  
                 }
 121  0
                 return isUserInRouteLog;
 122  
         }
 123  
 
 124  
         /**
 125  
          * Returns false, as the Route Log changes often enough that role membership is highly volatile
 126  
          * 
 127  
          * @see org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase#shouldCacheRoleMembershipResults(java.lang.String, java.lang.String)
 128  
          */
 129  
         @Override
 130  
         public boolean shouldCacheRoleMembershipResults(String namespaceCode,
 131  
                         String roleName) {
 132  0
                 return false;
 133  
         }
 134  
 }