1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.kuali.rice.kew.routemodule;
33
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Map;
39
40 import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
41 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
42 import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
43 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
44 import org.kuali.rice.kew.actionrequest.Recipient;
45 import org.kuali.rice.kew.api.action.RecipientType;
46 import org.kuali.rice.kew.api.exception.ResourceUnavailableException;
47 import org.kuali.rice.kew.api.exception.WorkflowException;
48 import org.kuali.rice.kew.engine.RouteContext;
49 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
50 import org.kuali.rice.kew.service.KEWServiceLocator;
51 import org.kuali.rice.kew.util.ResponsibleParty;
52
53
54
55
56
57 public class TestRouteModule implements RouteModule {
58
59 private static Map responsibilityMap = new HashMap();
60
61 public List findActionRequests(RouteContext context) throws ResourceUnavailableException, WorkflowException {
62 return findActionRequests(context.getDocument());
63 }
64
65 public List findActionRequests(DocumentRouteHeaderValue routeHeader) throws ResourceUnavailableException, WorkflowException {
66 TestRouteLevel routeLevel = TestRouteModuleXMLHelper.parseCurrentRouteLevel(routeHeader);
67 List actionRequests = new ArrayList();
68 if (routeLevel == null) {
69 return actionRequests;
70 }
71 for (Iterator iterator = routeLevel.getResponsibilities().iterator(); iterator.hasNext();) {
72 TestResponsibility responsibility = (TestResponsibility) iterator.next();
73 TestRecipient recipient = responsibility.getRecipient();
74 Recipient realRecipient = getRealRecipient(recipient);
75 ActionRequestFactory arFactory = new ActionRequestFactory(routeHeader);
76 String responsibilityId = KEWServiceLocator.getResponsibilityIdService().getNewResponsibilityId();
77 ActionRequestValue request = arFactory.addRootActionRequest(responsibility.getActionRequested(), new Integer(responsibility.getPriority()), realRecipient, "", responsibilityId, Boolean.FALSE, null, null);
78 responsibilityMap.put(request.getResponsibilityId(), recipient);
79 for (Iterator delIt = responsibility.getDelegations().iterator(); delIt.hasNext();) {
80 TestDelegation delegation = (TestDelegation) delIt.next();
81 TestRecipient delegationRecipient = delegation.getResponsibility().getRecipient();
82 Recipient realDelegationRecipient = getRealRecipient(delegationRecipient);
83 responsibilityId = KEWServiceLocator.getResponsibilityIdService().getNewResponsibilityId();
84 ActionRequestValue delegationRequest = arFactory.addDelegationRequest(request, realDelegationRecipient, responsibilityId, Boolean.FALSE, delegation.getType(), "", null);
85 responsibilityMap.put(delegationRequest.getResponsibilityId(), delegationRecipient);
86 }
87 actionRequests.add(request);
88 }
89 return actionRequests;
90 }
91
92 public Recipient getRealRecipient(TestRecipient recipient) throws WorkflowException {
93 Recipient realRecipient = null;
94 if (recipient.getType().equals(RecipientType.PRINCIPAL.getCode())) {
95 realRecipient = new KimPrincipalRecipient(recipient.getId());
96 } else if (recipient.getType().equals(RecipientType.GROUP.getCode())) {
97 realRecipient = new KimGroupRecipient(recipient.getId());
98 } else {
99 throw new WorkflowException("Could not resolve recipient with type " + recipient.getType());
100 }
101 return realRecipient;
102 }
103
104 public ResponsibleParty resolveResponsibilityId(String responsibilityId) throws ResourceUnavailableException, WorkflowException {
105 TestRecipient recipient = (TestRecipient)responsibilityMap.get(responsibilityId);
106 if (recipient == null) {
107 return null;
108 }
109 ResponsibleParty responsibleParty = new ResponsibleParty();
110 if (recipient.getType().equals(RecipientType.PRINCIPAL.getCode())) {
111 responsibleParty.setPrincipalId(recipient.getId());
112 } else if (recipient.getType().equals(RecipientType.GROUP.getCode())) {
113 responsibleParty.setGroupId(recipient.getId());
114 } else if (recipient.getType().equals(RecipientType.ROLE.getCode())) {
115 responsibleParty.setRoleName(recipient.getId());
116 } else {
117 throw new WorkflowException("Invalid recipient type code of '"+recipient.getType()+"' for responsibility id "+responsibilityId);
118 }
119 return responsibleParty;
120 }
121
122 @Override
123 public boolean isMoreRequestsAvailable(RouteContext context) {
124 return false;
125 }
126 }