Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.kuali.rice.kew.actions;
 import java.util.List;

Cancels a document at the request of a client app.

Kuali Rice Team (
 public class CancelAction extends ActionTakenEvent {
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CancelAction.class);
     public CancelAction(DocumentRouteHeaderValue rhPrincipalContract principal) {
     public CancelAction(DocumentRouteHeaderValue rhPrincipalContract principalString annotation) {
     // Template constructor for use by third parties
     CancelAction(ActionType typeDocumentRouteHeaderValue rhPrincipalContract principalString annotation) {
         super(type.getCode(), rhprincipalannotation);
     /* (non-Javadoc)
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
     public String validateActionRules() {
     public String validateActionRules(List<ActionRequestValueactionRequests) {
         // FYI delyea:  This is new validation check... was not being checked previously
             return "Document is not in a state to be cancelled";
         List<ActionRequestValuefilteredActionRequests = filterActionRequestsByCode(actionRequests.);
         if (!isActionCompatibleRequest(filteredActionRequests)) {
             return "No request for the user is compatible with the Cancel Action";
     	// check state before checking kim
         if (! KEWServiceLocator.getDocumentTypePermissionService().canCancel(getPrincipal().getPrincipalId(), getRouteHeader())) {
             return "User is not authorized to Cancel document";
         return "";
     /* (non-Javadoc)
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
     public boolean isActionCompatibleRequest(List<ActionRequestValuerequests) {
         // can always cancel saved or initiated document
         if (.isStateInitiated() || .isStateSaved()) {
             return true;
         boolean actionCompatible = false;
         Iterator ars = requests.iterator();
         ActionRequestValue actionRequest = null;
         while (ars.hasNext()) {
             actionRequest = (;
             String request = actionRequest.getActionRequested();
             // APPROVE and COMPLETE request matches CANCEL Taken code
            if ( (..equals(request)) ||
                 (..equals(request)) ) {
                actionCompatible = true;
        return actionCompatible;
    // Template method for subclasses
    protected void markDocumentStatus() throws InvalidActionTakenException {
    public void recordAction() throws InvalidActionTakenException {
        .debug("Canceling document : " + );
        .debug("Checking to see if the action is legal");
        String errorMessage = validateActionRules(actionRequests);
        if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
            throw new InvalidActionTakenException(errorMessage);
        .debug("Record the cancel action");
        ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(actionRequests));
        .debug("Deactivate all pending action requests");
        actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
        .debug("Canceling document");
        try {
            String oldStatus = getRouteHeader().getDocRouteStatus();
            String newStatus = getRouteHeader().getDocRouteStatus();
        } catch (WorkflowException ex) {
            throw new InvalidActionTakenException(ex.getMessage());
New to GrepCode? Check out our FAQ X