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