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