Coverage Report - org.kuali.rice.kew.actions.ReleaseWorkgroupAuthority
 
Classes in this File Line Coverage Branch Coverage Complexity
ReleaseWorkgroupAuthority
0%
0/29
0%
0/20
3.333
 
 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 org.kuali.rice.kew.actionitem.ActionItem;
 20  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 21  
 import org.kuali.rice.kew.api.action.ActionRequestStatus;
 22  
 import org.kuali.rice.kew.exception.InvalidActionTakenException;
 23  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 24  
 import org.kuali.rice.kew.util.KEWConstants;
 25  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 26  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 27  
 
 28  
 import java.util.List;
 29  
 
 30  
 
 31  
 
 32  
 /**
 33  
  * This is the inverse of the {@link TakeWorkgroupAuthority} action.  This puts the document back
 34  
  * in all the peoples action lists that have the document routed to them.
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  
 public class ReleaseWorkgroupAuthority extends ActionTakenEvent {
 39  
 
 40  
     private String groupId;
 41  
     /**
 42  
      * @param routeHeader
 43  
      * @param principal
 44  
      */
 45  
     public ReleaseWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 46  0
         super(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, routeHeader, principal);
 47  0
     }
 48  
 
 49  
     /**
 50  
      * @param routeHeader
 51  
      * @param principal
 52  
      * @param annotation
 53  
      * @param groupId
 54  
      */
 55  
     public ReleaseWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) {
 56  0
         super(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation);
 57  0
         this.groupId = groupId;
 58  0
     }
 59  
 
 60  
     /* (non-Javadoc)
 61  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
 62  
      */
 63  
     @Override
 64  
     public String validateActionRules() {
 65  0
         if (groupId == null) {
 66  0
             return "User cannot Release Workgroup Authority without a given workgroup";
 67  
         } else {
 68  0
             return performReleaseWorkgroupAuthority(true);
 69  
         }
 70  
     }
 71  
     
 72  
     /**
 73  
      * This overridden method ...
 74  
      * 
 75  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules(java.util.List)
 76  
      */
 77  
     @Override
 78  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 79  0
             return validateActionRules();
 80  
     }
 81  
 
 82  
     public void recordAction() throws InvalidActionTakenException {
 83  0
         String error = performReleaseWorkgroupAuthority(false);
 84  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(error)) {
 85  0
             throw new InvalidActionTakenException(error);
 86  
         }
 87  
 
 88  0
         queueDocumentProcessing();
 89  0
     }
 90  
 
 91  
     private String performReleaseWorkgroupAuthority(boolean forValidationOnly) {
 92  0
         if (!KimApiServiceLocator.getGroupService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId)){
 93  0
             return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId);
 94  
         }
 95  
 
 96  0
         List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
 97  
         //List groupRequestsToActivate = new ArrayList();//requests for this group that need action items
 98  0
         for (ActionRequestValue actionRequest : actionRequests)
 99  
         {
 100  
             //we left the group active from take authority action.  pending havent been normally activated yet
 101  0
             if (actionRequest.isGroupRequest() && actionRequest.isActive() && actionRequest.getGroupId().equals(groupId)) {
 102  0
                     List<ActionItem> actionItems = actionRequest.getActionItems();
 103  0
                 if (actionItems.size() == 1) {
 104  0
                     ActionItem actionItem = actionItems.get(0);
 105  0
                     if (! actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId())) {
 106  0
                         return "User attempting to release workgroup authority did not take it.";
 107  0
                     } else if (!forValidationOnly)
 108  
                     {
 109  0
                         actionRequest.setStatus(ActionRequestStatus.INITIALIZED.getCode());//to circumvent check in service during activation
 110  0
                         getActionRequestService().activateRequest(actionRequest);
 111  
                     }
 112  
                 }
 113  0
             }
 114  
         }
 115  0
         return "";
 116  
     }
 117  
 }