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