1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.action;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.log4j.Logger;
23 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
24 import org.kuali.rice.core.api.reflect.DataDefinition;
25 import org.kuali.rice.kew.actions.ActionTakenEvent;
26 import org.kuali.rice.kew.api.WorkflowRuntimeException;
27 import org.kuali.rice.kew.api.action.ActionInvocation;
28 import org.kuali.rice.kew.api.action.ActionInvocationQueue;
29 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
30 import org.kuali.rice.kew.api.exception.ResourceUnavailableException;
31 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
32 import org.kuali.rice.kew.service.KEWServiceLocator;
33 import org.kuali.rice.kim.api.identity.principal.Principal;
34
35
36
37
38
39
40 public class ActionInvocationQueueImpl implements ActionInvocationQueue {
41
42 private static final Logger LOG = Logger.getLogger(ActionInvocationQueueImpl.class);
43
44 @Override
45 public void invokeAction(String principalId, String documentId, ActionInvocation invocation) {
46 if (StringUtils.isBlank(principalId)) {
47 throw new RiceIllegalArgumentException("principalId is null or blank");
48 }
49
50 if (StringUtils.isBlank(documentId)) {
51 throw new RiceIllegalArgumentException("documentId is null");
52 }
53
54 if (invocation == null) {
55 throw new RiceIllegalArgumentException("invocation is null");
56 }
57
58
59 KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true);
60 DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId);
61
62 Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
63 List<DataDefinition> parameters = new ArrayList<DataDefinition>();
64 parameters.add(new DataDefinition(document));
65 parameters.add(new DataDefinition(principal));
66 parameters.add(new DataDefinition(""));
67
68 try {
69 final ActionTakenEvent action = KEWServiceLocator.getActionRegistry().createAction(invocation.getAction().getCode(), parameters);
70 if (!document.isValidActionToTake(invocation.getAction().getCode())) {
71 LOG.warn("Action "
72 + invocation.getAction()
73 + " is not a valid action to take against document "
74 + document.getDocumentId()
75 + " by principal with name '"
76 + principal.getPrincipalName()
77 + "'");
78 return;
79 } else if (!KEWServiceLocator.getActionRegistry().getValidActions(principal, document).getActionTakenCodes()
80 .contains(action.getActionTakenCode())) {
81 LOG.warn("Action "
82 + action.getActionTakenCode()
83 + " is not valid for document "
84 + document.getDocumentId()
85 + " by principal with name '"
86 + principal.getPrincipalName()
87 + "'");
88 return;
89 }
90 action.performAction();
91 } catch (ResourceUnavailableException e) {
92 throw new WorkflowRuntimeException(e);
93 } catch (InvalidActionTakenException e) {
94 throw new WorkflowRuntimeException(e);
95 }
96
97 }
98
99 }