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