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-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.actions;
 17  
 
 18  
 import org.kuali.rice.kew.actionitem.ActionItem;
 19  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 20  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 21  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 22  
 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
 23  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 24  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 25  
 import org.kuali.rice.kew.api.KewApiConstants;
 26  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 27  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.Collection;
 31  
 import java.util.List;
 32  
 
 33  
 
 34  
 
 35  
 /**
 36  
  * Removes all workgroup action items for a document from everyone's action list except the person
 37  
  * who took the workgroup authority
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  
 public class TakeWorkgroupAuthority extends ActionTakenEvent {
 43  
     
 44  
     private String groupId;
 45  
     
 46  
     /**
 47  
      * @param routeHeader
 48  
      * @param principal
 49  
      */
 50  
     public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 51  0
         super(KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal);
 52  0
     }
 53  
 
 54  
     /**
 55  
      * @param routeHeader
 56  
      * @param principal
 57  
      * @param annotation
 58  
      * @param groupId
 59  
      */
 60  
     public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) {
 61  0
         super(KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation);
 62  0
         this.groupId = groupId;
 63  0
     }
 64  
 
 65  
     /* (non-Javadoc)
 66  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
 67  
      */
 68  
     @Override
 69  
     public String validateActionRules() {
 70  0
         if  ( (groupId != null) && (!KimApiServiceLocator.getGroupService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId))) {
 71  0
             return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId);
 72  
         }
 73  0
         return "";
 74  
     }
 75  
 
 76  
     @Override
 77  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 78  0
             return validateActionRules();
 79  
     }
 80  
     
 81  
     public void recordAction() throws InvalidActionTakenException {
 82  
 
 83  0
         String errorMessage = validateActionRules();
 84  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 85  0
             throw new InvalidActionTakenException(errorMessage);
 86  
         }
 87  
 //        if (! workgroup.hasMember(getUser())) {
 88  
 //            throw new InvalidActionTakenException(getUser().getPrincipalName() + " not a member of workgroup " + workgroup.getDisplayName());
 89  
 //        }
 90  
 
 91  0
         List<ActionRequestValue> documentRequests = getActionRequestService().findPendingByDoc(getDocumentId());
 92  0
         List<ActionRequestValue> workgroupRequests = new ArrayList<ActionRequestValue>();
 93  0
         for (ActionRequestValue actionRequest : documentRequests)
 94  
         {
 95  0
             if (actionRequest.isGroupRequest() && actionRequest.getGroup().getId().equals(groupId))
 96  
             {
 97  0
                 workgroupRequests.add(actionRequest);
 98  
             }
 99  
         }
 100  
 
 101  0
         ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(workgroupRequests));
 102  0
         notifyActionTaken(actionTaken);
 103  
 
 104  0
         ActionListService actionListService = KEWServiceLocator.getActionListService();
 105  0
         Collection<ActionItem> actionItems = actionListService.findByDocumentId(getDocumentId());
 106  0
         for (ActionItem actionItem : actionItems)
 107  
         {
 108  
             //delete all requests for this workgroup on this document not to this user
 109  0
             if (actionItem.isWorkgroupItem() && actionItem.getGroupId().equals(groupId) &&
 110  
                     !actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId()))
 111  
             {
 112  0
                 actionListService.deleteActionItem(actionItem);
 113  
             }
 114  
         }
 115  0
     }
 116  
 }