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 public RouteModuleRemoteAdapter(RouteModuleRemote routeModule) {
47 if (routeModule == null) {
48 throw new IllegalArgumentException("RouteModuleRemoteAdapter cannot adapt a null RouteModuleRemote");
49 }
50 this.routeModule = routeModule;
51 }
52
53 public List findActionRequests(RouteContext context) throws Exception {
54
55 return findActionRequests(context.getDocument());
56 }
57
58 public List findActionRequests(DocumentRouteHeaderValue routeHeader) throws WorkflowException {
59 try {
60 List actionRequests = new ArrayList();
61 RouteHeaderDTO routeHeaderVO = DTOConverter.convertRouteHeader(routeHeader, null);
62 DocumentContentDTO documentContentVO = DTOConverter.convertDocumentContent(routeHeader.getDocContent(), routeHeaderVO.getDocumentId());
63 ActionRequestDTO[] actionRequestVOs = routeModule.findActionRequests(routeHeaderVO, documentContentVO);
64 if (actionRequestVOs != null && actionRequestVOs.length > 0) {
65 assertRootRequests(actionRequestVOs);
66
67 for (ActionRequestDTO actionRequestVO : actionRequestVOs) {
68 actionRequestVO.setDocumentId(routeHeader.getDocumentId());
69
70
71 if (actionRequestVO.getPrincipalId() == null && actionRequestVO.getGroupId() == null) {
72 throw new RiceRuntimeException("Post processor didn't set a user or workgroup on the request");
73 }
74
75 actionRequests.add(DTOConverter.convertActionRequestDTO(actionRequestVO));
76 }
77 }
78 return actionRequests;
79 } catch (RemoteException e) {
80 if (e.getCause() instanceof WorkflowException) {
81 throw (WorkflowException)e.getCause();
82 }
83 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 return DTOConverter.convertResponsiblePartyVO(routeModule.resolveResponsibilityId(responsibilityId));
90 } catch (RemoteException e) {
91 if (e.getCause() instanceof WorkflowException) {
92 throw (WorkflowException)e.getCause();
93 }
94 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 for (ActionRequestDTO actionRequest : actionRequestVOs) {
103 if (actionRequest.getParentActionRequestId() != null) {
104 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 }
108
109 }