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 | 0 | public class ActionInvocationQueueImpl implements ActionInvocationQueue { |
41 | |
|
42 | 0 | private static final Logger LOG = Logger.getLogger(ActionInvocationQueueImpl.class); |
43 | |
|
44 | |
@Override |
45 | |
public void invokeAction(String principalId, String documentId, ActionInvocation invocation) { |
46 | 0 | if (StringUtils.isBlank(principalId)) { |
47 | 0 | throw new RiceIllegalArgumentException("principalId is null or blank"); |
48 | |
} |
49 | |
|
50 | 0 | if (StringUtils.isBlank(documentId)) { |
51 | 0 | throw new RiceIllegalArgumentException("documentId is null"); |
52 | |
} |
53 | |
|
54 | 0 | if (invocation == null) { |
55 | 0 | throw new RiceIllegalArgumentException("invocation is null"); |
56 | |
} |
57 | |
|
58 | |
|
59 | 0 | KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true); |
60 | 0 | DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
61 | |
|
62 | 0 | Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId); |
63 | 0 | List<DataDefinition> parameters = new ArrayList<DataDefinition>(); |
64 | 0 | parameters.add(new DataDefinition(document)); |
65 | 0 | parameters.add(new DataDefinition(principal)); |
66 | 0 | parameters.add(new DataDefinition("")); |
67 | |
|
68 | |
try { |
69 | 0 | final ActionTakenEvent action = KEWServiceLocator.getActionRegistry().createAction(invocation.getAction().getCode(), parameters); |
70 | 0 | if (!document.isValidActionToTake(invocation.getAction().getCode())) { |
71 | 0 | 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 | 0 | return; |
79 | 0 | } else if (!KEWServiceLocator.getActionRegistry().getValidActions(principal, document).getActionTakenCodes() |
80 | |
.contains(action.getActionTakenCode())) { |
81 | 0 | 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 | 0 | return; |
89 | |
} |
90 | 0 | action.performAction(); |
91 | 0 | } catch (ResourceUnavailableException e) { |
92 | 0 | throw new WorkflowRuntimeException(e); |
93 | 0 | } catch (InvalidActionTakenException e) { |
94 | 0 | throw new WorkflowRuntimeException(e); |
95 | 0 | } |
96 | |
|
97 | 0 | } |
98 | |
|
99 | |
} |