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