Coverage Report - org.kuali.rice.kew.actions.TakeWorkgroupAuthority
 
Classes in this File Line Coverage Branch Coverage Complexity
TakeWorkgroupAuthority
0%
0/25
0%
0/20
3.4
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.actions;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.rice.kew.actionitem.ActionItem;
 24  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 25  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 26  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 27  
 import org.kuali.rice.kew.exception.InvalidActionTakenException;
 28  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 29  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 30  
 import org.kuali.rice.kew.util.KEWConstants;
 31  
 import org.kuali.rice.kim.api.entity.principal.PrincipalContract;
 32  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 33  
 
 34  
 
 35  
 
 36  
 /**
 37  
  * Removes all workgroup action items for a document from everyone's action list except the person
 38  
  * who took the workgroup authority
 39  
  *
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  *
 42  
  */
 43  
 public class TakeWorkgroupAuthority extends ActionTakenEvent {
 44  
     
 45  
     private String groupId;
 46  
     
 47  
     /**
 48  
      * @param routeHeader
 49  
      * @param principal
 50  
      */
 51  
     public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 52  0
         super(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal);
 53  0
     }
 54  
 
 55  
     /**
 56  
      * @param routeHeader
 57  
      * @param principal
 58  
      * @param annotation
 59  
      * @param groupId
 60  
      */
 61  
     public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) {
 62  0
         super(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation);
 63  0
         this.groupId = groupId;
 64  0
     }
 65  
 
 66  
     /* (non-Javadoc)
 67  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
 68  
      */
 69  
     @Override
 70  
     public String validateActionRules() {
 71  0
         if  ( (groupId != null) && (!KimApiServiceLocator.getIdentityManagementService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId))) {
 72  0
             return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId);
 73  
         }
 74  0
         return "";
 75  
     }
 76  
 
 77  
     @Override
 78  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 79  0
             return validateActionRules();
 80  
     }
 81  
     
 82  
     public void recordAction() throws InvalidActionTakenException {
 83  
 
 84  0
         String errorMessage = validateActionRules();
 85  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 86  0
             throw new InvalidActionTakenException(errorMessage);
 87  
         }
 88  
 //        if (! workgroup.hasMember(getUser())) {
 89  
 //            throw new InvalidActionTakenException(getUser().getPrincipalName() + " not a member of workgroup " + workgroup.getDisplayName());
 90  
 //        }
 91  
 
 92  0
         List<ActionRequestValue> documentRequests = getActionRequestService().findPendingByDoc(getDocumentId());
 93  0
         List<ActionRequestValue> workgroupRequests = new ArrayList<ActionRequestValue>();
 94  0
         for (ActionRequestValue actionRequest : documentRequests)
 95  
         {
 96  0
             if (actionRequest.isGroupRequest() && actionRequest.getGroup().getId().equals(groupId))
 97  
             {
 98  0
                 workgroupRequests.add(actionRequest);
 99  
             }
 100  
         }
 101  
 
 102  0
         ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(workgroupRequests));
 103  0
         notifyActionTaken(actionTaken);
 104  
 
 105  0
         ActionListService actionListService = KEWServiceLocator.getActionListService();
 106  0
         Collection<ActionItem> actionItems = actionListService.findByDocumentId(getDocumentId());
 107  0
         for (ActionItem actionItem : actionItems)
 108  
         {
 109  
             //delete all requests for this workgroup on this document not to this user
 110  0
             if (actionItem.isWorkgroupItem() && actionItem.getGroupId().equals(groupId) &&
 111  
                     !actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId()))
 112  
             {
 113  0
                 actionListService.deleteActionItem(actionItem);
 114  
             }
 115  
         }
 116  0
     }
 117  
 }