1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.routemodule; |
18 | |
|
19 | |
import java.rmi.RemoteException; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
24 | |
import org.kuali.rice.kew.dto.ActionRequestDTO; |
25 | |
import org.kuali.rice.kew.dto.DTOConverter; |
26 | |
import org.kuali.rice.kew.dto.DocumentContentDTO; |
27 | |
import org.kuali.rice.kew.dto.RouteHeaderDTO; |
28 | |
import org.kuali.rice.kew.engine.RouteContext; |
29 | |
import org.kuali.rice.kew.exception.WorkflowException; |
30 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
31 | |
import org.kuali.rice.kew.util.ResponsibleParty; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class RouteModuleRemoteAdapter implements RouteModule { |
43 | |
|
44 | |
private RouteModuleRemote routeModule; |
45 | |
|
46 | 0 | public RouteModuleRemoteAdapter(RouteModuleRemote routeModule) { |
47 | 0 | if (routeModule == null) { |
48 | 0 | throw new IllegalArgumentException("RouteModuleRemoteAdapter cannot adapt a null RouteModuleRemote"); |
49 | |
} |
50 | 0 | this.routeModule = routeModule; |
51 | 0 | } |
52 | |
|
53 | |
public List findActionRequests(RouteContext context) throws Exception { |
54 | |
|
55 | 0 | return findActionRequests(context.getDocument()); |
56 | |
} |
57 | |
|
58 | |
public List findActionRequests(DocumentRouteHeaderValue routeHeader) throws WorkflowException { |
59 | |
try { |
60 | 0 | List actionRequests = new ArrayList(); |
61 | 0 | RouteHeaderDTO routeHeaderVO = DTOConverter.convertRouteHeader(routeHeader, null); |
62 | 0 | DocumentContentDTO documentContentVO = DTOConverter.convertDocumentContent(routeHeader.getDocContent(), routeHeaderVO.getDocumentId()); |
63 | 0 | ActionRequestDTO[] actionRequestVOs = routeModule.findActionRequests(routeHeaderVO, documentContentVO); |
64 | 0 | if (actionRequestVOs != null && actionRequestVOs.length > 0) { |
65 | 0 | assertRootRequests(actionRequestVOs); |
66 | |
|
67 | 0 | for (ActionRequestDTO actionRequestVO : actionRequestVOs) { |
68 | 0 | actionRequestVO.setDocumentId(routeHeader.getDocumentId()); |
69 | |
|
70 | |
|
71 | 0 | if (actionRequestVO.getPrincipalId() == null && actionRequestVO.getGroupId() == null) { |
72 | 0 | throw new RiceRuntimeException("Post processor didn't set a user or workgroup on the request"); |
73 | |
} |
74 | |
|
75 | 0 | actionRequests.add(DTOConverter.convertActionRequestDTO(actionRequestVO)); |
76 | |
} |
77 | |
} |
78 | 0 | return actionRequests; |
79 | 0 | } catch (RemoteException e) { |
80 | 0 | if (e.getCause() instanceof WorkflowException) { |
81 | 0 | throw (WorkflowException)e.getCause(); |
82 | |
} |
83 | 0 | throw new WorkflowException("Remote exception when finding action requests from route module "+routeModule.toString(), e); |
84 | |
} |
85 | |
} |
86 | |
|
87 | |
public ResponsibleParty resolveResponsibilityId(String responsibilityId) throws WorkflowException { |
88 | |
try { |
89 | 0 | return DTOConverter.convertResponsiblePartyVO(routeModule.resolveResponsibilityId(responsibilityId)); |
90 | 0 | } catch (RemoteException e) { |
91 | 0 | if (e.getCause() instanceof WorkflowException) { |
92 | 0 | throw (WorkflowException)e.getCause(); |
93 | |
} |
94 | 0 | throw new WorkflowException("Remote exception when resolving responsibility ids from route module "+routeModule.toString(), e); |
95 | |
} |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
private void assertRootRequests(ActionRequestDTO[] actionRequestVOs) throws WorkflowException { |
102 | 0 | for (ActionRequestDTO actionRequest : actionRequestVOs) { |
103 | 0 | if (actionRequest.getParentActionRequestId() != null) { |
104 | 0 | throw new WorkflowException("Encountered an action request in the graph which was NOT a root request. RouteModuleRemote.findActionRequests should only produce root ActionRequestDTO objects."); |
105 | |
} |
106 | |
} |
107 | 0 | } |
108 | |
|
109 | |
} |