Coverage Report - org.kuali.rice.kew.role.service.impl.RouteLogDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteLogDerivedRoleTypeServiceImpl
0%
0/61
0%
0/44
9.75
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.core.api.exception.RiceIllegalArgumentException;
 20  
 import org.kuali.rice.core.api.membership.MemberType;
 21  
 import org.kuali.rice.kew.api.KewApiServiceLocator;
 22  
 import org.kuali.rice.kew.api.document.WorkflowDocumentService;
 23  
 import org.kuali.rice.kim.api.KimConstants;
 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.common.delegate.DelegationTypeService;
 27  
 import org.kuali.rice.kim.framework.role.RoleTypeService;
 28  
 import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase;
 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 DerivedRoleTypeServiceBase implements RoleTypeService, DelegationTypeService {
 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  
     @Override
 45  
     protected boolean isCheckRequiredAttributes() {
 46  0
         return true;
 47  
     }
 48  
         
 49  
         /**
 50  
          *        - qualifier is document number
 51  
          *        - the roles that will be of this type are KR-WKFLW Initiator and KR-WKFLW Initiator or Reviewer, KR-WKFLW Router
 52  
          *        - only the initiator of the document in question gets the KR-WKFLW Initiator role
 53  
          *        - user who routed the document according to the route log should get the KR-WKFLW Router role
 54  
          *        - users who are authorized by the route log, 
 55  
          *                i.e. initiators, people who have taken action, people with a pending action request, 
 56  
          *                or people who will receive an action request for the document in question get the KR-WKFLW Initiator or Reviewer Role 
 57  
          *
 58  
          */
 59  
         @Override
 60  
     public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 61  0
             if (StringUtils.isBlank(namespaceCode)) {
 62  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 63  
         }
 64  
 
 65  0
         if (roleName == null) {
 66  0
             throw new RiceIllegalArgumentException("roleName was null");
 67  
         }
 68  
 
 69  0
         validateRequiredAttributesAgainstReceived(qualification);
 70  0
                 List<RoleMembership> members = new ArrayList<RoleMembership>();
 71  0
                 if(qualification!=null && !qualification.isEmpty()){
 72  0
                         String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER);
 73  0
                         if (StringUtils.isNotBlank(documentId)) {
 74  
                                 try{
 75  0
                     WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService();
 76  0
                                         if (INITIATOR_ROLE_NAME.equals(roleName)) {
 77  0
                                             String principalId = KewApiServiceLocator.getWorkflowDocumentService().getDocumentInitiatorPrincipalId(
 78  
                                 documentId);
 79  0
                         RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, MemberType.PRINCIPAL, null).build();
 80  0
                             members.add(roleMembership);
 81  0
                                         } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) {
 82  0
                                             List<String> ids = KewApiServiceLocator.getWorkflowDocumentActionsService().getPrincipalIdsInRouteLog(
 83  
                                 documentId, true);
 84  0
                                             for ( String id : ids ) {
 85  0
                                                     if ( StringUtils.isNotBlank(id) ) {
 86  0
                                 RoleMembership roleMembership = RoleMembership.Builder.create(null,null,id, MemberType.PRINCIPAL, null).build();
 87  0
                                                             members.add(roleMembership );
 88  0
                                                     }
 89  
                                             }
 90  0
                                         } else if(ROUTER_ROLE_NAME.equals(roleName)) {
 91  0
                         String principalId = workflowDocumentService.getRoutedByPrincipalIdByDocumentId(documentId);
 92  0
                         RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, MemberType.PRINCIPAL, null).build();
 93  0
                             members.add(roleMembership);
 94  
                                         }
 95  0
                                 } catch(Exception wex){
 96  0
                                         throw new RuntimeException(
 97  
                                         "Error in getting principal Ids in route log for document id: "+ documentId +" :"+wex.getLocalizedMessage(),wex);
 98  0
                                 }
 99  
                         }
 100  
                 }
 101  
 
 102  0
                 return members;
 103  
         }
 104  
 
 105  
         @Override
 106  
         public boolean hasApplicationRole(
 107  
                         String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){
 108  0
                 if (StringUtils.isBlank(principalId)) {
 109  0
             throw new RiceIllegalArgumentException("principalId was null or blank");
 110  
         }
 111  
 
 112  0
         if (groupIds == null) {
 113  0
             throw new RiceIllegalArgumentException("groupIds was null or blank");
 114  
         }
 115  
 
 116  0
         if (StringUtils.isBlank(namespaceCode)) {
 117  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 118  
         }
 119  
 
 120  0
         if (StringUtils.isBlank(roleName)) {
 121  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 122  
         }
 123  
 
 124  0
         if (qualification == null) {
 125  0
             throw new RiceIllegalArgumentException("qualification was null");
 126  
         }
 127  
 
 128  
 
 129  0
         validateRequiredAttributesAgainstReceived(qualification);
 130  0
         boolean isUserInRouteLog = false;
 131  0
                 if(qualification!=null && !qualification.isEmpty()){
 132  0
                         String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER);
 133  0
             WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService();
 134  
                         try {
 135  0
                                 if (INITIATOR_ROLE_NAME.equals(roleName)){
 136  0
                                         isUserInRouteLog = principalId.equals(workflowDocumentService.getDocumentInitiatorPrincipalId(documentId));
 137  0
                                 } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){
 138  0
                                         isUserInRouteLog = KewApiServiceLocator.getWorkflowDocumentActionsService().isUserInRouteLog(
 139  
                             documentId, principalId, true);
 140  0
                                 } else if(ROUTER_ROLE_NAME.equals(roleName)){
 141  0
                                         isUserInRouteLog = principalId.equals(workflowDocumentService.getRoutedByPrincipalIdByDocumentId(
 142  
                             documentId));
 143  
                                 }
 144  0
                         } catch (Exception wex) {
 145  0
                                 throw new RuntimeException("Error in determining whether the principal Id: " + principalId + " is in route log " +
 146  
                                                 "for document id: " + documentId + " :"+wex.getLocalizedMessage(),wex);
 147  0
                         }
 148  
                 }
 149  0
                 return isUserInRouteLog;
 150  
         }
 151  
 
 152  
         /**
 153  
          * Returns false, as the Route Log changes often enough that role membership is highly volatile
 154  
          * 
 155  
          * @see org.kuali.rice.kns.kim.role.RoleTypeServiceBase#dynamicRoleMembership(java.lang.String, java.lang.String)
 156  
          */
 157  
         @Override
 158  
         public boolean dynamicRoleMembership(String namespaceCode, String roleName) {
 159  0
                 if (StringUtils.isBlank(namespaceCode)) {
 160  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 161  
         }
 162  
 
 163  0
             if (StringUtils.isBlank(roleName)) {
 164  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 165  
         }
 166  
 
 167  0
         return false;
 168  
         }
 169  
 }