Coverage Report - org.kuali.rice.kew.actions.RevokeAdHocAction
 
Classes in this File Line Coverage Branch Coverage Complexity
RevokeAdHocAction
0%
0/30
0%
0/12
2.8
 
 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.apache.log4j.MDC;
 20  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 21  
 import org.kuali.rice.kew.actionrequest.Recipient;
 22  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 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  
 
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.List;
 31  
 
 32  
 
 33  
 /**
 34  
  * The RevokeAdHocApprove revokes the specified AdHoc requests.
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  
 public class RevokeAdHocAction extends ActionTakenEvent {
 39  
 
 40  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RevokeAdHocAction.class);
 41  
 
 42  
     private AdHocRevoke revoke;
 43  
 
 44  
     public RevokeAdHocAction(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 45  0
         super(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, routeHeader, principal);
 46  0
     }
 47  
 
 48  
     public RevokeAdHocAction(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, AdHocRevoke revoke, String annotation) {
 49  0
         super(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, routeHeader, principal, annotation);
 50  0
         this.revoke = revoke;
 51  0
     }
 52  
 
 53  
     /* (non-Javadoc)
 54  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
 55  
      */
 56  
     @Override
 57  
     public String validateActionRules() {
 58  0
         if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) {
 59  0
             return "Revoke adhoc request is not valid on this document";
 60  
         }
 61  0
         return "";
 62  
     }
 63  
     
 64  
     @Override
 65  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 66  0
             return validateActionRules();
 67  
     }
 68  
 
 69  
     /**
 70  
      * Records the approve action.
 71  
      * - Checks to make sure the document status allows the action.
 72  
      * - Checks that the user has not taken a previous action.
 73  
      * - Deactivates the pending requests for this user
 74  
      * - Records the action
 75  
      *
 76  
      * @throws InvalidActionTakenException
 77  
      */
 78  
     public void recordAction() throws InvalidActionTakenException {
 79  0
             MDC.put("docId", getRouteHeader().getDocumentId());
 80  0
         updateSearchableAttributesIfPossible();
 81  
 
 82  0
         String errorMessage = validateActionRules();
 83  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 84  0
             throw new InvalidActionTakenException(errorMessage);
 85  
         }
 86  
 
 87  0
         LOG.debug("Revoking adhoc request : " + annotation);
 88  
 
 89  0
         List<ActionRequestValue> requestsToRevoke = new ArrayList<ActionRequestValue>();
 90  0
         List<ActionRequestValue> actionRequests = getActionRequestService().findPendingRootRequestsByDocId(getDocumentId());
 91  0
         for (ActionRequestValue actionRequest : actionRequests)
 92  
         {
 93  0
             if (revoke.matchesActionRequest(actionRequest))
 94  
             {
 95  0
                 requestsToRevoke.add(actionRequest);
 96  
             }
 97  
         }
 98  0
         if (requestsToRevoke.isEmpty() && revoke.getActionRequestId() != null) {
 99  0
                 throw new InvalidActionTakenException("Failed to revoke action request with id " + revoke.getActionRequestId() +
 100  
                                 ".  ID does not represent a valid ad hoc request!");
 101  
         }
 102  
 
 103  0
         Recipient delegator = findDelegatorForActionRequests(actionRequests);
 104  0
         LOG.debug("Record the revoke action");
 105  0
         ActionTakenValue actionTaken = saveActionTaken(delegator);
 106  
 
 107  0
         LOG.debug("Revoke all matching action requests, number of matching requests: " + requestsToRevoke.size());
 108  0
         getActionRequestService().deactivateRequests(actionTaken, requestsToRevoke);
 109  0
         notifyActionTaken(actionTaken);
 110  
 
 111  0
     }
 112  
 
 113  
 }