1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.actions; |
18 | |
|
19 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
20 | |
import org.kuali.rice.kew.actionlist.service.ActionListService; |
21 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
22 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
23 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
24 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
25 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
26 | |
import org.kuali.rice.kew.util.KEWConstants; |
27 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
28 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
29 | |
|
30 | |
import java.util.ArrayList; |
31 | |
import java.util.Collection; |
32 | |
import java.util.List; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class TakeWorkgroupAuthority extends ActionTakenEvent { |
44 | |
|
45 | |
private String groupId; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
52 | 0 | super(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) { |
62 | 0 | super(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation); |
63 | 0 | this.groupId = groupId; |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Override |
70 | |
public String validateActionRules() { |
71 | 0 | if ( (groupId != null) && (!KimApiServiceLocator.getGroupService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId))) { |
72 | 0 | return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId); |
73 | |
} |
74 | 0 | return ""; |
75 | |
} |
76 | |
|
77 | |
@Override |
78 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
79 | 0 | return validateActionRules(); |
80 | |
} |
81 | |
|
82 | |
public void recordAction() throws InvalidActionTakenException { |
83 | |
|
84 | 0 | String errorMessage = validateActionRules(); |
85 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
86 | 0 | throw new InvalidActionTakenException(errorMessage); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | 0 | List<ActionRequestValue> documentRequests = getActionRequestService().findPendingByDoc(getDocumentId()); |
93 | 0 | List<ActionRequestValue> workgroupRequests = new ArrayList<ActionRequestValue>(); |
94 | 0 | for (ActionRequestValue actionRequest : documentRequests) |
95 | |
{ |
96 | 0 | if (actionRequest.isGroupRequest() && actionRequest.getGroup().getId().equals(groupId)) |
97 | |
{ |
98 | 0 | workgroupRequests.add(actionRequest); |
99 | |
} |
100 | |
} |
101 | |
|
102 | 0 | ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(workgroupRequests)); |
103 | 0 | notifyActionTaken(actionTaken); |
104 | |
|
105 | 0 | ActionListService actionListService = KEWServiceLocator.getActionListService(); |
106 | 0 | Collection<ActionItem> actionItems = actionListService.findByDocumentId(getDocumentId()); |
107 | 0 | for (ActionItem actionItem : actionItems) |
108 | |
{ |
109 | |
|
110 | 0 | if (actionItem.isWorkgroupItem() && actionItem.getGroupId().equals(groupId) && |
111 | |
!actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId())) |
112 | |
{ |
113 | 0 | actionListService.deleteActionItem(actionItem); |
114 | |
} |
115 | |
} |
116 | 0 | } |
117 | |
} |