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