| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.actions; |
| 17 | |
|
| 18 | |
import org.apache.log4j.MDC; |
| 19 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
| 20 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
| 21 | |
import org.kuali.rice.kew.api.exception.WorkflowException; |
| 22 | |
import org.kuali.rice.kew.engine.node.ProcessDefinitionBo; |
| 23 | |
import org.kuali.rice.kew.api.exception.InvalidActionTakenException; |
| 24 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 25 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 26 | |
import org.kuali.rice.kew.api.KewApiConstants; |
| 27 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
| 28 | |
|
| 29 | |
import java.util.List; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class RouteDocumentAction extends ActionTakenEvent { |
| 39 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RouteDocumentAction.class); |
| 40 | |
|
| 41 | |
public RouteDocumentAction(DocumentRouteHeaderValue rh, PrincipalContract principal) { |
| 42 | 0 | super(KewApiConstants.ACTION_TAKEN_COMPLETED_CD, rh, principal); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public RouteDocumentAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) { |
| 46 | 0 | super(KewApiConstants.ACTION_TAKEN_COMPLETED_CD, rh, principal, annotation); |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
@Override |
| 53 | |
public String getActionPerformedCode() { |
| 54 | 0 | return KewApiConstants.ACTION_TAKEN_ROUTED_CD; |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
@Override |
| 61 | |
public String validateActionRules() { |
| 62 | |
|
| 63 | 0 | if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) { |
| 64 | 0 | return "Document is not in a state to be routed"; |
| 65 | |
} |
| 66 | 0 | if (! KEWServiceLocator.getDocumentTypePermissionService().canRoute(getPrincipal().getPrincipalId(), getRouteHeader())) { |
| 67 | 0 | return "User is not authorized to Route document"; |
| 68 | |
} |
| 69 | 0 | return ""; |
| 70 | |
} |
| 71 | |
|
| 72 | |
@Override |
| 73 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
| 74 | 0 | return validateActionRules(); |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public void recordAction() throws InvalidActionTakenException { |
| 82 | 0 | MDC.put("docId", getRouteHeader().getDocumentId()); |
| 83 | 0 | updateSearchableAttributesIfPossible(); |
| 84 | |
|
| 85 | 0 | LOG.debug("Routing document : " + annotation); |
| 86 | |
|
| 87 | 0 | LOG.debug("Checking to see if the action is legal"); |
| 88 | 0 | String errorMessage = validateActionRules(); |
| 89 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
| 90 | 0 | throw new InvalidActionTakenException(errorMessage); |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | 0 | LOG.debug("Record the routing action"); |
| 96 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
| 97 | |
|
| 98 | |
|
| 99 | 0 | List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId()); |
| 100 | 0 | LOG.debug("Deactivate all pending action requests"); |
| 101 | |
|
| 102 | 0 | for (ActionRequestValue actionRequest : actionRequests) |
| 103 | |
{ |
| 104 | |
|
| 105 | 0 | if ((getPrincipal().getPrincipalId().equals(actionRequest.getPrincipalId())) && (actionRequest.isActive())) |
| 106 | |
{ |
| 107 | 0 | getActionRequestService().deactivateRequest(actionTaken, actionRequest); |
| 108 | |
} |
| 109 | |
|
| 110 | 0 | else if (KewApiConstants.SAVED_REQUEST_RESPONSIBILITY_ID.equals(actionRequest.getResponsibilityId())) |
| 111 | |
{ |
| 112 | 0 | getActionRequestService().deactivateRequest(actionTaken, actionRequest); |
| 113 | |
} |
| 114 | |
} |
| 115 | |
|
| 116 | 0 | notifyActionTaken(actionTaken); |
| 117 | |
|
| 118 | |
try { |
| 119 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
| 120 | 0 | getRouteHeader().markDocumentEnroute(); |
| 121 | |
|
| 122 | 0 | if (((ProcessDefinitionBo)getRouteHeader().getDocumentType().getProcesses().get(0)).getInitialRouteNode() == null) { |
| 123 | 0 | getRouteHeader().markDocumentProcessed(); |
| 124 | 0 | getRouteHeader().markDocumentFinalized(); |
| 125 | |
} |
| 126 | |
|
| 127 | 0 | getRouteHeader().setRoutedByUserWorkflowId(getPrincipal().getPrincipalId()); |
| 128 | |
|
| 129 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
| 130 | 0 | notifyStatusChange(newStatus, oldStatus); |
| 131 | 0 | KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader()); |
| 132 | 0 | } catch (WorkflowException ex) { |
| 133 | 0 | LOG.warn(ex, ex); |
| 134 | 0 | throw new InvalidActionTakenException(ex.getMessage()); |
| 135 | 0 | } |
| 136 | |
|
| 137 | 0 | } |
| 138 | |
} |